Input capture mode

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Input capture mode

2,123 次查看
kdn
Contributor III

I am using Input capture mode of MC9S12XHZ512 for calculating frequency and duty cycle of square wave from 1KHz to 10KHz , I have attached image of setting i have done in codewarrior.

 

My problem is that when I try to display frequency on my LCD display I am getting random charter on , I also have problem with interrupt input capture mode I have enable input capture mode in codewarrior , but i'm not able to find it in program , I want to write my display and calculation code in interrupt sub routine of input capture mode. I have posted my code below.

 

I'm using 16MHz crystal

 

 

LCD_Cmd(0x80);

  

                  

         //  TM=65535*(TC0/16000000);

         //  TM=1/TM;

        

         t[i]=TC0;

        

          i++;

        

          if(i==2) {

          i=0;

         

        

        

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

         time_interval=(float)(0.0000000625*time_interval);

         frequency= 1/time_interval;

      

       

  

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

 

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

         {

         LCD_Data(buffer[j]);

         }

         }

       

18222_18222.pngINPUT caputre.png

标签 (1)
标记 (3)
0 项奖励
回复
3 回复数

1,504 次查看
trytohelp
NXP Employee
NXP Employee

Hi,

I've contacted the Processor Expert team.

See below their answer:

++++++++++++++++++++++++++++

The interrupt service routine of Capture component is not directly available for user. When you enable Interrupt service/event of the Capture component the OnCapture event (Cap1_OnCapture) is generated into Event.c program module of your project (see the attached screenshot OnCapture event.png). This event is called from the interrupt service routine that is available (code if generated by Processor Expert) in the Cap1.c program module:

ISR(Cap1_Interrupt)
{
/* TFLG1: C7F=0,C6F=0,C5F=0,C4F=0,C3F=0,C2F=0,C1F=0,C0F=1 */
TFLG1 = 0x01U; /* Reset interrupt request flag */
Cap1_OnCapture(); /* Invoke user event */
}

I.e. you can see the the Cap1_OnCapture event (function) is a part of interrupt service routine.

Please, use the Cap1_OnCapture event of the Capture component in your project.

++++++++++++++++++++++++++++


Have a great day,
Pascal
Freescale Technical Support
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复

1,504 次查看
kdn
Contributor III

Thanks for replay ,

I have done that , my new problem is that When i'm using

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

         time_period=(float)(0.000008*time_interval);

         frequency= 1/time_period;

       

      sprintf(buffer,"%f",frequency);                                   %f showing error . I am not able to use floating mathematics , I have selected floating point in codewarrior 

STARTED

RUNNING

ILLEGAL_BP

0 项奖励
回复

1,504 次查看
trytohelp
NXP Employee
NXP Employee

Hi

Attached you will find an example using sprintf() running on simulator.

A bkpt should be placed at the end of test_printf function.

Hope this will help you.


Have a great day,
Pascal
Freescale Technical Support
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复