-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expected bug in handling TIM3 (pulse width) in stepper.c #50
Comments
Сould you explain it in more detail? |
TIM3 is a timer used to fix the width of the step pulse. |
ok, you are absolutely right! I've checked it with logic analizer.
|
In TIM2_IRQHandler from stepper.c, after DIRECTION pins are written, interrupts on TIM3 are enabled with code
NVIC_EnableIRQ(TIM3_IRQn);
Still, TIM3->CNT is not reset to 0. As TIM3 was not disabled (only reset to 0 by his IRQ handler), CNT can have any value.
So we can't be sure that the step pulse will have the expected delay.
To solve this, I think you have to force a reload of TIM3 registers and clear interrupts just before enabling interrupt again.
So add
TIM3->EGR = TIM_PSCReloadMode_Immediate;
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
just before
NVIC_EnableIRQ(TIM3_IRQn);
Then, I think also that lines
TIM3->SR &= ~(1<<0); // clear UIF flag
TIM3->CNT = 0;
can be removed from TIM3_IRQHandler
The text was updated successfully, but these errors were encountered: