2015-12-02 01:28 AM
Hello there,
I was wondering either it is possible to count with microseconds resolution isntead of seconds resolution using RTC 32k clock? I am using HAL lib. In theRTC_TimeTypeDef time structure there are 2 members I dont quite understand:/*!< Specifies the RTC_SSR RTC Sub Second register content.
This parameter corresponds to a time unit range between [0-1] Second
with [1 Sec / SecondFraction +1] granularity */
uint32_t SubSeconds;
/*!< Specifies the range or granularity of Sub Second register content
corresponding to Synchronous pre-scaler factor value (PREDIV_S)
This parameter corresponds to a time unit range between [0-1] Second
with [1 Sec / SecondFraction +1] granularity.
This field will be used only by HAL_RTC_GetTime function */
uint32_t SecondFraction;
At the begining I thought I would be able to use them somehow to specify the time with more precision, but those values dont change.
I would apreciate all help in this case.
2015-12-02 06:32 PM
My recollection is that the HW works fine, and down counts.
2015-12-02 11:17 PM
But in this example HSI is used. When power is donw and only Vbat is left there is HSI as i recall. This wont work then. Is it possible to get more resolution from lsi 32k?
2015-12-03 03:26 AM
But in this example HSI is used...
Ok, HSE the STM32F4-DISCO doesn't have a LSE mounted, but it's illustrative, you're going to have to adapt things to your own needs. The take away is that the SubSecond is readable, and demarks time over the synchronous prescaler range. The usual settings for the LSE would give you 1/256th of a second units (~4ms), although I suspect you could play with the prescalers to get 1/1024th.2015-12-03 10:13 AM
I see, ill try that out tommorow. Thank you.
2015-12-04 02:32 AM
I am sorry, but I cannot figure out how to get the mSec part from the post you have posted. Could you help out?
2015-12-04 02:51 AM
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24; hrtc.Init.AsynchPrediv = 31; //127; hrtc.Init.SynchPrediv = 1023; //255; hrtc.Init.OutPut = RTC_OUTPUT_DISABLE; hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; HAL_RTC_Init(&hrtc); HAL_RTC_GetTime(&hrtc0, &sTime, RTC_FORMAT_BIN); HAL_RTC_GetDate(&hrtc0, &sDate, RTC_FORMAT_BIN); msec = 999 - (sTime.SubSeconds * 999 / 1023);2015-12-04 04:24 AM
msec = 999 - (sTime.SubSeconds * 999 / 1023);
Yeah, that doesn't look right, and wouldn't work on the SPL. SubSecond downcounts, in the range of the Synchronous Prescaler, ie 255..0 for a divide by 256 action #define SYNCPREDIV 256 .. RTC_InitStructure.RTC_SynchPrediv = SYNCPREDIV - 1; .. ms = (((SYNCPREDIV - 1) - SubSecond) * 1000) / SYNCPREDIV; Where 32768 = 128 * 256 = (127 + 1) * (255 + 1)2015-12-04 11:00 AM
2015-12-05 09:58 AM
Thank you for answers, ill try this monday morning.