PDA

View Full Version : PWM with 16F72



sudipmuk
- 16th July 2008, 13:00
Hi All
I am using 16F72 for a PWM application. I am using the hardware PWM module . I can see the PWM wave at the pin CCP1 and it is perfect. But when the CCP1 goes high i need to make RC0 and RC1 high and RC4 and RC5 low. And whenever CCP1 goes low , and i need to reverse these RC0 , RC1, RC4 and RC5.
Now the CCP1 going high can be tracked using the TMR2IF flag. But how do i track when CCP1 goes low ? CCP1 goes low when there is a dutycycle match with the TMR2 , but i cannot find or think of any way to track that.
I hope you all can help me in this.

Thanks in advance
Regards
Sudip

sougata
- 29th July 2008, 16:42
Hi,

I do not understand the relation of TMR2IF being set with the CCP1 going high in the PWM Mode. Honestly speaking I am less experienced with the 16 series. However the PWM modules should work in the same way

As far as I understand:
TMR2IF is only set when TMR2 rollsover. In PWM that cannot happen if PR (period register is less than 255) or the duty cycle is less than 100%. Cause the PR match resets TMR2 -- CCP-PWM output = high, CCPR register match (concatenated with 2 bit internal Q clock of the prescaler) clears it.



What you say is true when compare mode is used, not PWM mode.


Correct me if I am wrong.

Now coming to your problem.

It seems you would be driving a half bridge using the PWM

You can always use the compare mode to generate upto 16 bits of PWM and steer the outputs in the ISR as per your own requirement.

Your nickname gives me a hunch that you are from Kolkata India and your full name is Sudip Mukherjee . If that is true then welcome to this great place which actually helped me gain confidence and little expertise in PIC.

sudipmuk
- 29th July 2008, 18:38
Hi


It seems you would be driving a half bridge using the PWM.

I am using a full bridge and that is why i want four pins to control it. What i am doing is :- set the chip in PWM mode, made PR2 = 200 and CCPR1L is the duty cycle and also made TMR2IE=1. So whenever TMR2 matches CCPR register the CCP Pin goes low and then again when TMR2 mathes PR2 - 1) CCP pin goes high, 2) TMR2 rollsover, and 3) TMR2 interrupt is generated.


You can always use the compare mode to generate upto 16 bits of PWM and steer the outputs in the ISR as per your own requirement.

Anyway , can u please give me a litle idea about how to use the compare mode to generate PWM. I tried it initially , but whenever the duty cycle is getting small , it was not giving good result , so i thought of switching to PWM mode.

You are absolutely right about my name and location . I am from south kolkata (hazra).

Regards

Sudip Mukherjee