Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 2 months ago.
Why does not work the pwm_2 exmaple with Timer 2?
Hi,
I am using the Nucleo_ pwm2 example to try all the PWM outs in the Nucleo-F302R8 board. I have been able to make all the PWM outs work except the PWMs related to Timer 2. I mean, I have tried with this code:
<<#include "mbed.h"
DigitalOut my_led(LED1); InterruptIn my_button(USER_BUTTON); PwmOut my_pwm(PA_0);
void pressed() { if (my_pwm.read() == 0.25) { my_pwm.write(0.75); } else { my_pwm.write(0.25); } }
int main() { Set PWM my_pwm.period_ms(10); my_pwm.write(0.5);
Set button my_button.fall(&pressed);
while (1) { my_led = !my_led; wait(0.5); 500 ms } }>>
But when I use a pin which the PWM works using the Timer 2 I can not make it work. I have made it successfully with Timer 1 (PC_0, PC_1, PC_2...), Timer 15 (PB_14,PB_15...), Timer 16 (PB_4, PB_8...), Timer 17 (PA_7, PB_9...) but if I try with Timer 2, does not matter the pin I use because it does not work (PA_0, PA_2, PA_3,PA_5...)
Anyone knows why this does not work? How can I use these PWM outs? Is this happening because the Timer 2 is the only timer which uses 32 bits and it needs a special configuration?
Regards.
1 Answer
9 years, 2 months ago.
On the Nucleo F302R8 TIM2 is used as the system microsecond ticker and is thus unavailable for other uses.
Ok David,
Thank you very much for your answer because I was getting a little bit crazy with this matter.
But I have another question, what about if I am working only with the microcontroller separately (STM32F302R8T6)? Because in the datasheet says that the Timer 2 has 4 channels that you can use as PWM outs:
Channel 1 ==> PA_0, PA_5, PA_15
Channel 2 ==> PA_1, PB_3
Channel 3 ==> PA_2, PA_9, PB_10
Channel 4 ==> PA_3, PA_10, PB_11
How could I do that? I would be very grateful if you can help me.
posted by 09 Oct 2015