ADICON Support Forum Applied Digital, Inc.
Page 1 of 2 12>
Topic Options
#2208 - 02/28/05 02:15 AM negative temperature display
Brew Offline
newbie


Registered: 08/31/04
Posts: 20
I am converting to "degrees C" using -132 *5 /9. But when the reslut is less that zero Cmax does not display the result as a negative number. I understand why but can someone help me reslove the problem?
I have searched the board for a solution and found one other identical question, but it was not answered.

Top
#2209 - 02/28/05 04:07 AM Re: negative temperature display
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6401
Loc: Montreal, QC, Canada
C-Max itself (such as when viewing variables using "debug timers and variables") cannot display variables as negative numbers. The only places where this can be done is either on a Leopard screen or in a serial ASCII Message, using the signed formatting option, such as "%3d". For example, -3 within C-Max displays as 65533, and will also be that value within the running program (important to know for < and > tests) but will show as -3 in a formatted string like "The temperature is %3d degrees".
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#2210 - 02/28/05 04:52 AM Re: negative temperature display
Brew Offline
newbie


Registered: 08/31/04
Posts: 20
Guy, I have the following code that will not display as a negative number when the data from the bobcat is less than 132 (zero degrees F).

:
IF Data for Module# 1 is < 256 //always true
THEN Temp_Variable = Data for Module# 1
THEN Temp_Variable - 132
THEN Temp_Variable * 5
THEN Temp_Variable / 9 //Converted to C
THEN Outside_Temp = Temp_Variable
////////////////////////////////////////
Leopard display object for Outside_Temp is formatted as %3d

If the bobcat data is say 129 then the first part of the conversion, 129-132 is -3 or internally for Cmax "65533" so now the rest of the calculation is screwed up.

Am I right? If this is true I cannot think of the solution, mind you, I was never very good at Math.

Top
#2211 - 02/28/05 05:27 AM Re: negative temperature display
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6401
Loc: Montreal, QC, Canada
That's right, C-Max code is always working and calculating with positive numbers. You need to change the conversion formula to avoid dealing with multiplication or division of negative numbers. Avoiding negative numbers is also the reason for the +100 offset of the bobcat's output. Since we want a final result in degrees Celsius, I suggest that you increase that offset to 180, do the conversion, and then subtract the equivalent 100 from the final result (ie: an initial value that is too high by 180 deg F = final value that is too high by 100 deg C). Do it like this:

IF Data for Module# 1 is < 256 //always true
THEN Temp_Variable = Data for Module# 1
THEN Temp_Variable + 80 //increase offset to 180
THEN Temp_Variable - 32
THEN Temp_Variable * 5
THEN Temp_Variable / 9 //Converted to C
THEN Temp_Variable - 100 //subtract 100 offset
THEN Outside_Temp = Temp_Variable

This code is to illustrate all the math steps for better understanding. In the actual code, I would replace:

THEN Temp_Variable + 80
THEN Temp_Variable - 32

by

THEN Temp_Variable + 48
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#2212 - 02/28/05 06:17 AM Re: negative temperature display
Brew Offline
newbie


Registered: 08/31/04
Posts: 20
EXCELLENT!!!

That did the trick. Simple solution once you know.
Guy you are worth your weight in gold!

Now just have to get it to do decimal places...for which I will also use your recommendation post on this board. What would we do without you?

Top
#2213 - 02/28/05 07:09 AM Re: negative temperature display
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6401
Loc: Montreal, QC, Canada
Since C-Max only has whole numbers, you cannot get decimal values directly. Instead, you would do similar offset thing where you multiply the temperature reading by a larger number during the conversion to increase the precision. Its the division by 9 that produces the decimal value, so if instead of multiplying by 5 we multiply by 50, the result will be 10 times larger after the multiplication and division. We also now need to subtract an offset of 1000 because of this. We then use divide and modulo to extract the two numbers (whole and decimal). You would need to display the two variables side by side on the Leopard screen, with a text "." between the two fields. Say you want one digit past the decimal point:

IF Data for Module# 1 is < 256 //always true
THEN Temp_Variable = Data for Module# 1
THEN Temp_Variable + 80 //increase offset to 180
THEN Temp_Variable - 32
THEN Temp_Variable * 50 // multiply by 50
THEN Temp_Variable / 9 //Converted to C
THEN Temp_Variable - 1000 //subtract 1000 offset
THEN Outside_Temp_Whole = Temp_Variable / 10 //get whole number part
THEN Outside_Temp_Decimal = Temp_Variable % 10 //get the decimal part

For example: 73 degrees F:

bobcat returns 173. If you add 80 and subtract 32, you get 221. Multiply by 50 to get 11050 and divide by 9 to get 1227. Subtract the 1000 offset to get 227.

The whole number is obtained with division by 10, giving 22.

The decimal number is obtained with modulo 10, giving 7 ie: the temperature is 22.7 C.

On the Leopard screen, you would use three objects placed side by side:

"%3d", "." and "%1d". You might need to fiddle around with exact placement to get it just right.
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#19165 - 12/21/07 02:13 AM Re: negative temperature display [Re: Guy Lavoie]
chewbarker Offline
newbie


Registered: 01/01/07
Posts: 23
Hey Guy,

How do you do this in C-Max:

THEN Outside_Temp_Whole = Temp_Variable / 10 //get whole number part

I found I could only do this in 2 lines:

THEN Outside_Temp_Whole = Temp_Variable
THEN Outside_Temp_Whole / 10

Also I found a problem with this because sometimes it would display the variable on the screen for the first line, so I extend this to:

THEN Scratch = Temp_Variable
THEN Scratch = / 10
THEN Outside_Temp_Whole = Scratch

Is my assumptions correct and this is the simpliest way?

Thanks for you help

Matt

Top
#19172 - 12/21/07 10:25 AM Re: negative temperature display [Re: chewbarker]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6401
Loc: Montreal, QC, Canada
Yes, the screen might display the variable's value at any given program line so if you are making calculations on it, use a temporary variable for your calcuations (like what you're doing in your last example) and then copy the result to the variable that you are displaying.

The way you're doing it now is correct.
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#21239 - 07/13/09 01:54 AM Re: negative temperature display [Re: Guy Lavoie]
AlainD Offline
junior


Registered: 02/11/03
Posts: 27
Loc: Paris
Hi, I would be also interested to convert °F to °C ...
But I did not suceeded to enter these lines through C-Max ...

--- (Guy's suggestion) ---
IF Data for Module# 1 is < 256 //always true
THEN Temp_Variable = Data for Module# 1
THEN Temp_Variable + 80 //increase offset to 180
THEN Temp_Variable - 32
THEN Temp_Variable * 50 // multiply by 50
THEN Temp_Variable / 9 //Converted to C
THEN Temp_Variable - 1000 //subtract 1000 offset
THEN Outside_Temp_Whole = Temp_Variable / 10 //get whole number part
THEN Outside_Temp_Decimal = Temp_Variable % 10 //get the decimal part
---

Did I missed something with C-Max ??

Thanks.

Alain.


Edited by AlainD (07/13/09 01:57 AM)

Top
#21240 - 07/13/09 05:09 AM Re: negative temperature display [Re: AlainD]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6401
Loc: Montreal, QC, Canada
What exactly did you not succeed in entering?
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#21241 - 07/13/09 11:17 AM Re: negative temperature display [Re: Guy Lavoie]
AlainD Offline
junior


Registered: 02/11/03
Posts: 27
Loc: Paris
Hi Guy,
In fact, I would like to use your conversion method and send the result in Homeseer ...
But I do not see how to convert your code for this ...

Top
#21242 - 07/13/09 01:14 PM Re: negative temperature display [Re: AlainD]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6401
Loc: Montreal, QC, Canada
If you're referring to the last two lines, I might have not done it correctly, and would need extra steps (and another temporary variable):

IF Data for Module# 1 is < 256 //always true
THEN Temp_Variable = Data for Module# 1
THEN Temp_Variable + 80 //increase offset to 180
THEN Temp_Variable - 32
THEN Temp_Variable * 50 // multiply by 50
THEN Temp_Variable / 9 //Converted to C
THEN Temp_Variable - 1000 //subtract 1000 offset

THEN Temp_Variable2 = Temp_variable
THEN Temp_Variable2 / 10
THEN Outside_Temp_Whole = Temp_Variable2

THEN Temp_Variable2 = Temp_variable
THEN Temp_Variable2 % 10
THEN Outside_Temp_Decimal = Temp_Variable2


If you're not concerned with the decimal part, then you could just do this (and not need an extra temporary variable):

IF Data for Module# 1 is < 256 //always true
THEN Temp_Variable = Data for Module# 1
THEN Temp_Variable + 80 //increase offset to 180
THEN Temp_Variable - 32
THEN Temp_Variable * 50 // multiply by 50
THEN Temp_Variable / 9 //Converted to C
THEN Temp_Variable - 1000 //subtract 1000 offset
THEN Temp_Variable / 10
THEN Outside_Temp_Whole = Temp_Variable
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#21243 - 07/13/09 01:45 PM Re: negative temperature display [Re: Guy Lavoie]
AlainD Offline
junior


Registered: 02/11/03
Posts: 27
Loc: Paris
Thanks Guy.

And how to insert "Temp_Variable" key ? It is not accepted and recognized by C-Max ...

Thanks.


Edited by AlainD (07/13/09 01:46 PM)

Top
#21244 - 07/13/09 01:55 PM Re: negative temperature display [Re: AlainD]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6401
Loc: Montreal, QC, Canada
That variable names I'm using (and any names you want to use) are defined in the System Map (under "Project"), as Variables. In fact I have a naming convention where I precede the name with the variable number, such as V1-Temp_Variable. To do the same with timers: T3-IR_Interval, etc. These names will then appear instead of "Variable #1", etc in your code and make the program much easier to read.
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#22251 - 12/29/10 05:15 PM Re: negative temperature display [Re: Guy Lavoie]
AlainD Offline
junior


Registered: 02/11/03
Posts: 27
Loc: Paris
Hello Guy,

Thanks for this reply. Sorry to come back to you so lately (1,5 year later !) :-)

I use Homeseer. If I want to load the final result of this sequence to HS, how can I do ??

IF Data for Module# 1 is < 256 //always true
THEN Temp_Variable = Data for Module# 1
THEN Temp_Variable + 80 //increase offset to 180
THEN Temp_Variable - 32
THEN Temp_Variable * 50 // multiply by 50
THEN Temp_Variable / 9 //Converted to C
THEN Temp_Variable - 1000 //subtract 1000 offset
THEN Temp_Variable / 10
THEN Outside_Temp_Whole = Temp_Variable


Thanks.

Alain.

Top
#22254 - 12/29/10 06:22 PM Re: negative temperature display [Re: AlainD]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6401
Loc: Montreal, QC, Canada
You would have Homeseer track the value of the variable# you are using for the final result (Outside_Temp_Whole). So if this is variable #17 in your system map, then that is the variable to track. I'm not a Homeseer user so I don't know exactly how this is done.
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#22260 - 12/30/10 02:08 PM Re: negative temperature display [Re: Guy Lavoie]
AlainD Offline
junior


Registered: 02/11/03
Posts: 27
Loc: Paris
Thanks Guy,

In fact, that's I understood at first.

It is a stupid error from my side. When I did the tests with your conversion code, it was on a Bobcat-T unit located outside. The result notified in HS was 0. So, no result according to me.
In fact the temperature outside was ... 0°C. It was working fine !

:-)

Thanks a lot !

Happy to have now the results in Celsius.

Alain.


Edited by AlainD (12/30/10 02:14 PM)

Top
#22261 - 12/30/10 03:27 PM Re: negative temperature display [Re: AlainD]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6401
Loc: Montreal, QC, Canada
That's funny.

Enjoy!
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#22270 - 01/02/11 02:51 PM Re: negative temperature display [Re: Guy Lavoie]
AlainD Offline
junior


Registered: 02/11/03
Posts: 27
Loc: Paris
Hi Guy,

It seems that when the Bobcat-T reaches the value 132 (under 0°C), the value in HS displayed is 6553 ! Is it normal ?

Here is the conversion used :

0072 - IF Module #6 -BOBCAT-T is < 256 // Bobcat-T Ext. Nord
0073 - THEN Variable #4 = Data for Module# 6 //
0074 - THEN Variable #4 + 80 //
0075 - THEN Variable #4 - 32 //
0076 - THEN Variable #4 * 50 //
0077 - THEN Variable #4 / 9 //
0078 - THEN Variable #4 - 1000 //
0079 - THEN Variable #4 / 10 //
0080 - THEN Variable #2 = Variable #4 //

Thanks.

Alain.

Top
#22276 - 01/03/11 07:00 PM Re: negative temperature display [Re: AlainD]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6401
Loc: Montreal, QC, Canada
Yes, 65535 is "minus 1" in a signed 16 bit value. In the Leopard, the display can be programmed to display this as a negative number. In a program like Homeseer, you should be able to script something like "if the number is greater then 32767, then the number is a negative value equal to 65536 - variable"
_________________________
"If you don't know what you're doing, do it neatly..."

Top
Page 1 of 2 12>


Moderator:  Dan Smith, Monte G, ADI Tech Support, Guy Lavoie 
Hop to:
Who's Online
0 registered and 26 anonymous users online.
Recent Posts
how to post an icon
by manu
02/03/12 03:40 AM
Command Pair
by kuro
02/01/12 12:49 AM
Does anyone have a copy of the latest TSE?
by sevenzenith1
01/30/12 05:17 AM
Have HAL2000 do the work or the Ocelot?
by khem
01/28/12 02:49 PM
Ocelot + Powermid = Fail
by Guy Lavoie
01/27/12 03:37 PM
Shout Box

Newest Members
dfgg, manu, kuro, sevenzenith1, chuck214
2748 Registered Users
Forum Stats
2747 Members
19 Forums
3835 Topics
22711 Posts

Max Online: 67 @ 08/16/11 03:08 PM
February
Su M Tu W Th F Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29