cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Precision measure period of a signal

Bogdan
Senior
Posted on February 26, 2017 at 20:30

Hello all,

i need to measure an external clock source of 32768hz  with little variation as posible... this means to measure as true as possible,  with variations  maximum of +/- 2hz ...

Is this achievable with  input capture feature of a 32bit timer from the stm32f4?

From the hardware point of view, i was thinking to buffer the input with a opamp  just for impedance adaptation, and the output of the opamp to go into the timer channel

5 REPLIES 5
S.Ma
Principal
Posted on February 26, 2017 at 20:57

My two cents here: To measure a frequency precisely, one reference is needed such as a crystal as HSE.

For measuring the 2^15 Hz frequency, there would be different ways. To keep various ways, use a timer CH1 which can be used for input capture or timer clock. If the measurement can take one second, I would start to use HAL_Delay(1000) for 1 second delay as interrupt source. First interrupt, would start a measurement timer using 32kHz as clock source to a timer.

Second interrupt (1 second later), would simply read the timer count value which is the answer in hertz. Precision should be good enough vs interrupt jitter in microseconds. 

Alternate way: With input capture, use a HSE based source for the timer (with minimum prescale value) and prescale the input capture source to make the input capture interrupt frequencly reasonably long (and precise). Capture twice, substract and get the period for X input prescaled pulses.

T J
Lead
Posted on February 27, 2017 at 01:05

some of the F4 series processors run at 84MHz upto 168MHz

the clock input to the timers is ...  APB2 timer clocks can run upto 168MHz... APB1 timer clocks are only 84MHz

when I select the clock source in cube MX, there is only a selection of 'internal clocks' not sure which timer uses APB2...

assuming 0 pre-scaler on that timer input, it will count at 168MHz maximum.

168E6 / 32768  = 5125 counts per cycle.

yes, you can use the timers to check the crystal easily

I don't think you can access the RTC clock within the processor..  but maybe someone can answer that question.

you must  buffer the clock signal with an opamp, and take it into a Input capture pin.

your opamp selection must be very high impedance, like JFET input, and you may want to add a 10MOHM resistor in series, so not to load the crystal..

you have the added jitter on the pin sample clock. which may be only 48MHz, not sure there...

so you will see the counts jump around to a few constant numbers, like 5125, 5125, 5117, 5125, 5133, 5125

something like that anyway...

this will be the limit of your resolution, which includes this pin jitter.

if you need more than that, then you can find a High resolution timer, some other  ST processors can resolve to 215pS...

AVI-crak
Senior
Posted on February 27, 2017 at 01:11

Welcome to the world of temperature-controlled quartzes (OXCO), 50-500 euros.

The quartzes made on OXCO technology - maintain temperature of working area at highly stable level, about 25C.

Quartz and the generator are in the first small metal container. This container is welded on an element to a peltya, further on a transitional ceramic payment with elements of management of temperature and control of parameters of the generator. Everything from above is protected by the metal case, it is also the heat sink. There is no air, net vacuum.

The element to a peltya heats or cools the generator so that its temperature doesn't change, admissions on the 100-th shares of degree. Due to maintenance of ideal temperature, and almost ideal conditions of fluctuations of the crystal - accuracy at the level ±0,01ppm.

It is very close to the atomic standard. In the sense that the following step of accuracy - the atomic clock.

All the rest very strongly lies, the method won't be important.

Posted on February 27, 2017 at 01:14

the DS3232 has a TXCO on board, they suggest a maximum accuracy of about 2 minutes per year over a temperature range..

the main problem with crystal drift is humidity effecting the capacitance, so conformal coating the capacitors after drying, will help keep it stable over time.

Bogdan
Senior
Posted on February 27, 2017 at 03:53

Thank you all for sharing your ideas,  Ok so from what i seen, its desired for acuracy to use 'external count/trigger signal'... The idea with with OXCO is intresting, i will buy one and see what happens...

Just to have a idea of where this story started.... it happens  in a production test equipment where i measure RTC signal of the tested pcbs 'DUT'... and the measurment is done with a agilent counter ....  since my wiring from the fixture has about 2 meters of coaxial cable, plus routing via switching matrix... i get a lot of overshoot + parasitic capacitance  over the original signal which is afecting the measured signal value which keeps varying from the nominal value (32768) by +/- 20hz...

So from this , i was thinking of placing a 'local counter' inside the test fixture as close as posible to the measuring probe... a small pcb with a stm32f4 device + minimum required hardware... and send the measured value via usart protocol to the test software