Is it possible
Is it possible to have the prop take input on one cog, and execute it on another. And if so where would I get guidance to get started. I have the input on one cog already, its just get the input from that cog, and having it excute on another is where I am coming up with problems. All ideas are greatly appreciated. Thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!

Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!
Not knowing the ESC object, I simply assume it has an API which allows it to take the input value obtained by other means. So the easiest solution would be your main program reading the input value in whatever form it is delivered by the terminal and send it to the ESC object. You said that you have the input part ready. Is your current problem related to conversion (e.g. ASCII/binary) or more general? I mean once you started your objects (input, ESC) they (usually) run on their own cog anyway, so all you have to do is link them.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!
The main loop looks fine to me. You get a decimal value and deliver it to the ESC object.
You might want to check you repeat until condition. I assume you want to exit when throttle is 0 (throttle == 0). ATM you assign 0 (FALSE) to throttle which makes that an endless loop.
Also, in the ESC object, I assume the methods fullbrake/fullthrottle should use dira[noparse][[/noparse]pin]~~ rather than dira[noparse][[/noparse] 4 ]~~.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!
PUB throttle(pulseWidth) ctra[noparse][[/noparse]30..26] := %00100 'Configure counter A to NCO mode ctra[noparse][[/noparse]8..0] := pin frqa := 1 dira[noparse][[/noparse]pin]~~ tC := ((clkfreq/ 100_000) * 2000) tHa := ((clkfreq/ 100_000) * pulseWidth) t := cnt repeat phsa := -tHa t += tC waitcnt (t)▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!
Instead of calling "throttle", you would use a COGNEW to call it. You would need some kind of interface routine
that would either check for an existing cog running throttle and stop it before starting a new one or you'd have to
slightly rewrite "throttle" so it gets its pulse width from a common variable and reinitializes itself if the pulse width
changes.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 pin = 21 VAR long throttle, throttleStack[noparse][[/noparse]24] byte Cog OBJ debug : "FullDuplexSerialPlus" esc : "ElectronicSpeedControl" PUB main debug.start(31, 30, 0, 9600) 'Sets serial params for terminal use esc.delay(3500) debug.Str(String("Please wait while calibrating the ESC....")) esc.initialize 'Call initialize the ESC debug.Str(String(10, 13,"ESC calibrated")) 'Loop for speed change repeat debug.Str(String(10, 13,"Enter throttle speed: ")) throttle := debug.getDec debug.Str(String(10, 13, "Going to throttle speed: ")) debug.Dec(throttle) Stop cognew(esc.throttle(throttle), @throttleStack) PUB Stop if Cog cogstop(Cog~ -1)heres my·ESC object
CON pin = 21 VAR long tC, tHa, t PUB initialize fullBrake 'Fullbrake Delay(500) 'Delay 500 mS fullThrottle 'Fullthrottle Delay(500) 'Delay 500 mS fullBrake 'Fullbrake Delay(500) PRI fullBrake ctra[noparse][[/noparse]30..26] := %00100 'Configure counter A to NCO mode ctra[noparse][[/noparse]8..0] := pin frqa := 1 dira[noparse][[/noparse]pin]~~ tC := ((clkfreq/ 100_000) * 2000) ' Set up cycle and high times 20ms tHa := ((clkfreq/ 100_000) * 100) ' 1.0ms pulse t := cnt 'Mark counter time repeat 150 phsa := -tHa ' Set up the pulse t += tC ' Calculate next cycle repeat waitcnt(t) PRI fullThrottle ctra[noparse][[/noparse]30..26] := %00100 'Configure counter A to NCO mode ctra[noparse][[/noparse]8..0] := pin frqa := 1 dira[noparse][[/noparse]pin]~~ tC := ((clkfreq/ 100_000) * 2000) ' Set up cycle and high times 20ms tHa := ((clkfreq/ 100_000) * 220) ' 2.2ms pulse t := cnt 'Mark counter time repeat 150 phsa := -tHa ' Set up the pulse t += tC ' Calculate next cycle repeat waitcnt(t) PUB throttle(pulseWidth) ctra[noparse][[/noparse]30..26] := %00100 'Configure counter A to NCO mode ctra[noparse][[/noparse]8..0] := pin frqa := 1 dira[noparse][[/noparse]pin]~~ tC := ((clkfreq/ 100_000) * 2000) tHa := ((clkfreq/ 100_000) * pulseWidth) t := cnt repeat phsa := -tHa t += tC waitcnt (t) PUB Delay(mS) waitcnt((clkfreq / 1000 * mS) + cnt)▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!
Basically, you can't do it the way you tried. The cog that you start has its own counter and I/O registers so all of the initialization and counter manipulation code has to be running in that cog.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!
{{ EDF ESC spedd control via hyperterm Frank Shearer v.01 }} CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 pin = 21 VAR long throttlePulse, tC, tHa, t, Stack[noparse][[/noparse]100] byte Cog OBJ debug : "FullDuplexSerialPlus" PUB Main debug.start(31, 30, 0, 9600) 'Sets serial params for terminal use delay(3500) debug.Str(String("Please wait while calibrating the ESC....")) initialize debug.Str(String(10, 13,"ESC calibrated")) repeat getinput 'Stop 'Stopping previous cog 'cognew(getInput, @stack) 'Starting a new cog to update throttle method PUB getInput | prevPulse repeat debug.Str(String(10, 13,"Enter throttle speed: ")) throttlePulse := debug.getDec prevPulse := throttlePulse debug.Str(String(10, 13, "Going to throttle speed: ")) debug.Dec(throttlePulse) Stop cognew(throttle(throttlePulse), @stack) PUB initialize fullBrake 'Fullbrake Delay(500) 'Delay 500 mS fullThrottle 'Fullthrottle Delay(500) 'Delay 500 mS fullBrake 'Fullbrake Delay(500) PRI fullBrake ctra[noparse][[/noparse]30..26] := %00100 'Configure counter A to NCO mode ctra[noparse][[/noparse]8..0] := pin frqa := 1 dira[noparse][[/noparse]pin]~~ tC := ((clkfreq/ 100_000) * 2000) ' Set up cycle and high times 20ms tHa := ((clkfreq/ 100_000) * 100) ' 1.0ms pulse t := cnt 'Mark counter time repeat 150 phsa := -tHa ' Set up the pulse t += tC ' Calculate next cycle repeat waitcnt(t) PRI fullThrottle ctra[noparse][[/noparse]30..26] := %00100 'Configure counter A to NCO mode ctra[noparse][[/noparse]8..0] := pin frqa := 1 dira[noparse][[/noparse]pin]~~ tC := ((clkfreq/ 100_000) * 2000) ' Set up cycle and high times 20ms tHa := ((clkfreq/ 100_000) * 220) ' 2.2ms pulse t := cnt 'Mark counter time repeat 150 phsa := -tHa ' Set up the pulse t += tC ' Calculate next cycle repeat waitcnt(t) PUB throttle(pulseWidth) ctra[noparse][[/noparse]30..26] := %00100 'Configure counter A to NCO mode ctra[noparse][[/noparse]8..0] := pin frqa := 1 dira[noparse][[/noparse]pin]~~ tC := ((clkfreq/ 100_000) * 2000) tHa := ((clkfreq/ 100_000) * pulseWidth) t := cnt repeat phsa := -tHa t += tC waitcnt (t) PUB Delay(mS) waitcnt((clkfreq / 1000 * mS) + cnt) PUB Stop if Cog cogstop(Cog~ -1)▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!
Anyway, starting a cog for every function call is overkill (and adds unnecessary delay). You should exchange parameters through some defined hub location.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!
Get a Propeller controlling the rate of flashing a LED, put that in its own Cog and then control the rate of flashing from the main Cog. Upgrade that main Cog so you can change the rate of flashing via serial or whatever.
Once you've got the notion of parallel processing understood with data passed between the two working it will all become a lot easier than trying to crowbar what you have into shape.
Basically, you don't want to keep executing CogNew as has already been said. Get a second Cog running at the start of the program the hand the data it needs to it. That created cog should initialise once then run in a loop reading the data handed to it and doing whatever it needs to. Beyond that, there should be no other ongoing interaction between the two cogs.
Untested, but something like ...
CON PIN_NUMBER = 0 PUB CogPrimary | timePeriodMs CogNew( CogSecondary( PIN_NUMBER ), @stack ) timePeriodMs := 1000 repeat sharedData := timePeriodMs WaitCnt( CLKFREQ + CNT timePeriodMs -= 100 if timePeriodMs == 0 timePeriodMs := 1000 PUB CogSecondary( pinNumber ) | timePeriodMs DIRA[noparse][[/noparse] pinNumber ] := 1 repeat timePeriodMs := sharedData WaitCnt( CLKFREQ / 1000 * timePeriodMs + CNT ) ! OUTA[noparse][[/noparse] pinNumber ]Post Edited (hippy) : 6/2/2008 2:27:03 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 pin = 27 VAR long pulseMS, stack[noparse][[/noparse]20] PUB Main | SharedP cognew(ThrottleControl(SharedP), @stack) 'Throttle control on seperate cog SharedP := GetInput PUB GetInput : sp sp := 1_500 PUB ThrottleControl(pulseS) | pulse_MS dira[noparse][[/noparse]pin]~~ outa[noparse][[/noparse]pin]~ repeat pulse_MS := PulseS outa[noparse][[/noparse]pin]~~ 'pin on waitcnt((clkfreq / 1_000_000 * pulse_MS) + cnt) 'pulseMS on time between 1ms and 2.2ms outa[noparse][[/noparse]pin]~ 'pin off waitcnt(clkfreq / 1_000 * 20 + cnt) '20ms Pause time▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!
Yes, you can run a master object that starts, modifies and send data to other objects. Take a look at my Pnav project. It is a work in progress
Maybe this will help you in the theory. I have been slow-rolling an autopilot (...for the last year...) and you are welcome to use any of my code for you project.
www.PNav.net I'll be posting a newer rev of code there on Friday ( Jury duty tomorrow!)
Please share - You seem to be coding much faster than me!
Paul
Post Edited (Paul_H) : 6/5/2008 5:23:27 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!
Main Object :
OBJ subObject : "YourSubObject" VAR long sharedData PUB Main subObject.Start( @sharedData ) repeat sharedData := someInputSourceSub Object :
VAR long sharedDataPtr long stack[noparse][[/noparse] 100 ] PUB Start( pointerToSharedData ) sharedDataPtr := pointerToSharedData CogNew( SubObjectLoop, @stack ) PUB SubObjectLoop | sharedData repeat sharedData := long[noparse][[/noparse] sharedDataPtr ] DoWhatever▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!