Timer/HSerIn Issue

dalise

New Member
Hello all,

I currently have a project that involves two 40X2's that I need some assistance on.

The first 40X2 is a remote using a DORJI wireless module (essentially 3 pushbuttons to start, stop and reset a clock wirelessy)
The second 40X2 receives the serial commands using a 2nd DORJI module and shows a countdown clock with mins, seconds and hundredths on an LCD Display.

How it works...
The remote transmits every ~350mSec a check byte ($55) and the button status (Button 1, 2 ,3 or null).
The receiver looks at the received button byte and starts, stops or resets the 30min countdown clock. (Countdown is performed within the interrupt routine)

When start is pressed the following command is performed to start the clock
setintflags %10000000,%10000000

When stop is pressed the following command is performed to stop the clock
setint off

All was going well until I discovered an issue involving the Timer and HSERIN command.

The Serial command I was originally using is this:

hserin [500,exittransmit],0,1,($55) 'Receive console button status

However I found that when I had the DORJI module plugged in, the countdown values would speed up (i.e. the serial reception was affecting the timer).
I thought the timeout value in the hserin command maybe be the problem so I changed the command to the following:

hserin 0,1,($55) 'Receive console button status

With the DORJI module plugged in the countdown values work.
However when I unplug the DORJI module, the timer does not generate an interrupt at all!
(I fear the serial module is generating the interrupts!).

Furthermore I also tried using background receive however it appears you cannot have two interrupt flags (toflag and hserflag) generating interrupts!
Is it possible that the timer and serial port are connected in some way?

Any thoughts on a solution to this would be most appreciated!

thanks
 

oracacle

Senior Member
there would appear to be a reference to hsersetup on page 268 of manual 2 which can cause issues when being used at the same time as timer.
you may be able to overcome this by having some extra code to determine what fire the interrupt, you may end up having to send a flag with the data to indicate the second unit has sent data, this flag would than be removed at the end of the interrupt.
 

rossko57

Senior Member
Furthermore I also tried using background receive however it appears you cannot have two interrupt flags (toflag and hserflag) generating interrupts!
You can, but they both call the same interrupt routine. It's up to your code to determine why it was called (by examining the flags).
I'd guess your "speed up" observation is due to both comms and timer interrupts all being processed as 'ticks'
 

dalise

New Member
Thanks for the responses, I have tried using code to determine the interrupt by testing the TOFLAG...(see below)
However now I am even more baffled!
The code below should output a signal or in my case sound a piezo for 20ms on the timer interrupt, instead it will only emit a tone on a serial interrupt. What is even more confusing is if you comment out the HSER in command the tone will now sound!!
HELP!!!

#Picaxe 40x2
#Slot 0
#No_Data
setfreq em64

hsersetup B19200_64,%00 ; Set baud rate to 19200bps
sound b.0,(50,100)

'**************************************************************************
'Define variables
'**************************************************************************

setintflags %10000000,%10000000
settimer 63034; ; Hundreds of a second timer
timer=$FFFF

'**************************************************************************
'Main Program
'**************************************************************************


Main:

hserin 0,1,($55) 'Receive console button status
Goto Main


'**************************************************************************
' Interrupt Handler
'**************************************************************************

Interrupt:
if toflag=1 then goto timersound
return

timersound:
sound b.0,(50,2)
timer=$FFFF
let toflag=0
setintflags %10000000,%10000000
return
 

AllyCat

Senior Member
Hi,

Isn't it t0flag? I can't see it declared (as a symbol) anywhere in your code (but I'm not familiar with X2 defined variables)? EDIT: I shouldn't try to help without acess to a PICaxe Manual or the PE. :(

Cheers, Alan.
 
Last edited:

hippy

Technical Support
Staff member
What is even more confusing is if you comment out the HSER in command the tone will now sound!!
The HSERIN is used in its blocking form so the interrupt will not be activated until after that command completes execution and that will only happen when it receives the character you are waiting for.
 

rossko57

Senior Member
It is toflagm for Timer Overflow.
It is a 'special' predefined system variable, no synmol definition is needed.

Any thoughts then on creating a countdown timer which can receive serial data?
Don't use the blocking form of HSERIN, use the background version?
Or use the blocking form, but add a timeout to un-block periodically (shorter interval than your ticks)?
 

hippy

Technical Support
Staff member
You would probably need to use background serial receive mode then scan through the data you receive.
 

dalise

New Member
Thanks everyone for your help, I now have it working with background receive..yay!
I got caught out at first as I forgot to add the "OR" function in the SETINTFLAGS command, however once I was over this hurdle (and had some reasonable sleep!!) both Serial and Timer Interrupts worked.
The interrupt routine once triggered, checks the relevant flags and jumps to the correct routine for that interrupt.
 
Top