Page 1 of 1

I failed to output PWM with PA7 and PA8 at the same time

Posted: Tue Jan 23, 2024 7:18 am
by changlin1990
Problem description:
I failed to output PWM with PA7 and PA8 at the same time, but I succeeded in output PWM with PA7 or PA8 alone. Why? How to solve it?

Added:
I use STM32G030C8T6 and arduino IDE2.2.1.
As shown in the figure below, I guess the default PWM timer of PA7 and PA8 is TIM1, which leads to the above problem. Then how to change the default PWM timer of PA7, for example, to TIM3_CH2?
图片1.png
图片1.png (85.13 KiB) Viewed 1466 times

Re: I failed to output PWM with PA7 and PA8 at the same time

Posted: Tue Jan 23, 2024 8:44 am
by fpiSTM
PA7 have several other TIM:

https://github.com/stm32duino/Arduino_C ... .c#L95-L99

Simply use the suffixed _ALTx naming, example to use TIM3, use PA7_ALT1.
analogWrite(PA7_ALT1, 128);

Re: I failed to output PWM with PA7 and PA8 at the same time

Posted: Wed Jan 24, 2024 2:11 am
by changlin1990
非常感谢你!
Thank you very much!

Re: I failed to output PWM with PA7 and PA8 at the same time

Posted: Wed Jan 24, 2024 2:25 am
by changlin1990
analogWriteFrequency(1000);is to set the frequency of all PWM, how to set the frequency of 1 pin separately

Re: I failed to output PWM with PA7 and PA8 at the same time

Posted: Wed Jan 24, 2024 6:58 pm
by GonzoG
changlin1990 wrote: Wed Jan 24, 2024 2:25 am analogWriteFrequency(1000);is to set the frequency of all PWM, how to set the frequency of 1 pin separately
analogWriteFrequency(); changes frequency for next use of analogWrite(), but it will change frequency for all channels on a timer.
If you use 2 or more pins that use same timer for PWM, frequency will change on all of those pins.
One timer - one frequency.

If you want to use different frequencies, you need to use pins on different timers.