Ruth Hendrix

Output compare in HC908QT4

Discussion created by Ruth Hendrix Employee on Jan 24, 2006
This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.
 
Posted: Mon Nov 21, 2005 11:48 am    
 
Hi Guys,
I am trying to work with the Output compare on the HC908QT4 and I am having a few problems.
I have managed to get it working but now I need to generate an interrupt when the Counter reaches the value set for the channel. to the program that is working I modified TSC0 to set CH0IE (enable CH0 interrupts)
and wrote a ISR routine linked to VECTOR 4. the function of the routine is to reset the TIM counter and also gives me an indication in PTA1 if the chip is interruped, wich is not happening.
this is the program:
Code:
#include <hidef.h> /* for EnableInterrupts macro */
#include <MC68HC908QT4.h> /* include peripheral declarations */

int i=0;


// ---------------------------------------------------------------------------
// Interrupt Service Routine to handle TIM CH0 interrupt
// ---------------------------------------------------------------------------

 interrupt void TIMCH0_ISR(void)
{
   
    TSC_TRST=1;     // Will reset the TIM's free running Counter
      if (i==0){
        i++;
        PTA_PTA1=1;
      }
      if (i==1){
        i--;
        PTA_PTA1=1;
      }
}




// ---------------------------------------------------------------------------
// Peripheral Initialization routine
// ---------------------------------------------------------------------------

void Init_Setup(void){
 
  CONFIG2 = 0x01;
  CONFIG1 = 0x09;
 
  PTA = 0x00;       // Send all zeros to PORTA
  DDRA = 0xFF;         // Make all 8 bits outputs
 
 
  TSC_TSTOP=1;         // Stop TIM
  TSC_TRST=1;           // Reset TIM
 
   
  TSC = 0x05;       // TIM Status and control register setup of
                    // Prescaler to /32 which will give me 10uS per count
                    // I am also restarting TIM which may not be a good idea
 
  TSC0 = 0x54;         // setting Ch0 to be output compare and toggle on compare,
                    // was 0x14 now set to 0x54 to enable interrupt
 
 
  TCH0H = 0x61;         // setting compare limit to 25000 which will give me 250mS
  TCH0L = 0xA8;
 
  TSC_TSTOP=0;         // restarting and removing reset to TIM may not be required
  TSC_TRST=0;
 
 
}



// ---------------------------------------------------------------------------
// Main
// ---------------------------------------------------------------------------
void main(void) {
  Init_Setup();
  EnableInterrupts; /* enable interrupts */
 


  for(;:smileywink: {
  /*  int i=0;
     for(i=0;i<=255;i++) {
         PTA_PTA1=1;
     }
     for(i=0;i<=255;i++) {
         PTA_PTA1=0;
     }
   
  */ 
    //__RESET_WATCHDOG(); /* feeds the dog */
  } /* loop forever */
 
}


And the PRM file entry:

Code:
VECTOR 4 TIMCH0_ISR


is this correct?
the datasheet is a bit confusing, so I am getting a bit lost...
thanks for the help
best regards
Posted: Tue Nov 22, 2005 10:55 am    
 
can you show more detail about the problem you encountered?
by the way, the isr of channel0 seems a little puzzleheaded
 
Posted: Tue Nov 22, 2005 11:23 am  
 
Hi,
I want to generate a 500ms period wave so I set output compare to 250 ms and set channel 0 to toggle on compare. also on compare, channel 0 should generate an interrupt that with the ISR function should reset the TIM counter and start again from 0000h. But as far as I can see the Interrupt is not happening. I corrected the error on the program as the interrupt vector for channel zero is 3 not 4, but still no interrupt.
any ideas?
best regards

Posted: Wed Nov 23, 2005 1:54 am    

hi,
interrupt vector number for channel0 is 4 not 3, though it is 'IF3' correspond to channel 0 vetor in specification of qt4.The reset vector number is 0, SWI vector number is 1,and so on.
By the way,have you enable the channel 0 interrupt by set CH0IE in register TSC0?

Outcomes