3 years, 4 months ago.

How to invert two PWMs of two channels by mbed compiler?

First, Thank you for let me to solve my past question successfully in here: https://developer.mbed.org/questions/77108/Does-mbed-compiler-can-program-these/ . However, I meet a problem again. In my past question , I used library 'FastPWM' and changed the program like image1 to ' FastPWM_STM_TIM.cpp' to make a invert PWM sucessfully. Now, I need to invert two PWMs of two channels now. I change program like image2 to ' FastPWM_STM_TIM.cpp' but two PWMs cannot invert. What's the problem? And how to solve it? Thank you. I use F334R8 board and completed to add pin's channels to 'FastPWM_STM_TIM_PinOut.cpp'. /media/uploads/zeroex123/2_pwms_problem.jpg

1 Answer

3 years, 4 months ago.

I think you are overwriting the CCER register with the second statement in image 2. You should probably use this to avoid that. PWM_TIMER->CCER | = TIM_CCER_CC2P;

But that might not be the only problem. If you are using two PWMs you need to check the Reference manual of the F334R8 for compatibility problems. Also if you call FastPWM twice do you overwrite some of the other registers setting up the second one?

Is there any mehod for output two invert PWMs? Or any way to output the result that I need? In my case, I need to output a invert PWM by channel 3, and then output a same PWM signal by channel 2 after a time, PWM of channel 3 to be 0 at same time, and then loop again (channel 3->2->3->2...). I forget to say that I do not need to output two invert PWMs at same time.

posted by so k 05 Apr 2017

You might try asking this question on the st forum. https://community.st.com/community/stm32-community/stm32-forum/content There are more experts in setting up the TIM registers there.

Did you see the answer to this question? https://developer.mbed.org/questions/6723/How-do-you-generate-complementary-PWM-Ou/ It shows how you can change the registers in main.cpp

posted by Ian Kilburn 07 Apr 2017