Shop OBEX P1 Docs P2 Docs Learn Events
Assigning arrays with values from from BS2.PULSIN — Parallax Forums

Assigning arrays with values from from BS2.PULSIN

Paul_HPaul_H Posts: 85
edited 2007-03-18 15:01 in Propeller 1
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:

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

  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-18 04:19
    Unfortunately, the forum software uses stuff in square brackets to control formatting and an "i" in square brackets is used to set italics. Next time, put a space after the opening bracket and the "i" will be ignored.

    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.
  • Paul_HPaul_H Posts: 85
    edited 2007-03-18 14:37
    Thanks Mike,
    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
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-18 15:01
    It must be something wrong with the rest of the program (that you're not showing). Maybe you're not doing the COGNEW properly. Maybe you're not providing a large enough stack space (since the BS2 routines will use some). It's really important to post your whole program or, at least, those parts that call or are called up to the point you have a problem. If your program is large, post it as a text attachment.

    It's also helpful to include a schematic or at least a description of what's connected to what.
Sign In or Register to comment.