Sheldon,
What's happening there is ... it will look at the state of the specified pin, and use either 0 or 1 for the pulsin pin, which is usually PORTB.0 or PORTB.1 depending on the chip being used.
So let's say T = 3, then the LOOKUP returns 16.
An offset of 16 from PORTA.0 is PORTC.0, so it gets the state of that pin (0 or 1).
If PORTC.0 = 0, it does the PULSIN on PORTB.0.
If PORTC.0 = 1, it does the PULSIN on PORTB.1.
There's probably a hundred ways to accomplish it, but here's an untested/not compiled thought.
Code:
FOR T = 0 TO 17
lookup T [ 9,11,13,16,18,22,1,4,6,8,26,27,28,25,23,21,32,34], Portoffset ' Sensor input 1 - 18
Leader = 0
IF PORTA.0[PortOffset] = 0 THEN
WHILE PORTA.0[PortOffset] = 0 : WEND ; Wait for start of pulse
WHILE PORTA.0[PortOffset] = 1 ; Measure Pulse Width
Leader = Leader + 1
PAUSEUS 5 ; Adjust loop timing to your needs
WEND
ELSE
; error, pin was not low to start
ENDIF
Sensor(T) = Leader ; Store Result
NEXT T
Bookmarks