TSC0_CH0F - MC68HC908JK1CP

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

TSC0_CH0F - MC68HC908JK1CP

1,498 Views
tihomirtiankov
Contributor I
Hi everybody
I'm working with MC68HC908JK1CP
I would like to reach the interrupt routine during TIM Channel 0 overflow. Here is my code. TCH0L = TCNTL but CH0F bit is always equal to 0. I think that something is missing here.
Thank you in advance.
 
 
EnableInterrupts; /* enable interrupts */
  /* include your code here */
  TSC_TSTOP = 1; //counter stopped;
  TSC_TRST = 1;  //reset counter;
  TSC_PS0 = 0;
  TSC_PS1 = 1;
  TSC_PS2 = 1;  
  
  TCH0L = 20;
  TCH0H = 20;
  TSC0 = 112;

  TSC_TSTOP = 0;
    for(;:smileywink: {
  if (TCH0L == TCNTL && TCH0H == TCNTH)
   if (TSC_TOF == 1) 
      {
        TSC0_CH0IE = 1;
              
      }
    __RESET_WATCHDOG(); /* feeds the dog */
  } /* loop forever */
  /* please make sure that you never leave this function */
}
 
interrupt 4 void prek4(){
  
  TSC0_CH0IE = 0;
  TSC0_CH0F = 0;
 
  TSC_TRST = 1;
  
}
 
 
Added p/n to subject.


Message Edited by NLFSJ on 2008-02-05 07:44 AM
Labels (1)
0 Kudos
4 Replies

359 Views
bigmac
Specialist III
Hello, and welcome to the forum.
 
There may be some confusion about timer overflow, and output compare operation.  Timer overflow pertains to all channels of the TIM module, and occurs when TCNT is equal to the TMOD value.  The output compare is applicable to individual channels, and with the channel setting you have (would be much easier to read a hxadecimal, rather than decimal value), an interrupt will occur whenever register TCNT is equal to TCHO, a value of 0x1414.
 
It is unclear what you are attempting to achieve.
Your ISR simply clears the interrupt flag, and disables further channel interrupts.  You also zero the timer.
With the test in your main loop, it is quite possible that this will very rarely succeed since any match is a transient event that mostly won't occur at the time the test is made.  You should restrict the test to the upper byte value, or test the CH0F flag instead. 
After testing the timer overflow flag, you do not clear the flag.
 
If you simply wish to generate a periodic timer interrupt,  It is much simpler to increment the TCH0 value by a fixed amount, within the channel ISR.
 
Regards,
Mac
 


Message Edited by bigmac on 2008-02-05 10:07 PM
0 Kudos

359 Views
Ake
Contributor II
Hi,
I tried your code, and I think that the following must be added/taken away to make it do something.
 
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
void InitTIM(void) {
     
  TSC_TSTOP = 1; //counter stopped;
  TSC_TRST = 1;  //reset counter;
  TSC_PS0 = 0;
  TSC_PS1 = 1;
  TSC_PS2 = 1; 
 
 
 
  TCH0 = 2020;
     
      //  TSC0 = 112;    ???????
      TSC0 = TSC0_CH0IE_MASK|TSC0_MS0A_MASK|TSC0_ELS0A_MASK|TSC0_ELS0B_MASK; //what to do with Ch0
  TSC_TSTOP = 0;
};
void main(void) {
      InitTIM();
      EnableInterrupts; // enable interrupts
      for(;:smileywink: {
/*           if (TCH0 == TCNT)
            if (TSC_TOF == 1)      */
            if (TSC0_CH0IE == 0)
            {
                  TSC0_CH0IE = 1;
             
            }
    __RESET_WATCHDOG(); // feeds the dog
  }
}
 
interrupt 4 void prek4(){
  TSC0_CH0IE = 0; //stop interrupts
  TSC0_CH0F = 0;  //reset flag
 
  TSC_TRST = 1;   //reset counter
};
But if you could tell us more about exactly what you want it to do, I am sure someone coult write a much more elegant solution.
 
Regards,
Ake
0 Kudos

359 Views
tihomirtiankov
Contributor I
Hi everybody
Thank You for your answers. I found my error. When I'm in debug mode I couldn't enter in the interrupt 4. I changed prescaler and I succeed. Could you explain why this happens. This is my code here and it works well now.
 
Could I ask you where I can find this type of controler: MC68HC908JK1CP
I know that this is an old one but I have started programming with this controler and I would like to continue while I become more confident.
 
void main(void) {
  EnableInterrupts; /* enable interrupts */
  /* include your code here */
  TCH0H = 0;  // TIM Channel High;
  TCH0L = 2;  // TIM Channel Low;
   
  TSC_PS0 = 0; 
  TSC_PS1 = 1; // I changed only this line;
  TSC_PS2 = 1;
  TSC_TSTOP = 1; // Stop counter;
  TSC_TRST = 1;  // Reset counter;
 
  TSC0_MS0B = 0;
  TSC0_ELS0A = 1;
  TSC0_ELS0B = 0;
  TSC0_MS0A = 1;
 
  TSC0_CH0IE = 1; // Enable channel interrupt;
 
  TSC_TSTOP = 0;  // Start counter;
 
  for(;:smileywink: {
 
 
 
    __RESET_WATCHDOG(); /* feeds the dog */
  } /* loop forever */
  /* please make sure that you never leave this function */
}
////////////////////////////////////////////
///  TIM Channel 0 Interrupt  //////////////
////////////////////////////////////////////
interrupt 4 void prek4(){
TSC0_CH0F = 0; // Clear Channel flag bit;
TSC_TRST = 1;  // Reset counter;
}
0 Kudos

359 Views
Ake
Contributor II
Hi,
I ran your code on a ICS08JL board, and it produced a 8.164 kHHz squarewave on TCh0.
So the code ran OK. I then changed the PS1 to 0, and the frequency changed to 23.4 kHz. It ran OK.
 
Well I could not see any errors, but I must say that if you wanted to produce a square wave, this method is not the most elegant ones I have seen.
Use the PWM function, and you don't have to use any interrupts.
 
Regarding the HC908JK1, this is an old MCU. Look for the new 9S08 family instead. They are upwards code compatible, they have lots of interesting features and there are lots of 'em available.
 
Regards,
Ake
 
0 Kudos