Assigning arrays with values from from BS2.PULSIN
Hi All,
I've been struggling this weekend on using the propeller's BS2 PULSIN function to count radio control receiver's pulses. If I assign each of my 6 inputs to unique variable (like Rx3 := BS2.PULSIN(3,1), I have no problems. Also, If I manually assign values to an array (like rx := 1000) and display them I am good. But when I try to assign the array in a loop I get all zeros when I read out the array. My code snip:
In this example the input pins are the same as the counter value. The array is available to all cogs.
Any help with array assignment is appreciated!
Thanks,
Paul
I've been struggling this weekend on using the propeller's BS2 PULSIN function to count radio control receiver's pulses. If I assign each of my 6 inputs to unique variable (like Rx3 := BS2.PULSIN(3,1), I have no problems. Also, If I manually assign values to an array (like rx := 1000) and display them I am good. But when I try to assign the array in a loop I get all zeros when I read out the array. My code snip:
VAR
long rx[noparse][[/noparse]6] ' is this needed?
PUB AssignArray | i
repeat
repeat i from 1 to 6
rx[i] := BS2.PULSIN(i,1) 'to assign rx(i)
PUB ArrayShow | i
' repeat i from 1 to NumSrv
' text.dec(rx[i]) ' commented area doesnt work. trying to output value of rxi array in a column
' text.str(string(13))
' show receiver input from array (Works)
text.str(string($A,5,$B,4)) 'set position
text.dec(rx) 'display Rx Channel 1 pulse count
text.str(string($A,5,$B,5)) 'set position
text.dec(rx) 'display Rx Chan 2
text.str(string($A,5,$B,6)) 'set position
text.dec(Rx) 'display Rx Chan 3
text.str(string($A,5,$B,7)) 'set position
text.dec(Rx) 'display Rx Chan 4
text.str(string($A,5,$B,8)) 'set position
text.dec(Rx) 'display Rx Chan 5
text.str(string($A,5,$B,9)) 'set position
text.dec(Rx[noparse][[/noparse]6]) 'display Rx Chan 6
[/i][/i]
In this example the input pins are the same as the counter value. The array is available to all cogs.
Any help with array assignment is appreciated!
Thanks,
Paul

Comments
Assuming you're trying to write
PUB AssignArray | i repeat repeat i from 1 to 6 rx[noparse][[/noparse] i] := BS2.PULSIN(i,1) 'to assign rx(i) PUB ArrayShow | i ' repeat i from 1 to NumSrv ' text.dec(rx[noparse][[/noparse] i]) ' commented area doesnt work. trying to output value of rxi array in a column ' text.str(string(13))The biggest problem I see is that subscripts run from 0 to one less than the array size. You'll overwrite the next long after rx[noparse][[/noparse] 5].
I assume you're running AssignArray in a separate cog. What follows rx? Maybe AssignArray is overwriting it's stack area.
I still haven't figured out how you are able to read and reply to every post here. Wow! Thanks for the formatting tip - I didn't catch that but wondered about the italics... You are correct in what was meant.
Yes, I have ArrayAssign on its own cog, ArrayShow runs on the first cog, and I've tries on its own with the same result.
I've started at 0 and thought about the stack size, so I intentionally created an array larger than I needed - no luck :-(
I'm a new-again programmer, so I think I must have the logic wrong. I'l lkeep plugging away.
Paul
It's also helpful to include a schematic or at least a description of what's connected to what.