cancel
Showing results for 
Search instead for 
Did you mean: 

16bit Timer Problem

schmid
Associate II
Posted on January 14, 2005 at 07:17

16bit Timer Problem

3 REPLIES 3
schmid
Associate II
Posted on January 12, 2005 at 17:47

I use the 16bit-timer (ST72C215G) in output-compare-mode to generate different frequencies. For a wide range it is necessary to change the timer clock (CCbits in CR1) . Sometimes it works but sometimes the counter hangs ??, because after changing the CC bits no interrupts are generated.

Is a special sequence necessary ?

i tried loading the whole CR1register and bset/bres the CCbits.

I make the change between reading the current OC1Rvalue and writing the new OC1Rvalue(=current + fvalue). Is this correct ?

Is it a fault of my programming or is it not allowed to change the CCbits after enabling interrupt ?

wolfgang2399
Associate II
Posted on January 13, 2005 at 07:21

Hi,

the only trap I know is the order you read or write timer registers.

Please pay attention to the note 1. on page 46 of your datasheet.

1. After reading the ICiHR register, the transfer of

 

input capture data is inhibited and ICFi will

 

never be set until the ICiLR register is also

 

read.

See also Note 1 at page 53.

It depends on the compiler if reading/writing the 2 registers is done in the right order. Cosmic does it all right. With Metrowerks (HiWare) you have to force reading first IC1HR and then IC1LR. Writing analogic.

Never use

int_value = IC1R;

nor

OC1R = int_value;

if you are using the HiWare compiler to read/write the (2 bytes) integer value of a timer register.

Hope it helps

WoRo

schmid
Associate II
Posted on January 14, 2005 at 07:17

Hi,

Thanks woro for your hints.

I am programming in assembler and my program is similar to AN974.

After further testing i must see, that the hang happens also after loading a new value to OC1R without changing the CCbits.

After switching the unit off and on it works. After a few minutes switching on it works or not ?!

Are there forbidden values for the OC registers ?

Which register is better OC1R or OC2R ?

What to do with the unused register ?

Can the counter overflow disturb ?