2022-05-12 08:46 AM
When I make a timer,
1 ms error happens per every 1 s.
How can I revise it?
I'm using Necleo-wb55 and "TIM16"
The Prescaler is 31999 / 32000 (both are tested).
2022-05-12 09:07 AM
if I give HAL_Delay(100), the 1ms error happens every 100 ms... is it depends on the printf() commend?
2022-05-12 09:14 AM
Best way to debugg this is by toggling on/off a LED or a gpio.
Measure the 1Hz signal with your favourite oscilloscope and voila!
No need for non deterministic printf()
2022-05-12 09:21 AM
HAL_Delay(100) is not the best way to create accurate delays.
Try setting a Timer interruption to be triggered every 1 seconds.
2022-05-12 10:08 AM
How is your clock setup HSE or HSI ? Too HAL_Delay is sw implement , can have error.
Next HAL_Delay is based on tick int (systick or TIM) usw.
2022-05-12 07:29 PM
The current version is using 32 MHz HSE. I found that the interval of printf() is about 300 us. but I don't know whether it is due to the printf() or other scripts.
2022-05-12 07:31 PM
My system should work within 1 ms.....so, I'm using a timer to evaluate the speed of the script. but it has 300 us delay for each print() for USB USART communication. So, I'm confused about which speed I should believe or whether the system can be faster.
2022-05-12 11:54 PM
There are 3 600 000 milliseconds in an hour. Even if your crystal has a tolerance of 1ppm, 3.6ms error can be considered normal.
https://www.digikey.com/en/products/detail/connor-winfield/DOCSC012F-010-0M/13422056
for example if you use this oscillator there is a possibility of 1ms error in 27.8 hours
or
https://www.digikey.com/en/products/detail/connor-winfield/OH320-CC-700503CF-010-0M/13687442
If you use this oscillator, there is a possibility of 1ms error in 555.6 hours.
The real question is, is it worth it?
2022-05-13 12:32 AM
The fact that you called your code "script" makes me think you come from high level programming.
>My system should work within 1 ms
but it doesnt
>I'm using a timer to evaluate the speed of the script. but it has 300 us delay for each print()
Dont use a printf, use a HAL_gpio_toggle() inside the 1Hz timer ISR function.
>which speed I should believe or whether the system can be faster.
believe the speed you see in your oscilloscope, toggle gpios not printf to measure speed
2022-05-13 06:54 AM
1ms plus or minus ???
Read HAL_Delay code
__weak void HAL_Delay(uint32_t Delay)
{
uint32_t tickstart = HAL_GetTick();
uint32_t wait = Delay;
/* Add a freq to guarantee minimum wait */
if (wait < HAL_MAX_DELAY)
{
wait += (uint32_t)(uwTickFreq);
}
while ((HAL_GetTick() - tickstart) < wait)
{
}
}
write your own code ...