General discussion relating to the library modules supplied with the compiler
Moderators: David Barker, Jerry Messina
-
richardb
- Posts: 322
- Joined: Tue Oct 03, 2006 8:54 pm
Post
by richardb » Wed Dec 04, 2024 12:46 pm
Sorry to ask again but i seem to be having an issue with the "ISRTimer.bas" module
this is clearly my lack of understanding but i hardly ever use timers.
Code: Select all
Event OnTimer()
TP1 = 1
If Mscounter >= 1000 Then
Mscounter=0
TimePassedInMS=TimePassedInMS+1
flowcounts = counter
counter=0
Else
Mscounter=Mscounter+1
If FlowIP_Last<>FlowIP Then
counter=counter+1
FlowIP_Last = FlowIP
EndIf
EndIf
TP1 = 0
Timer.Initialize
Timer.Items(0).Interval = 1
Timer.Items(0).OnTimer = OnTimer // timer event handler
Timer.Items(0).Enabled = true // enable this timer
Timer.Start
End Event
I realise I haven't posted everything, but If I use this code on its own it works just fine , it's for measuring a frequency between 1Hz and 400Hz, from a water flow meter.
but if i try to output the data via the comport i get the data corrupted occationally, the even only seems to run for approximately 2us. is it likely to be some kind of context saving issue ?
Rich
Hmmm..
-
Jerry Messina
- Swordfish Developer
- Posts: 1493
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
Post
by Jerry Messina » Thu Dec 05, 2024 2:09 pm
is it likely to be some kind of context saving issue ?
It could be, depending on if you're trying to format and send the data inside the timer event. I wouldn't recommend that.
Also, calling those timer setup routines (timer.initialize, timer,start) inside the timer event isn't a good idea.
The event runs inside the timer ISR and those routines re-enable interrupts. Not something likely to work out very well.
Once you're setup the timer in your main code the timer will run and periodically call your event automatically.
-
richardb
- Posts: 322
- Joined: Tue Oct 03, 2006 8:54 pm
Post
by richardb » Fri Dec 06, 2024 7:19 am
oops that was a copy and paste error i was just showing the interval. the flowcounts variable was being sent in the main code loop.
Code: Select all
Device = 18F47Q43
Clock = 64
Config
FEXTOSC = OFF, // Oscillator not enabled
RSTOSC = HFINTOSC_64MHZ,// HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
CLKOUTEN = OFF // CLKOUT function is disabled
Event OnTimer()
TP1 = 1
If Mscounter >= 1000 Then
Mscounter=0
TimePassedInMS=TimePassedInMS+1
flowcounts = counter
counter=0
Else
Mscounter=Mscounter+1
If FlowIP_Last<>FlowIP Then
counter=counter+1
FlowIP_Last = FlowIP
EndIf
EndIf
TP1 = 0
End Event
Timer.Initialize
Timer.Items(0).Interval = 1
Timer.Items(0).OnTimer = OnTimer // timer event handler
Timer.Items(0).Enabled = true // enable this timer
Timer.Start
that's everything in the event.
Hmmm..