Pages

Wednesday, March 13, 2013

RPIO.PWM experiment notes

Now I went to my excel worksheet, hid the columns and rows I am not interested, to get the above cells highlighted.


Then I can experiment what RPIO demonstrated.



RPIO.PWM, PWM via DMA for the Raspberry Pi

http://pythonhosted.org/RPIO/pwm_py.html

...


Subcycles

Each DMA channel is setup with a specific subcycle, within which pulses are added, and which will be repeated endlessly. Servos, for instance, typically use a subcycle of 20ms, which will be repeated 50 times a second. You can add pulses for multiple GPIOs, as well as multiple pulses for one GPIO. Subcycles cannot be lower than 2ms.

For more information about subcycles, see the examples below. The left oscilloscope images zoom in on one subcycle, the right-handed images are zoomed out to show their repetition.


Pulse-width increment granularity

The pulse-width increment granularity (10µs by default) is used for all DMA channels (since its passed to the PWM timing hardware). Pulses are added to a subcycle by specifying a start and a width parameter, both in multiples of the granularity. For instance to set 500µs pulses with a granularity setting of 10µs, you’ll need to set the pulse-width as 50 (50 * 10µs = 500µs).

The pulse-width granularity is a system-wide setting used by the PWM hardware, therefore you cannot use different granularities at the same time, even in different processes.

Example with Oscilloscope

Setup PWM.Servo with the default 20ms subcycle. On the oscilloscope GPIO 15 the blue channel, GPIO 17 the yellow one.

from RPIO import PWM

servo = PWM.Servo()

Now we set a 4000us (4ms) pulse every 20ms for GPIO 15:

servo.set_servo(15, 4000)

Now a 1000us (1ms) pulse for GPIO 17:

servo.set_servo(17, 1000)

We can use the low-level PWM methods to add further pulses to a subcycle:

PWM.add_channel_pulse(0, 17, 200, width=100)


.END






No comments:

Post a Comment