2019-12-22 03:24 AM
2019-12-23 01:03 AM
> it looks like with each delay, it lasts 1ms more!
This is how HAL_Delay() works - it provides you a *minimum* N ms delay.
It looks at a timer which ticks continuously once in 1ms. So, when you call it, it looks at that timer's value, say it's K, and then waits until that timer rolls over from K+N to K+N+1.
If you happen to call it just moments before it rolls over from K to K+1, the delay will be just slightly longer than N ms. If you happen to call it slightly after it rolls over from K-1 to K, the delay will be just slightly shorter than N+1 ms.
JW
2019-12-22 06:50 AM
Well its worst thing to do if you want to generate pulse. For me it produced waveform with randomly changing period.
Set scope to capture single event, and set and reset pin once, not in loop. Also check clocks.
Try to use timer as pwm or just to toggle pin.
2019-12-22 08:50 AM
Make sure HSE_VALUE reports 8 MHz and not 25, and that the PLL and clock settings are correct.
2019-12-22 09:02 PM
Dear clive1
can you tell me in details what should I do?
should I set the HSE to Crystal/Ceramic Resonator?
what should I do in the CubeMX clock settings? like in the below image?
2019-12-22 10:13 PM
First enable HSE, in cubemx system RCC->HSE crystal resonator. Then go to clocks menu (image above). Change input frequency from 25 to 8, and check HSE option. Change HCLK to desired core clock and allow cubemx to recalculate all prescalers.
2019-12-22 11:23 PM
Dear Oeliks
I did as you said and I set the HCLK to 16, still it doesn't work
it looks like with each delay, it lasts 1ms more!
for example when I set HAL_Delay(2), for the pin PD12 to remain SET, it remains SET for 3ms!!!
WHY GUYS????
2019-12-22 11:45 PM
Sorry, cant help more.
For precise time base I use timers and interrupts. For no critical things I use delay. Mabey Clive1 can help more.
2019-12-23 01:03 AM
> it looks like with each delay, it lasts 1ms more!
This is how HAL_Delay() works - it provides you a *minimum* N ms delay.
It looks at a timer which ticks continuously once in 1ms. So, when you call it, it looks at that timer's value, say it's K, and then waits until that timer rolls over from K+N to K+N+1.
If you happen to call it just moments before it rolls over from K to K+1, the delay will be just slightly longer than N ms. If you happen to call it slightly after it rolls over from K-1 to K, the delay will be just slightly shorter than N+1 ms.
JW
2019-12-23 01:27 AM
THANKS Dear waclawek.jan!
It was a big help!:folded_hands: