7 years, 10 months ago.

TIMERS AND PWM

Hello Everybody This is my first question here. I have a little experience with PIC microcontrollers of 8 and 16 bits but this environment is new form me, so here is my problem:

I want to be able to produce 6 independent PWM outputs for six servos and manage 1 TIMER for some LED without affecting any of these PWM outputs.

I have been looking the APIs Timer and PwmOut. The first one is useful now because I know which Timer it uses, but the second one is not useful for two reasons, because I don't know which timer it uses (could be the same as Timer library) and because I can't assign a PwmOut API for each timer. It would be great if some body tells me how to do something like PwmOut1 (using timer 1) PwmOut2(using timer 2) and so on... And finally use timer7 for the LED and just for the LED.

Thanks in advance

Humberto

1 Answer

7 years, 10 months ago.

I see you have the LPC1768 (useful info to have ;) ). The PwmOuts all share a single timer on this platform, and you have 6 possible outputs with independent pulsewidths but equal periods. So the PwmOuts cannot have different periods (shouldn't be an issue for servo control). You just make a PwmOut object on 6 different PWM pins.

If you just use a Timer/Ticker for the LED it will use another hardware timer, so you are fine. Since there are only 6 PWM outputs (although if you really want you can manually also use others for PWM), you cannot use an mbed PWM also for the LED.

Here is the specific source code of the LPC1768: https://github.com/mbedmicro/mbed/tree/master/hal/targets/hal/TARGET_NXP/TARGET_LPC176X. Mainly the pwm_api and us_ticker files will be interesting for you.

Accepted Answer

Hello Erik

Thanks for answering! For what I understood, I can control 6 PWM output (same period but different duty cycles at the same time) with PwmOut library and the LED using Timer/Ticker library without affecting any of the PWM outputs. If that is correct you made my day today!

Thanks very much! I will check the link anyway to have a deeper knowledge about the libraries.

posted by Humberto Riveiro 09 Jun 2016

Yes correct, have fun with it :).

posted by Erik - 09 Jun 2016