PWM using the PRU instead of the PWM pins?

A while back I heard/read/saw/can’t remember where that you can use the PRU units to send PWM signals. Allowing for a lot more PWM pins.

I am getting used to the beagleboard, and I have gotten boxysean’s blink examples to work by using the magic script.
My question is has this been done/is there a library/code available?

Also can the PRU unit write to any pin? or only some of the pins?

Thanks for any help!
Steven

Its not so hard really. I assume you understand the concept of PWM, where you have a period of time and for that period of time the output pin is high for a certain percentage of it. Each instruction on the PRU executes in one clock cycle, with the exception of accessing devices outside of its memory map (i.e. most of the GPIO). I can write an example for you later today, although here is an example of using the PRU to time the ping of a sonar. (might help).

https://github.com/Teknoman117/beaglebot/tree/master/hcsr04-demo

http://teknoman117.wordpress.com/2013/04/30/using-a-beaglebone-with-an-hc-sr04-sonar/

see: http://elinux.org/Ti_AM33XX_PRUSSv2#Beaglebone_PRU_connections_and_modes

that explains what pins are hooked up directly to the PRUs

Tom

That helps a lot, also I noticed that in the “Beaglebone PRU connections and modes” table P9_31 is listed twice, i believe that the second one should be P9_29 based on this table:
https://beagleboard.googlegroups.com/attach/be98d9983155805/BBBlack%20GPIO%20Map.png?gda=0lp6N0QAAACG40M_y4ZX_oaJJy_FNLIRmYcFI5ci_BmMCtkYIrJobaiWw9J2wrQzMMQVbvGesdxV6u9SiETdg0Q2ffAyHU-dzc4BZkLnSFWX59nr5BxGqA&pli=1&view=1&part=4

PS: for the second table does anyone know what the colors refer too?

Do you have a login on the wiki? if not request one please so things like this can be fixed…

Thanks!

Tom

Just got approved :slight_smile:

Thanks for spotting and fixing this!

Tom

If you intend to use pwm for servo control you can try this:
https://github.com/pomarek/sw_pwm

You may need to update GPIO table to support your own board in pwm_drv_hw.c.
I use inverted logic (to reduce transistor count) so if you want normal logic you need to remove #define INVERTED_LOGIC from pru_pwm_sw.p. everything else should be in the readme.

The prus are there to wiggle pins in any way you want!

The two prus have a combined total of 22 gpio, that can be output, on the beaglebone header, so any of these could be used. Many are not available with the beaglebone black. See the “BeagleBone Capes” section at the circuitco wiki for details.

So, what kind of performance can you get from pru-gpio? The pru just runs a little asm program, so it depends on how few 200MHz clock ticks you can use.

For an example (each line below can be converted to one pru asm instruction):

  1. memory address = 0 (1 tick)

  2. load pin states from the memory address (2 ticks)

  3. set all pin states (1 tick)

  4. inc the memory address (1 tick)

  5. if the memory address < max address, repeat the loop, goto 2 (1 tick)

  6. need to restart pwm cycle, so goto 1 (1 tick)

So, with this, you could load the pru memory with an array of the pru-gpio pin states, and it would repeatedly cycle through them (up to max address states), giving you a pwm signal.

Since there are 5 ticks per pin-state-update loop in the code, and 5ns per tick, that would be 25ns control of the pwm. A 40kHz pwm signal takes 25us to repeat, so that would fit 25us/25ns = 1000 individual pin states, or nearly 10 bits of resolution, for 14 pwm signals (if you used pru1 and disabled hdmi).

The PRU package from ti has an interface that lets you access pru memory as a pointer/array, so the above would just involve updating an array to change any or all of the pwm patterns.

Also can the PRU unit write to any pin? or only some of the pins?

The pru has single tick access to the pru-gpio pins, and something like 3-5 tick (can’t remember exact range I saw) access to all non-privileged system memory. The system memory access varies because the cpu could be doing a read or write at the same time, causing a stall. Since the gpio registers are in non-privileged memory, the pru can be used to toggle regular gpio pins, but going through system memory will be much slower than a pru gpio pin, and put a load on the memory bus.

Please excuse any errors…I’m busy at work. :expressionless: