Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Extras/pru-pwm

Pulse width modulation on the PRU

This example uses the PRU onboard microcontroller to drive 8 channels of PWM. The default behaviour is to run with 8 channels of PWM, a PWM frequency of 24.038kHz and a precision of 8 bit.

You can set the pwm for each channel with set_widths() at any time in the code.

The carrier frequency and precision can be modified by changing PWM_MAX_WIDTH in common_defs.h

A slightly higher (25.773kHz) carrier frequency could be achieved by refactoring the code so to use only one byte per channel, which would clearly limit PWM_MAX_WIDTH <= 255

An even higher (30.864kHz)) carrier frequecny could be achieved by taking the LBBO operation out of USER_LOOP in pru_pwm.p, however this would mean that some PWM values (either close to 100% or close to 0%) could not be achieved

Pinout: we are using PRU1's R30, that is:

``` BBB pin PWM channel P8_45: 0 P8_46: 1 P8_43: 2 P8_44: 3 P8_41: 4 P8_42: 5 P8_39: 6 // this will require a change to the dtb P8_40: 7 // this will require a change to the dtb ```