PDA

View Full Version : Problems moving an array to a new cog



Joms
03-24-2012, 05:34 AM
I am trying to move an array address to a new cog. My code works without starting a new cog, so I know it has to do with trying to move the address of the array. The array I am dealing with is 50 longs.



Var
long stack[500]
long LEDstrip1

PUB Main | i, r

cognew (sendLED(@Ledstrip1), @Stack)

PUB sendLED(addr) | i, t

repeat i from 5 to 9
If (addr[t] & |< i)
outa[PinLEDdata]~~
else
outa[PinLEDdata]~

more code goes here...


If I change the addr in the if statement to the variable name, it works ok, so I know it has to do with passing the address. Is there a different way I should pass the address? Eventually I will move this part to its own object.

I left out a the complicated part of the code because it isn't commented yet, and just complicates it...

Thanks in advance!

kuroneko
03-24-2012, 05:41 AM
What's the purpose of "t" (it's an uninitialised local variable)? I assume you want to (effectively) scan the long variable LEDstrip1 so a long[addr] & |< i should do.

Also, you mention 50 longs, where are they? If addr is the address of a long array then long[addr][idx] should be used (idx = 0..49).

Mike G
03-24-2012, 05:45 AM
Joms, you are not passing an array. You are passing an pointer to an uninitialized long.

Joms
03-24-2012, 06:00 AM
-kuroneko
I did try that earlier and it didn't work. I did try again with a few different things, and still couldn't figure the syntax of it out.

-Mike G
Forgive me here, but what do you mean by unsigned?

I attached the file I am working with...it isnt commented out, but should be pretty easy to see the idea of what I am doing.

Basically, I have a strip of 50 LEDs that use the LPD6803 IC. I am trying to build something that will allow me to chase them, and change colors, etc. Basically, every long in the variable controls one LED. 5-bits are red, 5-bits green, 5-bits blue. I am hoping when I am done I can be able to shift bits left, right, etc to chase, or just set the array to all one number to make a steady color.

If I am over complicating this and there is a much simplier way, please point it out. I am fairly new to data and playing with this LED strip to try and learn more about managing data like the sparkfun LED strip...

kuroneko
03-24-2012, 06:22 AM
When you move to a different cog you also need to move any dira setup.

Mike G
03-24-2012, 06:28 AM
I said uninitialized not unassigned. Uninitialized means the value of LEDstrip1 is zero.



CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000

LED_ARRAY_LENGTH = 50

VAR
long leds[LED_ARRAY_LENGTH]
long stack[30]

DAT

OBJ
pst : "Parallax Serial Terminal"


PUB Main
pst.Start(115200)
InitializeLedArray
pause(1000)

cognew(LedProcess, @stack)


PRI InitializeLedArray | i
i~
repeat LED_ARRAY_LENGTH
leds[i++] := !i

PRI LedProcess | i
i~
repeat
repeat LED_ARRAY_LENGTH
pst.bin(leds[i++], 32)
pst.char($0D)
pause(1000)


PRI pause(Duration)
waitcnt(((clkfreq / 1_000 * Duration - 3932) #> 381) + cnt)
return

kuroneko
03-24-2012, 06:41 AM
FWIW, this

If (long[addr][t] & |< i)
outa[PinLEDdata]~~
else
outa[PinLEDdata]~

can be shortened to


outa[PinLEDdata] := long[addr][t] >> i

Joms
03-24-2012, 07:10 AM
OK...I have tried both of these...

kuroneko - I did get yours to work... And read up on what I was doing wrong...

Mike - I tried yours just because I wanted to learn more about how you did it... And found a new problem. I can't get my waitcnt to work, even in the simplest form.



waitcnt(clkfreq + cnt) ' should wait 1 second

waitcnt(clkfreq / 5 + cnt) 'should wait .5 second


when I use the 1/2 second, I get no delay, when I use the 1 second, it doesn't go on. I checked and the crystal is ok... Wondering if it is a problem with the cog?

On a side note, I am still haveing problems actually making a new object and getting the memory address to move to the object.

kuroneko
03-24-2012, 07:31 AM
On a side note, I am still haveing problems actually making a new object and getting the memory address to move to the object.
See if this helps. The main object initialises the array (at least part of it) and the child object sends the data repeatedly. No methods (and code) for life-cycle management have been added (i.e. you can't stop the emitter cog).

Joms
03-24-2012, 07:52 AM
I think that is what was happening... I actually found that in a different project and copied it over... THANKS A TON FOR HELPING WITH THAT!

Now I just need to figure out the waitcnt problem... I have been looking at the book and appears to be the right syntax, however it locks the prop up when I use the command...

kuroneko
03-24-2012, 08:01 AM
Now I just need to figure out the waitcnt problem... I have been looking at the book and appears to be the right syntax, however it locks the prop up when I use the command...
Can you send some sample code? What you posted doesn't look wrong as such.

Joms
03-24-2012, 08:12 PM
I got the waitcnt to work. To be fairly honest, I am not sure what I did. I added an LED to an output pin for testing, basically I could toggle the LED on and off at different places in the program to tell if it was working, like a very simple debug. I am guessing I didn't have something quite lined up correctly...

THANKS FOR THE HELP!