cancel
Showing results for 
Search instead for 
Did you mean: 

Frequency measurement with COMP1 and TIM2 NUCLEO-144 H723ZG board

Louie88
Associate III

I have NUCLEO-144 H723ZG board. 

I created a frequency meter app for the NUCLEO board, but the quality of the frequency measurement a sinusoidal voltage is very poor. I have a generated 720mV RMS, 126.7Hz signal between 0 and +2.5V (max) biased to +1.25V. On scope, the frequency meter connected to the output of the COMP1 shows 126.700x, the 4th digit is 1 or 0. The NUCLEO board measures almost 1Hz less than the frequency meter on scope (I checked it with a real frequency meter and the scope value is right).

My other problem is that the minimum value of the frequency = 125.451, the maximum value = 125.9264Hz, the average = 125.7246 and the standard deviation = 0.0775Hz. I could not measure the frequency as good as a simple scope.

Setup:

I enabled COM1 comparator. I connected the input sine voltage to the positive input (COMP1_INP) and I connected the negative input (COMP1_INN) to the +1.25V reference voltage to which the input signal is biased. With setting the COMP1 speed to “COMP_POWERMODE_HIGHSPEED�? I got terrible output voltage. Both edges of the output are bounced (200-250 spikes) at least 1-3us. Then I set the COMP1 speed to “COMP_POWERMODE_MEDIUMSPEED�? and I got only a couple of spikes. Then I set the COMP1 speed to “COMP_POWERMODE_ULTRALOWPOWER�? and I got no spikes. The hysteresis was always set to “COMP_HYSTERESIS_HIGH�?. Why? Can somebody explain it?

I connected the comparator output with a wire to the Capture Channel 1 input of the 32-bit TIM2. The timer runs on 275MHz (3.636ns) as a simple up counter, with ARR = 0xFFFFFFFF, Prescaler = 0. It is started with HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_1);

When rising edge of comparator detected on the Capture CHN1 input of TIM2 then TIM2 captures the value its 32-bit counter and calls the HAL_TIM_IC_CaptureCallback(). I read the capture 1 register and store the value in last period count if this is the first interrupt. It this is not the first interrupt then I subtract the current count from the last count (I also update the last value register to the current one). This is the period time in counts. I set a flag in the callback function to signal that I measured a new period time count. In the main() loop when this is true then I simply divide the 275MHz TIM2 clock with the period count. This is my measured frequency. Because I don’t have LCD and send it via serial port to the terminal APP of my notebook. The application runs continuously.

Even though this is a simple period time measurement I cannot not answer the following two questions.

  1. Why do I have so poor quality of the measurement? (See attached log picture)
  2. Why does the calculated frequency 1Hz less than the input signal frequency? This around 1Hz inaccuracy is constant. I can use any frequency it measures 1 Hz less. XTAL frequency problem? Or this is the side effect 2MHz * 275 with the PLL1?

Can somebody help. (Sample app for NUCLEO-144 H723ZG board is available if needed)

Thanks for any help, any idea.

Louis

21 REPLIES 21

Thanks Peter, I ordered the crystal and the caps (6x) from DIGI-KEY: $5 the price, $30 the shipping + $8 VAT. (The whole NUCLEO board was less than $30) We do not want to use NUCLEO board in production, we just use it in a prototype transmitter. We designed a motherboard, with all the extra circuits we need and the NUCLEO board will be plugged into the motherboard. This concept worked many times in the past. If the prototype transmitter will pass all the tests then we will design own custom board. By the way it would nice to know how ST supports designing custom boards...

Regards,

Louis

STMicroelectronics supports the development of custom boards by providing the tools to do so: software like STM32CubeIDE (completely free of charge) and hardware like DISCOVERY, NUCLEO and EVAL boards. This means that you can already start developing your own software without having to wait for the layouter or the board manufacturer.

Does it answer your question?

Otherwise, it would make sense to open a separate thread for this, as it is a new topic.

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

I meant designing the PCB, but you are right this is a different topic.

Thanks

Louis

Hi @Peter BENSCH​ ,

Can't the STLinkV3 switched to output HSE/3=8.33MHz as outlined in https://community.st.com/s/question/0D53W00000j62rkSAA/how-to-change-the-stlinkv3e-mco-hse-frequency ?

I don't have STLinkV3 to try but at least Clive appears to confirm that this is indeed possible.

Can you please try/confirm?

Jan

Oops, sorry, Jan is right.

Yes, with ST-LINK-V3E you can set the MCO output to one of three possibilities:

  • Default (HSI/2) = 8MHz
  • HSE/3 = 25/3 MHz
  • Off

I have already crossed out my statement above.

I apologise for forgetting this for a moment.

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Louie88
Associate III

Hi Peter,

Does it mean, if I select the HSE/3 check box in Help -> Upgrade ST-Link dialog box (and upgrade the firmware of ST-Link) then I will get 8.333 MHz crystal based clock? If so, then I have to modify the PLL settings because with the current settings it would generate 572.9166 MHz clock.

Thanks,

Louis

Yes, correct.

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Louie88
Associate III

Hi Peter,

It works! I have 1.00000kHz and the 5th digit is still stable.

0693W00000KdCdwQAF.bmp 

But the 25MHz/3 = 8.333333MHz cannot be set only to #define HSE_VALUE (8333333UL) (in the stm32h7xx_hal_conf.h file) so all the HAL_RCC_GetXXXClock() functions return a bit faulty frequencies. I do not understand why the 25MHz is divided by 3. Dividing by 4 would be better. This is 6.25MHz and 352 * 6,25MHz / 4 would still generate 550MHz. The #define HSE_VALUE (6250000UL) would be accurate and all the HAL_RCC_GetXXXClock() functions return right clock. Consider for the V4 version.

Thank you for your and jan's help. You saved the project.

Best regards,

Louis

Peter BENSCH
ST Employee
Great, excellent!
Maybe the software team will find another way to include the 25/4 and/or 25/5 option, let's wait and see.
Perhaps the 8.333MHz was choosen because that was closest to the MCO frequency of the older ST-LINK/V2 of 8MHz (HSI).
Regards
/Peter
In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi Peter,

Thank you very much and I appreciate your help.

Best regards,

Louis