User avatar
HermannSW
Posts: 1507
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: pigpio C sub µs single pulse generation

Fri Sep 06, 2019 1:18 am

Thanks for the information.

> There may be a problem starting a new wave before the previous one has completed.
>
I was able to recreate the crashes repeatedly, and I did send only one (short) wave in alert function (ten 9µs duration flashes at 6KHz, 1.7ms length in total). Then the program ended.

I connected GPIO18 with GPIO17 and used pigs to raise and lower GPIO18, which resulted in flashes of audio_shots running in "while true" loop. That way I was never able to freeze the Pi. When connecting back the microphone sensor to GPIO17 recreating Pi freeze was easy. If you say it cannot be the alert function, maybe the 5V microphone sensor (connected to Pi GND, 3V3 and GPIO17(with sensor D0, not A0)) is somehow possible to generate more than 3.6V spike despite its VCC connected to Pi 3.3V?


> Statistically a busy spin will likely give the least latency,
>
Thanks, I went ahead already and did that with latest commit, see:
https://www.raspberrypi.org/forums/view ... 7#p1531537

Code: Select all

...
   while (! gpioRead(gpioDaudio)) { }
   gpioWaveTxSend(wave_id, PI_WAVE_MODE_ONE_SHOT);
...
In the posting I describe as well how I determined that the flying pellet is spinning (I did blue dots on pellet north and south pole), and it is spinning fast(!), 93.75rps or 5625rpm:
Image
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

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

Re: pigpio C sub µs single pulse generation

Fri Sep 06, 2019 8:08 am

Thanks for the update.

Could you point me to a copy of the code which I can use to create the crash? Tell me what I need to do as well. I'll have a look and see if I can understand what is happening.

User avatar
HermannSW
Posts: 1507
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: pigpio C sub µs single pulse generation

Fri Sep 06, 2019 9:46 am

I did "git checkout aa45c1c2c5417d2dccd3a7e90fec475aede4f054" in order to get the freeze version.
I renamed it and was surprised that neither ".c" nor ".zip" are allowed attachment types in this forum.
I did put the file on my webserver:
https://stamm-wilbrandt.de/en/forum/aud ... s.freeze.c

This is the 5V(!) microphone sensor I used, GND/VCC/D0/A0 connected to GND/3V3/GPIO17/- on the Pi 3B.
The aliexpress link is for same sensor reorder of 6 sensors a week ago:
https://www.aliexpress.com/item/4000061262267.html
Image


As I said I was only able to trigger the Pi freeze (HDMI stops, ssh sessions stop, ping the Pi does not work) with that sensor, not with the wire from GPIO18 to GPIO17. I doubt that you will need the two IRF520 mosfets controlling the 50W led driver driving 5000lm led via GPIO13 being connected to see the freeze:
https://github.com/Hermann-SW/Raspberry ... al-shutter


For freeze recreate execute this command:

Code: Select all

$ sudo killall pigpiod; while true; do sudo ./audio_shots 10 9 6000 2000; done
Then clap loud in your hands, or otherwise trigger digital line D0 from microphone sensor to go from low to high, 10 times and you should see Pi freeze.
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

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

Re: pigpio C sub µs single pulse generation

Fri Sep 06, 2019 10:12 am

Okay I have compiled the code and can run it with

sudo ./audio_shots 10 9 6000 2000

I can then start piscope and trigger the sequence with pigs w 17 1 w 17 0
Screenshot from 2019-09-06 11-05-18.png
Screenshot from 2019-09-06 11-05-18.png (51.07 KiB) Viewed 1079 times
When I get a chance I'll dig a bit deeper. I have some of those sensors somewhere, i wonder if they might suffer from "contact bounce" and send multiple alerts in a short period. That I can simulate.

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

Re: pigpio C sub µs single pulse generation

Fri Sep 06, 2019 4:51 pm

I haven't managed to make it crash using software. Perhaps this is an electrical noise problem?

I used audio_shots.c amended to show if a previous wave was running when a new one was being started.

Code: Select all

/*
   $ gcc -O6 -o audio_shots audio_shots.c -lpigpio -lrt -lpthread
   $
   
   After start of raspivid_ges:
   $ sudo killall pigpiod
   $ sudo ./audio_alert N d f o
   $
   audio_alert waits for digital audio signal.
   After o[us], N flashes of length d[us] will be generated at frequency f[Hz].
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>

#include <pigpio.h>

#define gpioStrobe 13
#define gpioDaudio 17

int wave_id, N=1, done=0;

gpioPulse_t *pulse;

void alert(int gpio, int level, uint32_t tick)
{
   if (level!=0)  return;
   if (gpioWaveTxBusy()) printf("+"); else printf("-");
   gpioWaveTxSend(wave_id, PI_WAVE_MODE_ONE_SHOT);

   done=1;
}

int main(int argc, char *argv[])
{
   unsigned int d,f,o;
   assert(argc == 1+4);
   assert(0 < (N = atoi(argv[1])));
   assert(0 < (d = atoi(argv[2])));
   assert(0 < (f = atoi(argv[3])));
   f = 1000000/f - d;
   assert(0 < (o = atoi(argv[4])));
       
   assert(gpioInitialise()>=0);

   gpioSetMode(gpioStrobe, PI_OUTPUT);

   gpioWaveAddNew();

   assert(pulse = malloc(sizeof(gpioPulse_t) * (2*N+1)));
   pulse[0].gpioOn  = 0;
   pulse[0].gpioOff = 1<<gpioStrobe;
   pulse[0].usDelay = o;

   for(int i=1; i<=N; ++i)
   {
      pulse[2*i-1].gpioOn  = 1<<gpioStrobe;
      pulse[2*i-1].gpioOff = 0;
      pulse[2*i-1].usDelay = d;

      pulse[2*i-0].gpioOn  = 0;
      pulse[2*i-0].gpioOff = 1<<gpioStrobe;
      pulse[2*i-0].usDelay = f;
   }

   gpioWaveAddGeneric(2*N+1, pulse);

   wave_id = gpioWaveCreate();

   assert((wave_id >= 0) || !"wave create failed\n");

   gpioSetAlertFunc(gpioDaudio, alert);


   while (! done)  usleep(100000);

   usleep(N*(d+f)+1000000);

   gpioTerminate();

   free(pulse);

   printf("\n");

   return 0;
}
Batch file (ash) to run the code in the background.

Code: Select all

!/bin/bash

./audio_shots 10 9 6000 2000 &
I ran the test repeatedly with.

Code: Select all

for ((i=0;i<10000;i++)); do echo -n "$i ";sudo ./ash; sleep 1;pigs w 17 1 w 17 0 w 17 1 w 17 0 w 17 1 w 17 0 w 17 1 w 17 0 w 17 1 w 17 0 w 17 1 w 17 0 w 17 1 w 17 0 w 17 1 w 17 0 w 17 1 w 17 0 w 17 1 w 17 0 w 17 1 w 17 0; sleep 2; done
Producing the following log with all lines just containing -++++++++++ deleted. A - means no wave being transmitted, + means a wave is currently being transmitted.

Code: Select all

0 -++-+++++++
14 -+++-++++++
15 -+++++++-++
21 -+++-++++++
23 -+++++-++++
25 -+++++-++++
27 -++++++-+++
37 -++++++++-+
46 -+++++++-++
48 -+-++++++++
52 -++-+++++++
56 -+-++++-+++
59 -++++++-+++
62 -++-+++++++
73 -++++-++-++
76 -+++++++-++
77 -++-+++++++
91 -+++-++++++
93 -+-++++++++
101 -+++++++++-
105 -++++++++-+
113 -+++++++-++
116 -+++-++++++
125 -++++++-+++
129 -+++-++++++
132 -+++++-++++
137 -+++-++++++
142 -++++++-+++
143 -+++-++++++
146 -++++++++-+
149 -+++++++++-
157 -++++-+++++
163 -++-+++-+++
165 -++-+++++++
167 -+++-++++++
175 -+++++-++++
185 -++++++-+++
193 -++++-+++++
194 -+++-++++++
196 -++++-+++++
197 -++++++++-+
203 -+++++-++++
211 -++++-++++-
212 -+++++-++++
218 -+++++-++++
220 -+++-++++++
221 -++++++-+++
223 -++++++++-+
255 -+++-++++++
257 -+++++++++-
261 -+-++++++++
272 -+-++++++++
278 -+-++++++++
283 -+-++++++++
289 -++++++-+++
301 -++++-+++++
321 -++-+++++++
337 -+++-++++++
338 -+++-++++++
340 -++-+++++++
345 -+++-++++++
366 -+++++++++-
369 -+++-++++++
371 -+++++++-++
377 -++++++++-+
382 -+++++++++-
392 -++++++++-+
400 -++++++-+++
403 -++++++-+++
404 -+++++-++++
409 -+++++++-++
410 -+++++-++++
415 -++-+++++++
416 -+-+-++++++
418 -+++-++++++
420 -+-+-++++++
426 -+++-++++++
428 -++++++++-+
434 -+++++++-++
451 -++++++++-+
458 -+-+++++-++
479 -++++++++-+
480 -++++-+++++
482 -++++-+++++
485 -++-+++++++
486 -+++++++-++
489 -+++++++++-
492 -+++-++++++
493 -+++++++++-
498 -++++-+++++
510 -+++-++++++
511 -++-+++++++
519 -+++++++-++
520 -++-+++++++
521 -++++++-+++
523 -++-+++++++
526 -++++-+++++
541 -+++-++++++
544 -++-+++++++
551 ^C

User avatar
HermannSW
Posts: 1507
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: pigpio C sub µs single pulse generation

Sun Sep 08, 2019 9:06 pm

Sorry, I had too much interesting new stuff to do over the weekend in the other thread, really amazing!
https://www.raspberrypi.org/forums/view ... 6#p1532362


Now I compiled audio_shots.freeze.c, started this command and recreated Pi freeze after 5 shots (without magazine):

Code: Select all

$ while true; do sudo ./audio_shots.freeze 20 18 2500 2510; done
Before doing anything else, after power cycle of Pi I disconnected the three cables from Pi to the Mosfets that control the 5000lm led and executed the command again. I did 40 shots without Pi freeze (on Pi freeze the display on HDMI monitor disappears and "no signal" is shown, this did not happen). Then I disconnected mains connection from LED driver connected to Mosfets and connected the three cables to Mosfets again, still freeze. In order to be quieter, instead of shooting with airsoft pistol, I tapped the microphone with my finger. While I can see from a small LED on microphone sensor that this gets registered, more than 30 traps did not freeze the Pi. So essential list for freeze as of now is:
  • microphone sensor
  • connection to Mosfets via GPIO13 (LED driver disconnected from mains)
  • airsoft shots (without magazine)
Now I will connect logic analyzer and try to see what happens on microphone sensor D0 line.
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

User avatar
HermannSW
Posts: 1507
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: pigpio C sub µs single pulse generation

Sun Sep 08, 2019 9:32 pm

I did 9 shots after having connected logic analyzer to freeze the Pi again:
Image


This is zoom into 9th shot for microphone sensor D0 line:
Image


But it does not reflect the details, I exported the captured data, D0 and therefore GPIO17 goes from low to high 66 times:

Code: Select all

...
16.804133060000002, 0
18.274464630000001, 1
18.274464640000001, 0
18.274464649999999, 1
18.274465100000000, 0
18.274465850000002, 1
18.274465859999999, 0
18.274465870000000, 1
18.274465880000001, 0
18.274465890000002, 1
18.274597249999999, 0
18.274775510000001, 1
18.274775519999999, 0
18.274775529999999, 1
18.274775540000000, 0
18.274775550000001, 1
18.274775560000002, 0
18.274775569999999, 1
18.274775990000002, 0
18.274776610000000, 1
18.274776620000001, 0
18.274776630000002, 1
18.274776639999999, 0
18.274776650000000, 1
18.274776660000001, 0
18.274776670000001, 1
18.274788090000001, 0
18.275023530000002, 1
18.275023539999999, 0
18.275023550000000, 1
18.275023560000001, 0
18.275023570000002, 1
18.275023579999999, 0
18.275023590000000, 1
18.275023600000001, 0
18.275023610000002, 1
18.275023969999999, 0
18.275024750000000, 1
18.275024760000001, 0
18.275024770000002, 1
18.275024779999999, 0
18.275024790000000, 1
18.275024800000001, 0
18.275024810000001, 1
18.275024819999999, 0
18.275024830000000, 1
18.275187750000001, 0
18.275217229999999, 1
18.275217240000000, 0
18.275217250000001, 1
18.275217260000002, 0
18.275217269999999, 1
18.275217280000000, 0
18.275217290000001, 1
18.275217300000001, 0
18.275217310000002, 1
18.275217699999999, 0
18.275218389999999, 1
18.275218400000000, 0
18.275218410000001, 1
18.275218420000002, 0
18.275218429999999, 1
18.275218440000000, 0
18.275218450000001, 1
18.275218460000001, 0
18.275218469999999, 1
18.275386560000001, 0
18.275441570000002, 1
18.275441579999999, 0
18.275441590000000, 1
18.275441600000001, 0
18.275441610000001, 1
18.275441619999999, 0
18.275441630000000, 1
18.275441640000000, 0
18.275441650000001, 1
18.275500619999999, 0
18.275621210000001, 1
18.275621220000001, 0
18.275621229999999, 1
18.275621240000000, 0
18.275621250000000, 1
18.275621260000001, 0
18.275621270000002, 1
18.275621279999999, 0
18.275621290000000, 1
18.275621659999999, 0
18.275622330000001, 1
18.275622340000002, 0
18.275622349999999, 1
18.275622360000000, 0
18.275622370000001, 1
18.275622380000001, 0
18.275622389999999, 1
18.275622400000000, 0
18.275622410000000, 1
18.276292320000000, 0
18.276458690000002, 1
18.276458699999999, 0
18.276458710000000, 1
18.276458720000001, 0
18.276458730000002, 1
18.276458739999999, 0
18.276458750000000, 1
18.276459110000001, 0
18.276459930000001, 1
18.276459939999999, 0
18.276459950000000, 1
18.276459960000000, 0
18.276459970000001, 1
18.276459980000002, 0
18.276459989999999, 1
18.276460000000000, 0
18.276460010000001, 1
18.276547360000002, 0
18.276591329999999, 1
18.276591340000000, 0
18.276591350000000, 1
18.276591360000001, 0
18.276591370000002, 1
18.276591379999999, 0
18.276591390000000, 1
18.276591780000000, 0
18.276592470000001, 1
18.276592480000001, 0
18.276592489999999, 1
18.276592500000000, 0
18.276592510000000, 1
18.276592520000001, 0
18.276592530000002, 1
18.276592539999999, 0
18.276592550000000, 1
18.276782170000001, 0

Since currently only I can recreate the freeze, it seems to be a good idea to simulate the 9th shot low/high signals using pigpio library and getting rid of the microphone sensor while still being able to freeze ...

P.S:
Zooming in at different places into 9th shot, I see this pattern again and again -- each high/low is 10ns long -- but I used only my 100Msps logic analyzer (have a 400Msps as well), and 10ns is maximal resolution. Anyway, a 50Mhz PWM with 50% duty cycle might do the "freeze the Pi" job:
Image
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

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

Re: pigpio C sub µs single pulse generation

Sun Sep 08, 2019 9:51 pm

At the default sampling rate of every 5µs most of those edges would be missed by pigpio alerts. I think even more would be missed by the Linux ISR system.

I'm still of the mind that the root problem may be trying to restart a wave before the previous has finished, perhaps almost before the previous has been properly initialised.

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

Re: pigpio C sub µs single pulse generation

Sun Sep 08, 2019 9:54 pm

I'll connect the hardware PWM to the input and see if I can get the crash (tomorrow).

User avatar
HermannSW
Posts: 1507
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: pigpio C sub µs single pulse generation

Sun Sep 08, 2019 10:10 pm

I disconnected D0 from GPIO17, and connected GPIO18 to GPIO17.

In one ssh console I executed this command:

Code: Select all

$ while true; do sudo ./audio_shots.freeze 20 18 2500 2510; done

It took some tries, but this is first "freeze the Pi" without microphone sensor used -- still with GPIO13 connected to Mosfets:

Code: Select all

[email protected]:~ $ Raspberry_v1_camera_global_external_shutter/tools/shots 50 1 1 18
[email protected]:~ $ Raspberry_v1_camera_global_external_shutter/tools/shots 50 1 1 18
[email protected]:~ $ Raspberry_v1_camera_global_external_shutter/tools/shots 50 1 1 18
[email protected]:~ $ Raspberry_v1_camera_global_external_shutter/tools/shots 5000 1 1 18
[email protected]:~ $ Raspberry_v1_camera_global_external_shutter/tools/shots 5000 1 1 18

P.S:
I replaced the two mosfets with LED driver with a single new IRF520 Mosfet with GND/VCC/SIG connected to GND/3V3/GPIO17, and was once able to freeze the Pi, but after many shots commands ... (removed the logic analyzer, cable between GPIO18 and GPIO17)
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

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

Re: pigpio C sub µs single pulse generation

Mon Sep 09, 2019 5:05 pm

I have done over 4000 runs at 5µs sampling without error.

I then changed the sampling rate to 1µs and used 10Mhz PWM as the trigger source.

Code: Select all

   assert(gpioCfgClock(1, 1, 0) >= 0);

   assert(gpioInitialise()>=0);

   assert(gpioHardwarePWM(18, 10000000, 500000) >= 0);
I stopped after another 4422 runs without error.

I'd guess this is an electrical problem.

User avatar
HermannSW
Posts: 1507
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: pigpio C sub µs single pulse generation

Sun Sep 15, 2019 8:54 pm

joan wrote:
Mon Sep 09, 2019 5:05 pm
I'd guess this is an electrical problem.
I don't think so. Sorry for answering late, I had to complete work of creating my first 20000fps video, clean and commit the tools as well as github README.md on how to do that.

What you are missing is to connect "something" to GPIO13 as I described. Without anything connected to GPIO13 I cannot recreate as well. I will investigate this further tomorrow based on your code snippet, and hopefully come up with a setup that you will be able to reproduce (not sure whether Mosfet is needed on GPIO13, or other consumers of the generated signal will recreate as well).


https://github.com/Hermann-SW/Raspberry ... sideswhite
Image
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

User avatar
HermannSW
Posts: 1507
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: pigpio C sub µs single pulse generation

Mon Sep 16, 2019 4:12 pm

Because currently I have Pi2B connected (before it was Pi3B+ and Pi3B) I did redo the freeze experiments with microphone sensor first (same microphone sensor). It took much more shots (magazine removed) to trigger Pi freeze (>20). I was able to freeze 2 times, the 2nd time with 100Msps logic analyzer capturing GPIO17 (microphone sensor D0) and GPIO13 (connected to Mosfet).

I used this command on Pi:

Code: Select all

$ while true; do sudo ./audio_shots.freeze 10 9 6000 2000; done
A typical shot looks like this, all Mosfet triggers on GPIO13 (lower line) after last high on GPIO17 (microphone D0). But there are many triggers (calls to alert function):
Image

This is capture of last shot that did freeze the Pi (again):
Image

Zooming there is a low->high transition on top line during a 9µs high phase on GPIO13, that is during a waveform send in alert function in audio_shots.freeze.c:
Image


This is exported data from just before last audio trigger (24.11...s), last audio trigger is with 24.99...s. 336 of the 338 entries belong to last audio trigger. There are 162 low->high of D0(GPIO17) while GPIO17 is low. But there are 4 low->high of D0(GPIO17) while GPIO17 is high:

Code: Select all

24.111562950000000, 0, 1
24.111562970000001, 0, 0
24.991362190000000, 1, 0
24.991362200000001, 0, 0
24.991362210000002, 1, 0
24.991362219999999, 0, 0
24.991362230000000, 1, 0
24.991362700000000, 0, 0
24.991363270000001, 1, 0
24.991363280000002, 0, 0
24.991363289999999, 1, 0
24.991363300000000, 0, 0
24.991363310000001, 1, 0
24.991648940000001, 0, 0
24.992026750000001, 1, 0
24.992026760000002, 0, 0
24.992026769999999, 1, 0
24.992026780000000, 0, 0
24.992026790000001, 1, 0
24.992026800000001, 0, 0
24.992026810000002, 1, 0
24.992027180000001, 0, 0
24.992027889999999, 1, 0
24.992027900000000, 0, 0
24.992027910000001, 1, 0
24.992027920000002, 0, 0
24.992027929999999, 1, 0
24.992027940000000, 0, 0
24.992027950000001, 1, 0
24.992027960000001, 0, 0
24.992027969999999, 1, 0
24.992311230000002, 0, 0
24.992468909999999, 1, 0
24.992468920000000, 0, 0
24.992468930000001, 1, 0
24.992468940000002, 0, 0
24.992468949999999, 1, 0
24.992468960000000, 0, 0
24.992468970000001, 1, 0
24.992535140000001, 0, 0
24.992617989999999, 1, 0
24.992618000000000, 0, 0
24.992618010000001, 1, 0
24.992618020000002, 0, 0
24.992618029999999, 1, 0
24.992618040000000, 0, 0
24.992618050000001, 1, 0
24.992825820000000, 0, 0
24.992949290000002, 1, 0
24.992949299999999, 0, 0
24.992949310000000, 1, 0
24.992949320000001, 0, 0
24.992949330000002, 1, 0
24.992949339999999, 0, 0
24.992949350000000, 1, 0
24.993044820000001, 0, 0
24.993460470000002, 1, 0
24.993460480000000, 0, 0
24.993460490000000, 1, 0
24.993460500000001, 0, 0
24.993460510000002, 1, 0
24.993460519999999, 0, 0
24.993460530000000, 1, 0
24.994603000000001, 0, 0
24.994720709999999, 1, 0
24.994720720000000, 0, 0
24.994720730000001, 1, 0
24.994720740000002, 0, 0
24.994720749999999, 1, 0
24.994720760000000, 0, 0
24.994720770000001, 1, 0
24.994721139999999, 0, 0
24.994721850000001, 1, 0
24.994721860000002, 0, 0
24.994721869999999, 1, 0
24.994721880000000, 0, 0
24.994721890000001, 1, 0
24.994721900000002, 0, 0
24.994721909999999, 1, 0
24.994721920000000, 0, 0
24.994721930000001, 1, 0
24.994763550000002, 0, 0
24.995186190000002, 0, 1
24.995194770000001, 1, 1
24.995194780000002, 0, 1
24.995194789999999, 1, 1
24.995194800000000, 0, 1
24.995194810000001, 1, 1
24.995194820000002, 0, 1
24.995194829999999, 1, 1
24.995195180000000, 0, 1
24.995195219999999, 0, 0
24.995195270000000, 0, 1
24.995195280000001, 0, 0
24.995195989999999, 1, 0
24.995196000000000, 0, 0
24.995196010000001, 1, 0
24.995196020000002, 0, 0
24.995196029999999, 1, 0
24.995196040000000, 0, 0
24.995196050000001, 1, 0
24.995309360000000, 0, 0
24.995375870000000, 1, 0
24.995375880000001, 0, 0
24.995375890000002, 1, 0
24.995375899999999, 0, 0
24.995375910000000, 1, 0
24.995375920000001, 0, 0
24.995375930000002, 1, 0
24.995376280000002, 0, 0
24.995377210000001, 1, 0
24.995377220000002, 0, 0
24.995377229999999, 1, 0
24.995377240000000, 0, 0
24.995377250000001, 1, 0
24.995377260000001, 0, 0
24.995377269999999, 1, 0
24.995377720000000, 0, 0
24.995378429999999, 1, 0
24.995378440000000, 0, 0
24.995378450000000, 1, 0
24.995378460000001, 0, 0
24.995378470000002, 1, 0
24.995378479999999, 0, 0
24.995378490000000, 1, 0
24.995410740000001, 0, 0
24.995881550000000, 1, 0
24.995881560000001, 0, 0
24.995881570000002, 1, 0
24.995881579999999, 0, 0
24.995881590000000, 1, 0
24.995881600000001, 0, 0
24.995881610000001, 1, 0
24.995881620000002, 0, 0
24.995881630000000, 1, 0
24.995881960000002, 0, 0
24.995883030000002, 1, 0
24.995883039999999, 0, 0
24.995883050000000, 1, 0
24.995883060000001, 0, 0
24.995883070000001, 1, 0
24.995883080000002, 0, 0
24.995883090000000, 1, 0
24.995883500000001, 0, 0
24.995884329999999, 1, 0
24.995884340000000, 0, 0
24.995884350000001, 1, 0
24.995884360000002, 0, 0
24.995884369999999, 1, 0
24.995884380000000, 0, 0
24.995884390000001, 1, 0
24.995884820000001, 0, 0
24.995885590000000, 1, 0
24.995885600000001, 0, 0
24.995885610000002, 1, 0
24.995885619999999, 0, 0
24.995885630000000, 1, 0
24.995885640000001, 0, 0
24.995885650000002, 1, 0
24.995886120000002, 0, 0
24.995886850000002, 1, 0
24.995886859999999, 0, 0
24.995886870000000, 1, 0
24.995886880000000, 0, 0
24.995886890000001, 1, 0
24.995897820000000, 0, 0
24.995996710000000, 1, 0
24.995996720000001, 0, 0
24.995996730000002, 1, 0
24.995996739999999, 0, 0
24.995996750000000, 1, 0
24.995996760000001, 0, 0
24.995996770000001, 1, 0
24.995997120000002, 0, 0
24.995997989999999, 1, 0
24.995998000000000, 0, 0
24.995998010000001, 1, 0
24.995998020000002, 0, 0
24.995998029999999, 1, 0
24.995998040000000, 0, 0
24.995998050000001, 1, 0
24.996068059999999, 0, 0
24.996107530000000, 1, 0
24.996107540000001, 0, 0
24.996107550000001, 1, 0
24.996107560000002, 0, 0
24.996107569999999, 1, 0
24.996107580000000, 0, 0
24.996107590000001, 1, 0
24.996107600000002, 0, 0
24.996107609999999, 1, 0
24.996107980000001, 0, 0
24.996108690000000, 1, 0
24.996108700000001, 0, 0
24.996108710000001, 1, 0
24.996108720000002, 0, 0
24.996108730000000, 1, 0
24.996108740000000, 0, 0
24.996108750000001, 1, 0
24.996108760000002, 0, 0
24.996108769999999, 1, 0
24.996148739999999, 0, 0
24.996290110000000, 1, 0
24.996290120000001, 0, 0
24.996290130000002, 1, 0
24.996290139999999, 0, 0
24.996290150000000, 1, 0
24.996290160000001, 0, 0
24.996290170000002, 1, 0
24.996290179999999, 0, 0
24.996290190000000, 1, 0
24.996290540000000, 0, 0
24.996291330000002, 1, 0
24.996291339999999, 0, 0
24.996291350000000, 1, 0
24.996291360000001, 0, 0
24.996291370000002, 1, 0
24.996291379999999, 0, 0
24.996291390000000, 1, 0
24.996291400000000, 0, 0
24.996291410000001, 1, 0
24.996316680000000, 0, 0
24.996621449999999, 1, 0
24.996621460000000, 0, 0
24.996621470000001, 1, 0
24.996621480000002, 0, 0
24.996621489999999, 1, 0
24.996621500000000, 0, 0
24.996621510000001, 1, 0
24.996621520000001, 0, 0
24.996621529999999, 1, 0
24.996621870000002, 0, 0
24.996622750000000, 1, 0
24.996622760000001, 0, 0
24.996622770000002, 1, 0
24.996622779999999, 0, 0
24.996622790000000, 1, 0
24.996622800000001, 0, 0
24.996622810000002, 1, 0
24.996656640000001, 0, 0
24.996768169999999, 1, 0
24.996768180000000, 0, 0
24.996768190000001, 1, 0
24.996768200000002, 0, 0
24.996768209999999, 1, 0
24.996768220000000, 0, 0
24.996768230000001, 1, 0
24.996768240000002, 0, 0
24.996768249999999, 1, 0
24.996768599999999, 0, 0
24.996769430000001, 1, 0
24.996769440000001, 0, 0
24.996769450000002, 1, 0
24.996769459999999, 0, 0
24.996769470000000, 1, 0
24.996769480000001, 0, 0
24.996769490000002, 1, 0
24.996938680000000, 0, 0
24.997598889999999, 1, 0
24.997598900000000, 0, 0
24.997598910000001, 1, 0
24.997598920000001, 0, 0
24.997598929999999, 1, 0
24.997598940000000, 0, 0
24.997598950000000, 1, 0
24.997598960000001, 0, 0
24.997598970000002, 1, 0
24.997599300000001, 0, 0
24.997600250000001, 1, 0
24.997600260000002, 0, 0
24.997600270000000, 1, 0
24.997600280000000, 0, 0
24.997600290000001, 1, 0
24.997600300000002, 0, 0
24.997600309999999, 1, 0
24.997600779999999, 0, 0
24.997601469999999, 1, 0
24.997601480000000, 0, 0
24.997601490000001, 1, 0
24.997601500000002, 0, 0
24.997601509999999, 1, 0
24.997601520000000, 0, 0
24.997601530000001, 1, 0
24.997658990000001, 0, 0
24.998364210000002, 1, 0
24.998364219999999, 0, 0
24.998364230000000, 1, 0
24.998364240000001, 0, 0
24.998364250000002, 1, 0
24.998364259999999, 0, 0
24.998364270000000, 1, 0
24.998364280000001, 0, 0
24.998364290000001, 1, 0
24.998364620000000, 0, 0
24.998365670000002, 1, 0
24.998365679999999, 0, 0
24.998365690000000, 1, 0
24.998365700000001, 0, 0
24.998365710000002, 1, 0
24.998365719999999, 0, 0
24.998365730000000, 1, 0
24.998365740000001, 0, 0
24.998365750000001, 1, 0
24.998366140000002, 0, 0
24.998366930000000, 1, 0
24.998366940000000, 0, 0
24.998366950000001, 1, 0
24.998366960000002, 0, 0
24.998366969999999, 1, 0
24.998366980000000, 0, 0
24.998366990000001, 1, 0
24.998487539999999, 0, 0
24.999021110000001, 1, 0
24.999021120000002, 0, 0
24.999021129999999, 1, 0
24.999021140000000, 0, 0
24.999021150000001, 1, 0
24.999021160000002, 0, 0
24.999021169999999, 1, 0
24.999021519999999, 0, 0
24.999022549999999, 1, 0
24.999022560000000, 0, 0
24.999022570000001, 1, 0
24.999022580000002, 0, 0
24.999022589999999, 1, 0
24.999022600000000, 0, 0
24.999022610000001, 1, 0
24.999023019999999, 0, 0
24.999023789999999, 1, 0
24.999023800000000, 0, 0
24.999023810000001, 1, 0
24.999023820000001, 0, 0
24.999023830000002, 1, 0
24.999023840000000, 0, 0
24.999023850000000, 1, 0
24.999023860000001, 0, 0
24.999023870000002, 1, 0
24.999049160000002, 0, 0

For the other shots captured before the last I can see ten 9µs long high periods on GPIO13 to Mosfet. For the last shot that did freeze the Pi we only see the first 9µs long GPIO13 high phase of ten before freeze.
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

User avatar
HermannSW
Posts: 1507
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: pigpio C sub µs single pulse generation

Sun Sep 22, 2019 7:45 pm

@joan
Finally I have freeze recreate that does freeze the Pi with just cable between GPIO17 and GPIO18.
This recreate seems to confirm that 2nd waveform sent while 1st did not complete.

Here is the standalone code (was not able to post in code section, was asked if I am a robot, no submit possible):
https://stamm-wilbrandt.de/en/forum/alert_freeze.c

You need to clone the repo on Pi:
https://github.com/Hermann-SW/Raspberry ... al_shutter

Then open two consoles on the Pi, switch to "~/Raspberry_v1_camera_global_external_shutter/tools" in both.

Compiler alert_freeze.c.

Execute this command in 1st console:

Code: Select all

./raspivid_ges
Now execute this command in 2nd console:

Code: Select all

sudo killall pigpiod; sudo ./alert_freeze 5 900 6000 2010

After output of some dots Pi will freeze completely.
The screenshot shows that channel 1 (GPIO13) does not even go high from the alert function:
Image
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

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

Re: pigpio C sub µs single pulse generation

Sun Sep 22, 2019 9:22 pm

I've prepared the software. I won't be able to take this any further until I find my camera.

It seems likely that it's the interaction of raspivid and pigpio using DMA causing the problem. I wonder if they are actually using the same channel. Perhaps an experiment setting alternative secondary channels is needed (i.e. using gpioCfgDMAchannels).

User avatar
HermannSW
Posts: 1507
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: pigpio C sub µs single pulse generation

Mon Sep 23, 2019 9:06 am

joan wrote:
Sun Sep 22, 2019 9:22 pm
I've prepared the software. I won't be able to take this any further until I find my camera.
Sorry, my recreate was not minimal, no camera needed!

Forget about my repo, just compile alert_freeze.c
https://stamm-wilbrandt.de/en/forum/alert_freeze.c

Code: Select all

$ gcc -O6 -o alert_freeze alert_freeze.c -lpigpio -lrt -lpthread
and execute:

Code: Select all

$ sudo ./alert_freeze 5 900 6000 2010
That is all, wait a few seconds, the output of dots in ssh session will stop and connected HDMI monitor will show "no signal".
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

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

Re: pigpio C sub µs single pulse generation

Tue Sep 24, 2019 5:23 pm

Still doesn't crash for me.

I'm testing on a Pi4. I don't have anything connected to HDMI.

As an aside f ends up being more than an hour long in time. Each wave would take about 6 hours to complete.

Which Pi are you using and which pigpio version (pigs pigpv)?

User avatar
HermannSW
Posts: 1507
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: pigpio C sub µs single pulse generation

Wed Sep 25, 2019 8:13 am

I tested on Pi2B.

I did again, removed everything connected besides GPIO17--GPIO18 cable and ethernet cable, no HDMI, no comera, ...

I did

Code: Select all

$ ping 192.168.178.43
to see when Pi freezes.

Then I ssh into Pi and did the correct command (900 was typo):

Code: Select all

$ sudo ./alert_freeze 5 90 6000 2010
This creates wave of length 2010µs+90µs+(4*1000000/6000)µs=2766.7µs, and freezes after few seconds.


Just did it on a Pi4B and as you have stated, there it does not freeze.
I was able to compile and run alert_freeze without having installed pigpio as described here:
http://abyz.me.uk/rpi/pigpio/download.html

I then used method 3 to install, this is 4B version:

Code: Select all

[email protected]:~ $ sudo pigpiod
[email protected]:~ $ pigs pigpv
7101
[email protected]:~ $ 
On Pi2B:

Code: Select all

[email protected]:~ $ sudo pigpiod
[email protected]:~ $ pigs pigpv
64
[email protected]:~ $ 
I now installed latest pigpio per method 3 on the Pi2B as well.
And the freeze still happens with version 7101 ...

Code: Select all

[email protected]:~/pigpio-master $ pigs pigpv
64
[email protected]:~/pigpio-master $ sudo killall pigpiod
[email protected]:~/pigpio-master $ sudo pigpiod
[email protected]:~/pigpio-master $ pigs pigpv
7101
[email protected]:~/pigpio-master $ gcc -O6 -o alert_freeze alert_freeze.c -lpigpio -lrt -lpthread
[email protected]:~/pigpio-master $ sudo killall pigpiod
[email protected]:~/pigpio-master $ sudo ./alert_freeze 5 90 6000 2010
Will now look on Pi3B and Pi3B+ ...
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

User avatar
HermannSW
Posts: 1507
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: pigpio C sub µs single pulse generation

Wed Sep 25, 2019 8:27 am

On Pi3B it did freeze with version 68 on Stretch:

Code: Select all

[email protected]:~ $ sudo pigpiod
[email protected]:~ $ pigs pigpv
68
[email protected]:~ $ cat /etc/os-release 
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
[email protected]:~ $

I did install latest pigpiod per method 3 here as well, still freezes:

Code: Select all

[email protected]:~/pigpio-master $ sudo pigpiod
[email protected]:~/pigpio-master $ pigs pigpv
7101
[email protected]:~/pigpio-master $ sudo killall pigpiod
[email protected]:~/pigpio-master $ gcc -O6 -o alert_freeze alert_freeze.c -lpigpio -lrt -lpthread
[email protected]:~/pigpio-master $ sudo ./alert_freeze 5 90 6000 2010
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

User avatar
HermannSW
Posts: 1507
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: pigpio C sub µs single pulse generation

Wed Sep 25, 2019 8:38 am

On Pi3B+ I have Buster:

Code: Select all

[email protected]:~/pigpio-master $ cat /etc/os-release 
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
[email protected]:~/pigpio-master $

Installed version was "71", and it did freeze.
Installed latest pigpio and it still freezes:

Code: Select all

[email protected]:~/pigpio-master $ sudo pigpiod
[email protected]:~/pigpio-master $ pigs pigpv
7101
[email protected]:~/pigpio-master $ sudo killall pigpiod
[email protected]:~/pigpio-master $ gcc -O6 -o alert_freeze alert_freeze.c -lpigpio -lrt -lpthread
[email protected]:~/pigpio-master $ sudo ./alert_freeze 5 90 6000 2010
.
.

I hope you have a sub Pi4 to verify the freezes on 3B+, 3B, 2B, on Stretch as well as on Buster.

Only power cable and GPIO17--GPIO18 connected:
Image
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

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

Re: pigpio C sub µs single pulse generation

Wed Sep 25, 2019 8:48 am

Okay. Thanks for that. I'll try on my Pi3B.

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

Re: pigpio C sub µs single pulse generation

Wed Sep 25, 2019 2:35 pm

Okay, I tried on a Pi3B+ and it freezes. Hurrah!

I changed

Code: Select all

void alert(int gpio, int level, uint32_t tick)
{
   if (level!=0)  return;

   gpioWaveTxSend(wave_id, PI_WAVE_MODE_ONE_SHOT);

   ++done;
}
to

Code: Select all

void alert(int gpio, int level, uint32_t tick)
{
   if (level!=0)  return;

   if (gpioWaveTxBusy()) return;
   
   gpioWaveTxSend(wave_id, PI_WAVE_MODE_ONE_SHOT);

   ++done;
}
Checking if a wave is already running seems to be enough to stop the freeze.

I'll see if there is an underlying error other than don't start a new wave before killing the previous or waiting for it to complete.

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

Re: pigpio C sub µs single pulse generation

Thu Sep 26, 2019 12:18 pm

There is an underlying feature. The DMA hardware does not respond as I expected in some circumstances.

I have made a change to the way pigpio resets the DMA. It seems to work okay on my Pi3B+. I'll let your test run for a few hours and see if it falls over. If it doesn't I'll incorporate the change into the next pigpio release.

User avatar
HermannSW
Posts: 1507
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: pigpio C sub µs single pulse generation

Sun Sep 29, 2019 6:01 pm

Thank you! I am happy user of pigpio library (with pigs and C), and because of changed code I don't need a fix for this freeze issue currently. But it is always good to make "the product" better in fixing the freeze you were able to recreate.
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

Return to “C/C++”