- 阅读权限
- 200
- UID
- 2
- 帖子
- 343
- 精华
- 0
- 注册时间
- 2013-2-20
- 在线时间
- 368 小时
- UID
- 2
- 帖子
- 343
- 精华
- 0
- 注册时间
- 2013-2-20
- 在线时间
- 368 小时
|
正当疫情,需要经常测量体温,宿舍没有温度计。就用1N4148做感温头做了一个,使用效果很好。
二极管对温度十分敏感,温度的变化将改变它的管压降。温度上升时管压降减小;温度下降时管压降增加。 二极管(1N4148)的平均灵敏度约为-2mV/℃。由于它的线性度相当好,所以平均灵敏度可看作二极管的测温灵敏度。即温度每上升1℃时,管压降下降了2mV左右。
在海平面一个大气压的条件下,水的沸腾温度为100℃;在冰与水共溶的条件下其温度为0℃。在沿海一带或海拔不高的地区可以认为沸腾的水是100℃(误差不大)。
将100℃及0℃两个温度值作为标准温度来标定温度与管压降之间的定量关系。用沸水和冰水混合物分别标定100℃和0℃的管压降,测得100℃<->0.4124V 、0℃<->0.6184V。
线性拟合: y=a+bx ,Coefficient Data: a = 3.00194174757E+002 ,b = -4.85436893204E+002
电路中电压3.3V,串联4.7K电阻。
采样使用ADS1115(http://avr.cnta.net/forum.php?mod=viewthread&tid=83435),量程设置为 ±1.024V 。
' *********************************************
' * 1N4148温度计(ADC by ADS1115) *
' * (Ver 0.01) *
' * Copyright By Slyt 2020.2.22 *
' *********************************************
'.....................................................................................
'(
二极管对温度十分敏感,温度的变化将改变它的管压降。温度上升时管压降减小;温度下降时管压降增加。
二极管(1N4148)的平均灵敏度约为-2mV/℃。由于它的线性度相当好,所以平均灵敏度可看作二极管的测温灵敏度。即温度每上升1℃时,管压降下降了2mV左右。
在海平面一个大气压的条件下,水的沸腾温度为100℃;在冰与水共溶的条件下其温度为0℃。在沿海一带或海拔不高的地区可以认为沸腾的水是100℃(误差不大)。
将100℃及0℃两个温度值作为标准温度来标定温度与管压降之间的定量关系。用沸水和冰水混合物分别标定100℃和0℃的管压降,测得100℃<->0.4124V 、0℃<->0.6184V。
线性拟合: y=a+bx ,Coefficient Data: a = 3.00194174757E+002 ,b = -4.85436893204E+002
电路中电压3.3V,串联4.7K电阻。
采样使用ADS1115(http://avr.cnta.net/forum.php?mod=viewthread&tid=83435),量程设置为 ±1.024V 。
')
'.....................................................................................
$regfile = "m8def.dat" ' specify the used micro
$crystal = 8000000 ' used crystal frequency
'$baud = 19200 ' use baud rate
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 32 ' default use 10 for the SW stack
$framesize = 64 ' default use 40 for the frame space
Osccal = &H9F
'.....................................................................................
Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , Rs = Portb.0 , E = Portb.1
Config Lcd = 16 * 2 'configure lcd screen
Cursor Off Noblink
'Configure pins to to use for the I2C bus
Config Scl = Portb.7 'Is serial clock SCL
Config Sda = Portb.6 'Is serial data SDA
I2cinit
Deflcdchar 0 , 23 , 8 , 8 , 8 , 8 , 8 , 7 , 32 ' replace [x] with number (0-7)
'.....................................................................................
Declare Function Get_adc(byval Ain_x As Byte) As Integer
'.....................................................................................
Dim Mylong As Long
Dim Voltage As Single
Dim Vol_str As String * 10
'(
Write to Config register:
First byte: 0b10010000 (first 7-bit I2C address followed by a low read/write bit) (H90/H91 OK)
Second byte: 0b00000001 (points to Config register)
Third byte: 0b10000100 (MSB of the Config register to be written)
Fourth byte: 0b10000011 (LSB of the Config register to be written)
Write to Pointer register:
First byte: 0b10010000 (first 7-bit I2C address followed by a low read/write bit) (H90/H91 OK)
Second byte: 0b00000000 (points to Conversion register)
Read Conversion register:
First byte: 0b10010001 (first 7-bit I2C address followed by a high read/write bit)
Second byte: the ADS1113/4/5 response with the MSB of the Conversion register
Third byte: the ADS1113/4/5 response with the LSB of the Conversion register
')
'在14-12位,是 MUX 配置,决定了 ADS1115 的 A0-A3 接口的测量方式。
'比如,当设置为 0x04 时测量的为 A0-GND 的电压,当设置为 0x00 时测量的为 A0-A1 间的电压。
Dim Channel(8) As Byte
'AIN0-AIN1 'AIN0-AIN3 'AIN1-AIN3 'AIN2-AIN3
Channel(5) = &B00000000 : Channel(6) = &B00010000 : Channel(7) = &B00100000 : Channel(8) = &B00110000
'AIN0-GND 'AIN1-GND 'AIN2-GND 'AIN3-GND
Channel(1) = &B01000000 : Channel(2) = &B01010000 : Channel(3) = &B01100000 : Channel(4) = &B01110000
'Dim V100 As Single '0.4124V 100C
'Dim V000 As Single '0.6184V 0C
Dim Vnow As Single
Dim A As Single
Dim B As Single
A = 3.00194174757e002
B = -4.85436893204e002
'(
线性拟合: y=a+bx
Coefficient Data:
a = 3.00194174757E+002
b = -4.85436893204E+002
')
'*************************************************************************************
Cls
Do
Mylong = Get_adc(1)
Voltage = Mylong / 32768
Voltage = Voltage * 10240
Mylong = Round(voltage)
Vol_str = Str(mylong)
Vol_str = Format(vol_str , "0.0000") + " "
Locate 1 , 1
Lcd Vol_str
Vnow = Val(vol_str)
Voltage = B * Vnow
Voltage = A + Voltage
Voltage = Voltage * 10
Mylong = Round(voltage)
Vol_str = Str(mylong)
Vol_str = Format(vol_str , "0.0") + " "
Locate 2 , 1
Lcd Vol_str
Locate 2 , 6
Lcd Chr(0)
Waitms 500
Loop
End
'*************************************************************************************
Function Get_adc(byval Ain_x As Byte) As Integer
'(
'在11-9位,是 PGA 配置,决定 ADS1115 的量程。
Dim Pga(8) As Byte
'FS=±6.144V 'FS=±4.096V 'FS=±2.048V 'FS=±1.024V
Pga(1) = &B00000000 : Pga(2) = &B00000010 : Pga(3) = &B00000100 : Pga(4) = &B00000110
'FS=±0.512V 'FS=±0.256V 'FS=±0.256V 'FS=±0.256V
Pga(5) = &B00001000 : Pga(6) = &B00001010 : Pga(7) = &B00001100 : Pga(8) = &B00001110
')
'(
'在第7-5位,是每秒采样次数的配置。
Dim Data_rate(8) As Byte
'8SPS '16SPS '32SPS '64SPS
Data_rate(1) = &B00000000 : Data_rate(2) = &B00100000 : Data_rate(3) = &B01000000 : Data_rate(4) = &B01100000
'128SPS '250SPS '475SPS '860SPS
Data_rate(5) = &B10000000 : Data_rate(6) = &B10100000 : Data_rate(7) = &B11000000 : Data_rate(8) = &B11100000
')
Local Config_high As Byte
Local Config_low As Byte
Config_high = &B10000000
'Ain_x-> 1-8
If Ain_x > 8 Or Ain_x < 1 Then Ain_x = 1
Config_high = Config_high + Channel(ain_x)
'Config_high = Config_high + &B00000010 ' Pga(2) ±4.096V
Config_high = Config_high + &B00000110 ' Pga(4) ±1.024V
'Config_low = &B00000000
'Config_low = Config_low + Data_rate(5)
Config_low = &B10000000 ' 128SPS
'init I2C
I2cstart
I2cwbyte &H90 ' W_addr
I2cwbyte &B00000001 ' 指向Config寄存器
I2cwbyte Config_high
I2cwbyte Config_low
I2cstop
'Read_ad
I2cstart ' Generate start code
I2cwbyte &H90 ' W_addr ' send address
I2cwbyte &B00000000 ' 指向AD转换寄存器
I2cstart ' start condition
I2cwbyte &H91 ' R_addr ' slave address
I2crbyte Config_high , Ack
I2crbyte Config_low , Nack
I2cstop
Get_adc = Makeint(config_low , Config_high)
End Function
'-------------------------------------------------------------------------------------
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
|