Synchronizing with tmr2 output

Discuss PIC and electronic related things

Moderators: David Barker, Jerry Messina

Post Reply
liak
Registered User
Registered User
Posts: 195
Joined: Fri Oct 05, 2007 12:26 am

Synchronizing with tmr2 output

Post by liak » Wed Apr 23, 2008 10:22 pm

Dear all,
I am not entirely clear on the architecture of tmr2, the CCP/PWM module, after reading the datasheet numerous times. I am trying to workup a module to synchronize with the PWM output from tmr2 to certain events; with the PWM running, ie sending data using PWM as the reference clock pulse.
I roughly understand that it may involve using various interrupts. But again I am at lost at this very low level of programming in PIC. Can anyone show me any leads?
thanks.

liak
Registered User
Registered User
Posts: 195
Joined: Fri Oct 05, 2007 12:26 am

Need Help

Post by liak » Sat Apr 26, 2008 10:18 pm

I have referred to the datasheet again and also found great help at microelectronika's free PIC microcontroller book reference. The reference book did offer very good and clear explanation for beginners and helped a lot in my understanding. But still I cannot solve problem. I tried a simple test code segment like below, trying to catch the beginning of a PWM duty cycle, with final aim trying to do what I have posted earlier:

...
Dim Indicator as PortA.3 'LED indicator light
...

SetFreq(10000,50) 'from David's PWM module

INTCON.6 = 1 'enabling PEIE
INTCON.7 = 1 'enabling GIE
PIR1.1 = 0 'initialize the TMR2IF

while 1 = 1
If PIR1.1 = 1 then
High(Indicator)
DelayUs(10)
PIR1.1 = 0 'resetting TMR2IF Flag
End IF
If PIR1.0 = 0 then
Low(Indicator)
end If
wend

What I understand is that, once the PWM period is completed ie TMR2 = PR then the PIR1.1 will be flagged (overflow occured). Then, the segment will blink the LED for a very brief and reset will happen. But somehow I may have wrongly understood the code or wrongly interpreted how it should run. It blinks at certain SetFreq(freq, 50) only. At freq = 100k,it will give output but at 10K there is none.

Can anyone enlighten me? Or at least show me where I have done wrongly?

:( BTW, my hardware is PIC18F1320 running at 20Mhz. Thanks.

liak
Registered User
Registered User
Posts: 195
Joined: Fri Oct 05, 2007 12:26 am

Problem solved

Post by liak » Sat May 03, 2008 3:11 am

Thanks. I probed through the forum. Also Read several sites on the net. But the most useful in solving my problem is an article by Xor titled softRTC. Thank you again, Xor. You showed the solution brilliantly. Now I am clear about the timer and interrupt mechanism of PIC already. Just that I was not looking at the right place from the start. My project works perfectly now. :lol:

Post Reply