Difference between revisions of "SHIP:Data Types:Temperature"

From Serious Documentation
Jump to: navigation, search
Line 2: Line 2:
 
*'''[[SHIP:Data_Types|All Data Types]]'''
 
*'''[[SHIP:Data_Types|All Data Types]]'''
  
<onlyinclude>{{DataTypeTableStart|}}
+
<onlyinclude>
 +
The {{DataType|Temperature}} datatype is returned by the {{Port|gpio|pcbTemp}} portvar (the exact format is configured by setting {{Port|gpio|tempPrecision}}).
 +
{{DataTypeTableStart|}}
 
|-
 
|-
 
|{{DataType|Temperature}}||16 bit fixed-point-integer in which the upper portion is in whole degrees and the lower portion is in 256ths of a degree. Set {{SysVar|shipCelsius}} to {{Reserved|true}} for Celsius, or {{Reserved|false}} for Fahrenheit.
 
|{{DataType|Temperature}}||16 bit fixed-point-integer in which the upper portion is in whole degrees and the lower portion is in 256ths of a degree. Set {{SysVar|shipCelsius}} to {{Reserved|true}} for Celsius, or {{Reserved|false}} for Fahrenheit.
|}
+
|}</onlyinclude>
  
The {{DataType|Temperature}} datatype is returned by the {{Port|gpio|pcbTemp}} portvar (the exact format is configured by setting {{Port|gpio|tempPrecision}}).</onlyinclude> Generically, the value read from {{Port|gpio|pcbTemp}} is an 8-bit value in whole degrees followed by a <code>tempPrecision</code>-bit value in 1/256ths of a degree. The following are examples on how to properly interpret a {{DataType|Temperature}} value:
+
Generically, the value read from {{Port|gpio|pcbTemp}} is an 8-bit value in whole degrees followed by a <code>tempPrecision</code>-bit value in 1/256ths of a degree. The following are examples on how to properly interpret a {{DataType|Temperature}} value:
  
 
By default {{Port|gpio|tempPrecision}} is <code>0</code>:
 
By default {{Port|gpio|tempPrecision}} is <code>0</code>:

Revision as of 16:09, 1 February 2013


The Temperature datatype is returned by the pcbTemp portvar (the exact format is configured by setting tempPrecision).

Data Type Description
Temperature 16 bit fixed-point-integer in which the upper portion is in whole degrees and the lower portion is in 256ths of a degree. Set shipCelsius to true for Celsius, or false for Fahrenheit.

Generically, the value read from pcbTemp is an 8-bit value in whole degrees followed by a tempPrecision-bit value in 1/256ths of a degree. The following are examples on how to properly interpret a Temperature value:

By default tempPrecision is 0:

SIMTempWhole = GPIO.pcbTemp;  // the value is good as-is
SIMTempFrac  = 0;             // unnecessary

For handling any other value of tempPrecision:

SIMTempWhole = (GPIO.pcbTemp >> GPIO.tempPrecision);                  // once the fractional bits are gone, the value is correct
SIMTempFrac  = (GPIO.pcbTemp & (0x00FF >> (8 - GPIO.tempPrecision))); // get rid of the degree bits
SIMTempFrac  = (SIMTempFrac << (8 - GPIO.tempPrecision));             // re-adjust the fractional bits
SIMTempFrac  = (SIMTempFrac*100)/256;                                 // fix up the value to be a proper fraction (currently it is from 0/256 to 255/256 of a degree)

Note: SIMTempWhole and SIMTempFrac only need to be of type Byte to fit the highest possible values