10 years, 5 months ago.

Strange behaviour of PWM on Nucleo

I made sure the firmware was updated on my Nucleo F030R8 board. I attached a common anode tri-colour LED between 5V with a 200 ohm resistor and D9, D10, D11. I can use RGB blinky code successfully with these o/p pins, but if I use PWM, then only red and green works - blue comes out as green. If I comment out the red code, then blue and green works OK. Can the mbed software only handle 2 PWM signals, and if using more it gets scrambled? Perhaps some pins are dedicated to a particular PWM signal - where can I find this info? Tony

Here is the code:

  1. include "mbed.h" change to o/p pwm to tricolour LED - afa - 3 June 2014

PwmOut redpwm(D9); PwmOut greenpwm(D10); PwmOut bluepwm(D11);

int main() { int i; redpwm.period_ms(10); greenpwm.period_ms(10); bluepwm.period_ms(10);

printf("pwm set to %.2f %%\n", mypwm.read() * 100);

while(1) { for (i=0; i<11; i++) { redpwm.pulsewidth_ms(i); wait(0.2); } for (i=0; i<11; i++) { greenpwm.pulsewidth_ms(i); wait(0.2); } for (i=0; i<11; i++) { bluepwm.pulsewidth_ms(i); wait(0.2); } } }

Apparently I am not allowed to answer my own question, but hopefully I can in this comment. It seems the answer is in the small print of the pinout diagram - if I change the blue LED from D11 to D12 it uses a different PWM signal - D9 and D11 apparently both share PWM3/2, whereas D12 uses PWM3/1. I did not understand what these names meant when I wrote the code, but now I realise any pins outputting a PWM signal need a different named one (the purple labels on the pinout).

posted by Tony Abbey 04 Jun 2014

1 Answer

Tony Abbey
poster
10 years, 5 months ago.

It seems the answer is in the small print of the pinout diagram - if I change the blue LED from D11 to D12 it uses a different PWM signal - D9 and D11 apparently both share PWM3/2, whereas D12 uses PWM3/1. I did not understand what these names meant when I wrote the code, but now I realise any pins outputting a PWM signal need a different named one (the purple labels on the pinout).

I have added some explanations here:

http://mbed.org/teams/ST/wiki/pinout_labels

posted by bco stm 05 Jun 2014

Assigned to Tony Abbey 10 years, 5 months ago.

This means that the question has been accepted and is being worked on.