Finding period of a square wave using Input Capture

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

Finding period of a square wave using Input Capture

跳至解决方案
1,785 次查看
MO_84
Contributor III

I'm trying to find the period of a external square wave using the input capture interrupt.

There is one line of code causing the below error message and its driving me mad. The error is caused by the following line:

    actual_period = period/6000000;

 

The code works fine if I remove this line. But then I have to use a calculator to find the actual period every time.

Please Help. I'm not a very good programmer.


Here is the error message:

 

C4000: Condition always TRUE

main.c line 35   

Link Error   : L1822: Symbol _FSFLOAT in file C:\Documents and Settings\Mo\Desktop\Lakehead_U\Project\Input Capture\input capture\input_capture_Data\Standard\ObjectCode\main.c.o
is undefined


Link Error   : Link failed

 

 

Here is the code:

 

 

#include <hidef.h>      /* common defines and macros */#include "derivative.h"      /* derivative-specific definitions */volatile unsigned int rising, period;volatile unsigned int flag;#pragma CODE_SEG __NEAR_SEG NON_BANKED /* Interrupt section for this module.Placement will be in NON_BANKED area. *//* Interrupt on a rising edge of waveform connected to PT0 */interrupt void toc0_isr(void){       flag ++;    if(flag == 1)       rising=TC0;      if (flag == 2)    period = TC0 - rising;        if (flag == 3)    flag = 0;    }#pragma CODE_SEG DEFAULTvoid input_capture_initialize(void); /* prototype to initialize input capture */void main(void) {                             float actual_period;    DDRT = 0xFE;    /* PT0 is input, all the rest are unchanged */    flag = 0;    input_capture_initialize();    EnableInterrupts; /* clear I bit of CCR */    while(1)    {       actual_period = period/6000000;    }      }            void input_capture_initialize(void){  TSCR1=0x90; /* enable timer and fast clear, rather than writing to bit0 of TFLG1 */  TSCR2=0x02; /* prescale to 4  6000000 pps, longest pulse width measured using*/                  TIOS=0x00;  /* select input capture (all channels) */  TCTL3=0x00; /* capture disabled on channels 4 to 7 */  TCTL4=0x01; /*PORTT0 capture on rising edge, channels 1 to 3 disabled */  TIE=0x01;   /* enable timer interrupt on C0 */}

 

 




标签 (1)
0 项奖励
回复
1 解答
1,105 次查看
kef
Specialist I

_FSFLOAT is integer to float conversion routine. Clearly you told project wizard you don't want floating point. You probably selected 'None' for promised best code density :smileyhappy:. You should either 1) recreate project and select double is 32bits or 64bits, but not None. Or 2) remove integer only ansixxx.lib from your project, read <CW root>\lib\hc12c\readme.txt and add appropriate library with FP support.

 

  

volatile unsigned int period;
    float actual_period;
 

       actual_period = period/6000000;
 

Clearly actual_period will be always 0.0. To make it not zero, you should typecast dividend, divisor, or both them to float.

 

       actual_period = (float)period/6000000;

 

 

P.S. Subject has very little to do with the problem. "undefined _FSFLOAT" would be better. But again, it is a Codewarrior usage issue, not 16-bit MCU. Please use right forum next time.

在原帖中查看解决方案

0 项奖励
回复
2 回复数
1,106 次查看
kef
Specialist I

_FSFLOAT is integer to float conversion routine. Clearly you told project wizard you don't want floating point. You probably selected 'None' for promised best code density :smileyhappy:. You should either 1) recreate project and select double is 32bits or 64bits, but not None. Or 2) remove integer only ansixxx.lib from your project, read <CW root>\lib\hc12c\readme.txt and add appropriate library with FP support.

 

  

volatile unsigned int period;
    float actual_period;
 

       actual_period = period/6000000;
 

Clearly actual_period will be always 0.0. To make it not zero, you should typecast dividend, divisor, or both them to float.

 

       actual_period = (float)period/6000000;

 

 

P.S. Subject has very little to do with the problem. "undefined _FSFLOAT" would be better. But again, it is a Codewarrior usage issue, not 16-bit MCU. Please use right forum next time.

0 项奖励
回复
1,105 次查看
MO_84
Contributor III

Thank you very much.

The problem is fixed.

 

I will try to use the proper forum next time.

0 项奖励
回复