help with coding in c a timer

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

help with coding in c a timer

3,705 Views
Bud
Contributor I
I have generated the following test code to use with the simulator debugger.  I am utilizing a s08gt16 processor.
 
I am unable to get the interrupt to be generated.  Can one of you help me with where I am going wrong?  The frequency of the interrupt at this point is not important as that can be changed with the prescaler.
 
thanks in advance,
Bud
// SET DIVIDER TO DIVIDE BY 32
 
 TPM1SC_PS0 = 1;
 TPM1SC_PS1 = 0;
 TPM1SC_PS2 = 1;
 // CLOCKS SET TO BUS RATE CLOCK
 TPM1SC_CLKSA = 1;
 TPM1SC_CLKSB = 0;
 
 //TPM1MOD = 112;
 
 TPM1MOD = 0;
 //CENTER ALIGNED CLOCKS
 //TIMER OVERFLOW INTERRUPT ENABLED
 
 TPM1SC_TOIE = 1;
 TPM1SC_CPWMS = 1;
 //TPM1SC = 0x60;

  for(;:smileywink: {
    __RESET_WATCHDOG(); /* feeds the dog */
  } /* loop forever */
  /* please make sure that you never leave this function */
}
interrupt 8 void ProcessMyInterrupt(void){
//  TPM1SC;
  TPM1SC_TOF = 0;
}
Labels (1)
0 Kudos
3 Replies

458 Views
rhinoceroshead
Contributor I
I don't have the actual chip in front of me, so I can only confirm my answer with the simulator...
 
The reason this is not working for you is because you turned the timer on before you configured it and - at least in the simulator - the configuration can not be changed after the timer is already running.  So the problem lies only with the ordering of your code.  The timer is enabled as soon as you define the timer's clock source.
 
This works in the simulator:
Code:
#include <hidef.h> /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations */void main(void) {  EnableInterrupts; /* enable interrupts */// SET DIVIDER TO DIVIDE BY 32  TPM1SC_PS0 = 1; TPM1SC_PS1 = 0; TPM1SC_PS2 = 1;  //TPM1MOD = 112;  TPM1MOD = 0; //CENTER ALIGNED CLOCKS //TIMER OVERFLOW INTERRUPT ENABLED  TPM1SC_TOIE = 1; TPM1SC_CPWMS = 1; //TPM1SC = 0x60;   // CLOCKS SET TO BUS RATE CLOCK TPM1SC_CLKSA = 1;                     // <---- This line moved to the end TPM1SC_CLKSB = 0;  for(;;) {    __RESET_WATCHDOG(); /* feeds the dog */  } /* loop forever */  /* please make sure that you never leave this function */}interrupt 8 void ProcessMyInterrupt(void){//  TPM1SC;  TPM1SC_TOF = 0; }

 
0 Kudos

458 Views
Bud
Contributor I
Thanks, somewhere in the documentation I must have missed the ordering sequence of the code.
 
Bud
0 Kudos

458 Views
rhinoceroshead
Contributor I
I don't think you missed anything - I looked in the datasheet and saw nothing requiring the clocks to be selected last.  I suspect that usually you would write that configuration register all at once instead of one bit at a time so you would never run into that.  For all I know, this is just a peculiarity of the simulator and the problem might never occur on the real chip.  Maybe someone here can test it on the real thing and get back to us.
0 Kudos