Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2016-03

PWM on raspberry pi

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Koenraad Lelong

Hi,

I'm trying to configure a PWM-pin on the raspberry pi 2. I'm using pigpio, with the demo-program.
I configured pin 12 (GPIO 18) to be a PWM pin.
When I click the PWM-button on the demo-program, the pi hangs. I have to power-cycle to "recover".
I modified this:

   REG_GPIO = $3F000;

and this :

  fd := fpopen('/dev/gpiomem', O_RdWr or O_Sync); // Open the master

/dev/memory device

I'm trying to debug this :
delayNanoseconds(200); <-- breakpoint

       pwmf := Pointer(LongWord(Self.FPwm)+PWM0_RANGE);
       pwmf^ := $400 ;                             //max: 1023
       delayNanoseconds(200);
       pwmf := Pointer(LongWord(Self.FPwm)+PWM1_RANGE);
       pwmf^ := $400 ;                             //max: 1023
       delayNanoseconds(200);

Stepping further with F8.
When I press F8 on the first

       pwmf^ := $400;

the code "singe steps" automatically, but after a number of steps the application crashes and the pi hangs.
This is different from normally running the application where the application just hangs after pressing the PWM-button.

Input and output works fine, as user "pi".

Any thoughts ?

Thanks,

Koenraad.

Reply by email

Mark Morgan Lloyd
to Koenraad Lelong
Koenraad Lelong wrote 30 lines
Hi, I'm trying to configure a PWM-pin on the raspberry pi 2. I'm using pigpio, with the demo-program. I configured pin 12 (GPIO 18) to be a PWM pin. When I click the PWM-button on the demo-program, the pi hangs. I have to power-cycle to "recover". I modified this: REG_GPIO = $3F000; and this : fd := fpopen('/dev/gpiomem', O_RdWr or O_Sync); // Open the master /dev/memory device I'm trying to debug this : delayNanoseconds(200); <-- breakpoint pwmf := Pointer(LongWord(Self.FPwm)+PWM0_RANGE); pwmf^ := $400 ; //max: 1023 delayNanoseconds(200); pwmf := Pointer(LongWord(Self.FPwm)+PWM1_RANGE); pwmf^ := $400 ; //max: 1023 delayNanoseconds(200); Stepping further with F8. When I press F8 on the first pwmf^ := $400; the code "singe steps" automatically, but after a number of steps the application crashes and the pi hangs. This is different from normally running the application where the application just hangs after pressing the PWM-button. Input and output works fine, as user "pi".

Two things: first, Bo on 8th Oct mentioned that he'd had to modify pigpio.pas to make it compatible with the RPi2. Second, how are you physically driving the system, my experience is that remote access can be less reliable than using the directly connected screen and keyboard particularly when single-stepping.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Koenraad Lelong
to Mark Morgan Lloyd

Op 07-03-16 om 20:11 schreef Mark Morgan Lloyd:

Show quoted text 38 lines
Koenraad Lelong wrote: > Hi, > > I'm trying to configure a PWM-pin on the raspberry pi 2. I'm using > pigpio, with the demo-program. > I configured pin 12 (GPIO 18) to be a PWM pin. > When I click the PWM-button on the demo-program, the pi hangs. I have > to power-cycle to "recover". > I modified this: > REG_GPIO = $3F000; > and this : > fd := fpopen('/dev/gpiomem', O_RdWr or O_Sync); // Open the master > /dev/memory device > > I'm trying to debug this : > delayNanoseconds(200); <-- breakpoint > pwmf := Pointer(LongWord(Self.FPwm)+PWM0_RANGE); > pwmf^ := $400 ; //max: 1023 > delayNanoseconds(200); > pwmf := Pointer(LongWord(Self.FPwm)+PWM1_RANGE); > pwmf^ := $400 ; //max: 1023 > delayNanoseconds(200); > Stepping further with F8. > When I press F8 on the first > pwmf^ := $400; > the code "singe steps" automatically, but after a number of steps the > application crashes and the pi hangs. > This is different from normally running the application where the > application just hangs after pressing the PWM-button. > > Input and output works fine, as user "pi". Two things: first, Bo on 8th Oct mentioned that he'd had to modify pigpio.pas to make it compatible with the RPi2. Second, how are you physically driving the system, my experience is that remote access can be less reliable than using the directly connected screen and keyboard particularly when single-stepping.

I think the modifications I mentioned are what is needed (in and out works). I did all this on the pi itself, no remote.

Koenraad.

Reply by email

Bo Berglund
to Mark Morgan Lloyd: Two things: first, Bo on 8th Oct mentioned that he'd had to modify pigpio.pas to make it…
Mark Morgan Lloyd wrote
Two things: first, Bo on 8th Oct mentioned that he'd had to modify pigpio.pas to make it compatible with the RPi2. Second, how are you physically driving the system, my experience is that remote access can

In PiGpio I added the following (roundabout line #20:

{$DEFINE RPi2}
const
  REG_GPIO = {$IFDEF RPi2} $3F000 {$ELSE} $20000
{$ENDIF};//bcm2835/bcm2836 gpio register 0x2000 0000. new fpMap uses
page offset, one page is 4096bytes

then later down in the file (around line #150):

function TIoDriver.MapIo: boolean;
begin
 Result := True;
 {$IFDEF RPi2}
   fd := fpopen('/dev/gpiomem', O_RdWr or O_Sync); // Open the master
/dev/memory device
 {$ELSE}
   fd := fpopen('/dev/mem', O_RdWr or O_Sync); // Open the master
/dev/memory device
 {$ENDIF}

I do not know for a fact tha the second change is because of the RPi2 hardware, it was probably put there in order to make my program run as a normal user rather than su.

Bo Berglund Developer in Sweden

Reply by email

Koenraad Lelong
to Bo Berglund

Op 08-03-16 om 19:50 schreef Bo Berglund:

Show quoted text 28 lines
In PiGpio I added the following (roundabout line #20: {$DEFINE RPi2} const REG_GPIO = {$IFDEF RPi2} $3F000 {$ELSE} $20000 {$ENDIF};//bcm2835/bcm2836 gpio register 0x2000 0000. new fpMap uses page offset, one page is 4096bytes then later down in the file (around line #150): function TIoDriver.MapIo: boolean; begin Result := True; {$IFDEF RPi2} fd := fpopen('/dev/gpiomem', O_RdWr or O_Sync); // Open the master /dev/memory device {$ELSE} fd := fpopen('/dev/mem', O_RdWr or O_Sync); // Open the master /dev/memory device {$ENDIF} I do not know for a fact tha the second change is because of the RPi2 hardware, it was probably put there in order to make my program run as a normal user rather than su.

Well, that's what I did, although without the conditionals. Did you try PWM, e.g. with the demo-program ? Does it work ?

Koenraad.

Reply by email

Bo Berglund
to Koenraad Lelong
Koenraad Lelong wrote 5 lines
> REG_GPIO = {$IFDEF RPi2} $3F000 {$ELSE} $20000 > {$ENDIF};//bcm2835/bcm2836 gpio register 0x2000 0000. new fpMap uses Well, that's what I did, although without the conditionals. Did you try PWM, e.g. with the demo-program ? Does it work ?

No, I just needed to use In-Out to control relays and check digital levels.

Bo Berglund Developer in Sweden

Reply by email