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 |
Solved! Go to Solution.
Hello,
The Init_FTM component works for your purpose, first you select the Init_FTM component:
Then, configure the FTM component and the channels that you will use:
Finally, you can see the functions that Processor Expert provides in the tab Components.
I hope this helps. Please let me know if this works for you.
Best regards,
Earl.
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.
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
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?
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.
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)
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.
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.
and regarding Reset
I guess by selecting option "yes" we are disabling watchdog.
I also tried by enabling watchdog component
but neither option helped, issue still remains.
Thanks for your support.
Hello,
The Init_FTM component works for your purpose, first you select the Init_FTM component:
Then, configure the FTM component and the channels that you will use:
Finally, you can see the functions that Processor Expert provides in the tab Components.
I hope this helps. Please let me know if this works for you.
Best regards,
Earl.
Thanks Earl for your support.
Thanks Orlando, it helped.
But still there is some error - frequency provided at the input and counts captured.
Let me re look into calculations.