|
温度LTC1392 with PIC16C84单片机
|
|
|
Use of an LTC1392 10-bit Temperature, Vcc and Differential Voltage
Monitor - Basic Stamp 2 and PIC16C84
PIC单片机学习网www.pic6.com Introduction. The Linear Technology LTC1392 is an inexpensive 10-bit A/D converter with the added capability of measuring the temperature of the IC and the value of the nominal +5 V supply. This makes it ideal in monitoring the health of the environment in any electronic equipment. The low power dissipation also makes it an ideal IC for remote data logging using battery power. The quiescent current when idle is typically 0.2 uA. While performing a conversion the current drain rises to nominally 350 uA. The device is available from DigiKey (LTC1392CN8-ND) for $7.50 in single unit quantities. A data sheet in .pdf format may be obtained from Linear Technologies. In the following discussion, interfacing a Basic Stamp 2 with a single LTC1392 is illustrated. Interfacing the LTC1392 with a PIC is also discussed. Sequence. A measurement sequence is started by bringing /CS low which resets the device. Note that as it is the high to low transition, CS must first be at logic one. After bringing /CS low, a minimum delay of 80 usecs is required for a temperature measurement and 10 usecs for all other measurements. Four configuration bits are then serially transmitted by the processor using the TX_DATA and CLK leads. In transmitting toward the device, the data is first set up on the on the TX_DATA lead and the CLK is then brought momentarily low. The actual capture of the data by the LTC1392 is on the rising edge of the clock. Note that when the device is not selected (/CS high) and during the time this four bits is being sent by the processor, the devices D_out lead (RX_DATA) is in a high impedance mode. Upon sending the four configuration bits, the 1392's D_out lead (RX_DATA) comes out of tri-state and the result is serially shifted toward the processor, beginning with a logic zero and then the most significant bit or a 10-bit result. Each data bit is transmitted by the LTC1392 on the falling edge of the clock. Upon receipt of the 10 bits, the /CS is brought high, ending the measurement sequence. Actually, I left a little out. The device may be configured such that after receipt of the 10 bit result in most significant bit format, continued clocking will cause the result to again be output in least significant bit format. I do not deal with this capability in this discussion. Actually, I am uncertain I grasp why anyone would want it. The Command Bits. After bringing /CS low, a four bit conguration word is sent to the device. Bit b_3, (the most significant bit) is always a logic one and is termed the "start" bit. Bits b_2 and b_1 determine the measurement mode as shown; Mode b_2 b_1 Measurment 0 0 0 Temperature Bit b_0 is used to specify whether the least significant bit first sequence is to follow the most significant bit first sequence and mentioned above. Let's just cut through the confusion and set it to a logic 1. Thus, the configuration word is; mode = 0x09 | (mode << 1); where the mode is either 0, 1, 2 or 3 as noted in the above table. Conversions. Upon receiving the 10 bits of data, the temperature, V_cc or other voltage is calculated. Temperature. The range between -130 degrees C and 125.75 degrees C is broken into 1024 discrete bands. Thus, T_c = (125.75 - (-130)) * band / 1024 - 130.0 or T_c = 256/1024 * band - 130 For the Stamp; T_100 = 100 * T_c = 25 * band - 13000 V_cc. The range between 2.42 and three times 2.42 is broken into 1024 bands. Thus, V_cc = (3*2.42 - 2.42) * band / 1024 + 2.42 For the Stamp; V_CC_100 = 100 * V_cc = (60 * band)/128+242 Other. V_diff = band / 1024 * 1.0 For the Stamp; DIFF_VOL_100_1 = 100 * V_diff = (100 * band)/1024 When using the 0.5 V full scale; V_diff = band / 1024 * 0.5 For the Stamp; DIFF_VOL_100_2 = 100 * V_diff = (50 * band)/1024 Basic Stamp 2 - Program LTC1392.BS2. In program LTC1392.BS2 a Basic Stamp 2 is used to fetch the values of temperature, V_cc and V_diff using both of the references. Note that it is assummed there is an applied voltage of less than 0.5 Volts between +V_in and -V_in. The four-measurement sequence is repeated ten times.
m var byte ' index used in main T_100 var word ' 100 * T in degrees C rx_data var in11 mode = $00 'temperature measurement in (degrees C). mode = $01 'VCC measurement. mode = $02 'differential voltage measurement, 1V mode = $03 'differential voltage measurement, debug CR make_meas:
out_0: ''''''''''' get_data_10: ' read ten bits on rx_data, clock_pulse:
PIC16C84 - Program LTC1392.ASM. This program illustrates how to interface a PIC with an LTC1392. One measurement is made in each mode and the result is saved to a data buffer. Note that each measurement consists of 10-bits and thus, each measurement is saved in the data buffer as two bytes. The DAT_HI variable consists of the hgighest two bits and DAT_LO of the low eight bits. In the program, the raw measurement data is then displayed on a serial LCD. However, it is important to note that this data might be saved in a serial EEPROM for later retrieval and downloading to a PC. Unlike the program for the Basic Stamp, this program does not include any calculations on the raw data. Another discussion offers that in many instances, calculation is not necessary nor necessarily desireable. But, if it is thoughts are offered on how the calculations may be done with simple byte by byte multiplcation, two byte add and subtracts and BCD conversion routines. These are implemented in other discussions. One point of interest is the use of a two byte shift in the RX_DATA_10 routine which fetches the 10-bit result from the LTC1392. DAT_HI and DAT_LO are both initialized to zero and the following loop is executed ten times. BTFSS PORTB, RX_D Note that the carry bit is either set to a zero or one, depending on the state of the RX_D input bit. This is then left shifted into DAT_LO. Note that the most significant bit of DAT_LO is now in the carry bit. This is then left shifted into DAT_HI, such that it is now the least significant bit in DAT_HI.
LIST p=16c84 CONSTANT RX_D = 3 ; bits defined on PortB CONSTANT DATA_BUFF = 18H CONSTANT BASE_VAR = 0CH MODE EQU BASE_VAR+0 ; mode = 0, 1, 2, or 3 TEMP EQU BASE_VAR+1 ; scratchpad DELAY_LOOP EQU BASE_VAR+3 ; timing DAT_H EQU BASE_VAR+4 ; 10-bit quantity fetched from ltc1392 ORG 000H CLRF PORTB MAIN: MOVLW .0 MAIN_1: CALL MAKE_MEAS ; make a measurment MOVF DAT_H, W ; and save two bytes in data_buff INCF FSR, F INCF MODE, F ; go through mode 0. 1, 2, 3 CALL DISPLAY ; display content of data_buff
DISPLAY: ; display content of data_buff on serial LCD MOVLW DATA_BUFF ; initialize pointer to data_buff MOVLW .4 DISPLAY_1: DECFSZ NUM, F TX_DATA_4: ; send 4-bit command to ltc1392 MOVWF TEMP ; save to scratch pad MOVLW .4 ; 4 bits TX_DATA_4_1: CALL CLK_LO ; and then negative going clock pulse RLF TEMP, F ; next bit to bit 3 position DECFSZ NUM, F RX_DATA_10: ; fetches 10 bit result from ltc1392 CALL CLK_LO ; a dummy clock pulse MOVLW .10 ; 10 bits DECFSZ NUM, F CLK_LO: C_SEL_HI: C_SEL_LO: DELAY_100USEC: #INCLUDE <A:\LCD\LCD_CTRL.ASM> |
|