Author: eur.van.andel
Date: Mon Oct 27 11:36:49 2008
New Revision: 490

Added:
    trunk/unvalidated/include/external/humidity/
    trunk/unvalidated/include/external/humidity/humidity_sht.jal    
(contents, props changed)
    trunk/unvalidated/include/external/temperature/temperature_tc77.jal
       - copied unchanged from r418,  
/trunk/unvalidated/include/external/temperature/temp_tc77.jal
Removed:
    trunk/unvalidated/include/external/temperature/temp_tc77.jal
Modified:
    trunk/unvalidated/include/external/co2/co2_t6603.jal

Log:
adding humidity lib


Modified: trunk/unvalidated/include/external/co2/co2_t6603.jal
==============================================================================
--- trunk/unvalidated/include/external/co2/co2_t6603.jal        (original)
+++ trunk/unvalidated/include/external/co2/co2_t6603.jal        Mon Oct 27  
11:36:49 2008
@@ -101,7 +101,7 @@
  const SERIAL      = 0x01
  const ELEVATION   = 0x0F

-var word CO2_global         -- global CO2 value, keeps value when garbage  
reply
+var word co2_global         -- global CO2 value, keeps value when garbage  
reply

  -- returns a word with CO2 concentration in ppm
  -- note: if sensor is busy measuring the CO2 values, it will give garbage  
reply
@@ -154,10 +154,10 @@
  -- DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG
  -- -----------------------------------------------------
     if response[0] == 0xFF  & response[1] == 0xFA then
-      CO2_global = response[3]
-      CO2_global = (CO2_global << 8) + response[4]
+      co2_global = response[3]
+      co2_global = (co2_global << 8) + response[4]
     end if
-   return CO2_global  -- if not, send previous value
+   return co2_global  -- if not, send previous value
  end function

  -- returns status byte. bit_0 = error, bit_1 = warmup,
@@ -260,7 +260,7 @@
     elevation_ft = (elevation << 8) + response[4]      -- feet above  
sealevel
     elevation_ft = elevation_ft * 3048                 -- meters * 10_000
     elevation_ft = elevation_ft / 10000                -- meters above  
sealevel
-   elevation_m = elevation_ft                         -- generates warning
+   elevation_m = word(elevation_ft)                   -- generates warning
     return elevation_m
  end function


Added: trunk/unvalidated/include/external/humidity/humidity_sht.jal
==============================================================================
--- (empty file)
+++ trunk/unvalidated/include/external/humidity/humidity_sht.jal        Mon Oct 
27  
11:36:49 2008
@@ -0,0 +1,264 @@
+-- Title: SHTxx, for Sensirion humidity and temperature sensors
+-- Author: Eur van Andel, [EMAIL PROTECTED] Copyright (c) 2008
+-- Compiler: =2.4h
+--
+-- This file is part of jallib (http://jallib.googlecode.com)
+-- Released under the BSD license
+-- (http://www.opensource.org/licenses/bsd-license.php)
+--
+-- Sources:  
http://www.sensirion.com/en/01_humidity_sensors/00_humidity_sensors.htm
+--
+-- Description: The Sensirion SHT1x/SHT7x is a single chip relative  
humidity and
+-- temperature multi sensor module comprising a calibrated digital output.
+-- It comes in 5 flavors, with different accuracy and package style:
+-- sensor   hum acc  temp acc    package
+-- SHT10    4.5      0.5         SMD (LCC)
+-- SHT11    3.0      0.4         SMD (LCC)
+-- SHT15    2.0      0.3         SMD (LCC)
+-- SHT71    3.0      0.4         4-pin single-in-line
+-- SHT75    1.8      0.3         4-pin single-in-line
+-- all consist of the same silicon: the less accurate models are sold  
cheaper.
+-- My experience is mixed: I've seen some consistent +2C offset in  
temperature,
+-- but good humidty measurements. The 4-pin package breaks when you touch  
it.
+-- The SMD package has naked tracks underneath: you can't route under it!
+-- If exposed to >95% RH for 10 minutes, these sensors will go beserk and  
need
+-- <60% RH for an hour to recover. You might try heating them.
+-- protocol is close to I2C, but not the same. Remember to pull up DATA.
+-- 0b0000_0011  starts temperature measurement
+-- 0b0000_0101  starts humidity measurement
+-- device returns three bytes: MSB, LSB and CRC
+-- higher functions don't do a CRC check
+--
+-- Declarations:
+-- var bit SHT_SCK         -- output pin, clock signal to sensor
+-- var bit SHT_DATA        -- data pin, data flows in both directions
+-- var bit SHT_DATA_dir    -- direction of data pin
+--
+-- Still to do: Temperature calculations in different precisions
+-- switching heating on/off
+
+-- send start
+procedure SHT_start is
+   SHT_DATA_dir = output
+   SHT_DATA = high
+   delay_1us()
+   SHT_SCK = high    -- \
+   delay_1us()       --  \
+   SHT_DATA = low    --   \
+   delay_1us()       --    \
+   SHT_SCK = low     --      required sequence
+   delay_1us()       --    /
+   SHT_SCK = high    --   /
+   delay_1us()       --  /
+   SHT_DATA = high   -- /
+   delay_1us()
+   SHT_SCK = low
+end procedure
+
+
+-- send one byte to the SHT
+procedure SHT_put_data(byte in x) is
+   var bit b at x: 7
+   SHT_DATA_dir = output
+   for 8 loop
+      SHT_DATA = b
+      SHT_SCK = high
+      delay_1us()
+      SHT_SCK = low
+      delay_1us()
+      x = x << 1
+   end loop
+end procedure
+
+-- receive one byte from the SHT
+procedure SHT_get_data(byte out x) is
+   var bit b at x: 0
+   SHT_DATA_dir = input
+   for 8 loop
+      x = x << 1           -- 8 bits, but only 7 shifts
+      b = SHT_DATA
+      SHT_SCK = high
+      delay_1us()
+      SHT_SCK = low
+      delay_1us()
+   end loop
+end procedure
+
+-- pretend to wait for ACK
+procedure SHT_wait_ack is
+   SHT_DATA_dir = input
+   SHT_SCK = high
+-- if !data then loop         -- don't touch this. if no reply
+-- end loop                   -- routine could become stuck here
+   delay_1us()
+   SHT_SCK = low
+   delay_1us()
+   SHT_DATA_dir = output
+   SHT_DATA = high
+end procedure
+
+-- send ACK
+procedure SHT_put_ack is
+   SHT_DATA_dir = output
+   SHT_DATA  = low
+   delay_1us()
+   SHT_SCK = high
+   delay_1us()
+   SHT_SCK = low
+   delay_1us()
+end procedure
+
+-- reset SHT
+procedure SHT_reset is
+   SHT_start
+   SHT_put_data(0b000_11110)   -- soft reset of SHT
+   SHT_wait_ack
+end procedure
+
+-- reset SHT interface, must be followed with SHT_start and command
+procedure SHT_conn_reset is
+   SHT_DATA = high
+   for 9 loop
+      SHT_SCK = high
+      delay_1us()
+      SHT_SCK = low
+      delay_1us()
+   end loop
+end procedure
+
+
+-- read raw 14-bit temperature from SHT
+-- default value of resolution bit is 14 bit temperature
+-- SHT takes 210 ms for measurement @ 14 bits
+-- we will wait 300 ms
+-- SHT may only be switched on for 10% of the time because of self-heating
+-- so this measurement can only happen every two seconds!
+procedure read_raw_temp_SHT(byte out MSB, byte out LSB, byte out CRC) is
+   var byte counter = 32
+   SHT_start
+   SHT_put_data(0b000_00011)   -- start temperature measurement
+   SHT_wait_ack
+   SHT_DATA_dir = input
+
+   while (SHT_DATA == high)  & (counter > 1) loop
+      delay_1ms(10)
+      counter = counter - 1
+   end loop
+
+   SHT_get_data( MSB )      -- read SHT_DATA
+   SHT_put_ack
+   SHT_get_data( LSB )      -- read SHT_DATA
+   SHT_put_ack
+   SHT_get_data( CRC )      -- read SHT_DATA
+   SHT_DATA_dir = output
+   SHT_DATA = high         -- no ack, end transmission
+   delay_1us()
+   SHT_SCK = high
+   delay_1us()
+   SHT_SCK = low
+end procedure
+
+
+-- read raw 12-bit humidity from SHT
+-- default value of resolution bit is 12 bit RH
+-- SHT takes 55 ms for measurement @ 12 bits
+-- we will wait 70 ms
+-- SHT may only be switched on for 10% of the time because of self-heating
+-- so this measurement can only happen every 500ms
+procedure read_raw_hum_SHT(byte out MSB, byte out LSB, byte out CRC) is
+   var byte counter = 8
+   SHT_start
+   SHT_put_data(0b000_00101)   -- start humidity measurement
+   SHT_wait_ack
+   SHT_DATA_dir = input
+
+   while ((SHT_DATA == high)  & (counter > 1)) loop
+      delay_1ms(10)
+      counter = counter - 1
+   end loop
+
+   SHT_get_data( MSB )      -- read SHT_DATA
+   SHT_put_ack
+   SHT_get_data( LSB )      -- read SHT_DATA
+   SHT_put_ack
+   SHT_get_data( CRC )      -- read SHT_DATA
+   SHT_DATA_dir = output
+   SHT_DATA = high         -- no ack, end transmission
+   delay_1us()
+   SHT_SCK = high
+   delay_1us()
+   SHT_SCK = low
+end procedure
+
+
+-- read humidity from SHT, result in byte precision 1%RH
+-- SHT may only be switched on for 10% of the time because of self-heating
+-- so this measurement can only happen every 500ms
+procedure read_hum_sht(byte out hum) is
+   var byte MSB, LSB, CRC
+   var dword tmp
+   var byte counter = 8
+   SHT_start
+   SHT_put_data(0b000_00101)   -- start humidity measurement
+   SHT_wait_ack
+   SHT_DATA_dir = input
+
+   while ((SHT_DATA == high)  & (counter > 1)) loop
+      delay_1ms(10)
+      counter = counter - 1
+   end loop
+
+   SHT_get_data( MSB )      -- read SHT_DATA
+   SHT_put_ack
+   SHT_get_data( LSB )      -- read SHT_DATA
+   SHT_put_ack
+   SHT_get_data( CRC )      -- read SHT_DATA
+   SHT_DATA_dir = output
+   SHT_DATA = high         -- no ack, end transmission
+   delay_1us()
+   SHT_SCK = high
+   delay_1us()
+   SHT_SCK = low
+
+   tmp = MSB
+   tmp = tmp *  256 + LSB
+   tmp = -4 + ((tmp * 10) / 247) - (tmp * tmp / 357143)     -- 3 digit  
precision
+   hum = byte (tmp)
+
+end procedure
+
+-- read humidity from SHT, result in word precision 0.01%RH
+-- SHT may only be switched on for 10% of the time because of self-heating
+-- so this measurement can only happen every 500ms
+procedure read_hum_word_SHT(word out hum) is
+   var byte MSB, LSB, CRC
+   var dword tmp
+   var byte counter = 8
+   SHT_start
+   SHT_put_data(0b000_00101)   -- start humidity measurement
+   SHT_wait_ack
+   SHT_DATA_dir = input
+
+   while ((SHT_DATA == high)  & (counter > 1)) loop
+      delay_1ms(10)
+      counter = counter - 1
+   end loop
+
+   SHT_get_data( MSB )      -- read SHT_DATA
+   SHT_put_ack
+   SHT_get_data( LSB )      -- read SHT_DATA
+   SHT_put_ack
+   SHT_get_data( CRC )      -- read SHT_DATA
+   SHT_DATA_dir = output
+   SHT_DATA = high         -- no ack, end transmission
+   delay_1us()
+   SHT_SCK = high
+   delay_1us()
+   SHT_SCK = low
+
+   tmp = MSB
+   tmp = tmp *  256 + LSB
+   tmp = -400 + ((tmp * 10000) / 2469) - (tmp * tmp /3571)  -- 4-digit  
precision
+   hum = word (tmp)
+
+end procedure
\ No newline at end of file

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to