MC9S12XEP100 intermittent timer fails to start O/C operation

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

MC9S12XEP100 intermittent timer fails to start O/C operation

跳至解决方案
1,595 次查看
roberthiebert
Contributor V

MC9S12XEP100, absolute assembler. I have a program that uses channels on both ECT and TIM timers that are set up for output compare. The first call sets a delay time for the output to go high. Most of the time it all works fine, but occasionally it will miss, but be fine the next call. In this example code snippet I am using ECT channel 3, but it is typical for all of the timer channels I am using.

TimerDelay   ds 2

BSET  ECT_TCTL2,#$80  ; Set bit 7 (Set Ch3 output line to 1 on compare) 

BSET  ECT_TCTL2,#$40  ; Set bit 6 (Set Ch3 output line to 1 on compare)

LDD   ECT_TCNT              ;  Timer Count Register -> Accu D

ADD  TimerDelay                ; Add without carry TimerDelay with current timer count

STD   ECT_TC3                   ; Copy result to Timer IC/OC register 3 (Start OC operation)

Am I doing anything wrong here?

Regards,

Robert

0 项奖励
回复
1 解答
1,584 次查看
roberthiebert
Contributor V

I discovered the error of my ways. Even though the first call is not from an interrupt, it is necessary to clear the flag first anyway. I made this change and all is good now.

在原帖中查看解决方案

0 项奖励
回复
2 回复数
1,593 次查看
roberthiebert
Contributor V

Oops, Typo, Should read:

 

TimerDelay   ds 2

BSET  ECT_TCTL2,#$80  ; Set bit 7 (Set Ch3 output line to 1 on compare) 

BSET  ECT_TCTL2,#$40  ; Set bit 6 (Set Ch3 output line to 1 on compare)

LDD   ECT_TCNT              ;  Timer Count Register -> Accu D

ADDD  TimerDelay              ; Add without carry TimerDelay with current timer count

STD   ECT_TC3                   ; Copy result to Timer IC/OC register 3 (Start OC operation)

0 项奖励
回复
1,585 次查看
roberthiebert
Contributor V

I discovered the error of my ways. Even though the first call is not from an interrupt, it is necessary to clear the flag first anyway. I made this change and all is good now.

0 项奖励
回复