I have a program where each step, two GPIO pins have their duty cycle updated (I'm using pigpio). I'm running the program for millions of steps (think 50 to 100 million) and running the PWM outputs through a low pass filter and then to an oscilloscope. It updates kinda slowly. How might I speed this up so I don't have to wait 15+ minutes to watch all of the motion on the oscilloscope? (Note: the rest of the program is pretty fast; I timed it at one point at it was ~30 seconds on its own, but I have to see the output.)
Have you looked at the source for pigpio? Or programmed a microcontroller that required you to access pins at the hardware level? I'll explain why I ask this in a few lines.
If you're running this application in Python, then the communication between python and the pigpio is run through a socket, which is another layer that slows things down.
Pigpio is an abstraction layer to allow access to the raw hardware of the Raspberry Pi's processor. It is well written and made to be fast, but it's a large library because it has to be. At the hardware level, the gpio are not organized by pin, but rather by registers. Typically these are 8 bytes wide, so each register controls 8 gpio pins. So to set a single pin high or low, the following must take place.
Setup: This happens once unless you change something about a pin's setup. Let's say this is just to set the pin to input or output, with a pullup resister. This is just a rough description based on my experience 15 years ago. Basically all the ease of use that pigpio gives you comes at a price.
- Determine which register the pin p is in. I'm going to say its in resister A.
- Determine which bit of register A is needed for pin p. I'll call this x.
- Create a constant C so that you can set the pin you wish without effecting the other pins. This constant is C = 0x01 << x.
- First, make the pin into an input/output by and'ing or or xor'ing the i/o register A with C.
- Second, make the pin have a pullup resister by doing a very similar thing with the pullup register A.
Done every pin access Now we're working directly with resister A.
Steps 1-3 are the same. 4. And/or C with register A.
And there are some sanity checks that are used. Some registers aren't fully used. Pigpio must make sure that the pin is within range (in other words, there is a pin with that number).
If you're willing to do this all yourself, you can speed up the access quite a bit.
But please remember that I'm writing this from memory. I used to do this all the time on PIC microcontrollers, but that was 15 years ago.