S08QG8 MTIM Prescaler: Can I clear it?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

S08QG8 MTIM Prescaler: Can I clear it?

4,881件の閲覧回数
Wings
Contributor I
I want to use the Modulo Timer to give me a 10ms delay. My question is, how do I insure the MTIM prescaler is cleared when I enable the MTIM?

I can clear the COUNTER of the MTIM whenever I set the TRST bit or write to the modulo register, but the data sheet doesn't say whether or not either of these events also clear the prescaler. If I can't clear the prescaler then my delay could be in error by as much as the prescaler's period.
ラベル(1)
0 件の賞賛
返信
4 返答(返信)

1,010件の閲覧回数
rhinoceroshead
Contributor I
I don't know this for a fact, but I highly doubt you can change the states of the prescaler stages.  There is really no point in doing it.  If you need higher resolution time measurements then you should not use the prescaler at all.  Of course, you will need to implement the timer overflow interrupt and have it update a counter to store the higher-order bits.
0 件の賞賛
返信

1,010件の閲覧回数
Wings
Contributor I
"There is really no point in doing it."

I beg to differ. There is a very good point in doing it - I can get the accuracy I need if I can, and I don't if I can't.

Both channels of the TPM are already in use, and that is why I've turned to the modulo timer for my needed delay. I *could* share one of those timers with my 10ms delay requirement but I'd rather not (that would get just a little messy) if I can use the modulo timer.

"Of course, you will need to implement the timer overflow interrupt and have it update a counter to store the higher-order bits."

I don't understand why I would need to do this. 10msec is short enough to mark off without overflowing either the modulo timer or the TPM.

Anyway, I'm hoping that at least the TRST bit will clear the prescaler - after all, that bit does have the word "reset" in it. I'll be testing it soon but I thought I'd ask here first. Someone may have already tried.
0 件の賞賛
返信

1,010件の閲覧回数
rhinoceroshead
Contributor I
Excuse me, I hastily interpreted this as a standard timer question.  Reseting the prescaler would be an elegantly simple solution to your problem while using the MTIM.  But still the same thing applies.  You can think of the modulo register as being an output compare (with no pin) that shares the same ISR as the overflow.
 
Anyway, here are a couple of ideas:
 
1)  You can try setting the prescaler to 1 then set it back to your desired value.  This might reset the prescaler states.  But still - you only have as much resolution as you can get with this scaled clock.  What if 10ms happens to be impossible to achieve with any combination of prescaler and modulo?
 
2)  You can set the prescaler to 1 and set the modulo to 0 and count all the overflows.  In the overflow ISR, when you have reached the last overflow, you can change the modulo register to the value it needs in order to equal 10ms.  Then, on the next overflow, the ISR will know that the delay is done.  This would give you full precision and allow long delays.  It's not as clean as your proposed method, but it would work - and it could get as close as possible to 10ms.
 

Message Edited by rhinoceroshead on 2006-07-26 01:43 PM

0 件の賞賛
返信

1,010件の閲覧回数
Wings
Contributor I
I've tested this extensively and can say that the prescaler IS cleared whenever the TRST bit is set or when storing a value into the MODULO register.

But, see my post about MTIM quirks if you plan on using the MTIM for anything other than a simple repetitive timer.
0 件の賞賛
返信