cancel
Showing results for 
Search instead for 
Did you mean: 

Generating PWM modulated sinewaves fails sometimes on some outputs - G431RBT6

Tobe
Senior III

I have setup Timer 8 to generate PWMs, to modulate a sinewave. I use preload, but that is only used once.

I have debugged and compared the registers, but i could not find a cause. I have also partially compared the sram bytes, but i could not find the cause there either. I checked my program too. But now after about 18 hours of searching i have to create this post.

Interestingly, it looks like the compare registers dont compare. But it looks to me, like the output is enabled (see picture). Sometimes, the complementary output stays high!

Before i post the code, i would like to know if someone knows of any hardware issues/difficulties.

A good idea how to troubleshoot this, would be welcome.

8 REPLIES 8

Read out and check/post content of TIM and relevant GPIO registers.

JW

I did, but i found no difference in the relevant ones, when it was working and when it was not (see picture). But after revisiting now, i dont know what DMAR->DMAB does.

LCE
Principal

I think what Jan also meant was:

How does your source code set things up? TIM & DMA (circular?) settings.

Please show relevant code, using the "</>" button.

In case you are using HAL: the timers are not that mystical, try using direct register access to better understand what's going on, set it up step by step.

I have now gotton further. I found out, that the problem appeared, depending of how the timer settings (preload) were before. I could constantly reproduce the issue when keeping them fixed. Then i found out, that after setting the preload values, with a delay of 150-200us, it works with any timer settings that there were before.

See picture attached.

I also tried disabling updates while changing settings, and update event via UG bit after chaning the setting. None fixed the issue.

See fail.txt for registers.

I never use HAL, except in the init or for testing purposes.

Tobe
Senior III

I have now created a minimum working code. The missing headerfile only contains millis(), delay() and such.

 

 

 

 

Tobe
Senior III

I have found another issue, that does not seem to be related, but maybe the chip is bad?

 

It seems, that there was some problem, that has been resolved with a power cycle. Neither this topics issue, nor the issue in the link does exist anymore. I wonder what has led to this issue.

My guess is, that is has something to do with the debug system. Somehow the setting of registers was blocked, or read wrong with the debugger.

https://community.st.com/t5/stm32-mcus-products/startup-time-of-nucleo-g431rb-varies-greatly/m-p/720594#M260937

Tobe
Senior III

Current test setup:

I reset the device every 590ms, and have a pwm input to the (hall-)input pin. The pwm input has a constant phase to the reset signal. Depending on the phase, there are freezes in the pwm signal more or less often, on one channel OR  the other, or even none at all. Interestingly, the fail/freeze rate of certain channels changes, if i disconnect the reset signal line, and connecting it back (the phase does not change).

The code has the delay removed again, to investigate this issue further.

Tobe
Senior III

After a lot of time used for tests, i dont really havent worked out what the problem exactly is here. It seemed to me, that writing twice to the preload register would drop the last written value. Since i changed my code, i will not test any further here.