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

Post here first, or if you can't find a relevant section!
Post Reply
changlin1990
Posts: 7
Joined: Tue Jan 23, 2024 6:52 am

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

Post 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 1465 times
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

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

Post 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);
changlin1990
Posts: 7
Joined: Tue Jan 23, 2024 6:52 am

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

Post by changlin1990 »

非常感谢你!
Thank you very much!
changlin1990
Posts: 7
Joined: Tue Jan 23, 2024 6:52 am

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

Post by changlin1990 »

analogWriteFrequency(1000);is to set the frequency of all PWM, how to set the frequency of 1 pin separately
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 26
Location: Prudnik, Poland

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

Post 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.
Post Reply

Return to “General discussion”