Need Help running multiple cogs
garyg
Posts: 420
Hi
I'm working on setting up a pump timer gizmo.
It's my 1st OBEX plus cut/paste/modify project.
I'm using FullDuplexSerial, RealTimeClock.spin, RTC_DEMO.spin and another object I'm trying to
run on yet a separate cog.
I modified, With Help, RTC_DEMO to drive my LCD serial display.
It appears to be working correctly
Now, I'm trying to get my PumpControl.spin to play along.
I'm sure there is something very fundamental that I'm not understanding.
This is how I'm trying to start the PumpControl:
'Start Real time clock
RTC.Start
'Start the Pump Control
Pumps.Start 'The PumpControl.spin needs the start/stop subroutines set up properly to run in a new cog.
'Now this Pumps.Start compiles correctly without errors.
'ON STARTUP PROGRAM STOPS WHEN IT GETS TO Pumps.Start
'Preset time/date... nice demostration of rollovers..
RTC.SetTime (hrset,minset,secset) '(23,59,50) '10 seconds to midnight
RTC.SetDate(16,9,14) '31,12,07 'New years eve, 2007
'
'
The following is the PumpControl.spin
When I run the program, I can set the current time and start RTC, but the PumpControl causes everything to stop working.
If I remark out the Pumps.Start line, I get proper time display, but my pumps blue flashing led does not work.
If you need more information to help me out, please ask.
Thanks
Garyg
I'm working on setting up a pump timer gizmo.
It's my 1st OBEX plus cut/paste/modify project.
I'm using FullDuplexSerial, RealTimeClock.spin, RTC_DEMO.spin and another object I'm trying to
run on yet a separate cog.
I modified, With Help, RTC_DEMO to drive my LCD serial display.
It appears to be working correctly
Now, I'm trying to get my PumpControl.spin to play along.
I'm sure there is something very fundamental that I'm not understanding.
This is how I'm trying to start the PumpControl:
'Start Real time clock
RTC.Start
'Start the Pump Control
Pumps.Start 'The PumpControl.spin needs the start/stop subroutines set up properly to run in a new cog.
'Now this Pumps.Start compiles correctly without errors.
'ON STARTUP PROGRAM STOPS WHEN IT GETS TO Pumps.Start
'Preset time/date... nice demostration of rollovers..
RTC.SetTime (hrset,minset,secset) '(23,59,50) '10 seconds to midnight
RTC.SetDate(16,9,14) '31,12,07 'New years eve, 2007
'
'
The following is the PumpControl.spin
{{ I'm starting my Pump Control by saving the RealTimeClock.spin file as PumpControl.spin I'll set up simialar variable blocks etc and try to get this thing to turn on the Blue LED's Blue LED's on the Quickstart board when a particular hour and minute are reached. }} VAR ''Global vars... 'long Cog 'Cog issued tracking long PumpStack[32] 'Stack for PumpControl object in new cog byte Pumps 'Pumps stores the CogID of the new cog. 'gg I'm not sure what this start:Success thing is all about 'I Kept it in case I need it later. 'PUB Start:Success 'Start the RTC object in a new cog... ' If not cog 'RTC not already started ' Success := Cog := Cognew(RtcMain(@LclRtc),@RtcStack) 'Start in new cog 'PUB Stop 'Stops the Real Time Clock object, frees a cog. ' If Cog ' Cogstop(Cog) PUB Start 'Start is from Spin Language Reference -COGNEW page 81 Stop Pumps := cognew (Pump1, @PumpStack) PUB Stop 'Stop is from Spin Language Reference -COGNEW page 81 if Pumps>-1 cogstop(Pumps) PUB Pump1 ' Pin 16 is the buzzer, make it an output and set it low. dira[16] := 1 outa[16] := 0 'Pin 20 is the center LED on the Quickstart board, Make it an output and set it low. dira[20] := 1 outa[20] := 0 Blink20 PUB Blink20 'I want the P20 center led on the Quickstart to start blinking at some rate while the 'clock is running and displaying things on the LCD monitor. repeat !outa[20] waitcnt(3_000_000+cnt) 'This should run forever in a single new cog.
When I run the program, I can set the current time and start RTC, but the PumpControl causes everything to stop working.
If I remark out the Pumps.Start line, I get proper time display, but my pumps blue flashing led does not work.
If you need more information to help me out, please ask.
Thanks
Garyg
Comments
I modified the Blink20 method.
I should have seen that.
Now the repeat tracking lines show up.
However:
Program still does not seem to continue after running the Pumps.start line.
I'm thinking that I goofed up in the PUB Start, PUB Stop part of this object.
This is the 1st time I'm trying to get something I've written running on a separate cog.
garyg
The Start method start a new cog but the original cog is left to die.
The RTC stuff looks incomplete. Did you just post a portion of the code?
-- Describe the outcome in bigger terms -- defining it in code that you're struggling with isn't very helpful
-- Use named constants for pins -- "magic numbers" often lead to bugs and can cause one part of a program to interfere with another
-- Do you need an RTC? Or do you just want to run for a specific amount of time?
-- You may be able to start your RTC in the global space
If you just want to run your pump and flash an LED for a specific time -- in a separate cog -- the attached demo will be helpful.
I'll attempt to clarify. This may get a bit long winded.
Duane, " The Start method start a new cog but the original cog is left to die".
That is exactly what I don't want to happen, but death of the original cog is exactly my problem.
Mike, I used the Propeller Tool to make an archive
I'll attempt to attach it. RTC_DEMO-GGMODIFIED3-PumpControl2 - Archive [Date 2014.09.17 Time 18.14].zip
Jonny, My computer wants to save your attachment as a PNG file. I don't know what that is.
I attempted to clean up my commenting of code, but am still using pins.
I'll Submit this reply, then post again explaining exactly what this gizmo is supposed to do.
In post #7 I tried to answer requests of post #6.
Now in this post, I'll explain exactly what it is and what it will do.
I'm working on a timer system to be used in next years Hydroponic Garden.
The timer will control water flow to neutrient feed pumps and makeup water pumps.
I'm using a Propeller Quickstart board and 2line Parallax Serial LCD display to show time.
On Propeller Reset, The program places 0,0,0 as current time and waits until I wish to set the current time.
I press button 15 and hold it while pressing either button 11(sets hours) or button 12(sets minutes)
I keep pressing button 15 until my watch reads the same as my setting, then I release button 15.
My initial time setting is now complete.
RTC real time clock starts at the time I set and displays current time on my LCD display.
I display the hours number on the 2nd line of the display, just to show I can use hours from the RTC raw data.
Now that the display is working correctly, It keeps very accurate time over a number of days as far as I can tell so far.
I want to control pump cycle times.
My thought is to start by getting another object, PumpControl2, to run in a separate cog.
For now, PumpControl2 should only flash the blue LED P20 on the Quickstart board.
I wanted to keep PumpControl2 as simple as possible because I do not understand how to set up the PumpControl2 to
run in a separate cog.
If the LCD clock keeps good time and the P20 LED is flashing, this would tell me that I have successfully started the
Pumpcontrol in it's own cog.
The end game here is to always have the LCD display showing correct time, When pumps are running I will display pump1 on/off Pump2 on/off
on the 2nd line of the LCD display.
I have come up with a simple uninterruptable power strategy using a simple relay circuit.
With battery connected and power switch turned on, the power comes from the battery.
When I plug in my 7.5Vdc wall wart supply, the relay picks and the power to the Quickstart circuitry comes from the Wall Wart.
I needed to add 2000uF capacitor to the regulated side of my supply to make up for the time in which the relay is changing states,
but it appears to be working pretty good so far.
I'll attempt to Post my code.
This is the main program:
This is the real time clock code.
This is the pump code
After I made the archive of the not functional program, Wrote a better description of outcome in bigger terms and posted all of the code involved,
I got to thinking about Duane's comment about the original cog left to die.
I went back and looked over the top 3 sections of the program.
I made the sections I had remarked out active again and added the Long cog statement
I deactivated the part that I thought I needed.
Then I replaced some of the terms that looked incorrect to me and EVERYTHING STARTED WORKING.
Below is the working code.
LCD display is reading and updating correct time, while the Blue P20 LED is blinking away.
I'm sure I'll be having more questions as I develop this timer gizmo.
I really don't understand exactly why this works, but it appears to work.
and
I really would like to figure out how to use the PNG file Jonny had attached to his comments.
Thanks again
Garyg
I'm glad my comment helped but I'm starting to think I might not have been correct. I was assuming the object you had posted was the top object but if it was a child object then the control would return to the parent object and the cog wouldn't be left to die.
There's a lot to be said for working code. This is good to hear.
I've attempted to use all of the words of wisdom provided by all who replied.
The end result is that I now have a working multicog program.
I learned a lot from this exercise.
The completed file is attached here. RTC_DEMO-GGMODIFIED3-PumpControl2REV2 - Archive [Date 2014.09.30 Time 17.57].zip
I'm hoping that someone would have a look at my now working pump timer.
I tried to make documentation as clear as I can.
Some of my timing programming might appear to be clutzy, but for now,
it's the very best I can do.
Any suggestions as how I can improve this program or my documentation would
be greatly appreciated.
I'll make another post to show where this all came from and where it is going.
Thanks for all your help.
So,
I've been running my 3Timer, 4Terminal strip with Hot Male interconnection for about 12Years with good success.
my timers started giving me trouble last summer, I could not find exactly what I needed without rebuilding the
entire thing.
These are photos of my old timer rig and my test rig running the new program.
Thanks again
Garyg