Time Of Day interrupt shared by Second and Match

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Time Of Day interrupt shared by Second and Match

跳至解决方案
1,137 次查看
DRichards
Contributor III

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

 

标签 (1)
标记 (3)
0 项奖励
回复
1 解答
986 次查看
bigmac
Specialist III

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

在原帖中查看解决方案

0 项奖励
回复
2 回复数
987 次查看
bigmac
Specialist III

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

0 项奖励
回复
986 次查看
DRichards
Contributor III

I tried the suggesstion and it works. Thank you.

0 项奖励
回复