My timer (Timer1) is set up as a simple counter, the signal I'm measuring comes in continuously as Timer1's clock on T1CKI. All I do is set timer1L and timer1H registers to 0 when I want to and wait one second then read their contents to get the number of pulses in one second. Works great.
To try and make a gate work next I set up an SF timer (using the SF timer module) and Timer3 in the PIC to call an interrupt once every second (exactly as in the SF interrupt timer help sample program). Works great and toggles my LED in the interrupt function. I want to use this to gate timer1. But on compilation it stops my timer1 from working. And vice versa. It looks like my Timer1 and the SF Timer3 function are trying to use only one resource? I don't know what happens in the SF timer module. If I delete the T1CON.7=1 and T1CON.6=0 lines below my timer fails and the SF Timer 3 works. If I put them back in my Timer1 function works and the SF Timer3 stops. Both timers dont seem to be independent.
If anyone has suggestions where I should look, much appreciated......
T1CON.6=0
Here is my simple Timer1 set up
Code: Select all
Public Sub SetupTimer1()
'
' Set up Timer 1 as counter
'
ANCON0.4 = 0 ' set pin 33 as digital
'
' Timer 1 source
'
T1CON.7=1 ' source depends on SOSCEN bit
T1CON.6=0
T1CON.5=0 ' no prescaler
T1CON.4=0
T1CON.3=0 ' source is T1CKI pin 33 signal comes in here
T1CON.2=0
T1CON.1=0 ' read as 16 bit not 8 bit
TMR1H= 0
TMR1L= 0
T1CON.0=1 ' turn timer 1 on
End Sub
Here is my timer setup using the SF interrupt library
Code: Select all
Timer.Initialize(4)
Timer.Items(3).Interval = 1000 // 1s
Timer.Items(3).OnTimer = @OnTimer // timer event handler
Timer.Items(3).Enabled = true
Timer.Start