2

Using Pigpio to drive a couple of stepper motors on a CNC-like system, I'd like to "initialize" by setting up a repeating wave to continually step until a limit switch has been reached, at which point I'd issue a wave_tx_stop() to halt the stepper. I'm curious if there's any way of seeing how many pulses have been issued at the point the wave was stopped, so that I could deduce how many steps "wide" the area is between limit switches.

That is, is there any way to see how many total pulses have been executed by the currently-running wave chain? Am I just way off base here and need to try something different?

Jordan Day
  • 23
  • 3

2 Answers2

2

For all those still searching: Actually there is - contradictory to the current answer - a pretty good solution also provided by pigpio (at least for me there was)!

You can use either piscope (a way too much overhead) or if the frequency is not too high you can use pigpio.callback() too keep accurate track of the total pulses sent.

cb = pi.callback(GPIO)
# to create a simple "callback counter" on the pin where the PWM pulses are sent
print(cb.tally()) # to display number of pulses made
cb.reset_tally() # to reset the counter

See also following Stackexchange Post

n0sr3v
  • 21
  • 2
  • I'd like to point out that this is not accurate if your wave pulses are on the order of 100 us or less. Around 30% of the time it'll miss a few pulses. – Slight Feb 01 '22 at 02:35
1

You will have to find an alternative mechanism. There is no way to tell how many pulses have been transmitted by an interrupted wave chain (unless the pulses are quite slow and you have an alert set up on the pulse GPIO).

If you run a wave chain with a loop count to completion it will have executed the number of pulses in the loop count.

joan
  • 71,024
  • 5
  • 73
  • 106
  • Ah, that's a bummer, but it makes sense. Out of curiosity, do you have an idea as to what constitutes "quite slow" in this context? 100 us? 1ms? More? Anyway, thank you for the quick response. – Jordan Day Oct 26 '17 at 13:43
  • @JordanDay Speed would depend on the language (e.g. C is likely to be better than Python) and principally the interface, e.g. the socket interface (used by Python) will be slower than a directly linked C application. As a ball park something like 40k per second on a Pi3 using Python. – joan Oct 26 '17 at 15:40