Very basic prop code help
VAR
·· long Stack[noparse][[/noparse]9]
PUB Main
··· cognew(Toggle(16,3000000,10),@Stack)
··· Toggle(17 ,2000000,20)
PUB Toggle(Pin,Delay,Count)
··· dira[noparse][[/noparse]pin]~~ 'set to output
··· REPEAT Count
······· !outa[noparse][[/noparse]Pin]
······· waitcnt(Delay + cnt)
I need a little help with the above code.
The program is supposed to blink led's off and on. When I look at it I dont see how this works.
The dira sets pins 16 and 17 to ouput.
outa sets pins to high or low. I dont see how the RETURN function is going to set the [noparse][[/noparse]pin]
to turn off and on the LEDS. The return loop is going to continually turn or·keep the LED's on ?·······
Also when I use VAR instead of CON , for some of my spin trials it will not compile using VAR. ??·
Post Edited (thewhiteoxe) : 9/13/2009 7:11:07 AM GMT
·· long Stack[noparse][[/noparse]9]
PUB Main
··· cognew(Toggle(16,3000000,10),@Stack)
··· Toggle(17 ,2000000,20)
PUB Toggle(Pin,Delay,Count)
··· dira[noparse][[/noparse]pin]~~ 'set to output
··· REPEAT Count
······· !outa[noparse][[/noparse]Pin]
······· waitcnt(Delay + cnt)
I need a little help with the above code.
The program is supposed to blink led's off and on. When I look at it I dont see how this works.
The dira sets pins 16 and 17 to ouput.
outa sets pins to high or low. I dont see how the RETURN function is going to set the [noparse][[/noparse]pin]
to turn off and on the LEDS. The return loop is going to continually turn or·keep the LED's on ?·······
Also when I use VAR instead of CON , for some of my spin trials it will not compile using VAR. ??·

Post Edited (thewhiteoxe) : 9/13/2009 7:11:07 AM GMT
Comments
1. The pin is toggled using the ! (not) operator. Basically, it converts a 1 into a 0 and a 0 into a 1, which when done to outa will make it high or low.
2. There is no "return" function. What did you mean by this?
3. The loop repeats count number of times, however many times that is (10 and 20 for this code)
4. The toggle function ends when the loop finishes, and will go into a limbo state since there's nothing else to do.
5. VAR where?
·· long Stack[noparse][[/noparse]9]
PUB Main
··· cognew(Toggle(11001100,3000000,10),@Stack)
··· Toggle(11110000 ,2000000,20)
PUB Toggle(Pin,Delay,Count)
··· dira[noparse][[/noparse]pin]~~ 'set to output
··· REPEAT Count
······· !outa[noparse][[/noparse]Pin]
······· waitcnt(Delay + cnt)
When cog 0 Pin of 11110000 goes through the REPEAT loop Twenty times·!outa changes the Pin value to
00001111. But does'nt the pin value stay at 00001111 for each pass ?
Also the manual says the delay , in the case of cog 0 ,of 2,000,000, is the number of clock cycles for the delay. But if that was so there would be no need for + cnt . So does the clock count up to 10,000,000
and then starrt from 0 again ?
Ps. I just used random binary numbers in the above. I dont understand Binary if you have a tip where I can learn this I'll follow it up.
Post Edited (thewhiteoxe) : 9/13/2009 3:38:11 PM GMT
Read the waitcnt description in the manual. It says that waitcnt waits for count to be equal to the argument, so if you just put in 2_000_000 then it will wait for the clock to equal that. If instead you add it to cnt, then it will effectively wait for 2_000_000 cycles, then continue.
For learning binary, just google binary tutorial. There's lots of stuff out there; find something that works for you.
Was I correct about the value staying the same for each loop in REPEAT ?
Picture a row of 32 light switches on a wall. Each switch has a number (1 to 32) so that each switch corresponds to a pin on the Propeller chip. We will call this row of switches "outa".
If we want to turn every switch on we would say "outa ~~", to turn them all off, "outa ~"
To turn on a group of switches we could say "outa[noparse][[/noparse]4..6]~~" That would turn on switches 4, 5 and 6.
To turn on just switch 17 we would say "outa[noparse][[/noparse]17]~~".
To change switch 17 we say "!outa[noparse][[/noparse]17]".
"pin" does not change within the repeat loop. "pin" is like the number on the switch, not the position the switch is in.
Rich H
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Servo Boss, a 12 channel servo tester kit from Gadget Gangster.