Four different pwm using PIC 18f45k80

microcontrollermotorpic

iIn a 4 phase dc motor control application, I have to excite the coil using Mosfet with the pwm of 12.5 Hz with the train of pulses of 12 khz on each phase. So I am in a position to create 4 different pwms each with the above mentioned frequencies. I have planned to use Pic 18f45k80 which has four CCP modules. But these modules use only two timers TIMER 2 and TIMER 4 for PWM. So I could create only 2 different pwm at a time. Is there a way to create 4 pwms using PIC 18f45k80 with using CCP modules? I like to create a pwm waveform like the image that I have added.

Best Answer

Section 19.4 of the datasheet discusses PWM operation. In reality, the PWM functionality uses only Timer 2. This timer controls the period (frequency) as explained by equation 19-1:

PWM Period = [(PR2) + 1] • 4 • TOSC • (TMR2 Prescale Value)

Thus, so long as the frequency is common to all 4 outputs, you are all set there. Then, you can set each duty cycle independently using the CCPRxL and CCPxCON registers where x is equal to 1, 2, 3, or 4 depending on which duty cycle you want to set. Equation 19-2 explains how to calculate the duty cycle:

PWM Duty Cycle = (CCPR4L:CCP4CON<5:4>) • TOSC • (TMR2 Prescale Value)

Now, when timer 2 equals one of the 10 bit values in CCPRxL and CCPxCON, that particular pin will toggle. Then, when timer 2 matches the value in PR2, all pins will toggle back to the original state.

Related Topic