Jorgen Riisom

How can I stop a timer?

Discussion created by Jorgen Riisom on Feb 6, 2008
Latest reply on Feb 7, 2008 by bigmac
I have made a small radio sw, using SMAC for the MC1321 chip (HCS08). The whole system consists of one send unit and one receiver unit.
 
I'm using a timer to time out if messages stops comming in on the receiver side.
So when I receive a message I have to stop the timer and then restart it, but I cannot make it work. Once the timer is initiated and started it allways calls the ISR, even if i try to stop it before!
 
Can anyone see the error??
 
-------------------------------
 
void TimerInit(void)
{
  TPM1C0SC = 0x07 |  // prescale divisor = 128
             0x10;   // fixed system clock
       
  TPM1SC = 0x07 |  // prescale divisor = 128
           0x10;   // fixed system clock 
}
 
void TimerStart(unsigned char modH, unsigned char modL)
{
  TPM1MODH = modH;
  TPM1MODL = modL;
  TPM1C0SC |= 0x40;   // interrupt enable
}

void TimerClear(void)
{
  if(TPM1C0SC & 0x80)
    TPM1C0SC &= ~0x80;
}

void TimerStop(void)
{
  TPM1SC = 0x00;
}
 
interrupt void TimerISR(void)
{
  // We have a timeout!
  TimerClear();
  TimerStop();
  // Do stuff  
}
 
// MCPSDataIndication is called when data is received on the radio
void MCPSDataIndication(tRxPacket *gsRxPacket)
{
    TimerClear();
    TimerStop();
           
    if (gsRxPacket->u8Status == SUCCESS)
    {
 
       TimerStart(); // Restart the timer
 
 

Outcomes