capture frequency+TRK-KEA128+Code Warrior

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

capture frequency+TRK-KEA128+Code Warrior

Jump to solution
1,401 Views
vijenad
Contributor III

Evaluation board - TRK - KEA 128

IDE - Code warrior, Ver 10.6.4

Activity: To capture Square Waves at pin PTC2 using Capture component in process expert

Issue: We were getting wrong in correlating the counter register value with the frequency fed at the input pin.

Need Support: How to calculate Frequency with the help of Counter register value

And

What is the significance of “maximum time event” and How to set it

Supporting Data

1. Clock Settings

2.     Code, I have used example code with small modifications, counter register value will get into variable “result”

for(;;)

  {

     if ((Cap1_GetEventStatus(CapPtr) & LDD_CAPTURE_ON_CAPTURE)!=0U){

            Error = Cap1_GetCaptureValue(CapPtr, &Data);

            current_data = Data;

            if(current_data > previous_data)

                   result = current_data - previous_data;

            else{

                   result1 = max_data - previous_data;

                   result1 = current_data + result; 

            }

            previous_data = current_data;

     }    

}

Frequency in Hz

Counter Register Value

100 Hz

43641

200 Hz

54600

300 Hz

14558

400 Hz

60074

500 Hz

48062

1 kHz

24030

5kHz

4803

10 kHz

2401

Labels (1)
0 Kudos
1 Solution
856 Views
EarlOrlando
Senior Contributor II

Hello,

The Init_FTM component works for your purpose, first you select the Init_FTM component:

pastedImage_1.png

Then, configure the FTM component and the channels that you will use:

pastedImage_3.png

Finally, you can see the functions that Processor Expert provides in the tab Components.

pastedImage_4.png

I hope this helps. Please let me know if this works for you.

Best regards,

Earl.

View solution in original post

0 Kudos
9 Replies
856 Views
EarlOrlando
Senior Contributor II

Hello Vijeendra,

Since the module is fed with a 20.971520 MHz clock, every count represents 1 / 20.971520 MHz = 47.683 ns. The issue here is that the counter is 16-bit width so the maximum count is 65535 which is equivalent to 3.125 ms which represents a 320 Hz signal. If you put a signal with a lower frequency the timer will be overflowed and you will get erroneous data. What you can do is to configure an overflow interrupt and play with flags to obtain a correct conversion.

Best regards,

Earl.

0 Kudos
856 Views
vijenad
Contributor III

Hello Orlando,

We want to be clear on the calculation part, then we want to look into the code.

Frequency expected range - 80 Hz to 5000 Hz ....it converts to 12.5 ms to 2 ms

pastedImage_1.png

Clock Source is Bus_CLK..... Presclaer is 32.....Low limit is 0.1ms......and High limit is 15ms.......(because that is our frequency range)

Module is fed with a 655.36 kHz, every count respresent 1/655.36 kHz = 1.52 uS.  So the lowest frequency I can read is 10 Hz.

Is it correct or does it lead to any error?

0 Kudos
856 Views
EarlOrlando
Senior Contributor II

Hello Vijeendra,

Yes, you are right with the calculation of the range, with this clock you will be able to count signals from 10 Hz to 655.36 KHz. (from 1.52 us to 100 ms). This is a correct configuration for your approach.

Regards,

Earl.

0 Kudos
856 Views
vijenad
Contributor III

pastedImage_0.png

pastedImage_1.png

Hello Earl,

We were able to have a demo with TRK-KEA 128 Evaluation board.

We are having few issues on our prototype board (As we were in bit hurry, we went for prototype board without evaluating on evaluation board)

Our design on prototype is

1. PTC3 is configured to capture frequency

2. PTC2 is configured to generate frequency

As Capture_LDD and PPG both uses same timer unit in FTM2 module, we are getting error in configuring.   Is there any way to use both Capture and PPG component with FTM2 module (we are using processor expert)

Another issue is with Reset

In debug mode, prototype board is functioning properly.

But in Flash mode, after flashing the code - we are getting 3uS low pulse at every 7.27 kHz frequency at the Reset Pin.

Then we tried by isolatling LM809 and 100K and tied Reset Pin to +5V through 1K resistor, but still the same issue.

(In processor expert, PTA5 is configured for RESET)

0 Kudos
856 Views
EarlOrlando
Senior Contributor II

Hello Vijeendra,

I recommend you to use a FTM instance and configure two channels, one as PWM and another as input capture. This won't cause you problems. The PPG is a very high level component so it is harder to configure when you need such level of customization.

About the reset issue, it seems that the WDOG is generating a periodic reset, please be sure that it is disabled (or properly configured). The reset pin is bi-directional, it goes low when the MCU is reset.

Best regards,

Earl.

0 Kudos
856 Views
vijenad
Contributor III

Hello Earl,

FTM iinstance - is it Init_FTM as shown in this snapshot or does the components is called with some other name in code warrior -  Version: 10.6.4

I guess its only for Initialization, but I didn't find FTM component in other folders.

I also refereed thread 358826.

pastedImage_0.png

and regarding Reset

pastedImage_3.png

I guess by selecting option "yes" we are disabling watchdog.

I also tried by enabling watchdog component

pastedImage_4.png

but neither option helped, issue still remains.

Thanks for your support.

0 Kudos
857 Views
EarlOrlando
Senior Contributor II

Hello,

The Init_FTM component works for your purpose, first you select the Init_FTM component:

pastedImage_1.png

Then, configure the FTM component and the channels that you will use:

pastedImage_3.png

Finally, you can see the functions that Processor Expert provides in the tab Components.

pastedImage_4.png

I hope this helps. Please let me know if this works for you.

Best regards,

Earl.

0 Kudos
856 Views
vijenad
Contributor III

Thanks Earl for your support.

856 Views
vijenad
Contributor III

Thanks Orlando, it helped.

But still there is some error - frequency provided at the input and counts captured.

Let me re look into calculations. 

0 Kudos