0
votes

I use the PIC16F88 for my project, with XC8 compiler.

What I'm trying to achieve is to control 4 LEDs with 4 buttons, when you press a buttons it increases the duty cycle of the corresponding LED by 10%. When you press the button on RB0 it increases the duty cycle of the LED on RB4, and so on. Every LED is independent, therefore it can have a different duty cycle.

The problem is that the PIC i'm using only have one PWM module on either RB0 or RB3 (using CCPMX bit).

After some research I decided to implement software PWM to have four different channels, each channels would control one duty cycle, but most of the sources I found didn't provide any explanation on how to do it. Or is there a way to mirror PWM to multiple pins ?

Thanks by advance for helping me out.

1

1 Answers

1
votes

Mirroring is not an option.

PWM is relatively simple. You have to set PWM frequency (which you will not change) and PWM duty cycle (which you need to change in order to have 0-100% voltage range). You have to decide about resolution of PWM, voltage step that you need (built in PWM for example is 8-bit and has 0-255 steps).

Finally, you have to set timer to interrupt based on PWM frequency * PWM resolution. In Timer ISR routine you need to check resolution counts and PWM value of all your channels. Resolution count will have to reset when resolution value is reached (and start to count from 0 again, all outputs go HIGH here, also). When PWM value of output is reached you have to toggle (pull it LOW) corresponding pin (and reset it back to HIGH with every resolution count reset).

This is only one way of doing it, involves only one timer and should be most simple since your PIC is low with resources.

Hope it helps...