-
Pulsin on multipins
Hi Guys ,
I have need to do pulsin on a device that has 18 inputs connected to sensors the changes are generally large and updated every 2 mins. so basicly a status summery of the sensors is done
the code would be the same with only the array varable storing the change for each sensor
I thought using the nice method hendric showing of using lookup , with an port offset would work , but sadly not for pulsin as i am getting rubbish on readings which are above 15
, i think its cos the offset number from porta is larger value than 15 and pulsin has a value limit at 15 ????
Can anyone advise how to solve this prob with multi inputs with pulsin or am i incorrect ???
Cheers
Sheldon
Code:
Eg
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
pulsin PORTA.0[PortOffset],1,Leader
Sensor(T) = Leader
Next T
-
Re: Pulsin on multipins
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
-
Re: Pulsin on multipins
thanks darrel, that worked , i also added a timeout .
You must have redone pulsin, rctime others commands , in replacement code many times , a code equivalent link page to those code examples would be handy if they were one place for a reference
Cheers
Sheldon