Showing posts with label Literature. Show all posts
Showing posts with label Literature. Show all posts

Pulse rate Sensor to monitor heart beat rate of human

 Introduction of heart rate monitoring sensor:

To monitor the heart rate or pulse rate of any human body, a dedicated sensor is required. The sensor is basically a device which convert the information of blood flow in vain of body into electrical signal. The signal generated from pulse rate sensor are then process further to interface with microcontroller or microprocessor of Arduino board. Where the digital signal are analyzed and then results are displayed using any convenient means of display like LED display or using LCD display. Therefore we can say that the Pulse Sensor is a especially designed device which is ready for plug and play to measure the heart rate with help of any kind of microcontroller like AVR on Arduino board or Microchip PIC or Atmel 8051 family. This sensor is used by electronics engineering students, professional engineers, software engineers, embedded project developers to easily include the live data of heart rate into projects. There are variety of sensors available for this purpose. The pulse monitoring sensor are usually fixed or attached with help of a clip onto a fingertip or sometimes it can be used on earlobe to get the heart rate data from the body of human.

Principle of construction of Heart Rate Sensors:

The important point of in the discussion regarding the construction of heart arte sensor is that the technique used for the detection of pulse rate is non-invasive type of detection or measurement. These sensors are consisting of optical electrical devices. The majority of the optical heart rate sensor do have f an electronic circuit built-in with them in addition to sensing element to proper shape the electronics signal so that these could be easy interfaced with microcontroller or any digital signal processing device. The operation of the sensors starts with the monitoring of heart beat by clipping these onto a fingertip.

The working principle involved in the working of the Heart beat Sensor is Photo-ple-thysmo-graph. This principle in based to detect the changes in the volume of blood in apart of body like finger. The volume of blood is measured by the variation in the intensity of the light passing or blocked through that organ. The source of light in a heart beat sensor is usually an IR LED and the detector may be of any light intensity Detector like a Photo Diode, a Light Dependent Resistor (LDR) or a Photo Transistor. These two parts work tighter to form an understandable electronics signal.

Parts of pulse sensor:

Parts of a typical pulse rate sensor are basically two;

1.   IR transmitter: The function of IR transmitter is to emit IR which will be used to detect the blood in veins. Basically the media used for the detection of pulse is Infra-Red Radiations.

2.   IR receiver: The function of the IR receiver is to collect the IR passes through the finger. Some of the IR will be blocked when blood passes through the veins. The difference in the intensity will be actually the determination of pulse.

Types of pulse sensor:

There are two techniques which are used for the detection of heart beat;

1.     Reflection Based Detection of Heart Beat:

In this method the light or IR radiation is emitted from IR transmitter and received by IR receiver or photo diode or photo transistor. The light source (IR Transmitter) and the detector (Photo Transistor) are place at same side of a finger or organ (adjacent to each other). The finger of the person is placed in front of the transmitter and receiver. The light is reflected through the finger and a portion of it is blocked and rest of the light passed when blood sticks in veins. The light is shining on the finger and the part reflected back to photo transistor is measured. The quantity of light varies with the amount of blood in veins of finger. As the quantity of blood changes significantly in corresponding the heart function continuously. As a result the pulses are formed through the photo diode or photo transistor end.

Heart beat, Pulse rate Sensor Construction
 Reflection Based Detection of Heart Beat


2.     Transmission Based Detection of Heart Beat:

In this method the light or IR radiation is emitted from IR transmitter and received by IR receiver or photo diode or photo transistor. The light source (IR Transmitter) and the detector (Photo Transistor) are place facing each other and the finger of the person is placed in between the transmitter and receiver. The light is passed through the finger and a portion of it is block when blood sticks in veins. The light is shined and passes through the finger which is directly relates to the quantity of blood in vein at that time. As we know that the quantity of blood always changes, as a result we get pulse at the light collection device which is in our case the photo-transistor or photo-diode. This is a continuous process of up and down as a function of blood pumped into the finger.

Pulse rate Monitor, Heart Beat Pulse rate sensor
Transmission Based Detection of Heart Beat


Working of Heart beat Sensor with an electronics circuit # 1:

So far we have discussed the theory of working of a pulse sensor. Now we should move to its particle used. In fact the pair of light emitting device and light sensing device are not all the components to get the desired output. We attach some of analog electronics components to make them working. Here we will discuss the construction a simple circuit in which we could be able to detect a pulse using above discussion about the sensor. Therefore we can say that a typical Heart beat Sensor will be consisting of detection based devices along with electronics circuit. The detection part of the Heart beat Sensor will have an IR LED and a Photo Diode/ transistor placed in a clip. The electronics circuit will be consisting of an Op-Amp along with a few other analog electronics components like resistor & capacitors. This electronics circuit will help us to connect the detection part of sensor to signal processing unit like a Microcontroller. The working of the Heart Beat sensor is easily and becomes more interesting when we do a detailed study of the circuit diagram.

Circuit diagram heart beat sensor, detection pulses
Obtaining Electrical Signal from Heart Beat Sensor


The circuit diagram shown in above figure is based on assumption that the clip sensor part or detection part is attached with the finger. When the heart beat sensor have finger in place between the detectors the pulses are started to detect. As we have already discussed that with every heart beat the amount of blood in the finger will change from minimum to maximum level in the vein. The light emitted from the IR LED on passing through the finger get interactions with the blood quantity. The amount of light managed to pass through the obstacle of blood will be thus detected by the Photo Diode. The amount of light will be the function of amount of blood in vein as a result a changing electrical signal will be available at the photo diode terminal which is then processed through the use of OP-AMP. Here we will use LM358 OP-AMP which is consisting of two op-amp inside a single ship. The output of the photo diode is feed to the non–inverting input of the first op–amp through a capacitor. The use of capacitor at this stage is to block the DC Components of the signal coming from the detection unit. The amplification factor of at this stage is kept around 1001. It is sufficient to amplify the week signal to a level which is desirable. The output of first non-inverting amplifier is feed to second op-amplifier which is built in a comparator mode. The output of second op-amplifier (Comparator0 is used to feed to a transistor to have train of pulses as shown in the circuit diagram above. It may be noted that the construction of this circuit is very simple and efforts are made to use the general purpose components which are easily available in local electronics market or on a radio shop. For example the use of op-amp LM358, the transistor could be any NPN like c828 or BC 547.

Working of Heart beat Sensor with an electronics circuit # 2: 

The above circuit has been built in order to have response from optical sensor used to monitor the heart rate pulses as discussed earlier. The only difference is that it is very simple circuit as compared to previous one but it has very good results too.  

Optical sensor for heart rate Monitor
Interface of optical heart rate sensor


In this circuit we are using the IR transmitter coupled with the photo transistor. Again it is the assumption that the finger is placed in between the optical transmitter and optical receiver so that the light have obstacle with blood. For the optical sensor assembly (U2), we used a reflective optical sensor. This sensor has transistor output. Coming to the Op-Amp again we can use the LM358 or Lm 741 as per our convenient choice. But I think for the sake of experiments the results of LM358 are good enough. It is to be noted that the light of the LED is at the peak emitter wavelength 950 nm. The Designers or engineers normally use a range between 700 nm (Red light) to 1000 nm (infrared light) for biological instruments. The light beam have to cross the narrow parts of the body like a fingertip or an earlobe or the lower lip therefore use of this range of light is safe and workable.

PIC 18f452 Battery Internal Resistance Monitor plus desulfator

 Part-3: Battery Tester based on Microcontroller

Construction of battery health Monitor and battery desulfator:

As it has been explained in previous two posts and the name of project also describes that the actual project has two main parts and associated functions.

1. Battery Heath Monitor 

2. Desulfator

Now we will discuss its construction in detail. This project is constructed using microcontroller PIC18452. It has been programmed and the code of the project has been written in basic language and compiled using proton PIC basic complier. The program or code listing is provided in the end of this post.

Circuit diagram of the microcontroller based two in one project of battery performance monitor or tester and desulphator is as below.

PIC 18f452 Battery Internal Resistance Monitor plus desulfator
Circuit diagram of Microcontroller based battery internal resistance Monitor

There are Four Segments of the schematic shown in above figure:

1. The Interface of Microcontroller with LCD

2. For adjustment of parameters, the provision of three input push button

3. The measurement of voltages at various stages of project during operation

4. Power module of battery tester which is again consisting of two parts:

        (a) The battery Tester side, which left side of power module section

        (b) The desulfator power section which is at the right side of power module

These will be discuss one by one in detail in below sub-section of this post. Various components used in each section will be introduced and their functionality will be explained as under.

Microcontroller Project Schematic Part-1: 18f452 interfacing with 4-lines 20-Character LCD:

In the first part of whole schematic of this microcontroller project, we will discuss the interfacing of LCD with the PIC Microcontroller which is 18F452. The LCD we are using here in this battery tester cum desulphator is a large LCD which is consisting of Four Lines and each line will have twenty Character spacing. The various parameter will be display at different lines of LCD using microcontroller. The alpha-numeric LCD is interfacing using standard four line interface method as shown in the figure below:

4-line-20 characters LCD-Interface PIC18f452
Microcontroller interfacing LCD for Battery Tester Project

Microcontroller Project Schematic Part-2: 18f452 interfacing with Three Push Buttons:

Three push button have been provided to user for the adjustment of values of critical parameters to be adjusted according to the needs of user real time. These Push buttons are as under:

1. The Setting Selection Mode Switch

2. To increase the parameter values, the ICREMENT Button

3. To decrease the parameter values, the DECREMENT Button

The push switches are pull-up with 10kohm resistors and when press the logic zero is transmitted to microcontroller which is sensed during key-button scanning and the function is performed as per request of user of battery tester at that time, as shown in figure below:

key-switch-interface with microcontroller
Three push button with 18F452 PIC Microcontroller

Microcontroller Project Schematic Part-3: Analog Voltages Measurement Interface to Microcontroller:

As the battery Attached for testing may have voltage 6V, or 12V, or 24V which are larger to be interface with microcontroller which accept voltage up to 5v. Therefore voltage divider is used as shown in the figure below: Two resistor are used one is 33Kohm and second is 10Kohm which divide the 12V divided by a factor of approximately 3.3 which is in acceptable range. If user have to interface larger battery the values of above resistor can be re-adjusted and factor used in program as well.

 

Voltage Divider Circuit Diagram
Voltage Divider Circuit Diagram

Microcontroller Project Schematic Part-4: Power Module of Battery Tester and Battery Desulfator:

The N-Channel MOSFET Transistor , shunt resistor of 0.05Ohm, is used in Battery Tester side. Whereas The N-Channel MOSFET Transistor, two inductors, diode, capacitor is used in desulphator side of power module as shown in figure below. The battery is at the center of these two type of interfaces. It may be noted that only one function is performed at a time. It means that when we are measuring the internal resistance, the desulfator part is turned off. At an other time when the desulfation of battery is in progress the measurement of internal resistance is switched off. So that each function is performed independently without interference to each other. In this way the results are achieved perfectly.

PIC Microcontroller 18F452 Battery Tester CUM battery Desulfator
Battery Tester CUM battery Desulfator

Complete circuit diagram of the battery tester project:

Battery Tester Complete Schematic Circuit Diagram using PIC Microcontroller
Battery Tester Complete Schematic Circuit Diagram using PIC Microcontroller


Programming of Battery Tester:

The program is written in PIC Basic Language and compile using proton basic compiler, the code listing is provided as under:

    Device = 18F452
    Declare Xtal = 4

    Config_Start
    OSC = HS         ' Oscillator Selection HS
    OSCS = Off       ' Osc. Switch Enable Disabled
    PWRT = On        ' Power-up Timer Enabled
    BOR = Off        ' Brown-out Reset Disabled
    BORV = 42        ' Brown-out Voltage 4.2v
    WDT = Off        ' Watchdog Timer Disabled
    WDTPS = 128      ' Watchdog Postscaler 1:128
    CCP2MUX = On     ' CCP2 MUX Enable (RC1)
    STVR = On       ' Stack Overflow Reset enabled
    LVP = Off        ' Low Voltage ICSP Disabled
    Debug = Off      ' Background Debugger Enable Disabled
    CP0 = Off        ' Code Protection Block 0 Disabled
    CP1 = Off        ' Code Protection Block 1 Disabled
    CP2 = Off        ' Code Protection Block 2 Disabled
    CP3 = Off        ' Code Protection Block 3 Disabled
    CPB = Off        ' Boot Block Code Protection Disabled
    CPD = Off        ' Data EEPROM Code Protection Disabled
    WRT0 = Off       ' Write Protection Block 0 Disabled
    WRT1 = Off       ' Write Protection Block 1Disabled
    WRT2 = Off       ' Write Protection Block 2 Disabled
    WRT3 = Off       ' Write Protection Block 3 Disabled
    WRTB = Off       ' Boot Block Write Protection Disabled
    WRTC = Off       ' Configuration Register Write Protection Disabled
    WRTD = Off       ' Data EEPROM Write Protection Disabled
    EBTR0 = Off      ' Table Read Protection Block 0 Disabled
    EBTR1 = Off      ' Table Read Protection Block 1 Disabled
    EBTR2 = Off      ' Table Read Protection Block 2 Disabled
    EBTR3 = Off      ' Table Read Protection Block 3 Disabled
    EBTRB = Off      ' Boot Block Table Read Protection Disabled
Config_End
    
    Declare LCD_DTPin = PORTD.4
    Declare LCD_ENPin = PORTD.2
    Declare LCD_RSPin = PORTD.3
    
    Declare LCD_Interface = 4               ' 4-bit Interface
    Declare LCD_Lines = 4                   ' 2-Line LCD
    Declare LCD_Type = 0                    ' Alphanumeric LCD type

    Symbol I_R = PORTC.3  'DEC_SWITCH
    
    Symbol B1 = PORTC.5 ' Select_MODE_Switch
    Symbol B2 = PORTC.6 ' INC_SWITCH
    Symbol B3 = PORTC.7  'DEC_SWITCH
    
    TRISD = %00000000  'All OUTPUT
    TRISC = %11110000  '// 0 t0 3 output and 4 to 7 input

    Declare Adin_Tad = FRC              ' Set clock source (x/FOSC or FRC)
    Declare Adin_Stime = 150            ' Set sampling time (in uS)
    Declare Adin_Res = 10
    ADCON1 = %10000000                  ' Set PORTA analog and right justify result
    Dim     Vol_Un_LOAD     As Word     ' Volatge at termminal without load
    Dim     Vol_Ter         As Word     ' 10-bit result of A/D conversion for Volatge at battery terminal
    Dim     Vol_High        As Word     ' 10-bit result of A/D conversion for Voltage at high side of shunt resistor
    Dim     Vol_Low         As Word     ' 10-bit result of A/D conversion For Voltage At low side of shunt resistor
    Dim     Vol_Charge      As Word     ' 10-bit result of A/D conversion For Voltage At charging side of shunt resistor
    Dim     R_inT           As Float    ' Internal Resistance measurement 
    Dim     Dis_C           As Float     ' Discharge current
    'Dim     Char_C          As Float     ' charging Current
    'Dim     d               As Byte
    Dim     mode_op         As Byte      ' The two mode of functions are selected by this variable
    Dim     mode_0_count     As Byte     ' The times to function each paert of project
    Dim     secondary_cycle_count As Byte ' Time slice
    Dim duty_cycle          As Byte       ' PWM DUTY CYCLE valraible
    Dim cycle_count         As Byte       ' Program CYCLE are counted and displayed on LCD
    I_R = 0 ' Internal Resistance measuremtn Signal OFF
    ''''' INITIAL WELLCOME MESSAGE'''''''''
    Print At 1,1, "Wellcome..DeSulfator"
    Print At 2,1, " Battery Project"
    Print At 3,1, "microcontroller-atmel-"
    Print At 4,1, "pic-avr.blogspot.com"
    DelayMS 1000   ' One Second Time delay
    Cls        ' Clear The LCD DISPLAY
 ''' INITIALIZATION of LOCAL Variables
     mode_op = 0
     secondary_cycle_count = 0
     mode_0_count = 5
 ' for a PIC16F877, 
 'Channel 1 is CCP1 which is pin PortC.2. 
 'Channel 2 is CCP2 which is pin PortC.1.
' Start loop, reads temperature. Loop forever

'''''' Main program Starts here'''''''''''
    While 1 = 1
    
    If cycle_count < mode_0_count Then       '' The check the cycle for approprate functioning
    mode_op = 0
    Else
    mode_op = 1
    EndIf
    '''''Adjustment of testing time''''''
         If B2 = 0 Then Inc mode_0_count
         If B3 = 0 Then Dec mode_0_count
         If mode_0_count <=1 Then mode_0_count = 1
         If mode_0_count >=5 Then mode_0_count = 5
 ''''''' Select SWITCH CASE for execution of each function one by one'''''''        
        Select mode_op
        
        Case 0
        ''''CASE 0 for the measurement of battery health by calculating the internal resistance
        Cls
        HPWM 2,0,8000  '' Turn OFF the PWM during measurement of internal resistance
       '''' The battery Voltages are being measured without any load'''''
        I_R = 0  '' MOSFET is OFF
        Vol_Un_LOAD = ADIn 0   ''' analog to digital conversion of un-load terminal voltage of battery
        DelayMS 100
       
        I_R = 1  '' MOSFET is ON
        Vol_Ter = ADIn 0  ' Analog to Digital Conversion of Terminal Voltages of battery with load
        DelayMS 10
        Vol_High = ADIn 1 ' Analog to Digital conversion of voltage at high side of shunt resistor
        DelayMS 10
        Vol_Low = ADIn 2  ' Analog to Digital conversion of voltage at low side of shunt resistor
        DelayMS 10
        I_R = 0    '' MOSFET is OFF
' The Internal resistance of battery will be calculated using following formula'''''
''''R_int =  shunt * (Unload_V - Terminal_V)/ (High_V - Low_V) '''''
        R_inT = 0.05 * (Vol_Un_LOAD - Vol_Ter) / (Vol_High - Vol_Low )
'''Current passed through the shunt resistor during load will be calculted using this'''
        Dis_C = R_inT * (Vol_Un_LOAD - Vol_Ter)
''' The results are displayed on LCD''''        
        Print At 1,1, "V_U=", Dec2 Vol_Un_LOAD* 0.02101 ," VT=", Dec2 Vol_Ter* 0.02101 
        Print At 2,1, "V_H= ", Dec2 Vol_High* 0.02101,"  S_C ", Dec cycle_count 
        Print At 3,1, "V_L=", Dec2 Vol_Low* 0.02101  
        Print At 4,1, "Ri=", Dec2 R_inT * 1000, "  Ds_C=", Dec2 Dis_C
        DelayMS 1000   ' wait for one second
        
      ''''The second function the desulfator starts in next case'''''  
        Case 1
        
        I_R = 0   '' The MOSFET for iternal resistance load side must be OFF
        Cls   '' clear the display
        Print At 1,1, "mode = 2 "  
        Print At 2,1, "desulfation started"
        Print At 3,1, "S-Cnt ", Dec cycle_count
        HPWM 2,duty_cycle,8000  '''' Generate PWM signal of 8kHz with 50% duty Cycle     
       
        DelayMS 1000
        'If duty_cycle >=254 Then duty_cycle = 10
        Case Else
                 Cls
        EndSelect
        
        Inc cycle_count
        If cycle_count >= 254 Then  cycle_count = 0
                 
    Wend

Interfacing DS1620 with PIC Microcontroller

 Project Over View:

In this project we are interfacing DS1620 chip with the PIC Microcontroller. The Temperature will be read from DS1620, its feature for indication of high , low temperature will also be used. 

Description of DS1620:

The DS1620 is a single chip having two major functionalities combine together named Digital Thermometer and the Thermostat. The DS1620 provides 9bit temperature measurement results the temperature of this chip corresponds to the environmental temperature. The second functionality is thermostatic control with the three alarm outputs correspond to three set points which are also programable. Due to the provision of this feature in this chip, we can say that the DS1620 can be used as a thermostat. The name of the three alarms pins are THIGH, TLOW and TCOM. The THIGH pin will be high if the temperature is greater than or equal to defined temperature named TH. The TLOW pin will be high if the measured temperature is less than or equal to predefined temperature named TL. The TCOM pin will be high when the measured temperature is greater than TH and will remain high until the measured temperature is lesser than TL.

The predefined temperature values for TH and TL are saved in the nonvolatile memory of DS1620.It may be noted that these values can be programmed any time during the execution while going through the procedure for updating these values to DS1620 by using microcontroller. If DS1620 is going to be used as a stone alone system, then these values will be programmed first, so that chip can perform proper operation as required by user. The predefined Temperature values of TH and TL can be written or read to or from the chip DS1620 by using the simple 3 wire interface.

The chip DS1620 measures the temperature using a built-in temperature sensor. The measured temperature value is available to read in a specific format which is a 9bit and two’s complement. The measured values are only possible to read by proper utilization of a “READ TEMPERATURE” command. After receiving the “READ TEMPERATURE” command by DS1620 the measured temperature value is transmitted serially LSB first. The chip DS1620 is usable to measure temperature in the range of -55°C to +125°C with the increment of 0.5°C. The temperature in degree Celsius can be converted to Fahrenheit using a lookup table or conversion factor.

OPERATION AND CONTROL OF DS1620

There is configuration register in the DS1620 which is required to address properly before expecting any useful operation from the chip. The configuration register of DS1620 is defined as under:

Configuration Register of DS1620
Configuration Register of DS1620

The values of this register is explained as under:

DONE is the Conversion Done Bit the value in this bit shows logical 1 if the conversion is completed the logical 0 will show that the conversion is in progress. Then the next bit comes it is THF which corresponds to the Temperature High Flag. This bit will be set to logical level 1 when the measured temperature is greater than or equal to the predefined value of TH. This bit will remain at logical level 1 until reset by writing 0. This is very useful feature which provides a way to determine if the DS1620 has ever high temperatures above TH since it is powered up. The next bit is TLF which corresponds to the Temperature Low Flag. This bit will be set to logical level 1 when the measured temperature is less than or equal to the predefined value of TL. It will remain at the logic level 1 until reset by writing 0. This is a very useful feature of DS1620 which provides a way to determine if the chip measured temperature below TL since powered up. The next bit is NVB which corresponds to the Nonvolatile Memory Busy Flag. The logical level 1 indicates that the writing to memory cell is in progress. Whereas the logical level 0 means that the nonvolatile memory is not busy at this time. The next bit is CPU corresponds to the CPU Use Bit. If CPU is 0, the CLK and / or CONV pin will act as the conversion start control. If CPU is 1, the DS1620 will be used with a CPU communication using the 3 wire port protocol.

Components used in Thermostat Project:

  1. Microcontroller : PIC 16f876A
  2. DS1620, The Digital Temperature sensor and Thermostat
  3. Crystal: 4MHz
  4. Capacitors: 22pF x 02Nos
  5. LCD: The liquid crystal Display; 2line 16 Character
  6.  Resistors: as required and shown in diagram
  7. Power Supply: +5V regulated DC power supply
  8. LEDs: 03Nos of different colors
  9. push button as required
  10. Variable resistors: as required and shown in diagram.

circuit diagram of DS1620 interface with PIC Microcontroller 16F876A:

The following is the circuit diagram in which the electrical connection of various components is described and DS1620 is interfaced with Microcontroller 16f876A along with the other components. The LEDs of three different colors are used to show the functions of thermostat of DS1620. The red LED indicates the high temperature then user defined temperate set value if occur. The Orange LED indicates the low Temperature than the user defined set value if occur. The green LED indicates the normal behavior of thermostat.
DS1620 PIC 16f876A
Circuit diagram of the Digital Thermometer and Thermostat

Software part of project:

The Proton plus basic compiler is used for the coding of this project and source code is placed below:
'*****************************************************************
'*Name : DS1620_PIC16f876A.BAS                                   *
'*Author : Dr.Rana                                               *
'*Notice : https://microcontroller-atmel-pic-avr.blogspot.com/   *
'*: All Rights Reserved                                          *
'*Date : 9/4/2022                                                *
'*Version : 1.0                                                  *
'*Notes :                                                        *
'*:                                                              *
'*****************************************************************
' Display the temperature from a Dallas DS1302 sensor
'
' For use with the ISIS 16F628 Virtual Evaluation Board.
 Device = 16F876A ' PIC 16f876A is selected for this project
 DECLARE Xtal = 4 ' Crystal used in this project is 4MHz
 ''LCD is used in 4 bit interface Mode, Upper four I/O lines
 '' of PortB are connected to the Upper four data lines of LCD
 DECLARE LCD_DTPin = PORTB.4 ' 4 bit LCD interface 
 DECLARE LCD_RSPin = PORTB.1 ' LCD RS PIN connection
 DECLARE LCD_ENPin = PORTB.2 ' LCD E PIN connection
 DECLARE LCD_Interface = 4 ' 4-bit Interface
 DECLARE LCD_Lines = 2 ' 2-Line LCD
 DECLARE LCD_Type = 0 ' Alphanumeric LCD type
' Define DS1620 Pins
 Symbol DQ = PORTC.5 ' DQ = Data pin
 Symbol CLK = PORTC.6 ' CLK = Clock pin
 Symbol RST = PORTC.7 ' RST = Reset pin
' Define Variables
 DIM DSdata AS Word ' Word variable to hold 9-bit data.

' Define variables
 DIM IdCt AS Byte
 DIM HighVal2 AS Byte
 DIM LowVal2 AS Byte
' Define Constants for DS1620 configuration
 Symbol Rconf = $AC ' Read Configuration
 Symbol Wconf = $0C ' Write Configuration
 Symbol CPUon = %10 ' Operate with Microcontroller mode
 Symbol Cont = %00 ' Continuous conversions on start
 Symbol StartC = $EE ' Start Conversion
 Symbol Rdtemp = $AA ' Read Temperature
 ' Define Thermostat functions
 Symbol RhiT = $A1 ' Read High-Temperature Setting
 Symbol WhiT = $01 ' Write High-Temperature Setting
 Symbol RloT = $A2 ' Read Low-Temperature Setting.'
 Symbol WloT = $02 ' Write Low-Temperature Setting.'
 DIM HighVal AS Byte = $32 
' High Temperature Setting 25C for Thigh
 DIM LowVal AS Byte = $31 
' High Temperature Setting 24C for Tlow
'----------------------------------------------------------
' Define Push Button Interface
 Symbol Sw1 = PORTC.4 ' Sw1 = Mode Switch "Push Button"
 Symbol Sw2 = PORTC.3 ' Sw2 = Increment the variables
 Symbol Sw3 = PORTC.2 ' Sw3 = Decrement the variables 

' Start of main Program
 DECLARE All_Digital = ON 
' All analog PINs will be treated as Digital
 CLS ' Clear the LCD
 LowVal2 = ERead 0 
' Read the stored data in EEPROM Built in MCU 
 HighVal2 = ERead 1 
' Two bytes are just stored for temperature 
settings
 OUTPUT RST ' Make the RST pin an output
 OUTPUT CLK ' Make the CLK pin an output
 INPUT Sw1 ' push Button Switches are declared as input to MCU
 INPUT Sw2
 INPUT Sw3
 PRINT At 1,1, "WELLCOME"
 PRINT At 2,1,"DS1620 Interface"
 CLEAR RST ' Shutdown the DS1620
 DelayMS 1 ' Time for reset to occur
 Set RST ' Get ready to write data
 SHOut DQ,CLK,LsbFirst,[Wconf\8,CPUon|Cont\8] 
' Set configuration
 CLEAR RST ' Reset teh DS1620
 DelayMS 50
 Set RST
 SHOut DQ,CLK,LsbFirst,[StartC\8] 
' Start a conversion
 CLEAR RST ' Reset the DS1620
' Writes the config byte for THigh, set for 25C
' With a LED connected THigh pin 7, 
'at 25C or higher the LED will light.
 DelayMS 50
 HighVal = HighVal2 << 1 
' the normal number is converted to two complement
 Set RST
 SHOut DQ,CLK,LsbFirst,[WhiT\8,HighVal\9]
 CLEAR RST
' Writes the config byte for the TLow, set for 24C
' With a LED connected TLow pin 6, 
'at 24C or below the LED will light.
 DelayMS 50
 LowVal = LowVal2 << 1 
' the lower value is converted to two complement
 Set RST
 SHOut DQ,CLK,LsbFirst,[WloT\8,LowVal\9]
 CLEAR RST
 
 DelayMS 1000
 CLS
 DelayMS 1
 IdCt = 0
' Start loop, reads temperature. Loop forever
 WHILE 1 = 1
 DelayMS 100 ' Wait 0.1 second between readings
 IF Sw1 = 0 THEN Inc IdCt ' index function for menu
 IF IdCt >=3 THEN IdCt = 0
 SELECT IdCt
 CASE 0
         IdCt = 0
 CASE 1
        CLS
        IF Sw2 = 0 THEN Inc HighVal2
        IF Sw3 = 0 THEN Dec HighVal2
        IF HighVal2 >=99 THEN HighVal2 = 1
        IF HighVal2 <= 0 THEN HighVal2 = 99
        DelayMS 100
        HighVal = HighVal2 << 1
        Set RST
        SHOut DQ,CLK,LsbFirst,[WhiT\8,HighVal\9]
        CLEAR RST
        EWrite 1, [HighVal2]
 
 CASE 2
         CLS
         IF Sw2 = 0 THEN Inc LowVal2
         IF Sw3 = 0 THEN Dec LowVal2
         IF LowVal2 >= 99 THEN LowVal2 = 1
         IF LowVal2 <= 0 THEN LowVal2 = 99
         DelayMS 100
         LowVal = LowVal2 << 1
         Set RST
         SHOut DQ,CLK,LsbFirst,[WloT\8,LowVal\9]
         CLEAR RST
         EWrite 0,[LowVal2]
 CASE ELSE
         DelayMS 100
         IdCt = 0
 EndSelect
 
 CLEAR CLK
 Set RST ' Start the DS1620
 SHOut DQ,CLK,LsbFirst,[Rdtemp\8] ' Request temperature
 SHIn DQ,CLK,LsbPre,[DSdata\9] ' Get temperature
 CLEAR RST
 PRINT At 1,1,"LTp ",Dec LowVal2,"C"
 PRINT At 1,9,"HTp ",Dec HighVal2,"C"
 DSdata = DSdata >> 1 ' Shift the sign bit into the 
correct position
 ' Display signed temperature in Celsius.
 PRINT At 2,1,"RTp ",Dec DSdata.LowByte,"C"
 PRINT At 2,16, Dec IdCt
 WEND
''Microcontroller PIC16F876A has built in EEPROM 
'The user defined values for High Temperature and 
'Low Temperature limits
' are being stored in EEPROM of MCU
 EData AS Byte 25, 30


temperature sensor interfacing using adc and i2c with pic microcontroller projects interfacing lm35 with microcontroller. How to interface temperature sensor with PIC microcontroller? LM35 interfacing with PIC16F877A pic microcontroller projects pdf How to connect temperature sensor to microcontroller? What is DS1620? Digital Thermometer Ds1620& Pic | PDF | Microcontroller ds18b20 temperature sensor with pic microcontroller projects for beginners Appkit: DS1620 Digital Thermometer, pic, PIC Microcontroller based Dallas DS18S20, What is temperature sensor interfacing?, Temperature sensor using PIC16F877A microcontroller, Digital Thermometer using a PIC Microcontroller, Interfacing the DS1620 with a DS5000/8051 Microcontroller, DS18S20 interfacing with pic and avr microcontroller, Interfacing Temperature Sensor (DS1620) with AT89S51, Interfacing Temperature sensor with lcd, Interfacing at89c2051 & PCF8591 in displaying temperature, pic microcontroller projects pdf, pic microcontroller projects for beginners, temperature sensor interfacing using adc and i2c with pic, pic16f877a projects with source code pdf, ds18b20 temperature sensor with pic, pic projects with source code, Temperature sensor using PIC16F877A microcontroller, LM35 interfacing with PIC16F877A, 

Popular Post (All Time)