2023-09-26 07:44 PM
I tried to change PWM output duty without stopping or suspending PWM output, but between two times of writing new value to CCR, there must be a delay time inserted in. Following is the example code:
/* if delay_ms(300), code can run correctly, if changing it to delay_ms(200), a hardfault would occur
2023-09-26 10:53 PM
2023-10-08 05:57 PM - edited 2023-10-08 05:59 PM
Hello,
Thanks for your reply!
I really want to know why this happens. Is there something wrong within my code or it a bug of the chip.
2023-10-08 06:35 PM - edited 2023-10-08 06:35 PM
How is delay_ms implemented? It is not a HAL function.
2023-10-09 01:15 AM - edited 2023-10-09 01:16 AM
__HAL_TIM_SetCompare() just writes a value to TIMx_CCRx, so there's something else which throws the fault, not this function.
Do you have some sort of interrupt bound to this timer channel? If yes, maybe start there.
And, debug as usually hardfaults are debugged, i.e. observe stacked values of registers, mainly PC, observe disasm few lines before the value of PC, etc.
JW