cancel
Showing results for 
Search instead for 
Did you mean: 

Range of frequency counter is being limited. Why?

Raahul Jagannathan
Associate II
Posted on June 14, 2018 at 07:38

The original post was too long to process during our migration. Please click on the attachment to read the original post.
9 REPLIES 9
Posted on June 14, 2018 at 09:59

If I understand correctly, you are trying to count pulses of  the measured signal in TIM2, gated by TIM21, set to 1 second period, correct?

As TIM2 is 16-bit only in 'L0, this cannot work higher than up to 65.535kHz. The demo you are mentioning, hasn't it been demonstrated on a different STM32 model?

You have to change your approach. There are many ways to do that. One of them is described here:

https://community.st.com/0D50X00009bMMA8SAO

 

JW

Posted on June 14, 2018 at 10:16

Thank you so much for the response. I know that the counter is only 16-bit. I can measure proper values upto 65KHz. After this, my OLED display shows me the overflow. This continues upto 72Khz. After this value, the frequency directly goes to 0. It does not record anything. That is what is confusing me.

Posted on June 14, 2018 at 10:56

As for the demo, it is for the STM32L053C8. It is able to measure frequency in MHz as well. And when I say overflow, I mean to say that it actually displays the difference between the actual frequency and 65535. I can easily print the right value for this as well. But what I am not able to understand, is why no frequency is measured after 72KHz.

Posted on June 14, 2018 at 11:18

can you rearrange your code ?

here is your error, commonly understood as a code 9

Raahul Jagannathan wrote:

/* USER CODE BEGIN 2 */

HAL_TIM_Base_Start(&htim2);

HAL_TIM_IC_Start(&htim2, TIM_CHANNEL_1);

HAL_TIM_Base_Start(&htim21);

HAL_TIM_OC_Start(&htim21, TIM_CHANNEL_1);

for high frequency you should configure a timer/counter as a counter.

count the pulses in 0.1seconds, and calculate the frequency.

the limit there is 1/2 input pin clocking frequency

what is the maximum pin clock frequency ?

what page in the reference manual are you on ?

Posted on June 14, 2018 at 11:27

Thank you for replying. I am not able to understand what you want me to do. If you could type out exactly what I am to change, it would be great. I did not have the time to look through the entire manual. I only read up on clocks and timers. 

Posted on June 14, 2018 at 12:00

for high frequency you should configure a timer/counter as a counter.

count the PIN pulses in 0.1seconds, and calculate the frequency.

initialise one timer to interrupt to exactly 0.1sec

initialise the other timer to count pin input edges.

in the 0.1Sec interrupt, subtract this count value for the last count value, to get a relative difference in counts per 0.1Sec.

Posted on June 14, 2018 at 12:05

I did that. It records values up to 72999. The value of the frequency becomes 0 after this.

Posted on June 14, 2018 at 12:43

Raahul Jagannathan wrote:

I did that. It records values up to 72999. The value of the frequency becomes 0 after this.

HAL_TIM_Base_Start(&htim2);

HAL_TIM_IC_Start(&htim2, TIM_CHANNEL_1);

HAL_TIM_Base_Start(&htim21);

HAL_TIM_OC_Start(&htim21, TIM_CHANNEL_1);

that is not what I suggested.

Posted on June 14, 2018 at 12:58

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6vh&d=%2Fa%2F0X0000000by8%2F_dD_eVR1LjTF42RjcZ6UGruYRIaCNfWZfQ4dS96aiu0&asPdf=false