Timer in MC9S08GT60

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Timer in MC9S08GT60

1,278 Views
ppanicker
Contributor I

Hi,

 

My application code requires me to send data through the SPI interface every one minute. I want to write an interrupt routine using the timer. I am using MC9S08GT60, running at 8MHz. 

 

I am not sure how to initialize the timer module. And set the register values to get an interrupt every one minute.

 

Thanks,

Poornima 

Labels (1)
0 Kudos
Reply
2 Replies

428 Views
PeterHouse
Contributor I

Poornima,

 

Find a divisor setup which will make 65536 counts last longer than one second.  Get as short as possible without going less than one second.

 

Calculate the exact number of counts for one second and set this as the modulo.  If it is not exact and you need EXACT for the long term you may need to adjust the modulo count at each interrupt to make sure the long term count is exact.  If you need EXACT over the short term, then you will possibly need to change crystals - I do not think this will be the case for an 8 MHz crystal as I believe there is an exact divisor.

 

Enable the Overflow interrupt and put some code in it.

 

Good Luck,

 

Peter House

0 Kudos
Reply

428 Views
bigmac
Specialist III

Hello Poomima,

 

I don't think that it is possible to directly achieve a 1 minute TPM overflow period with a bus frequency of 8MHz.  However, if a much shorter TPM overflow period, perhaps 10 milliseconds, is generated, a one minute timeout period could then be achieved by counting every 6000 overflows.

 

With a bus frequency of 8 MHz, a TPMMOD setting of 39999 and a prescale value of 2 should give 10 ms overflow period.

 

Using an 16-bit global variable tcount, the TPM overflow ISR then might incorporate the following code snippet:

 

tcount--;

if (tcount == 0) {

tcount = 6000;

SPI_process();

}

 

Regards,

Mac

 

Message Edited by bigmac on 2009-08-18 05:07 AM
0 Kudos
Reply