Hardware PWM on GPIO



I need to generate a 500Hz PWM with a duty cycle from about 5% (100uS) to 100% (2mS) on a Legato system to output on a GPIO.

I’ve tried using the Legato GPIO service and a timer, but it’s just not fast enough. The bottleneck appears to be in the GPIO service - according to my oscilloscope, the following piece of code:

Gpio22_Activate(); Gpio22_Deactivate();

takes between 600 and 900uS (horrible jitter). I suspect that this is because the underlying Legato GPIO control is actually done via file system read/write into /sys/class/gpio/gpioN, rather than touching the underlying hardware directly. And there appears to be an overhead of around 2.2mS between timer invocations.

Is there any way to generate a PWM signal on a GPIO in hardware?

ciao, Dave


What hardware are you using? The mangOH Green has SX1509 GPIO expander chips on it and those have hardware support for PWM. I believe it should be possible to configure the SX1509’s LED driver functionality to drive the I/O with the pulse width you want. Having said that, I have never used the PWM feature of the chip myself. Perhaps the WP8548 module (assuming that’s what you’re using) also supports hardware PWM, but I couldn’t find any documentation on it. Maybe someone else can clarify.



I’ve got a mangOH green DV3 and mangOH red DV2 hardware, both with WP8548 module.

Was trying to use the GPIO pins on the IoT connector as output - these pins ( on the mangOH green DV3 at least) are directly connected to the GPIO on the WP8548 - which is why I tried using the timer and GPIO service in Legato.

I’ll see if I have a mangOH green DV2 board lying around and try the GPIO expander. Short term fix though.

Might have to look through the GPIO kernel module and see what the hardware addresses are and see if I can cobble together a service that directly accesses the hardware (yuk).

Ciao, Dave


I can confirm the pwm on the sx15 chips works well I use them for LCD and keypad backlights and buzzer function.

LCD 4x4 keypad and relays are driven off these chips

This is on a developed board not the mango platform…



Thanks for that. Much appreciated.

Unfortunately, the pins from SX15 gpio expanders are not brought out to the IoT slots on the mangOH Green DV3/DV4 boards … so I can’t get at them on the IoT slot. Sigh.

ciao, Dave


Use the atmel chip on the board i have not bothered with it but should do the trick …



Thanks for that.

Good thought … but I’ve already using the IoT slot for my external I/O and don’t really want to have to add another piece of hardware. And I also need to show customers this running on the FX30 which doesn’t have the atmel chip…

Sigh. Back to the pcb layout tool I think.

ciao, Dave