are you using interrupts for that timer?
Because an interrupt will interrupt serin2 in the middle of whatever it is doing at the time and you will lose data.
are you using interrupts for that timer?
Because an interrupt will interrupt serin2 in the middle of whatever it is doing at the time and you will lose data.
"I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams
Try
DISABLE
before the SERIN2 command
and
ENABLE
after the SERIN2 command
Dave
Always wear safety glasses while programming.
I'm not using an interrupt as such I'm polling the Timer1 flag.
Some code extracts here below
My Serin2 command is here in the code.Code:Initialise: 'Initialise 250ms Timer 8mhz clock PreLoad = 3035 'Preload Constant Loads Timer with 3035 to get 250ms ticks PIE1.0 = 1 'Enable TMR1 Interrupts (Not sure about this) TMR1L = PreLoad.LowByte 'Load the Timer with preload value TMR1H = PreLoad.HighByte 'Load the Timer with preload value TMR1IF = 0 'Clear TMR1 int flag
So you can see i intialise the timer for 250ms ticks. Then poll the flag. If it is set then I execute some code and then reinitialise the timer adding any overrun to the preload value.Code:IF TMR1IF = 0 THEN TimerJump 'If 250ms has not elapsed then jump over below section T1CON.0=0 'Stop the Clock TMR1RunOn.Highbyte = TMR1H 'Load the Run-On (Over-Run) value (if any) TMR1RunOn.Lowbyte = TMR1L 'Load the Run-On (Over-Run) value (if any) TMR1RunOn = PreLoad + TMR1RunOn 'Calculate new Preload setting to include any timer overrun TMR1H = TMR1RunOn.HighByte 'Load the timer with new value TMR1L = TMR1RunOn.LowByte 'Load the timer with new value T1CON.0=1 'Restart the Clock TMR1IF = 0 'Clear TMR1 int flag 'PIR1.0=0 'Reset TMR1's Interupt Flag (Not sure about this)
I'm working on this and a bit confused by the 12F683 data sheet.
I don't want an interrupt (i.e. jump to some assembly level routine) I'm just polling the TMR1 overflow flag.
So do i need to do the stuff below?Code:if PIR1.0 = 1 then T1Handler 'If Timer1 has overflowed then
I just want to clear the TMR1 overflow flag every time it overflows, load my 250ms preload value etc and carry on.The Timer1 register pair (TMR1H:TMR1L) increments
to FFFFh and rolls over to 0000h. When Timer1 rolls
over, the Timer1 interrupt flag bit of the PIR1 register is
set. To enable the interrupt on rollover, you must set
these bits:
• Timer1 interrupt enable bit of the PIE1 register
• PEIE bit of the INTCON register
• GIE bit of the INTCON register
The interrupt is cleared by clearing the TMR1IF bit in
the Interrupt Service Routine.
> I just want to clear the TMR1 overflow flag every time it overflows, load my 250ms preload value etc and carry on.
Then that's all you need to do. The roll-over event will set the interrupt flag even if the actual interrupt enable bit and/or GIE bit isn't set. Just clear it, reload and you're good to go.
Thanks got the timer working now but have one more question.
In the above code i stop the timer then work out any TMR1 overun and add it to my timer reload value.Code:T1CON.0 = 0 'Stops Timer TMR1RunOn.Highbyte = TMR1H 'Load the Run-On (Over-Run) value (if any) TMR1RunOn.Lowbyte = TMR1L 'Load the Run-On (Over-Run) value (if any) TMR1RunOn = PreLoad + TMR1RunOn 'Calculate new Preload setting to include any timer overrun TMR1H = TMR1RunOn.HighByte 'Load the timer with new value TMR1L = TMR1RunOn.LowByte 'Load the timer with new value PIR1.0 = 0 'Clear TMR1 int flag T1CON.0 = 1 'Starts Timer
But how do i compensate for the instructions above which clearly take some time to execute?
I must need to add a few more timer ticks to my reload value, but how many? My clock is running at 8mhz.
You could just do it by trial and error, let it run for a while and see if and how much it drifts. Otherwise you need to dig into the generated .lst file and count the actual instructions. I'm guessing somewhere around 16 cycles.
Or, why not use a second timer (TMR0 etc) to actually time it. Stop TMR1, start TMR0, do the reload, stop TMR0, start TMR1. TMR0 will now give you your answer.
If you tick the timer with the main oscillator it matter if you run at 8kHz or 8MHz, a cycle is a cycle.
/Henrik.
Bookmarks