Shop OBEX P1 Docs P2 Docs Learn Events
I need help with a call to a class — Parallax Forums

I need help with a call to a class

hooktxuhooktxu Posts: 33
edited 2009-07-18 17:27 in Propeller 1
I have got this class:

CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000

High = 1
Low = 0
Out = %1

OBJ
  iWifi : "iWiFiXXX"

VAR
long sensorStack[noparse][[/noparse]20]
byte readed
byte nMag

PUB arrancar
'Reservamos el uso de un cog para la rutina testeo asignandole un espacio en pila
'Metodo que me reserva el uso de un nuevo cog, haciendo llamada a la rutina parpadeo
'y reservando un espacio de memoria en la pila

cognew(testearMagnetico,@sensorStack)

PUB testearMagnetico 

  
  DirA[noparse][[/noparse]14]:=0 'Patita del sensor magnetico 1 configurada como entrada
  DirA[noparse][[/noparse]13]:=0 'Patita del sensor magnetico 2 configurada como entrada   
  DirA[noparse][[/noparse]12]:=0 'Patita del sensor magnetico 3 configurada como entrada   
  DirA[noparse][[/noparse]11]:=0 'Patita del sensor magnetico 4 configurada como entrada   
  DirA[noparse][[/noparse]16]~~  'LED VERDE

  'Rutina en forma de bucle que se encarga de chequear de forma continua si el sensor detecta un nivel
  waitcnt(clkfreq*10 + cnt)

  repeat

    if(InA[noparse][[/noparse]14]==0)
      waitcnt(18_000_000+cnt)
      outa[noparse][[/noparse]16] := High
      nMag:=1
      ''iWifi.compassServerConnection(0,1)
      readed:=1
    elseif(InA[noparse][[/noparse]14]==1)
      waitcnt(40*12_000_000+cnt)
      outa[noparse][[/noparse]16] := Low
      
    if(InA[noparse][[/noparse]13]==0)
      waitcnt(18_000_000+cnt)
      outa[noparse][[/noparse]16] := High
      nMag:=2  
      ''iWifi.compassServerConnection(0,1)
      readed:=1
    elseif(InA[noparse][[/noparse]13]==1)
      waitcnt(40*12_000_000+cnt)
      outa[noparse][[/noparse]16] := Low
      
    if(InA[noparse][[/noparse]12]==0)
      waitcnt(18_000_000+cnt)
      outa[noparse][[/noparse]16] := High
      nMag:=3 
      ''iWifi.compassServerConnection(0,1)
      readed:=1
    elseif(InA[noparse][[/noparse]12]==1)
      waitcnt(40*12_000_000+cnt)
      outa[noparse][[/noparse]16] := Low
      
    if(InA[noparse][[/noparse]11]==0)
      waitcnt(18_000_000+cnt)
      outa[noparse][[/noparse]16] := High
      nMag:=4 
      ''iWifi.compassServerConnection(0,1)
      readed:=1
    elseif(InA[noparse][[/noparse]11]==1)
      waitcnt(40*12_000_000+cnt)
      outa[noparse][[/noparse]16] := Low
      
PUB leernMag
  return nMag




I want to call to this class and obtain nMag. i do this, but it can´t work:

sensorMagnetico.arrancar
waitcnt(clkfreq*2 + cnt)
A:=sensorMagnetico.leernMag




What can I do¨???

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2009-07-16 09:36
    Do you want the content of nMag or do you want the adress, so that you can access it directly?
    Currently you will get the content of nMag. So each time you want to know what the state of nMag is, you have to call leernMag.

    Variable A will be always empty (= 0), as you have a waitcnt(clkfreq*2+cnt) in the code that should obtain nMag, but you have a waitcnt(clkfreq*10+cnt) inside of arrancar.
  • hooktxuhooktxu Posts: 33
    edited 2009-07-16 09:59
    I want the content of nMag (1, 2, 3 or 4).
    How can I get the solution? I don't understand what you say me about the times
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-07-16 10:05
    You call sensorMagnetico.arrancar, which will start a new COG with the testearMagnetico running.
    sensorMagnetico.arrancar will return immediately - not waiting for the new COG to be started AND not waiting for testearMagnetico which waits 10 seconds.
    So, after 2 seconds you read nMag, but after 10 seconds it will be written by testearMagnetico for the first time. That's the problem.
  • hooktxuhooktxu Posts: 33
    edited 2009-07-16 10:12
    And how can I solve it?
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-07-16 11:06
    I don't speak spanish, so I cant read the comment above the waitcnt, but I suppose the testearMagnetico waits for 10 sec for a good reason?!

    So, the fix would be : wait for at least 11 sec before you call leernMag for the first time.

    sensorMagnetico.arrancar
    waitcnt(clkfreq*12 + cnt)
    A:=sensorMagnetico.leernMag
  • heichheich Posts: 26
    edited 2009-07-17 15:36
    Hi.

    i do speak spanish.

    let's see if i can help you with my poor english [noparse]:)[/noparse]


    'Rutina en forma de bucle que se encarga de chequear de forma continua si el sensor detecta un nivel
    waitcnt(clkfreq*10 + cnt)
    
      repeat
    
    
    




    The comment says, in other words "continous loop to validating if the level sensor detects a level raising"

    IMOO, besides the code posted by @MagIO2, i'd put all the pin settings on sensormagnetico.arrancar routine


    PUB arrancar
        'Reservamos el uso de un cog para la rutina testeo asignandole un espacio en pila
        'Metodo que me reserva el uso de un nuevo cog, haciendo llamada a la rutina parpadeo
        'y reservando un espacio de memoria en la pila
    
        DirA[noparse][[/noparse]14]:=0 'Patita del sensor magnetico 1 configurada como entrada
        DirA[noparse][[/noparse]13]:=0 'Patita del sensor magnetico 2 configurada como entrada   
        DirA[noparse][[/noparse]12]:=0 'Patita del sensor magnetico 3 configurada como entrada   
        DirA[noparse][[/noparse]11]:=0 'Patita del sensor magnetico 4 configurada como entrada   
        DirA[noparse][[/noparse]16]~~  'LED VERDE
    
        cognew(testearMagnetico,@sensorStack)
    
    
    





    Regards

    Heich
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-07-17 16:31
    Nope, pin setting was correct. Please remember, each COG has it's own set of dira and outa registers. So, YOU HAVE TO set the pins as output in the COG that uses these pins! Only thing is ... for input pins it makes no difference, as the DIRA of each COG is initialized as input.
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2009-07-17 21:20
    hooktxu speaks Spanish, so you can jabber away to him if you know the language. smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Toys are microcontroled.
    Robots are microcontroled.
    I am microcontroled.



    If it's not Parallax then don't even bother. :-)
    ·

    Mini-Din/PS2 connectors are for sale! 5 for $1! PM me if you wish to make an order.
    Cheap·shipping unless specified!··········150 left!!··


  • SamMishalSamMishal Posts: 468
    edited 2009-07-18 17:27
    Hola HookTxU,

    Le aconsejo cambiar su co'digo a eso de abajo....
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
      High = 1
      Low = 0
      Out = %1
       
    OBJ
      iWifi : "iWiFiXXX"
     
    VAR
      long sensorStack[noparse][[/noparse]20]
      byte readed
      byte nMag
      byte Cog
     
    PUB arrancar:OK
    'Reservamos el uso de un cog para la rutina testeo asignandole un espacio en pila
    'Metodo que me reserva el uso de un nuevo cog, haciendo llamada a la rutina parpadeo
    'y reservando un espacio de memoria en la pila
      Stop
      OK := Cog:= cognew(testearMagnetico,@sensorStack)+1
     
    Pub Stop
      if Cog
        CogStop(Cog~ - 1)
     
    PUB leernMag|T
      T := ClkFreq*12+Cnt
      repeat until Readed or cnt => T
      if cnt => T
         return 0
      else   
         return nMag
       
    Pri testearMagnetico|i 
      DirA[noparse][[/noparse]14..11]~ 'Patita del sensor magnetico 1..4 configurada como entrada
      DirA[noparse][[/noparse]16]~~  'LED VERDE
      'Rutina en forma de bucle que se encarga de chequear de forma continua si el sensor detecta un nivel
      waitcnt(clkfreq*10 + cnt)
      repeat
        Readed~
        repeat i from 0 to 3
          if(InA[noparse][[/noparse]14-i]==0)
            waitcnt(18_000_000+cnt)
            outa[noparse][[/noparse]16] := High
            nMag:=i+1
            ''iWifi.compassServerConnection(0,1)
            readed:=1
          elseif(InA[noparse][[/noparse]14-i]==1)
            waitcnt(40*12_000_000+cnt)
            outa[noparse][[/noparse]16] := Low
    

    Asi esto
    ··· sensorMagnetico.arrancar
    ··· waitcnt(clkfreq*2·+·cnt)
    ··· A:=sensorMagnetico.leernMag


    Siempre returnara' o Zero or el numero 1..4 depende si Readed esta' uno o no....

    Samuel

    Post Edited (SamMishal) : 7/18/2009 5:48:23 PM GMT
Sign In or Register to comment.