cancel
Showing results for 
Search instead for 
Did you mean: 

problem with 8-bit timer

menno
Associate II
Posted on November 29, 2006 at 08:30

problem with 8-bit timer

5 REPLIES 5
menno
Associate II
Posted on November 28, 2006 at 13:27

On my ST7 2F561 I have a problem with the 8 bit timer. Goal is to create a 10ms interrupt, which I need for running a certain task.

This is done by using the 8 bit timer, running with the 8000 prescaler. Al seems to work fine, but I can't get it shorter than +-14ms. When setting the timercounter OC1R lower than 0x08, or higher than 0xFA, the software seems to get stuck in its interrupt-service routine. With higher values, leading to longer period times, everything works fine. No problem with resetting the interrupt flags in that situation.

Does anybody know about this problem? I can't find it in documentation.

Thanks in Advance, Menno

peterwrigley9
Associate II
Posted on November 28, 2006 at 13:49

Hi Menno,

The reset value for the timer is 0xfc. Therefore when you set the timer to interrupt quickly using nested interrupts, you will not have time to clear the flag before another interrupt is generated. The processor will get locked in the ISR. Try clearing the interrupt flag on the way out of the interrupt and using the sim instruction when you enter the ISR. This still will not help you on a *very* short timeout but will help you if you have time to disable interrupts before another one is generated. Remember the processor takes a (short) time to enter the interrupt routine. During this time the timer still increases (and can generate an interrupt).

What frequency is your crystal? Are you using a prescalar on the timer?

At 8MHz fcpu you will need 80 cpu cycles to generate your particular timeout. This should be plenty of time when CC1 = 0 and CC0 = 1.

Try the datasheet, page 107 for the CC bits.

Cheers

menno
Associate II
Posted on November 29, 2006 at 04:02

Hi PRW,

Thnx for your answer. I need an interrupt only every 10 ms, that's why I choose for a timer prescaler of 8000. When I use a value of 8, it will generate a TOF interrupt every 0.256 ms. Off course I can reduce this to 10ms by making my own software-prescaler, but I still have the higher interrupt load, which is not nice, so I try with 8000 prescaler ( CC0=1 CC1=1 )

I understand I need some time to handle the intterupt, but with the very slow timer, and the cpu still running on full speed, I expected that one or two counts would be enough. 10 ms must be by far long enough to handle the interrupt.

peterwrigley9
Associate II
Posted on November 29, 2006 at 06:32

Hi Men,

Sounds like your method is correct. Is there any chance you could post your code, at least the part where you load the registers? What is the crystal frequency?

10ms should be plenty of time to process the interrupt (a few thousand instructions @fcpu = 8MHz).

menno
Associate II
Posted on November 29, 2006 at 08:30

*solved* :)

Problem was in not correctly resetting the counter register CTR in the interrupt.

It looked like a minimum time of 13 ms. In reality this was the result of 2 interrupts (timer 1 and 2 ) during the comlete cycle of 25.6 ms.

[ This message was edited by: Men on 29-11-2006 13:04 ]