User Tools

Site Tools


en:pfw:linear-conversion

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
en:pfw:linear-conversion [2025-02-11 23:19] – created alberten:pfw:linear-conversion [2025-02-12 12:36] (current) albert
Line 1: Line 1:
- A very simple method (no floating point, no algebraic formulas) for+ ===== Simple linear conversion ===== 
 +A very simple method (no floating point, no algebraic formulas) for
  linear conversion of sensor output data to human-understandable units.  linear conversion of sensor output data to human-understandable units.
  
- --- Example 1, temperature ---+ === Example 1, temperature ===
  
  Two points are given: Sensor output 400 and 1200 correspond  Two points are given: Sensor output 400 and 1200 correspond
- to 10 and 36.3 degrees Celsius respectively. + to 10 and 36.3 degrees Celsius respectively.\\
  To get rid of floating point, we calculate Celsius in tenths of degrees:  To get rid of floating point, we calculate Celsius in tenths of degrees:
  
- Sensor  Celsius +    Sensor  Celsius 
-  400     100 +     400     100 
- 1200     363 +    1200     363 
- (800)   (263)  (Distance)+    (800)   (263)  (Distance)
  
- Take+ Let's take
- SensorZ     = the given sensor value closest to zero (400) +    SensorZ     = the given sensor value closest to zero (400) 
- CelsiusZ    = the corresponding Celsius value (100) +    CelsiusZ    = the corresponding Celsius value (100) 
- SensorDist  = distance between the two sensor values (800) +    SensorDist  = distance between the two sensor values (800) 
- CelsiusDist = distance between the two Celsius values (263)+    CelsiusDist = distance between the two Celsius values (263)
  
- The conversion then looks like this:+ Then the conversion looks like this:
  
     : >CELSIUS    ( sensor -- celsius )     : >CELSIUS    ( sensor -- celsius )
Line 28: Line 28:
  
     : >CELSIUS ( sensor -- celsius ) 400 - 263 800 */ 100 + ;     : >CELSIUS ( sensor -- celsius ) 400 - 263 800 */ 100 + ;
-    ---------------------------------------------------------+
  
  
Line 34: Line 34:
  correspond to decreasing Celsius values.  correspond to decreasing Celsius values.
  
- --- Example 2 ---+ === Example 2 ===
  
- Sensor  Celsius +    Sensor  Celsius 
-  400     363 +     400     363 
- 1200     100 +    1200     100 
- (800)   (263)  (Distance)+    (800)   (263)  (Distance)
  
 + The forth definition:
     : >CELSIUS ( sensor -- celsius ) 400 - 263 800 */ NEGATE 363 + ;     : >CELSIUS ( sensor -- celsius ) 400 - 263 800 */ NEGATE 363 + ;
-    ----------------------------------------------------------------+
  
  ( an,jan2025)  ( an,jan2025)
  
en/pfw/linear-conversion.1739312350.txt.gz · Last modified: 2025-02-11 23:19 by albert