Problem using a global variable a second time in a single repeat while statemen
MrBean
Posts: 8
Hi everyone, this is my first post. I've almost completed the programming of my propeller usb stick. I've managed to
fix all the bugs in my programming except for one and I just can't figure it out without possible having to read many
books before I do. I admit I haven't finished reading the propeller education kit fundamentals labs book yet, but this is
really bothering me and I have doubts that the answer will be in that book. All the outputs have an LED connected to
them until I see that my code is working. Also I am using the DS2760 Thermocouple from parallax, as well as the only
set of objects you will find on the propeller object exchange when you search DS2760.
I've shortened my code to simplify it for testing purposes. Here is the entire code needed (except for the ds2760
objects) which will work with the breadboard setup from Labs 4, 5, or 6 from the Propeller education kit fundamentals
lab book, also connecting the DS2760 directly to 5 volts power as well as directly to pin25 for data transfer, I haven't
calculated the exact stack space i need but it seems to be more than enough:
First, here is the part of the code that is the culprit:
This part of the code does not work and gives very strange results for the LED on pin7 when using "repeat while
(readingtemp > 01155) and (readingtemp < 01403)". Most of the time the LED does not light at all. It seems to cause a
bug like when you try to launch a method in a cog that is already running another method. Both methods just do
strange things.
The problem seems to be only with the second "and (readingtemp < 01403)". If I remove the second one so the line
just reads "repeat while (readingtemp > 01155)", then it functions just as it should without any problem. However,
what I need the code to do is not to look at just one temperature and see if it is greater than or less than that single
temperature. Instead I need to have the repeat while statement check to see if the current temperature is in the range
between 01155 and 01403 for it to decide whether or not to flash the led on pin7. By the way, 01155 and 01403 are 29
and 35 degrees celcius on the T-Type wire, so I can just hold the thermocouple twisted end of the wire between my 2
fingers or breath hot air on it to activate the repeat while condition since the temperature in the room is around 26 or
27 degrees. Also I think it is important to note that a second condition in the repeat while statement such as pressing a
pushbutton on pin24 works perfectly as well without any problem, such as, "repeat while (readingtemp > 01155) and
(ina[noparse][[/noparse]24] == 1)", so somehow it seems that using the same global variable twice in a single repeat statement causes the
problem in some way. I've tried everything I can think of. Does any one know how to write a range of temperatures as
a condition using "repeat while".
fix all the bugs in my programming except for one and I just can't figure it out without possible having to read many
books before I do. I admit I haven't finished reading the propeller education kit fundamentals labs book yet, but this is
really bothering me and I have doubts that the answer will be in that book. All the outputs have an LED connected to
them until I see that my code is working. Also I am using the DS2760 Thermocouple from parallax, as well as the only
set of objects you will find on the propeller object exchange when you search DS2760.
I've shortened my code to simplify it for testing purposes. Here is the entire code needed (except for the ds2760
objects) which will work with the breadboard setup from Labs 4, 5, or 6 from the Propeller education kit fundamentals
lab book, also connecting the DS2760 directly to 5 volts power as well as directly to pin25 for data transfer, I haven't
calculated the exact stack space i need but it seems to be more than enough:
CON _xinfreq = 5_000_000 _clkmode = xtal1 + pll16x VAR long stack[noparse][[/noparse]30] Word readingtemp ' Thermocouple reading value returned from TC.Temp OBJ TC : "Brilldea-DS2760-Ver004.spin" 'Thermocouple control PUB GetReadingTemp dira[noparse][[/noparse]4..5] ~~ if TC.start(25) 'this line starts the ds2760 startup routine to make it active on pin25 outa := 1 coginit(2, PowerAdjust, @stack[noparse][[/noparse]0]) else 'If return true, continue with program, else light led on pin5 repeat outa := 1 repeat readingtemp := TC.TCtemp 'Then you can get a thermocouple reading and return to readingtemp PUB PowerAdjust dira[noparse][[/noparse]7] ~~ repeat repeat while (readingtemp > 01155) and (readingtemp < 01403) 'Removing the second readingtemp makes outa[noparse][[/noparse]7] := 1 'the program function properly but is not what waitcnt(clkfreq/2 + cnt) 'I want outa[noparse][[/noparse]7] := 0 waitcnt(clkfreq/2 + cnt)
First, here is the part of the code that is the culprit:
repeat while (readingtemp > 01155) and (readingtemp < 01403) outa[noparse][[/noparse]7] := 1 waitcnt(clkfreq/2 + cnt) outa[noparse][[/noparse]7] := 0 waitcnt(clkfreq/2 + cnt)
This part of the code does not work and gives very strange results for the LED on pin7 when using "repeat while
(readingtemp > 01155) and (readingtemp < 01403)". Most of the time the LED does not light at all. It seems to cause a
bug like when you try to launch a method in a cog that is already running another method. Both methods just do
strange things.
The problem seems to be only with the second "and (readingtemp < 01403)". If I remove the second one so the line
just reads "repeat while (readingtemp > 01155)", then it functions just as it should without any problem. However,
what I need the code to do is not to look at just one temperature and see if it is greater than or less than that single
temperature. Instead I need to have the repeat while statement check to see if the current temperature is in the range
between 01155 and 01403 for it to decide whether or not to flash the led on pin7. By the way, 01155 and 01403 are 29
and 35 degrees celcius on the T-Type wire, so I can just hold the thermocouple twisted end of the wire between my 2
fingers or breath hot air on it to activate the repeat while condition since the temperature in the room is around 26 or
27 degrees. Also I think it is important to note that a second condition in the repeat while statement such as pressing a
pushbutton on pin24 works perfectly as well without any problem, such as, "repeat while (readingtemp > 01155) and
(ina[noparse][[/noparse]24] == 1)", so somehow it seems that using the same global variable twice in a single repeat statement causes the
problem in some way. I've tried everything I can think of. Does any one know how to write a range of temperatures as
a condition using "repeat while".
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
Your code looks good though. Not sure what the problem is.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
Post Edited (Dave Hein) : 8/5/2010 9:35:34 PM GMT
Thanks Harley for your suggestion, but I've tried everything I can think of already in any different combination that
might make a difference with no success. so I've already tried
That made no difference.
changing the and to or also has strange results.
I've even nested the second (readingtemp < 01403) in another repeat while condition inside the first one condition just
to see if it would work even though I would have a problem with using it that way. It still had the same problem.
I've also tried to run the TC.TCtemp object a second time to store the result in a second global variable to use the second
global variable in the second temperature condition for the range, so one would show readingtemp and the other
readingtemp2. That still came up with the same problem.
It doesn't make sense to me because logically and even in the education kit fundamentals book, I am using the proper syntax.
Thank you Kye. I didn't try that one though because I already went through the coding for the objects I found for the ds2760
and I already saw it initiates a cog with cognew, so I didn't use cog1 for that reason. I just tried your suggestion though
just to see if I missed something and it didn't work. Thanks for your thoughts though. It was a good idea.
Dave, i'll get back to you asap. but for now, so you know, the temperature in my room is 26 degrees celcius where the
led doesn't flash yet. 01155 is 29 degrees celcius which is when the led starts to flash as I blow hot air on to it when it works
with the single condition and for the second condition 1403 is 35 degrees which is around how hot it gets when I blow hot air
on the wire. I've set the second condition to 50 degrees celcius and it didn't make a difference So if all you need to know
is that I know what I'm doing when I test it and the temperature ranges are correct, then they are. However I will try
your suggestion and post back soon.
sorry I took so long to respond.
I saw only one cognew c
DS2760 is working and returns the proper temperature when I use only one readingtemp condition in the repeatwhile
statement.
Post Edited (MrBean) : 8/5/2010 10:52:09 PM GMT
so I don't know how long it will take for me to figure out how to do it. I'm pretty sure it's in the chapter I am currently reading now. From the exact way
the circuit is reacting, it seems there is a good chance you are correct.
Graham
I have to cook dinner now, so I suppose I will post back in 2 hours. It shouldn't take much longer than that to finish getting the answer for dave.
It was easy to get the paralax serial terminal to work. I got back the result of readingtemp at an interval of 1 second using the dec method of fullduplexserial.spin
Here is what the terminal displayed:
23
24
24
24
24
25
25
25
24
26
26
27
27
27
28
28
65535
65535
65535
65535
65535
I'll explain these values. 23 and 24 was the temperature in the room. Then when I pinched the twisted end of the thermocouple in between two fingers (only for half a second at a time so it didn't heat up too quickly) it started to show 25, 26, 27, 28, 29 and I could not get it to show anything past 29 before it jumped to 65535, which is the largest word value and is not a valid value for the object for the ds2760. So it seems that the programming in the object I downloaded is not working properly. It does seem to work up to 29 degrees celcius. The object did have a warning that it was not perfect yet, but it did say that it did work. I will have to pm Mr. Timothy Sweiter who made the object for the ds2760 and see if he has any thoughts on this result.
Thank you so much Dave for your expert analysis and advice. You were absolutely right! Thank you everyone else as well for your thoughts.
SO besides the erroneous value above 29 degrees I was also using voltage values from a voltage/celcius table in the DAt section of the Object I downloaded such as 01403 instead of its equivalent celcius value which is 35. I didn't realize that the code returns the celcius value. And to finalize this post I checked the code "repeat while (readingtemp >25) and (readingtemp < 29)" (since those celcius values seem to be working) using the parallax serial terminal to check the values of readingtemp at the same time, and it works PERFECTLY!
If anyone has any ideas how to fix this problem with the ds2760, please post here. I will check this topic for the next week or so. Although I will try and figure this out myself and if I have any questions, I will post a new topic in the sesors section of the propeller forum. I'll tell you my thoughts however. I don't think it is a hardware issue because TC.Start returns true which means that the DS2760 started up correctly and the propeller pin got specifically the value $33 from a register in the DS2760. But one thing that bothers me a bit is that the 5 volt data connection from the DS2760 is connected to a 3.3volt pin on the propeller without a resistor. A resistor supposedly makes the amperage so low that the propeller pin recieves erroneous readings because the ds2760 doesn't send that much amperage to begin with through its data line, so since there is not that much amperage, supposedly the propeller pin can handle it (so says technical support at parrallax). So I would be more inclined to think it is the programming of the object for the ds2760. I will start to troubleshoot the object by removing the calculation from the final calculated voltage to celcius (as soon as I figure out how) so I have to program the conditional repeat while statement with 01403 instead of 35 for degrees celcius. I would like to see what value the parallax serial terminal returns. If that doesn't work, I know that part of the code is probably ok and I will troubleshoot backwards from there.
Sorry again for not finishing the educational kit fundamentals book before posting. But I was sure it was a problem with syntax even though that didn't make sense. I actually new about the serial terminal, but I thought that either the ds2760 would work or if it didn't I thought it would show only one erroneous value no matter what temperature it should be detecting. So thank you Dave once again for setting me straight on how I should be testing the ds2760. This is my first programming language and I've never worked with a microcontroller or a sensor before, so I really needed that slap in the face. I'll make sure I finish the book before I post any other topic.