I am using an 18F252 to count pulses into Timer0 and Timer1. The following is that part of the program for pulse counting into Timer0 for 100ms. Similar bits of code are used to control Timer1, as indicated.
'Initialise Timer0
T0CON.3=1 'Do not use prescaler
T0CON.4=0 'Increment on low-high edges
T0CON.5=1 'Count on external pulses
T0CON.6=0 'Configure as 16 bit counter
'.... similarly for Timer1
TMR0H=0: TMR0L=0 'Clears Timer0 Note: MUST write in this order
T0CON.7=1 'Start Timer0
pause 100 'Count into Timer0 for 0.1s
T0CON.7=0 'Stop Timer0
'.... similarly for Timer1
'Form Timer0 Pulsecount word
Lobyte0=TMR0L: Hibyte0=TMR0H 'Note: MUST read in this order
Pulsecount=Hibyte0
Pulsecount=Pulsecount1<<8
Pulsecount=Pulsecount+Lobyte0
'.... similarly for Timer1
My question is: how can I modify my code to ensure that both timers start and stop EXACTLY at the same time. Obviously, because of code delays in my program, this can not be the case and there will be a phase lag in the counts. At the moment, the only way I can see to solve this is to switch both pulse streams externally using another pin on the PIC to control a CMOS gate.
Bookmarks