Expert help is needed
I am running several cogs and trying to figure out why this is not working.
I simply have dedicated one cog to measure temperature. It also takes some 200 samples and averages it. This is in turn given to my main cog that sends it to a computer program every secound.
This is the main cog running code *note not all the code is given due to length but i am sure the problem is in the
And this is the code that measures temperatures can be downloaded
Any help would be great thanks
I simply have dedicated one cog to measure temperature. It also takes some 200 samples and averages it. This is in turn given to my main cog that sends it to a computer program every secound.
This is the main cog running code *note not all the code is given due to length but i am sure the problem is in the
OBJ Ser : "FullDuplexSerial" '1 cog Ft : "FloatMath" Strings : "FloatString" TempObj : "Temps" '1 cog + 1cog PID : "PIDf" '2 cog Pub Init ConfigProp ' Set up pins StartCogs ' Start up cogs Main Pub ConfigProp Error_Report := "0" Stir_On := "-" Temp_Con := "-" Status := "C" Kp := 14.0 Ki := 0.0 Kd := 0.0 maxArea := 0.0 minArea := 0.0 OffSet := 0.0 TargetTemp := 20.00 Ct_Time := 15 timer1 := cnt 'make inital snapshot of systemcounter Pub StartCogs TempObj.start Ser.Start(31,30,0,baud) Pid.init(Kp, Ki, Kd, TargetTemp, offset, maxArea, minArea) Pub Main | Value, eTime1, Control Control := 0 repeat IF (ser.rxcheck == $5B) Value := getcom Case Value 'Checking for changes made from program 1 : Temp_Con := "+" Control := 1 2 : Temp_Con := "-" Control := 2 3 : Pid.Update(3,TargetTemp) Temperature := TempObj.OneShot '''''''''''''''''''''''''''''''''''''<--------------------------------------Problem area IF (eTime1 => Ct_Time * Secound) 'Check time in sec/s timer1 := cnt ser.str(string("[noparse][[/noparse]Current Temperature ")) ser.str(strings.FloatToFormat(Temperature,8,4)) ser.str(string("]"))
And this is the code that measures temperatures can be downloaded
Any help would be great thanks
spin
![](/plugins/FileUpload/images/file.png)
8K
Comments
But there is 1 quesiton I have, TempObj.start starts a cog that runs OneShot which takes a temp reading averaged, ignores the calculated temp and returns shuting the cog down.
You then call TempObj.OneShot from your main code directly which gets a temp value and returns it. The tempobj cog has no purpose - why?
as you wrote only it is not working the forum has to guess what
from the code you have posted it is not clear if
variable etime1 is updated regurlarly
it's not clear what's the result of Ct_Time * Secound
The averaging goes about the 30 samples inside Oneshot
with every new loop and call of method TempObj.OneShot
the old value of variable Temperature will be overstored
you always get the average of the last 30 sample from the last
Temperature := TempObj.OneShot
I think you are using my elapsed_time_msec-method
you have to code
or directly
If the problem is something else you have to describe it
to give the forum a good chance to write a useful problem-solving answer
you should check your posting about
can somebody - who does NOT know anything about the specialties of my project -
understand what is going on ?
decide for posting even more than even less of information.
If you have a suspect about the part where the error is
make it easy to find in your code be '''<<<====== MARKING IT
like you did it here. But attach your complete project
please please please I have seen it SO MANY TIMES over all the years:
making a quick and short posting then the time to get a SOLVING answer is much longer than
if you take yourself the time for a well written FIRST posting
best regards
Stefan
It seems that the main code running in the repeat loop will wait for this variable to update. This is a real big bottle neck when i use the PID object that calculates this temp reading.
Post Edited (grasshopper) : 9/25/2008 8:58:44 PM GMT
Well depending on how long Oneshot takes it could be still running when you call Oneshot form the main cog, the results of 2 cogs talking to the device will be "interesting"
I still do NOT fully understand what your description of the error means.
To be honest: I get a little upset by your way of hurry AGAIN in the postings above !
So I will ask concrete questions to make it clear:
Do you KNOW how you can DEBUG codeline execution ?
Do you KNOW how you can DEBUG values of variables?
Did you debug the method main, how often the loop is executed in time ?
Did you debug what values are stored in the variable Temperature ?
What values do you EXPECT to be displayed when using the commands
ser.str(string("[noparse][[/noparse]Current Temperature "))
ser.str(strings.FloatToFormat(Temperature,8,4))
ser.str(string("]"))
What values do you REALLY GET when using these commands?
Inside temp.spin the method "start" starts method OneShot in a new cog. Let's say this cog has ID-No "2".
Then method OneShot runs down ONLY ONE TIME in cog "2". After that cog 2 does NOTHING ANYMORE !
In your PUB Main you call TempObj.OneShot. This makes cog "1" ATTENTION ! cog "1" NOT cog "2" execute method OneShot
So from this I can see that you have a lack of understanding what are cogs and what are objects and when is running what
in which cog and how often.
It might be that the position of the error is somewhere else.
So where is the problem to attach your COMPLETE code to a posting ?
Are you not allowed to do so from the chief of your company ?
Are you afraid of let others see your style of programming ?
Are you afraid of this could be too much for the forum-members ?
If you write a posting that will answer my questions and has your project attached I will calm down
and will analyze yor code. Otherwise I simply will not.
regards
Stefan
Please no need to get upset with me. I am not the best writer so ill try again. My code is so long, this is the reason don't send it all. I am not embarrassed, hell only last week I went ridding nude on my bike. Ok that was a bit of the stretch of the truth. I am have no clue how to debug except running small pieces of code and checking for the expected result. Not sure if this is the correct approach.
Perhaps you could help me getting my New object - Temps to measure temperature and hold the value in a variable. All I wish it to do is constantly measure temperature and average it (as a filter). The code works as far as measureing temperature, however I am not familuar with running a seperate cog that recieves the temperature from - Temps object.
If you want a cog running getting averaged temp and having the main cog getting the current average temp. Then you want
FilterTemp to have a repeat loop, storing Value in a VAR variable and adding a routine (GetTemp) that returns this variable.
Then FilterTemp will running updating the average temp and the main cog calls GetTemp.
Can you post and example of how I address this.
Now, only the cog started from Start is accessing the hardware.
The data that i get is some string of numbers that is not correctly sent to the computer program. Hum... I think having the Temps object running in its own cog in a continuous loop is not possible?
you still have NOT understand what is an object and what runs inside a cog
The Temps-1.spin-file from Timmoore does the following
in method start there is a command
this command starts a new cog. Let's say this is cog No "2"
Now what is running inside THIS cog No "2" ?
Just the method FilterTemp NOTHING MORE !
PUB FilterTemp has a infinite repeat-loop. So just THIS loop is running all the time
PUB FilterTemp averages the temperature-values
and STORES the averaged temperature in variable averagetemp
PUB FilterTemp is ONLY WRITING to variable averagetemp
the PUB GetTemp
is ONLY READING variable averagetemp
by this way of programming only ONE cog does the bitbanging with the serial interface of the temperature-sensor
I discovered a bug in PUB FilterTemp from Timmoore.
As you don't want to ATTACH your complete code to a posting I will NOT tell you where the bug is, - and because this would keep your programming-skills on the level of "have to ask for almost everything"
Just a hint: To find the bug - DEBUG Pub FilterTemp by sending the values of ALL variables used by FilterTemp
to a PC within every repeat of the loops and take a close look how the values change
best regards
Stefan
Or did i miss that also?
Thanks for the help and the razzing ^^
Hum .. Back to Stefan's post.
perhaps this may help ???
Calling 'TempObj.Start' is launching the function 'Temps.OneShot' on a new cog. That function will run, and eventually generate a computed value, but it won't 'go' anywhere, because cognew's only return value is which cog it started on. That means your computed value is lost. You could fix this by setting a global VAR to some known (but impossible) number, like -999 or something, and then setting it to the computed temperature in OneShot when it's ready. Your main program could wait until Temps.ReturnValue was not -999 and then display the answer.
The other problem is that your main function is ALSO calling the Temps.OneShot function directly. So here's what your program flow looks like:
Init:
calls StartCogs : Launches Temps.OneShot on a new cog. This will run, produce a result, and then do nothing
(does some other setup)
calls Main
Main: calls Temps.OneShot directly, from the main cog, probably in parallel with the one that's already running, but a little behind it.
I'm not sure what the behavior of calling the OneShot function from the main cog will be, since it depends on the Math object. Having two cogs trying to access the same math object at the same time might be your problem. The Float32 functions set a global variable and then wait for a result from some assembly code running on another cog. Calling those functions from two cogs at the same time might corrupt the state and cause the functions to wait indefinitely. Changing the code as I suggested above should correct this as well.
Jason
I would have a test program that calls CalcTemp(1) and make sure that returns the correct result
then test the average code as a standalone piece of code and make sure it works. Then run it within a seperate cog.
Post Edited (Timmoore) : 9/26/2008 9:04:23 PM GMT
your gueesing was right out of the fog into the fog
if you read very carefully I wrote "IN" the PUB FilterTemp NOT at the cognew of FilterTemp
the debugging works like this:
you are already using a serial com-object
now the debugging is to use serial output to trace what ever you like
here is the code with added debugging via serial output
running this version of FilterTemp and analyzing the debugoutput will guide you to the bug
best regards
Stefan
That --^ works fine
and this --^ wont. I am thinking that the timing is off or something
I commented that local variables are not initialized and your average assumes that locals are initialized to 0.
Without RESETTING variable temp1 in PUB FilterTEMP inside the outer and infinite loop
temp1 is counting up much too far because it is not resetted to zero and this gives strange results.
I hope you can see from this example that GUESSING where the bug might be can lead you in a COMPLETE WRONG DIRECTION
And the only two ways to find the bug are:
1.) knowing a programing-language VERY WELL and be experienced enough to SEE the bug from reading the code
2.) CAREFUL debugging STEP by STEP.
You can start where you GUESS where the bug might be
But ! - GUESSING oh I'm sure the bug is NOT there. I can drop checking this IS STRONGLY FORBIDDEN
If you drop it, there will be cases where you will ran around in circles again and again and again maybe trying wild things
until you decide to check the dropped point
(and by doing 2.) going along the way to 1.)
Grasshopper - please do me a favor and post the results that you get from your first and the second version of main
Be sure that the PC-terminalsoftware is ready to receive the very first characters of ser.str(FloatToFormat(...
by
1.) loading the program to the EEPROM
2.) open the comport in the PC-terminalsoftware
3.) reset the propeller to let the prop start NEW while the comport is already opened
best regards
Stefan
what happens if you move that closer to your ser.str() ? Does that improve things ? How about
just sending the values of Temp0.GetTemp and Temperature in a readable format to see what
differences there are with minimal extra processing ?