2020-07-10 02:04 AM
I have set up a timer to generate a given waveform using the capture-compare register, fed from DMA. The OCxREF output is set to TOGGLE mode. The waveform consists of a pattern, repeating n times, after each ARR update. A new pattern is loaded into DMA every n cycles.
Everything works, except for the fact that:
It would help if:
I am losing the will to live! Any ideas? I can share code if that helps.
2020-07-13 07:21 AM
Gents (@alister @Community member ),
Many thanks for your input. I have fixed the issues in the following way.
In addition, I do the following:
TIMx->CR1 &= ~TIM_CR1_CEN; // Disable the master timer
TIMx->CR1 |= TIM_CR1_UDIS; // Update disabled. UG resets CNT/PRESCALE
TIMx->EGR |= TIM_EGR_UG;
// wait until the RESET of UG bit
while((TIMx->EGR & TIM_EGR_UG) == SET){}
TIMx->CR1 &= ~TIM_CR1_UDIS; // Update enabled
All of these factors together seem to give the desired result.
I am still not completely clear as to why I first need to do the 5us interrupt timeout. @alister , it may be that your suggestion above would work instead.
I may yet post again on this topic, in an attempt to get final, full clarity.
2020-07-13 01:35 PM
> Finally, the timer UIF is reset bitwise (&= ~UIF), rather than my previous lazy use of TIMx->SR=0 (!)
Don't use RMW (&=) to clear TIMx_SR bits, use direct write.
JW