Możliwość włączenia ciągłej konwersji, ale tez domyślnie dokonuje tylko jednej konwersji i przechodzi w tryb oszczędzania energii.
Ma też możliwość ustawienia progów dolnego i górnego i reakcji po ich przekroczeniu. Dokładność do 12 bit.
Napisałem kilka podstawowych linijek które mogą ułatwić start z tym układem.
Można by jeszcze przesunąć przecinek i pozbyć się obliczeń na liczbach zmiennoprzecinkowych (tutaj Single).
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $nocompile
- '----------UNMARK ONLY ONE-----------WRITE < READ-------------THAT MATCH HARDWARE-----
- Const Tp100_addr = &B1001_0000 'ADD1=0 ADD0 = 0
- 'Const Tp100_addr = &B1001_0010 'ADD1=0 ADD0=Float
- 'Const Tp100_addr = &B1001_0100 'ADD1=0 ADD0=1
- 'Const Tp100_addr = &B1001_1000 'ADD1=1 ADD0=0
- 'Const Tp100_addr = &B1001_1010 'ADD1=1 ADD0=Float
- 'Const Tp100_addr = &B1001_1100 'ADD1=1 ADD0=1
- 'Const Tp100_addr = &B1001_0110 'ADD1=Float ADD0=0
- 'Const Tp100_addr = &B1001_1110 'ADD1=Float ADD0=1
- Const Temp_reg = 0
- Const Conf_reg = 1
- Const Min_temp = 2
- Const Max_temp = 3
- Const Shuttdown_mode = 0 'bit 0 default 1=Shhuttdown ON
- Const Thermostat_mode = 1 'bit 1
- Const Polarisation = 2
- Const Fault_bits0 = 3
- Const Fault_bits1 = 4
- Const Resolution_bits0 = 5
- Const Resolution_bits1 = 6
- Const Start_conv = 7
- Const 9bit = 0.5
- Const 10bit_res = 0.25
- Const 11bit_res = 0.125
- Const 12bit_res = 0.0625
- 'R1=0,R0=0 ->9bits 40ms
- 'R1=0.R0=1 ->10bits 80ms
- 'R1=1,R0=0 ->11bits 160ms
- 'R1=1,R0=1 ->12bits 320ms
- Dim Conf_byte As Byte , Tempb(2) As Byte , Error As Byte , Sum As Long , Count As Byte
- Dim Raw As Integer At Tempb(1) Overlay
- Dim Temperature As String * 10 , Temps As Single
- 'Conf_byte = Bits(resolution_bits0 , Resolution_bits1 , Start_conv) 'continuos read 12bits
- Conf_byte = Bits(shuttdown_mode , Resolution_bits0 , Resolution_bits1 , Start_conv) 'single shot 12bits
- Sub Start_conversion()
- I2cstart
- I2cwbyte Tp100_addr 'write address
- I2cwbyte Conf_reg 'chose Reg1 (config or start conversion)
- I2cwbyte Conf_byte 'start conversion by setting bit 7
- I2cstop
- End Sub
- Function Read_t100() As Byte
- I2cstart
- I2cwbyte Tp100_addr
- If Err = 0 Then
- I2cwbyte Temp_reg 'we will be reading first
- I2cstart
- I2cwbyte Tp100_addr + 1 ' address for read
- I2crbyte Tempb(2) , Ack
- I2crbyte Tempb(1) , Nack
- I2cstop
- Else
- 'no acknowledge from the sensor
- Read_t100 = 1
- Exit Function 'will skip the math
- End If
- Shift Raw , Right , 4 , Signed
- Read_t100 = 0 'no error
- End Function
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $regfile = "m32u4def.dat"
- $crystal = 16000000
- $swstack = 64
- $hwstack = 64
- $framesize = 64
- Config Submode = New
- Config Timer1 = Timer , Prescale = 8 , Compare_a = Disconnect , Compare_b = Disconnect , Clear_timer = 1
- Compare1a = 39999 '20ms @16MHz/8
- Dim Miliseconds As Byte
- $lib "i2c_twi.lbx"
- Config Scl = Portd.0
- Config Sda = Portd.1
- Config Twi = 100000
- I2cinit
- $include "TMP100_lib.inc" ' <<-- dołączenie funkcji
- 'SUBS READY
- ' MAIN LOOP STARTS HERE
- Do
- 'every 20ms
- If Tifr1.ocf1a = 1 Then
- Tifr1.ocf1a = 1
- 'every320ms
- If Miliseconds < 15 Then '16x20ms=320ms
- Incr Miliseconds
- Else
- Miliseconds = 0
- If Read_t100() = 0 Then 'if no error
- If Count < 3 Then 'count to 4
- Incr Count
- Sum = Sum + Raw
- Else
- Count = 0
- Sum = Sum + Raw
- Shift Sum , Right , 2 , Signed 'divide by four
- Temps = Sum * 12bit_res '0.0625
- Temperature = Fusing(temps , "#.#")
- Locate 1 , 1 : Lcd Temperature ; " "
- Sum = 0
- End If
- Else
- Count = 0 : Sum = 0 'error so we must start from the begining
- Lcd "No Answear"
- End If
- 'start of next conversion
- Call Start_conversion()
- End If
- End If
- Loop
- End