I am attempting to implement a cooperative task scheduler, as described in the book Patterns for time-triggered embedded systems by Michael J. Pont, on the X2 chips and for this I need:
1) to be able to put the chip to sleep, and
2) a timer interrupt that will wake the chip from sleep and that can be configured as a sytem tick in the 10 - 100ms range. The interrupt subroutine is used to run the task scheduling code.
The SETINTFLAGS command allows me to set an interrupt on the timer 0 overflow.
The SETTIMER command together with TIMER=65535 allows me to configure the timer 0 overflow in the 10 - 100ms range.
The "DOZE 0" command puts the chip to sleep puts the chip to sleep while leaving the timers running.
If I run this first code I get the character "." sent to the terminal once per second, which is what I expect.
If I run this second code I get no characters sent to the terminal, which is what I expect.
If I run this third code, which has both the timer interrupt and the DOZE command, I get a sequence of characters where the character "." is sent once per second and the character "M" is sent eight times per second: MMMMMMMM.MMMMMMMM.MMMMMMMM.
i.e. I appear to be getting a hardware timer interrupt waking the chip from the DOZE command at a frequency which is eight times my setting for the PICAXE interrupt on the overflow of timer 0.
All tests done on a 20X2 chip reporting the vC.3 firmware at 4MHz.
Does anyone have any insight on how the hardware interrupts associated with the PICAXE timer interrupt combine to give this behaviour and/or can anyone spot something I'm not doing right?
1) to be able to put the chip to sleep, and
2) a timer interrupt that will wake the chip from sleep and that can be configured as a sytem tick in the 10 - 100ms range. The interrupt subroutine is used to run the task scheduling code.
The SETINTFLAGS command allows me to set an interrupt on the timer 0 overflow.
The SETTIMER command together with TIMER=65535 allows me to configure the timer 0 overflow in the 10 - 100ms range.
The "DOZE 0" command puts the chip to sleep puts the chip to sleep while leaving the timers running.
If I run this first code I get the character "." sent to the terminal once per second, which is what I expect.
Code:
#NO_DATA
#NO_TABLE
#PICAXE 20X2
SETFREQ M4
; Setup timer0 to overflow for the scheduler tick
SETTIMER t1s_4
timer=65535
; Set a polled interrupt on the timer0 overflow
SETINTFLAGS %10000000,%10000000
Main:
GOTO Main
interrupt:
toflag=0
timer=65535
; We need to re-enable our interrupt. This won't take effect until after we return.
SETINTFLAGS %10000000,%10000000
SERTXD (".")
RETURN
If I run this second code I get no characters sent to the terminal, which is what I expect.
Code:
#NO_DATA
#NO_TABLE
#PICAXE 20X2
SETFREQ M4
Main:
DOZE 0
SERTXD ("M")
GOTO Main
Code:
#NO_DATA
#NO_TABLE
#PICAXE 20X2
SETFREQ M4
; Setup timer0 to overflow for the scheduler tick
SETTIMER t1s_4
timer=65535
; Set a polled interrupt on the timer0 overflow
SETINTFLAGS %10000000,%10000000
Main:
DOZE 0
SERTXD ("M")
GOTO Main
interrupt:
toflag=0
timer=65535
; We need to re-enable our interrupt. This won't take effect until after we return.
SETINTFLAGS %10000000,%10000000
SERTXD (".")
RETURN
All tests done on a 20X2 chip reporting the vC.3 firmware at 4MHz.
Does anyone have any insight on how the hardware interrupts associated with the PICAXE timer interrupt combine to give this behaviour and/or can anyone spot something I'm not doing right?