Anyone please help!!!
Guido
Posts: 195
I would apprecaite if someone could tell me what I am doing wrong. I am trying to log Low and High Temperatures at the time it happens. With this program I continue to elaspe time until Low or High temperatures are out of range.
I did remove the "=" out of the equation =<, or => but the logic will not function. I have tried other logic statements, but it seems to never get past the statement to save it. Any help would be appreciated
GetTemperature:
HIGH Reset ' ALERT THE DS1620
SHIFTOUT DQ,Clock,LSBFIRST,[noparse][[/noparse]RdTmp]
SHIFTIN DQ,Clock,LSBPRE,[noparse][[/noparse]tempIn\9]
LOW Reset
tempIn.BYTE1 = -tempIn.BIT8 ' extend sign
tempC=tempIn*5 'Celsius value *10, resolution 0.5 degree
tempF = tempC + 1000 * 9 / 5 - 1800 + 320
TL=(TEMPF + 1024) MAX (TL+1024) - 1024
TH=(TEMPF + 1024) MIN (TH + 1024) -1024
IF TEMPF/10 => TH/10 THEN U:
IF TEMPF/10 =< TL/10 THEN V:
RETURN
U:
GOSUB SAVE
RETURN
V:
GOSUB SAVE1
RETURN
SAVE:
· HIGH RTCCS
· SHIFTOUT DTA, Clk, LSBFIRST, [noparse][[/noparse]%1\1,BrstReg\5,%10\2]
· SHIFTIN DTA, Clk, LSBPRE, [noparse][[/noparse]Seconds,Minutes,Hours,Date,Month,Day,Year]
· WRITE 900,HOURS,MINUTES,SECONDS,DATE,MONTH,DAY,YEAR
· LOW RTCCS
· RETURN
SAVE1:
· HIGH RTCCS
· SHIFTOUT DTA, Clk, LSBFIRST, [noparse][[/noparse]%1\1,BrstReg\5,%10\2]
· SHIFTIN DTA, Clk, LSBPRE, [noparse][[/noparse]Seconds,Minutes,Hours,Date,Month,Day,Year]
· WRITE 150,HOURS,MINUTES,SECONDS,DATE,MONTH,DAY,YEAR
· LOW RTCCS
RETURN
I did remove the "=" out of the equation =<, or => but the logic will not function. I have tried other logic statements, but it seems to never get past the statement to save it. Any help would be appreciated
GetTemperature:
HIGH Reset ' ALERT THE DS1620
SHIFTOUT DQ,Clock,LSBFIRST,[noparse][[/noparse]RdTmp]
SHIFTIN DQ,Clock,LSBPRE,[noparse][[/noparse]tempIn\9]
LOW Reset
tempIn.BYTE1 = -tempIn.BIT8 ' extend sign
tempC=tempIn*5 'Celsius value *10, resolution 0.5 degree
tempF = tempC + 1000 * 9 / 5 - 1800 + 320
TL=(TEMPF + 1024) MAX (TL+1024) - 1024
TH=(TEMPF + 1024) MIN (TH + 1024) -1024
IF TEMPF/10 => TH/10 THEN U:
IF TEMPF/10 =< TL/10 THEN V:
RETURN
U:
GOSUB SAVE
RETURN
V:
GOSUB SAVE1
RETURN
SAVE:
· HIGH RTCCS
· SHIFTOUT DTA, Clk, LSBFIRST, [noparse][[/noparse]%1\1,BrstReg\5,%10\2]
· SHIFTIN DTA, Clk, LSBPRE, [noparse][[/noparse]Seconds,Minutes,Hours,Date,Month,Day,Year]
· WRITE 900,HOURS,MINUTES,SECONDS,DATE,MONTH,DAY,YEAR
· LOW RTCCS
· RETURN
SAVE1:
· HIGH RTCCS
· SHIFTOUT DTA, Clk, LSBFIRST, [noparse][[/noparse]%1\1,BrstReg\5,%10\2]
· SHIFTIN DTA, Clk, LSBPRE, [noparse][[/noparse]Seconds,Minutes,Hours,Date,Month,Day,Year]
· WRITE 150,HOURS,MINUTES,SECONDS,DATE,MONTH,DAY,YEAR
· LOW RTCCS
RETURN
Comments
And is 900 a safe location to write to?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Post Edited (Jon Williams) : 10/18/2004 8:07:02 PM GMT
"never get past the statement to save it"
I am not sure what you mean by that.
Have you tried this with debug commands in place of the saves, to see if the logic is working as you want?
I don't understand either what the logic is supposed to do. The values TH and TL are moving targets. That is, TH is pushed up so that it is always higher than the current temperature, and then you want to branch if the current temperature is higher than TH. That will never happen!
Math note: Note that division, as in...
IF (tempF/10) <= (TL/10)
will not work if the temperature is negative. But I don't think that is the problem here.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
I gave that a try, but I still have the problem of the clock running until either·TH or·TL does not equal TH or TL. Any other ideas. I was thinking about a flag, but how would I reset it? Also don't laugh, but I still have not figured out how to read the memory map. I did some reading and they said as far as memory locations they would not be displayed in the map..The whole project seems to work except the constant writing of either low or high temperatures when the confitions exisits.
Tracy,
I am not going to be dealing with negative temperatures, probably as low as I will see is about 20F. Also when I said I can not get by to save the readings was when I removed the equal sign.
I did remove the "=" out of the equation =<, or => but the logic will not function. I have tried other logic statements, but it seems to never get past the statement to save it. Any help would be appreciated
IF TEMPF/10 > TH/10 THEN U:
IF TEMPF/10 < TL/10 THEN V:
If I can get this statement to work, then I can flag it from repeating itself.
He sets 'location' to be 150 or 900, then uses WRITE to write a set of data to that location.
Is that correct useage?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
I think it is working ok. Jon's example with using a variable does save space...This is one of my biggest problems when being new and writing a new program....Dam I love the challenge!!!!
This is for Jon.
Why can I not use a statement Like:
IF ((tempF/10) => (TH/10))AND NOT TEMPF/10=TH/10·THEN ADDR = 900
GOSUB Save
Again with using your statement the = to or greater·will make it constantly write until the conditions are not equal..
I have tried this statement but I can not get by that dang =.
Also the memory map is free from 033 - 200.....does that mean 900 is a bad location? seems to work ok?
Note: You're already using PBASIC 2.5 syntax, so stick with it.· *Good* programming practice says NOT to put THEN claues on the same line as the IF-THEN statement.
If your Memory Map is painting address 900 with a blue background then you are overwriting part of your program -- don't do this!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Thanks for your help, but this still continues to elapse time. On startup both TH and TL will count time until tempf <> TH or TL. When condions are equal they continue to run the time. I have attached program, maybe something I have done is causing this.
Really thanks for your help...we will get it to work!
1. Use our standard template -- it will help you keep your code more organized (attached).
2. Use PIN instead of CON for IO pins
3. You don't need to use multiple DEBUGs -- you can separate items with commas
4. Single-letter labels are difficult to follow and give the reader no help -- be verbose with your labels
5. Intent code that is part of a loop (FOR-NEXT, DO-WHILE) or IF-THEN-ENDIF block
Enough on style ... you are recalculating TH and TL before you do the save comparison.· Shouldn't you do this after?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
(The previous program would never get to the Save routine, because it was expanding the limit _before_ it tested the branch condition.).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Thank you both for your help. I am new to all this and even with all the reading I have done it seems I learn better by example. I usually spend a lot of time working on it before I ask for help.
First off I choose 150 and 170 by chance. I have no data between 033 and 200.
After Jon mentioned how to find the area, I could not find 900 in the upper attached program. Jon I really do appreciate all the advice and as far as the debug I was just trying to put all information to be displayed in a block order. I do realalize this takes up programming space.
Tracy I just looked at your sample, never using the select, here we go I will give it a try and see what happens....will let both of you know
This will cause the High temperature to continue to count even if the Tempf is lower then TH. I think all the calculations are done above with the tempf and conversion to·TH and TL.
Again thank you both again!!!!!
IF (tempF > TH) THEN
· addr = 170
· TH = ((tempF + 1024) MIN (TH + 1024)) - 1024
· GOSUB Save
· ENDIF
IF (tempF < TL) THEN
· addr = 150
· GOSUB Save
· TL = ((tempF + 1024) MAX (TL + 1024)) - 1024
ENDIF
Using this formula will give me the proper conditions, but it will keep the clock running until the TH or TL are not equal.
TL=(TEMPF + 1024) MAX (TL+1024) - 1024
TH=(TEMPF + 1024) MIN (TH + 1024) -1024
IF (tempF >= TH) THEN
· addr = 170
· GOSUB Save
· ENDIF
IF (tempF <= TL) THEN
· addr = 150
· GOSUB Save
· ENDIF
Tracy your program was right on the money worked perfect!! Again want to Thank both of you. I am going to clean up this program and try and learn how to save the data I have just got.
Again thank you both for your time!!!
Guido