Shop OBEX P1 Docs P2 Docs Learn Events
Passing an Array — Parallax Forums

Passing an Array

SailerManSailerMan Posts: 337
edited 2007-12-08 13:25 in Propeller 1
I have a COG 1 Running a Spin program that is collecting 12 Pulse and putting them in An Array continually. How can I pass that array to a program in another Cog?

Can someone point me in the right direction.

Thanks,
Eric
·

Comments

  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-12-08 03:28
    Let's say your array is declared as myArray[noparse][[/noparse]12]. You can reference the start of the array in memory with @myArray. someMethod(@myArray).

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    SelmaWare Solutions - StampPlot GUI for controllers, XBee and Propeller Application Boards

    Southern Illinois University Carbondale, Electronic Systems Technologies
  • SailerManSailerMan Posts: 337
    edited 2007-12-08 04:45
    Thanks, can you provide a small example?
  • CardboardGuruCardboardGuru Posts: 443
    edited 2007-12-08 10:19
    Take a look at the manual under COGNEW. Everything you need is documented there with examples on how to share a variable. Sharing an array is no different than sharing a simple variable.*

    (* - So long as you don't care that whilst reading with one COG the other COG might change the contents of the array half way through. If you do care about that, you need to look at the topic of LOCKS in the manual.)

    If you try something and have trouble getting it to work, then you can post a snippet here for further suggestions.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Help to build the Propeller wiki - propeller.wikispaces.com
    Play Defender - Propeller version of the classic game
    Prop Room Robotics - my web store for Roomba spare parts in the UK

    Post Edited (CardboardGuru) : 12/8/2007 10:27:09 AM GMT
  • deSilvadeSilva Posts: 2,967
    edited 2007-12-08 12:54
    You have not made clear that COG #2 is running an assembly program... If it is a SPIN program then no "passing" is needed at all.
  • Ron SutcliffeRon Sutcliffe Posts: 420
    edited 2007-12-08 13:17
    Sailer, does this help?





    'pilot.spin




    CON
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000
    cs =4 'pin 4 on adc cs ADC0830 pin assignments cs,clk,di,do.
    clk =5 'pin 7 on adc clk adc pins via 1K resitors to Prop (tempory solutions but works)
    dao =6 'pin 6 on adc do
    dai =7 'pin 5 on adc di
    dec = 10 'pin 10 decrement... simple push button
    as = 9 'pin 9 auto/standby.... simple push button ... for cal long hold down
    inc = 8 'pin 8 increment....simple push button
    mux_v =%011 'select channel 1 mux data .....monitor vane
    mux_ =%111 'select channel 2 mux data......monitor rudder position





    var
    long stack_1[noparse][[/noparse]10]
    long stack_3[noparse][[/noparse]10]
    long stack_2[noparse][[/noparse]20]
    long stack_4[noparse][[/noparse]40]
    long stack_5[noparse][[/noparse]40]
    byte mux_id 'channel select passed to PUB ADC returns "v"
    byte ib 'incoming data bit from ADC
    byte mode 'cal, standby, apparent wind steer of steer waypoint supplied by NMEA sentence from NAV center
    byte dir 'steer direction....port startboard
    byte c_r 'rudder setup in cal mode, one time set up
    byte c_v 'vane setup in cal mode, one time setup
    byte v 'normalized wind vane position
    byte r 'normalized ruder position
    byte p_len 'auto rudder gain
    byte ra 'rudder angle
    byte vd 'vane damping
    byte db 'dead band detect repetative course changes, ignor but keep checking pattern
    byte ss 'sea state
    byte cte 'cross track error
    byte rl 'rudder limit setup in cal mode
    byte k

    pub main
    'cognew(panel, @stack_1)
    'cognew(steer, @stack_3)
    cognew(adc(@v), @stack_2)
    'cognew(nmea(@wp),@stack_3)
    'cognew(control,@stack_5)
    mode:=0
    dira[noparse][[/noparse]4..7]:=%1101
    repeat
    v:=adc(mux_v)

    '*********************************************adc cog*******************************************
    pri adc (x)| y
    mux_id:=x
    y:=0
    outa[noparse][[/noparse]4..5]:=%10
    !outa[noparse][[/noparse]cs]
    repeat 3
    clkpulse
    outa[noparse][[/noparse]dai]:=mux_id
    mux_id:=mux_id>>1
    ib:=0
    repeat 9
    clkpulse
    ib:=ina[noparse][[/noparse]dao]
    y:= (y << 1) + ib
    return y


    pri clkpulse
    pse
    !outa[noparse][[/noparse]clk]
    pse
    !outa[noparse][[/noparse]clk]



    pri pse
    waitcnt(clkfreq/1000+cnt)


    Extract from auto.pilot
    Assuming the both cogs are spin
    ron
  • Ron SutcliffeRon Sutcliffe Posts: 420
    edited 2007-12-08 13:25
    It won't because no indents..Yuk !!.......if you think it might help I will re submit, but the code pretty basic stuff.
Sign In or Register to comment.