joan2937 / pigpio

pigpio is a C library for the Raspberry which allows control of the General Purpose Input Outputs (GPIO).
The Unlicense
1.46k stars 410 forks source link

feature request: increase number of allowed loops in gpioWaveChain #382

Open kektobiologist opened 4 years ago

kektobiologist commented 4 years ago

Right now there is a hard limit of 20 loop counters (as per documentation) in a wave chain I am trying to create a ramp pulse input with ~100 square waves of 10 ms duration each of increasing frequencies (5000us pulse width to 10us pulse width), however the library only allows 20 loop counters (so 20 waves) at most. Is this a hardware limitation or can it be changed? In the code I can see the limit is defined as

#define WCB_COUNTERS (WCB_CNT_PER_PAGE * PI_WAVE_COUNT_PAGES)

where WCB_CNT_PER_PAGE is 2 and PI_WAVE_COUNT_PAGES is 10 Any help would be appreciated. EDIT: changed wording to make it clearer

guymcswain commented 4 years ago

Where are you seeing this limitation? The documentation, as I read it, shows a loop count of

loop x + y*256 times

is possible. Both x, y are 8-bit integers.

kektobiologist commented 4 years ago

sorry i meant loop counters, not loop count

The code is currently dimensioned to support a chain with roughly 600 entries and 20 loop counters.

i.e. i can have only 20 loop blocks in the chain, having more throws PI_CHAIN_COUNTER

guymcswain commented 4 years ago

Ok, thanks for clarifying. The limitation may be due to the allocated dma control blocks in memory which may have been arbitrary when @joan2937 implemented the code. Even if it is, to change it could require a fairly involved effort.

Also, you may want to check if sending waves synchronously, each with 20 loop counters, is workable for your application. You would only need to monitor the wave status and send another wave every 200ms (if I'm understanding your requirement).

kektobiologist commented 4 years ago

Thank you. I'm up for contributing if @joan2937 thinks this is worthwhile, or I'd like to know if there's another way around this.

kektobiologist commented 4 years ago

I couldn't find any documentation related to sending synchronous wave chains. Do you mean using wave_send_using_mode(PIN, pigpio.WAVE_MODE_ONE_SHOT_SYNC) to send individual waves?

guymcswain commented 4 years ago

Yes. But now that I think about it, you would have to send each individual wave. If they are 10ms long and your network isn't slow, you should be able to keep up using gpiowavetxat to know when the next wave is playing.