Hi,
I haven't posted for a while and things look different from what I remember, so I hope I'm in the right place.
I am trying to use the Time Of Day module with both a one-second and a timer match interrupt.
As both these interrupts use the same interrupt vector, I want to differentiate between them in the interrupt routine.
I thought this would just involve checking which interrupt flag(s) were set and performing the appropriate actions. However, clearing the one-second interrupt flag TODSC_SECIE appears to also clear the match interrupt flag TODSC_MTCHF.
I have interrupts disabled while stepping, but it looks as if the time of day counter may still be running while the micro is halted?
I know I do not need to do things this way, I currently have a 60s count in the one second interrupt, but I'm looking at using the match interrupt to provide a variable delay and keep the micro in Stop3 for longer and only use the one-second interrupt as necessary. For this I want to make sure the two interrupt flags are truely separately clearable.
Micro MC9S08LL8
Code Warrior 6.1
Solved! Go to Solution.
Hello,
I assume that you are attempting to clear the flags using -
TODSC_SECF = 1;
TODSC_MTCHF = 1;
Unfortunately, with more than one flag within the register, this code will have the effect of clearing all flags, as you have observed. The reason lies with the compiler using a read-modify-write process within the generated code, i.e BSET command. Any of the bits, other than the specified bit, will also read as a 1, if set. The bits will then be written back to the register as 1s, which will clear all the flag bits.
The solution is to use a write only process -
#define TODSCval 0x0E;
TODSC = TODSCval | TODSC_SECF_MASK;
TODSC = TODSCval | TODSC_MTCHF_MASK;
If the TOD counter is to be used as a wakeup source, it would need to be running whilst the MCU is in stop mode.
Regards,
Mac
Hello,
I assume that you are attempting to clear the flags using -
TODSC_SECF = 1;
TODSC_MTCHF = 1;
Unfortunately, with more than one flag within the register, this code will have the effect of clearing all flags, as you have observed. The reason lies with the compiler using a read-modify-write process within the generated code, i.e BSET command. Any of the bits, other than the specified bit, will also read as a 1, if set. The bits will then be written back to the register as 1s, which will clear all the flag bits.
The solution is to use a write only process -
#define TODSCval 0x0E;
TODSC = TODSCval | TODSC_SECF_MASK;
TODSC = TODSCval | TODSC_MTCHF_MASK;
If the TOD counter is to be used as a wakeup source, it would need to be running whilst the MCU is in stop mode.
Regards,
Mac
I tried the suggesstion and it works. Thank you.