Input capture mode problem

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

Input capture mode problem

1,804 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!!! ***/

Labels (1)
0 Kudos
Reply
10 Replies

1,449 Views
steph
Contributor I

hello, when you initialise your interrupt add :

TFLG2 = 0x80;  

//clear interrupt fla

to make sure this flag is clear

0 Kudos
Reply

1,449 Views
kdn
Contributor III

I try

TFLG2 = 0x80; 

It's not working

0 Kudos
Reply

1,449 Views
steph
Contributor I

sorry, i don't look on the data sheet, when you set TFLG2= 0x80 , it's only for timer over flow not for timer C01.

i mean the flag you must clear on initialise is TFLG1 = 0x01 and in your interrupt program too.

have you set the good vector adress in your project.prm file ?

there is a vector adress for C01 interrupt, and a vector adress for overflow interrupt .

as i look your program, you try to find a frequency, but if you take TC0 register i think you have 0 in return.

if you take TCNT you going to have a good value :

Tnew = TCNT;

Tperiod = Tnew - Told; (be careful to the carry)

Told = Tnew;

0 Kudos
Reply

1,449 Views
kdn
Contributor III

I have not set vector adress in your project.prm file. I do't now how to set it.

I clear this also TFLG1 = 0x01

I posted below my prm file . Help me in setting vector address

/*

** ###################################################################

**     THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.

**     Filename  : Project_11.PRM

**     Project   : Project_11

**     Processor : MC9S12XHZ512MAG

**     Compiler  : CodeWarrior HCS12X C Compiler

**     Date/Time : 31/12/2014, 4:06 PM

**     Abstract  :

**        This file is used by the linker. It describes files to be linked,

**        memory ranges, stack size, etc. For detailed description of the PRM file

**        see CodeWarrior documentation. This file is generated by default.

**        You can switch off generation by setting the property

**        "Generate PRM file = no" on the "Build options" tab in CPU component and then modify

**        this file if needed.

**

**     Copyright : 1997 - 2010 Freescale Semiconductor, Inc. All Rights Reserved.

**   

**     http      : www.freescale.com

**     mail      : support@freescale.com

** ###################################################################

*/

NAMES

END

SEGMENTS  /* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */

      RAM           = READ_WRITE    0x2000 TO   0x3FFF;

      ROM_C000      = READ_ONLY     0xC000 TO   0xFEFF;

      PAGE_E0       = READ_ONLY   0xE08000 TO 0xE0BFFF;

      PAGE_E1       = READ_ONLY   0xE18000 TO 0xE1BFFF;

      PAGE_E2       = READ_ONLY   0xE28000 TO 0xE2BFFF;

      PAGE_E3       = READ_ONLY   0xE38000 TO 0xE3BFFF;

      PAGE_E4       = READ_ONLY   0xE48000 TO 0xE4BFFF;

      PAGE_E5       = READ_ONLY   0xE58000 TO 0xE5BFFF;

      PAGE_E6       = READ_ONLY   0xE68000 TO 0xE6BFFF;

      PAGE_E7       = READ_ONLY   0xE78000 TO 0xE7BFFF;

      PAGE_E8       = READ_ONLY   0xE88000 TO 0xE8BFFF;

      PAGE_E9       = READ_ONLY   0xE98000 TO 0xE9BFFF;

      PAGE_EA       = READ_ONLY   0xEA8000 TO 0xEABFFF;

      PAGE_EB       = READ_ONLY   0xEB8000 TO 0xEBBFFF;

      PAGE_EC       = READ_ONLY   0xEC8000 TO 0xECBFFF;

      PAGE_ED       = READ_ONLY   0xED8000 TO 0xEDBFFF;

      PAGE_EE       = READ_ONLY   0xEE8000 TO 0xEEBFFF;

      PAGE_EF       = READ_ONLY   0xEF8000 TO 0xEFBFFF;

      PAGE_F0       = READ_ONLY   0xF08000 TO 0xF0BFFF;

      PAGE_F1       = READ_ONLY   0xF18000 TO 0xF1BFFF;

      PAGE_F2       = READ_ONLY   0xF28000 TO 0xF2BFFF;

      PAGE_F3       = READ_ONLY   0xF38000 TO 0xF3BFFF;

      PAGE_F4       = READ_ONLY   0xF48000 TO 0xF4BFFF;

      PAGE_F5       = READ_ONLY   0xF58000 TO 0xF5BFFF;

      PAGE_F6       = READ_ONLY   0xF68000 TO 0xF6BFFF;

      PAGE_F7       = READ_ONLY   0xF78000 TO 0xF7BFFF;

      PAGE_F8       = READ_ONLY   0xF88000 TO 0xF8BFFF;

      PAGE_F9       = READ_ONLY   0xF98000 TO 0xF9BFFF;

      PAGE_FA       = READ_ONLY   0xFA8000 TO 0xFABFFF;

      PAGE_FB       = READ_ONLY   0xFB8000 TO 0xFBBFFF;

      PAGE_FC       = READ_ONLY   0xFC8000 TO 0xFCBFFF;

      PAGE_FE       = READ_ONLY   0xFE8000 TO 0xFEBFFF;

END

PLACEMENT /* here all predefined and user segments are placed into the SEGMENTS defined above. */

      _PRESTART,              /* Used in HIWARE format: jump to _Startup at the code start */

      STARTUP,                /* startup data structures */

      ROM_VAR,                /* constant variables */

      STRINGS,                /* string literals */

      NON_BANKED,             /* runtime routines which must not be banked */

      COPY              INTO  ROM_C000;

      DEFAULT_ROM       INTO  PAGE_FE, PAGE_FC, PAGE_FB, PAGE_FA, PAGE_F9, PAGE_F8, PAGE_F7, PAGE_F6,

                              PAGE_F5, PAGE_F4, PAGE_F3, PAGE_F2, PAGE_F1, PAGE_F0, PAGE_EF, PAGE_EE,

                              PAGE_ED, PAGE_EC, PAGE_EB, PAGE_EA, PAGE_E9, PAGE_E8, PAGE_E7, PAGE_E6,

                              PAGE_E5, PAGE_E4, PAGE_E3, PAGE_E2, PAGE_E1, PAGE_E0;

      DEFAULT_RAM             /* all variables, the default RAM location */

                        INTO  RAM;

END

INIT _EntryPoint                       /* The entry point of the application. This function is generated into the CPU module. */

STACKSIZE 0x0080                       /* Size of the system stack. Value can be changed on the "Build options" tab */

0 Kudos
Reply

1,449 Views
steph
Contributor I

By verifying on data sheet of the component you use, in the end of .prm file, you must add the vector adress of your program interrupt.

in your case, it's look like :

STACKSIZE 0x100   /* size of the stack (will be allocated in DEFAULT_RAM) */

/* use these definitions in plane of the vector table ('vectors') above */

VECTOR 0 _Startup /* reset vector: this is the default entry point for a C/C++ application. */

VECTOR ADDRESS 0xFFxx IC0_ISR  //see on data sheet how is the vector adress for "input capture 0 interrupt" i.e. for HCS12XDP512, it's 0xFFEE

VECTOR ADDRESS 0xFFxx TOI_ISR //see on data sheet how is the vector adress for "overflow interrupt" i.e. for HCS12XDP512, it's 0xFF6F

0 Kudos
Reply

1,449 Views
kdn
Contributor III

how can I use  sprintf(buffer,"%d",time_interval); to print double and long integer

what in place of %d?

0 Kudos
Reply

1,449 Views
kdn
Contributor III

I am using processor expert, is that work in it or processor expert generate interrupt vectors itself.

0 Kudos
Reply

1,449 Views
steph
Contributor I

when i look your prm file you have not this interrupt vector, so add it in .prm file

regards

0 Kudos
Reply

1,449 Views
kdn
Contributor III

What mask value I have to set to receive 0x01 in receiver. I think my interrupt is working but filter section is not working.

0 Kudos
Reply

1,449 Views
kdn
Contributor III

Thanks for replay , tomorrow I will try this on my hardware .  Is there any problem with Timer or input capture mode setting ?

Do I have to Initialize timer separately ?

0 Kudos
Reply