2025-07-16 5:17 AM
I've encountered a problem, when my software CC1 generation flag produces IRQ but don't change GPIO output level on STM32F401CCU6. In my programm I'm frequently recalculating TIM11->CCR1 value (no preload on CCR1) in another timer IRQ (TIM5 update event). And sometimes in TIM5 IRQ after TIM11->CCR1 calculation I'm getting TIM11->CNT > TIM11->CCR1. To prevent rolling over and time lag I'm checking for this and if it's true I'm calling for TIM11->EGR |= TIM_EGR_CC1G;. It triggers IRQ but, however, doesn't change GPIO output level. Didn't see mentions of that behaviour in DS/RM. Is this behaviour okay? I'm forced to use no preload on CCR1 to increase response of TIMER when value changes.
Best regards, Alex.
2025-07-16 6:24 AM
Why are you expecting it to change the output level? How is the timer configured? Show the relevant code.
2025-07-16 6:47 AM - edited 2025-07-16 6:48 AM
1. Because it's probably supposed to? What's the point of software generation of IRQ with no 'side effect' from hardware periphery if I can change register values on the go (almost on all, which are not prohibited or using preload)?
2. Configured as TIMER with OC function. What actual bits/registers you interested in? And in what TIMER? Attached screenshot from codegenerator for TIMER with OC function (TIM11). Using CMSIS obly ended with same behaviour.
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if(htim->Instance == TIM5) //should be every 10 ms
{
if((axisSystem.aAxis.currentVelocity + axisSystem.aAxis.accelVelocityStep) < axisSystem.aAxis.targetVelocity) //need to accelerate to reach target velocity
{
axisSystem.aAxis.currentVelocity += axisSystem.aAxis.accelVelocityStep;
TIM11->CCR1 = (uint32_t)(.5f * TIM11_FREQ * axisSystem.aAxis.distancePerRevolution
/ (axisSystem.aAxis.pulsesPerRevolution * axisSystem.aAxis.currentVelocity));
if(TIM11->CNT > TIM11->CCR1)
{
TIM11->EGR |= TIM_EGR_CC1G;
}
}
}
}
Please note that only part of code is given (it's like 3k lines only in handlers). In TIM11 (OC elapsed callback) only some varables are incremeted and performed boundary check for that variables