Shop OBEX P1 Docs P2 Docs Learn Events
passing a varible to a cog — Parallax Forums

passing a varible to a cog

SawmillerSawmiller Posts: 276
edited 2006-07-18 23:10 in Propeller 1
hi guys, i seem to not be able to figure out how to pass a varible to a cog...
what i want is for the adc to constantly update a memory location, and the rest of the program to access it when needed. i made a separate object max_1270 , but i cant seem to interface it, ( does bad things to the tv display )
heres the programs , if you can fix it so i can have max_1270 running in a cog continously and the rest able to access it i'd appricate it...
but please comment it so i can figure it out.. that way i'll get the concept.( have been at the manual several times now)
dan
sawmillmain works, sawmillmain rev1 and max_1270 are where i tried to separate them

thanks for lookin
dan

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2006-07-18 18:17
    With just a cursory glance, you are trying to use the same stack space for both new cogs (you used stack where you should have had stack1). I don't know why it mucks up the tv display, but most anything can happen when two cogs try to run on the same stack.

    The basic idea is sound ... Start a cog that continuously updates a variable referenced by the main cog. The way you did it is fine otherwise. I didn't look at the rest of the logic.
  • SawmillerSawmiller Posts: 276
    edited 2006-07-18 20:18
    but does this varible have to be in a dat area, or is it good enuf to declare it as a global varible ?
    dan
  • Mike GreenMike Green Posts: 23,101
    edited 2006-07-18 21:08
    It could be either. Usually the DAT area is for initialized data or assembly routines and the VAR area is for spin variables. If you use two copies of an object with VAR and DAT areas, the VAR areas get allocated once for each copy, but the DAT areas (like the PRI/PUB code) get allocated only once.
  • SawmillerSawmiller Posts: 276
    edited 2006-07-18 21:31
    sorry mike, i can get it to display if i dont have a additional repeat at the top of get_count ( i think the cog ends , then the display can contiune) but if i get that cog ( using stack1) to run continously, i cant get anything to display on my video out, also have tried this with up to long stack1[noparse][[/noparse]2000] just to be sure the stack wasnt the prob.
    ahh well, all in one program is ok, for me, was just hoping to be able to contribute max_1270 as a object for others.
    thanks for the help
    dan
  • Mike GreenMike Green Posts: 23,101
    edited 2006-07-18 21:47
    In rev1, you have "cognew(adc.get_count(%10001000, 10, @ADC_temp),stack)". The "stack" needs to be "@stack". Does that help?
  • SawmillerSawmiller Posts: 276
    edited 2006-07-18 22:22
    well thats one bug i didnt see [noparse]:([/noparse]

    still doesnt work thou, its like it never comes back from cognew
  • SawmillerSawmiller Posts: 276
    edited 2006-07-18 23:10
    sorta wierd mike, but i got it to work, took a example from the one wire demo and created a start object in max_1270 that runs the newcog, and it works

    i just have to refer to adc.start in my main program

    var·· long stack1[noparse][[/noparse]20]
    ·
    pub start(control,average,ADC_addr)

    · cognew(get_count(control,average,ADC_addr),@stack1)
    ·
    ·············
    pub get_count(control_bit, average_sample, ADC_count_address) | temp, adresult_temp

    dont know why it wouldnt work from main, but at least it works now.

    dan
Sign In or Register to comment.