cancel
Showing results for 
Search instead for 
Did you mean: 

chronometer... is the right way

Damiano
Associate II
Posted on April 15, 2016 at 18:17

Hi,

I'm building a time trial race, to do this i'm using the STM32F334R8T6 microcontroller with the RTC and timestamp, resolution must be of hundredths of a second, for this type of project is correct to use a RTC clocked at 32.768KHz?

Or to have a greater accuracy is convenient to use a 32-bit timer TIMER1 with HSE clock?

#rtc #timer #chronometer
4 REPLIES 4
Posted on April 15, 2016 at 19:31

I don't recall TIM1 being 32-bit

I probably wouldn't clock it at the processor rate, 1 MHz would clearly be more than adequate. Not sure the 32.768 KHz source has the granularity/precision you are looking for.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Walid FTITI_O
Senior II
Posted on April 15, 2016 at 20:14

Hi Lollo,

I rencommend that you refer to

http://www.st.com/web/en/resource/technical/document/application_note/DM00025071.pdf

''Using the hardware real-time clock (RTC)'', section ''Periodic timebsae/wakeup configuration for clock'' and choose which configuration between 2 and 3 is suitable to your case.

-Hannibal-

Damiano
Associate II
Posted on April 19, 2016 at 17:53

Thank you Clive1,

TIM2 is 32 bit not TIM1,

in AN3371 page 9/45, to obtain an internal 

clock frequency of 1 Hz (ck_spre) 

LSE = 32.768 kHz

PREDIV_A = 127

PREDIV_S = 255 (for some product max 13bit = 8192)

LSE = 32.768 kHz

PREDIV_A = 0

PREDIV_S = 32767 (in my case max 0x7FFF, see note)

HSE_RTC = 1MHz

PREDIV_A = 124

PREDIV_S = 7999

i use 32.768 KHz to obtain best precision

Fraction second = 1000 - (RTC->SS)*1000)/(RTC->SynchPrediv)

1/32767 = 30.52 uSec

with HSE_RTC = 1MHz

Fraction second = 1000 - (RTC->SS)*1000)/(RTC->SynchPrediv)

1/7900 = 126.58 uSec

So if i right with RTC peripheral i only had 30.52 uSec precision,

for building a chronometer is better RTC or a program with 32bit timer?

NOTE:

UM1786 -> HAL RTC Generic Driver -> pag 570/861

uint32_t RTC_InitTypeDef::AsynchPrediv

Specifies the RTC Asynchronous Predivider value.

 This parameter must be a number

between Min_Data = 0x00 and Max_Data = 0x7F

uint32_t RTC_InitTypeDef::SynchPrediv

Specifies the RTC Synchronous Predivider value. 

This parameter must be a number

between Min_Data = 0x00 and Max_Data = 0x7FFF

Posted on April 19, 2016 at 19:31

If I were building a reasonably time critical system, I'd use the 32-bit counter, and a TCXO rated at a few ppm.

Running at 1ms a 32-bit counter would wrap at around 49.7 days, at 0.1ms 4.97 days, and at 0.02ms just shy of a day.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..