PDA

View Full Version : I need help with a call to a class



hooktxu
07-16-2009, 05:05 PM
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[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[14]:=0 'Patita del sensor magnetico 1 configurada como entrada
DirA[13]:=0 'Patita del sensor magnetico 2 configurada como entrada
DirA[12]:=0 'Patita del sensor magnetico 3 configurada como entrada
DirA[11]:=0 'Patita del sensor magnetico 4 configurada como entrada
DirA[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[14]==0)
waitcnt(18_000_000+cnt)
outa[16] := High
nMag:=1
''iWifi.compassServerConnection(0,1)
readed:=1
elseif(InA[14]==1)
waitcnt(40*12_000_000+cnt)
outa[16] := Low

if(InA[13]==0)
waitcnt(18_000_000+cnt)
outa[16] := High
nMag:=2
''iWifi.compassServerConnection(0,1)
readed:=1
elseif(InA[13]==1)
waitcnt(40*12_000_000+cnt)
outa[16] := Low

if(InA[12]==0)
waitcnt(18_000_000+cnt)
outa[16] := High
nMag:=3
''iWifi.compassServerConnection(0,1)
readed:=1
elseif(InA[12]==1)
waitcnt(40*12_000_000+cnt)
outa[16] := Low

if(InA[11]==0)
waitcnt(18_000_000+cnt)
outa[16] := High
nMag:=4
''iWifi.compassServerConnection(0,1)
readed:=1
elseif(InA[11]==1)
waitcnt(40*12_000_000+cnt)
outa[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¨???

MagIO2
07-16-2009, 05:36 PM
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.

hooktxu
07-16-2009, 05:59 PM
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

MagIO2
07-16-2009, 06:05 PM
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.

hooktxu
07-16-2009, 06:12 PM
And how can I solve it?

MagIO2
07-16-2009, 07:06 PM
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

heich
07-17-2009, 11:36 PM
Hi.

i do speak spanish.

let's see if i can help you with my poor english :)




'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[14]:=0 'Patita del sensor magnetico 1 configurada como entrada
DirA[13]:=0 'Patita del sensor magnetico 2 configurada como entrada
DirA[12]:=0 'Patita del sensor magnetico 3 configurada como entrada
DirA[11]:=0 'Patita del sensor magnetico 4 configurada como entrada
DirA[16]~~ 'LED VERDE

cognew(testearMagnetico,@sensorStack)







Regards

Heich

MagIO2
07-18-2009, 12:31 AM
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.

Microcontrolled
07-18-2009, 05:20 AM
hooktxu speaks Spanish, so you can jabber away to him if you know the language. http://forums.parallax.com/images/smilies/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!!··

SamMishal
07-19-2009, 01:27 AM
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[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[14..11]~ 'Patita del sensor magnetico 1..4 configurada como entrada
DirA[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[14-i]==0)
waitcnt(18_000_000+cnt)
outa[16] := High
nMag:=i+1
''iWifi.compassServerConnection(0,1)
readed:=1
elseif(InA[14-i]==1)
waitcnt(40*12_000_000+cnt)
outa[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