Using Counters for Ping?
                    Is it possible to use the Propeller counters to read the results from a PING? It's easy enough to bit bang the start pulse, but waiting and blocking for the response is valuable program time wasted. I'd much rather use a counter to get that duration.                
                            
                            
Comments
mov ctrb,#0 'Setup Counter B to monitor high state time of PW pin on MAXBOTIX ping sensor mov ctrb,cntrstate mov frqb,#1 PING mov dummy1,ina ' Sample pins and dummy1,PING_PIN ' Limit to PW pin of MaxBotix ping sensor cmp dummy1,#0 wz ' If ina==0, between pulses cmp min_cmp,phsb wc ' If phsb>0, phsb contains pulse width of previous pulse if_c_and_z call #PING_WRITE PING_RET ret cntrstate LONG (%11010 << 26 ) | (%001 << 23) | (0 << 9) | (9) 'Last digit is pin declarationCON _clkmode = xtal1 + pll8x ' _xinfreq = 5_000_000 NCOMODE = % 00100 << 26 POSDETMODE = % 01000 << 26 OBJ pst : "Parallax Serial Terminal" PUB PingCount(pin) | trigger frqa := 1 trigger := -(clkfreq/1000000 * 8) ' for 8us duration repeat ' send an 8us trigger pulse dira[pin]~~ ctra := NCOMODE | pin phsa := trigger waitpeq(0, |<pin, 0) ' until end of trigger pulse ' capture the return pulse with counter dira[pin]~ ctra := POSDETMODE | pin phsa := 0 ' do other stuff here ' at least 20ms, but less than 26 seconds (at clkfreq=80MHz) pause(1000) ' just a pause for example pst.dec(phsa) pst.newline PRI Pause(ms) waitcnt(clkfreq/1000*ms+cnt)