Input capture on HC908JL16

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

Input capture on HC908JL16

2,130 Views
matri
Contributor I
Hi everybody,

I'm using HC908JL16. One channel of the modulo timer I'm using with input capture function. The TIM is programmed to capture on rising and falling edge, I need to measure the duty cycle of a PWM signal.
I've already wrote the code for the interrupt service routine (ISR), and it works fine. However I've observed a strange behavior, when I power, without to apply signal on that pin, the execution of the code go inside the ISR, it do that only the first time. Later, when I apply the PWM signal, the execution of the code is right.
I've observed that using the PCB stand-alone and by using inDART.
I'm curious to know if someone can explain me what happens.
Thank you too much.

Marilena
Labels (1)
0 Kudos
5 Replies

424 Views
bigmac
Specialist III
Hello Marilena,
 
A spurious input capture event is always possible during initialisation of the TIM channel.  You can avoid this causing an interrupt by the careful sequencing of the initialisation process.
  1. Globally disable all interrupts (SEI).
  2. Setup channel for required input capture configuration.
  3. Clear channel flag process, in case flag is spuriously set.
  4. Enable channel interrupt.
  5. Globally, re-enable all interrupts (CLI).
Regards,
Mac
 
0 Kudos

424 Views
matri
Contributor I
    Thanks Mac,
I've followed your suggestion, but the result isn't changed:smileysad:
To avoid mistake, I've opened a new full project, with essential things, like init of different module and declaration of interrupt service routine. Only for the input capture channel routine I've wrote code, that:

__interrupt void TIM1_CH1Interrupt(void)
{
   
    T1SC1 &= ~0x80;
            capture_counter++;
           
            if (capture_counter & 0x00)
            {   
                PTA_PTA4 = 1;//led switched on
            }
            else
            {
                PTA_PTA4 = 0;//led switched off
                capture_counter = 0;
            } 
}

Init of the channel is that:
    T1SC = 0x00;//counter timer active
    T1SC1 = 0x4C;//input capture on rising and falling edge
I use timer1 channel 0 as input capture. Timer counter is active, I've tried to stop it, but the input capture function doesn't works, as I expect!
About other module, init islike default because I don't use them.
My first instruction in the main is disable all the interrupts and the last before while for-ever allows to enable interrupts.

So, I really don't know the problem. For my application DT's measure is very important, I hope this is my mistake, otherwise I don't know....sorry :smileysad:

I don't know if is important, I use CW3.1.

Thanks a lot,

Marilena


0 Kudos

424 Views
bigmac
Specialist III
Hello Marilena,
 
I cannot quite see how you have implemented my previous suggestion.  I might have expected initialisation code similar to the following -
 
asm sei;         // Disable interrupts
T1SC1 = 0x0C;    // Input capture mode, both edges
T1SC1 &= ~0x80;  // Clear spurious flag
T1SC1_CH1IE = 1; // Enable IC interrupt
T1SC = 0x00;     // Start TIM, prescale 1
asm cli;         // Re-enable all interrupts
 
Youf code actually uses TIM channel 1 as the input capture channel, not channel 0.
 
Regards,
Mac
 

 

 




Message Edited by bigmac on 2007-05-11 02:41 PM
0 Kudos

424 Views
matri
Contributor I
    Hello Mac,

now I've used your initialization,  the execution flow correctly without first coming in ISR for the input capture.

For me, this means that before to allow channel interrupt I must clear from spurious flag T1SC1, without believe it integrity.

In my code, I use timer1 channel0 as system clock  (tick pulse, I means) and channel1 of the same timer as input capture.

Thank you to much for your help, :smileyhappy:
Marilena
0 Kudos

424 Views
kdn
Contributor III

I am not getting interrupt in input capture mode. I posted my code below , Please help someone

#pragma CODE_SEG __NEAR_SEG NON_BANKED

interrupt void  IC0_ISR(void)

{   

  //  new_capture = TC0;   //save the value of input capture register

   

   

    LCD_Cmd(0x80);

  

              PORTA = 0xFF;

        

         t[i]=TC0;

        

          i++;

        

          if(i==2) {

          i=0;

         

       //    6.0742270546073012209196379760675e-8

        

         time_interval=(t[1]-t[0]);

         time_period=(float)(0.0000256* time_interval);

         frequency= 1/time_period;

     

        

      

         sprintf(buffer,"%f",frequency);

         for(j=0;j<4;j++)

         {

         LCD_Data(buffer[j]);

         }

   

}

   TFLG1 = 0x01;       //clear interrupt flag  

}

interrupt void  TOI_ISR(void)

{

  

   

    TFLG2 = 0x80;       //clear interrupt flag

}

unsigned int TM;

/* User includes (#include below this line is not maintained by Processor Expert) */

void main(void)

{

  /* Write your local variable definition here */

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/

  PE_low_level_init();

  /*** End of Processor Expert internal initialization.                    ***/

  /* Write your code here */

 

 

        LCDIni();

  

//   LCD_Cmd(0x01);

   LCD_Cmd(0x80);

  

   LCD_Data('T');

  

    PPST_PPST0 = 0;  //set pull-up

    PERT_PERT0 = 1;  //enable pull-up   

   TSCR1 = 0xE7;       //enable timer, stop timer during wait and freeze, disable fast flag clear

   TIOS_IOS0 = 0;      //channel 0 as an input capture

    TCTL4 = 0x01;       //capture on rising edge

    TIE_C0I = 0x01;        //enable interrupt on channel 1   

    TSCR2 = 0x80;       //timer overflow interrupt enable, timer prescaler is 0

 

 

 

 

  for(;;){}

  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/

  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/

 

} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

0 Kudos