User avatar
BenScarb
Posts: 12
Joined: Thu Jul 19, 2012 10:14 pm
Location: Kent, UK

RPIO.PWM - DMA Channels

Sat Sep 06, 2014 9:59 pm

Hello there,

I'm trying to set up quite a simple bit of code that uses RPIO.PWM to control the brightness of 8 LEDs.
Long story short, I think I might be using the "wrong" channel numbers when initializing the code.

At the moment I do:

Code: Select all

        for i in range(1, len(self.LEDs)+1):
            PWM.init_channel(i)
self.LEDs is a list of 8 pin numbers to use. It was a range(0, len(self.LEDs)) but I read that channel 0 was being used by the OpSys.

It all seems to run as I expect it to, with the LEDs behaving as I want, the problem is after a short while the file system goes "read-only" and I can't edit the Python script any more!

I've copied the card to an image and flashed that on to a different SD card but the same thing happens.
Am I using a DMA channel that I shouldn't be? Or is it possible I have a duff file system (which I've transferred to another card!) and I need to do another back up quite soon?

Any help or pointers would be very much appreciated (rebooting all every time this happens is becoming boring! :) )
Thanks in advance.

Ben
---

User avatar
joan
Posts: 14352
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: RPIO.PWM - DMA Channels

Sat Sep 06, 2014 10:29 pm

Can't you just use one DMA channel?

Avoid channels 0, 1, 2, 3, 6, 7. The GPU uses 1, 3, 6, 7. The frame buffer uses 0 and the SD card uses 2.

User avatar
BenScarb
Posts: 12
Joined: Thu Jul 19, 2012 10:14 pm
Location: Kent, UK

Re: RPIO.PWM - DMA Channels

Sun Sep 07, 2014 9:10 am

Can I just use one DMA channel.... This is a good question and one I'd not considered...!
I'd formed the opinion that each PWM set up needed it's own DMA channel, no idea where that idea came from, not good logical thinking there :)

I'll give it a go with one DMA channel and avoid the ones you've mentioned.

Thank you
Ben
---

User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK
Contact: Website

Re: RPIO.PWM - DMA Channels

Sun Sep 07, 2014 10:07 am

The DMA channel is where you set the rate of the PWM carrier signal, but you can attach many PWM pulses attached to a single channel.

So in my case, it's set to a pulse every 3ms using channel 1.

Code: Select all

	PWM.set_loglevel(PWM.LOG_LEVEL_ERRORS)
	PWM.setup(1)                                    # 1us increment
	PWM.init_channel(RPIO_DMA_CHANNEL, 3000)        # 3ms carrier period
But in that 3ms period, I send PWM signals between 1ms and 2ms at a resolution of 1us:

Code: Select all

		PWM.add_channel_pulse(RPIO_DMA_CHANNEL, self.bcm_pin, 0, self.current_pulse_width)
I have 4 seperate GPIO pins (self.bcm_pin) each being fed their own PWM pulse (self.current_pulse_width in microseconds), each updated at 3ms, but with different pulse widths.

I do use channel 1, but I assume that because my RPi is headless, any effect this has on the GPU doesn't matter?
www.pistuffing.co.uk - Raspberry Pi and other stuffing!

User avatar
joan
Posts: 14352
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: RPIO.PWM - DMA Channels

Sun Sep 07, 2014 10:50 am

Hove wrote: ...
I do use channel 1, but I assume that because my RPi is headless, any effect this has on the GPU doesn't matter?
I have no idea, I guess not.

You can see the channels reserved for GPU use by

cat /sys/module/dma/parameters/dmachans

Mine shows 32565 or 0111 1111 0011 0101

If bit n is 0 it is reserved for GPU use.

In addition channels 0 and 2 are used by the ARM software.

User avatar
BenScarb
Posts: 12
Joined: Thu Jul 19, 2012 10:14 pm
Location: Kent, UK

Re: RPIO.PWM - DMA Channels

Thu Sep 18, 2014 9:53 pm

Thank you for the help, it was spot on. I've now got my LEDs all pulsing (almost) as I want then, using just the one channel for all 8.

Again, thanks for all the help.

Ben
----

gromain
Posts: 1
Joined: Tue Dec 30, 2014 9:01 am

Re: RPIO.PWM - DMA Channels

Tue Dec 30, 2014 9:09 am

Hi all,

Just for the sake of the record, this information helped me debug a problem I had while using RPIO where my raspberry would freeze to death, and my console would just show a cryptic error message about my system being read-only and the console throwing back every command with "command not found".

Maybe this should figure in the RPIO doc somewhere (the information about the channels being used elsewhere), unless it's already here and I should learn to read properly!

Anyway, nice lib! (Also, I'll put this comment somewhere on the github repo!)

Cheers,

R

Return to “Python”