cancel
Showing results for 
Search instead for 
Did you mean: 

GPIO output pulse stability

Lorenzo38
Associate

Hello,

I'm using the STM32H723 (at 550MHz) to generate pulses on a GPIO output at a certain frequency (around 4KHz)

I'm generating the pulses with assembly code. I've stopped systick and interrupts. However, looking at the signal with a scope, I'm discovering that the frequency is not fixed, moving around the desire frequency. I've tried both with external cristal or internal HSI. Same result.

What is the reason ? Is there a possibility to stabilise the output signal ?

Thanks for your help,

Laurent

 

1 ACCEPTED SOLUTION

Accepted Solutions

On the contrary, this is easy to do in PWM but rather impossible in assembly for the reasons outlined before. Note that "writing" to an address doesn't take effect immediately. This is a big fancy complicated chip, with complicated pipelines and busses, and it needs to be to run at 550 MHz. No way around this. This may be done somewhat easily on a cortex-M1 or cortex-M4 chip where you can rely on instructions taking a known amount of cycles. Not so on the M7 (STM32H7) or M55 (STM32N6).

> my complete need is to produce 2 square signals (with variable duty cycle), the second one being shifted by 180° wrt the first signal

Ways this could be done:

  • Two timers with one channel each. Synchronize the start of the timers.
  • Two channels on one timer in Combined PWM mode.
If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

4 REPLIES 4
TDK
Super User

Use a timer PWM channel to generate a steady pulse.

 

Using the CPU in this manner will always have some jitter. How much variation are you seeing? Should be able to get edge timing down below 1us if that's all you're doing with the CPU. HSI will also introduce a small amount of jitter. HSE (from a crystal or oscillator) will be more accurate.

If you feel a post has answered your question, please click "Accept as Solution".
Lorenzo38
Associate

I see a variation of 1 to 4 Hz around the 4KHz frequency. Same result with HSE. I'm doing nothing else with the CPU.

I've also an STM32N657, producing also jitter, but depending on the CPU clock : at 400MHz, I saw a real stable signal, but at 600MHz there was quite some jitter.

However, my complete need is to produce 2 square signals (with variable duty cycle), the second one being shifted by 180° wrt the first signal. Easy to do in assembly code. Not with PWM ?

Regards,

Laurent

On the contrary, this is easy to do in PWM but rather impossible in assembly for the reasons outlined before. Note that "writing" to an address doesn't take effect immediately. This is a big fancy complicated chip, with complicated pipelines and busses, and it needs to be to run at 550 MHz. No way around this. This may be done somewhat easily on a cortex-M1 or cortex-M4 chip where you can rely on instructions taking a known amount of cycles. Not so on the M7 (STM32H7) or M55 (STM32N6).

> my complete need is to produce 2 square signals (with variable duty cycle), the second one being shifted by 180° wrt the first signal

Ways this could be done:

  • Two timers with one channel each. Synchronize the start of the timers.
  • Two channels on one timer in Combined PWM mode.
If you feel a post has answered your question, please click "Accept as Solution".
Pavel A.
Super User

For explanation why please look here: http://efton.sk/STM32/gotcha/g14.html

Easy to do in assembly code. Not with PWM ?

Even if not easy - still not rocket science. Please look for PWM examples or ask your favorite AI. More help with STM32 programing is available here.