newb question
Bobb Fwed
Posts: 1,119
I am very new to the propeller....eh, just got it this morning.
I am trying to start something simple, something I am familiar with...rctime ... I know there are other objects and whatnot that do the same thing, but I'm learning a new language, so I'd like to figure it out for myself.
I am using the DIP chips on the Propeller RPM.
Here is the code I have:
What I am trying to accomplish: one cog (cog 1) continuously reads the RCtime of a photoresistor I have, and the other cog (cog 2) continuously displays the value (at a reduced brightness).
What happens: as the RCtime increases the LEDs start to blink (as it seems it is waiting for the RCtime), and for some unexplainable reason, no matter what divider I put on the "store time to global var" line, it doesn't actually affect the output, which seems to mean, I am getting the value from somewhere else.
I would also like to add some type of max time allowed to wait for the pin to go low. But everything I did made the resolution of RCtime go way down.
Please help, and let me know of any errors I have in my code.
Post Edited (Bobb Fwed) : 6/25/2008 9:13:41 PM GMT
I am trying to start something simple, something I am familiar with...rctime ... I know there are other objects and whatnot that do the same thing, but I'm learning a new language, so I'd like to figure it out for myself.
I am using the DIP chips on the Propeller RPM.
Here is the code I have:
'' RCTIME test CON pin = 3 VAR long time1 long timestack[noparse][[/noparse]6] ' stack space for rctime cog long dispstack[noparse][[/noparse]6] ' stack space for LED display cog PUB Main coginit(1, RCTIME(@time1), @timestack) ' start cog 1 on RCTIME coginit(2, Disp_no(@time1), @dispstack) ' dislpay RCTIME results on cog 2 repeat ' do nothing for forever PUB RCTIME(timeAddr) | time ' get RCTIME value repeat DIRA[noparse][[/noparse]pin]~~ ' set as output OUTA[noparse][[/noparse]pin]~~ ' set HIGH waitcnt(clkfreq / 1000 + cnt) ' wait 1ms time := cnt ' store current count DIRA[noparse][[/noparse]pin]~ ' set as input waitpeq(|< pin, |< pin, 0) ' wait until low again ?I think? ... it seems to work like this long[noparse][[/noparse]timeAddr] := ((cnt - time) - 3300) / 2000 ' store time to global var and compensate for minimum time and variable size PUB Disp_no(nfoAddr) | tmp ' display binary value to 10 segment LED on PRPM dira[noparse][[/noparse]16..25]~~ ' set leds to output outa[noparse][[/noparse]16..25]~~ ' set leds HIGH (turns off LED...why?) repeat ' repeat forever tmp := long[noparse][[/noparse]nfoAddr] <# 1023 ' get global var and limit it to 1023 (10 bits) outa[noparse][[/noparse]16..25] := tmp ' on (show binary value) waitcnt(381 + cnt) ' wait minimum outa[noparse][[/noparse]16..25]~~ ' off waitcnt(40000 + cnt) ' reduce these friggin' bright LEDS!
What I am trying to accomplish: one cog (cog 1) continuously reads the RCtime of a photoresistor I have, and the other cog (cog 2) continuously displays the value (at a reduced brightness).
What happens: as the RCtime increases the LEDs start to blink (as it seems it is waiting for the RCtime), and for some unexplainable reason, no matter what divider I put on the "store time to global var" line, it doesn't actually affect the output, which seems to mean, I am getting the value from somewhere else.
I would also like to add some type of max time allowed to wait for the pin to go low. But everything I did made the resolution of RCtime go way down.
Please help, and let me know of any errors I have in my code.
Post Edited (Bobb Fwed) : 6/25/2008 9:13:41 PM GMT
Comments
The WAITCNT in Disp_no is too small for Spin. 381 + CNT will probably pass before the WAITCNT can execute. The minimum is more like 1100 if I remember correctly.
I can't use 20 longs, anything higher than 6 makes the LED segments stay on permanently, and below six makes them stay off. Someone tell me why. At 6 stacks it operates, just not exactly how I want.
I don't get the whole stack thing anyway...I thought each of these cogs have their own RAM...what do the stack accomplish?
But someone explain the need for stacks?
381 may be the "official" minimum, but I'd not count on it being adequate.
And thanks for the info...I'll keep in mind: "when in doubt, more stack space!"