2024-11-15 10:31 AM
I am trying to use pin PA8 as a PWM output using timer 1 on channel 1 for a stm32f103rct6. I have successfully programmed pins PA9, PA10, and PA11 to provide PWM output on channels 2, 3, and 4, but when I do the same for PA8 on channel 1, I do not get any output. I am pretty sure that the pin works because if I manually toggle it on and off it works fine.
Is there something special about this particular pin? I do see that that pin can be configured as MCO and if I do that, I do see an 8mhz signal. But when I am using it for PWM is is not configured in that way.
Could there be some kind of conflict with other pins?
Any insight would be appreciated.
Thanks.
Solved! Go to Solution.
2024-11-15 04:12 PM
Ok, I found the problem (it is actually a wonder that it worked at all). In one part of the initialization I was using the structure TIM_OC_InitTypeDef and I was only setting some of it's members before calling HAL_TIM_PWM_ConfigChannel (note that I was just using code that I found). This, of course, meant that the other fields had uninitialized values. Apparently when initializing PA9, PA10, and PA11, as luck would have it, those uninitialized values did not cause a problem. However when using PA8 they, for some reason, did. I now set the entire structure to zero before I set the values and this fixed the problem. I do wonder, however, what the other fields are for and if setting them to zero is the correct action.
My thanks to anyone who looked into this problem.
2024-11-15 11:04 AM
Prepare a minimal but complete compilable example exhibiting the problem, and post.
JW
2024-11-15 11:11 AM
As a test, I disabled the output on all of the other pins except for the Oscillator, UART4 and Debug, and PWM output on PA8 still does not work. Do I conclude from this that there must be something wrong with the chip?
Thanks
2024-11-15 11:26 AM
Here is the test project. For this project the only pins that are enabled are the Oscillator, UART4, DEBUG, PA8, PA9, PA10 and PA11. It is currently set up to output a PWM signal on PA8 (line 15 of Robot.cpp) and this does not work. If I have it use PA9, PA10, or PA11, it does work.
Thanks for the help.
2024-11-15 04:12 PM
Ok, I found the problem (it is actually a wonder that it worked at all). In one part of the initialization I was using the structure TIM_OC_InitTypeDef and I was only setting some of it's members before calling HAL_TIM_PWM_ConfigChannel (note that I was just using code that I found). This, of course, meant that the other fields had uninitialized values. Apparently when initializing PA9, PA10, and PA11, as luck would have it, those uninitialized values did not cause a problem. However when using PA8 they, for some reason, did. I now set the entire structure to zero before I set the values and this fixed the problem. I do wonder, however, what the other fields are for and if setting them to zero is the correct action.
My thanks to anyone who looked into this problem.