Showing posts with label Hobby. Show all posts
Showing posts with label Hobby. Show all posts

Bidirectional Production line Counter using ATMEGA8 Microcontroller

Display unit of  Industrial Production Line Counter

Synopsis of Microcontroller project for the Final year Student of Engineering

In this Microcontroller Experiment we will learn to develop an Automatic Production Line counter Using Microcontroller and We will design the circuit diagram along with the writing of software for the effective implementation of the Automatic production line counting system and display of counter at dominant place in the factory for its effective use.

Scope of Project:

This project is related to the design of an automatic production line counting system for the product counter in an industrial environment. This project will be helpful for the students of Electronics, Software, and Mechatronics field of engineer to develop this project for their final year degree project.

Introduction of Microcontroller Degree Project

A counting system for the products during the production from an industrial machine is always of greater concern for the management point of view. Therefore the counter and display of production line is required to design. Here we will make the schematic circuit designing and software coding for the development of automatic event counter. The use of Microcontroller make the counting of product more efficiently, the other main components to be used in the project will be like sensor which are based on optoelectronic switch associated electronics component like resistor, capacitors and digital Integrated Circuits (ICs). There is provision of Data acquisition so that a Personnel Computer (PC) could be interfaced with the counting system to get the data into the PC through the use of RS-232 serial communication Protocol. The Software on PC will be capable enough to register the actual quantity of the Production line, event date & time and planning efficiency for future production rate etc. The experimental use of this automatic event counting or production line counting will prove its credibility with the advantages like reliability, easiness in operation and accurate results. It is worth mentioned that this system has many application and uses in real world like its usability starting from the home appliance to large scale industrial manufacturing factories states. Some of the usage of this system are elaborated as it can be used as Meter-age Counter for the counting of length of cloth production textile industry, Folding Machine Counter, Jigger Programmer for the counting of length of cloth in dying machine and several round of that cloth in dying tube, each time it is required to measure the length of cloth very accurately by giving it desirable Temperature and tension and many more,  Weaving Length Counter, Shift Production Counter, Dosing Controller or dozing counter are also the requirement of industry and counter are widely used for it, Production Data Monitor,  Deca & Doff counter, cloth Length measurement system, Inspection Machine Counter, Speed Indicator, Shrinkage Monitor, Warping Length Counter, Loom Production Meter,  Yarn Length Counter, Spinning Automations, etc. Industrial production lines products final product from raw materials and their counting is done by the use of appropriate counter. To keep all record up-to-date about the above said production lines is really a job. In an industry many processes will be running simultaneously. Thus automatic counters are a big need of industry. Therefore above counters are frequently used in various places.

Construction of Microcontroller based Automatic Counter and display System:

This counting and display system uses Microcontroller Atmega with optical sensors to ensure the forward and reverse counting through the effectively use of electronic circuitry with them. The Microcontroller optical Sensor, LED seven segment display, suitable power supply, necessary electronics components will be mounted on a PCB board to develop. The LED display will work on the famous technique of multiplexing the digits which will be describes later in this post. The system will work as a fully automated industrial production line counting system. The optical sensor will transmit and receive light signals to detect product or things which are required to count. When an object will crosses the sensor path, then a response will be generated by sensor indicating an object. This technique will ensure that all objects are being counted.

Direction base Counting of Objects:

When the object start moving in front of the optical sensors, the pulses will be generated and these will be counted using the systems attached with it. Similarly when any machine moves then the optical sensors attached with the shaft will continue to produces the pulses on making and breaking of the light between the sensor elements. What if one wants to know in which direction the shaft is rotating, clockwise or anticlockwise direction because the direction of rotation is important in any industrial applications.  As the counting of pulse does not serve the purpose all the time. Like, if it is desired that counter may increment with one direction of rotation and decrement with the reverse direction of rotation. In these situation one have to use an up & down counter with proper circuit to identify the direction of rotation.

Direction of rotation detection
Direction of rotation detection


Redesigning of Counter for Direction Information:

So let’s redesign the existing simple pulse counter to a special up & down counter with help of a very simple circuit. There will be two optical sensor pair will be used instead of one pair of LED and receiver. So that we have two pulses one after another. These pair of pulses will be feed to a D-type flip-flop integrated IC like TTL IC 74LS74. The 74LS74 will sense the sequence of occurring of these pulse and will distinguish that which pulse come first among pulse “A” or Pulse “B”. The direction will be identified using the D-type flip-flop 74LS74 like is it clockwise or anti-clock wise rotation. So the counter will increment the count or decrement the count as per the direction of rotation. This type of motion detection along with direction of motion detection is required in many applications likes in the field of robotics, in the control of various arms of CNC machine, and similarly in many applications involving the bidirectional mechanical motion.

The D-Type Flip Flop 74LS74

It is an integrated IC having two D-type flip flops, these flip flops are here used to identify the direction of rotation of the encoder. As we have already told that the two pairs of optical sensors will produces to set of pulses name “A” and “B”.  These pulses will be feed to the flip flops as per configuration shown in the schematic circuit diagram below. As a result, we will be obtained two pulses labeled clock wise and anti-clockwise. If the encoder will rotate clock wise the pulses will be available on clockwise pulse train only. If the encoder will rotate anti-clockwise direction then the pulse will be available on the anticlockwise train. Each is feed to external interrupts of microcontroller.

Counting of Pulses:

The external interrupts of Atmega8 Microcontroller are configured as activate on the fallen edge. If the pulses come on clockwise pulse train then interrupt number 1, be activated and increment in counts will be resulted. If the encoder will rotate counter-clockwise direction then anti-clock-wise pulse train will generate pulse and the second external interrupt of microcontroller will be activated which will decrement the counts.

Schematic Circuit diagram of the Project:

ATmega8 Microcontroller based Bidirectional Counter
ATmega8 Microcontroller based Bidirectional Counter


Multiplexed Seven Segment Display:

The display of the project is a four-digit common cathode type LED seven segment display. The Seven segment display is configured in the multiplexing way. The digit will glow one by one. Thus, is done in the software.

By using the technique of multiplexing, the control of display using seven segments to displays the production count becomes very simple. The main advantage of use of this technique is that it requires a smaller number of IO pins of microcontroller as compared to conventionally attaching all pins of seven segment display to the microcontroller which seems not easy with small microcontroller. It will require either an IO expander or a microcontroller having larger set of IOs. As we are using a small microcontroller of AVR named atmega8, which have limited number of IOs, thus we used the multiplexing technique of display number on the four seven segment digits. Therefore, the number of pins used to drive the displays are a few only. In the way the segments are driven high by the micro-controller turn by turn. First we turn one the transistor attached to first decimal place and at that time the code for digit is send to PORTB of microcontroller, as a results first digit place glows with that digit. At that time all other transistors are kept off, means all three remaining seven segment display digit will be OFF. After a delay of about 500 milli second, then the turn comes for second digit place and so on.

Microcontroller Atmega8:

In this project the AVR Microcontroller Atmegaa8 is used. The AVR Microcontroller ATmega8 is a low-power CMOS 8-bit microcontroller. It is based on the AVR RISC architecture. The ATmega8 has inbuilt ADC : the analog to digital converter, the built-in  internal oscillator and the serial data communication, performs the instructions in a single execution cycle. The ATMEGA8 has 1Kbyte Internal SRAM, 8 Kb of Flash program memory and 512 Bytes of EEPROM. The ATMEGA8 has three ports, port-B, port-C, and port-D. There are total 23 IOs line are available on these ports. There are two External Interrupt lines which are configured at port D. There are three-Internal Timers. This microcontroller is very efficient for small and medium size projects. The working of microcontroller is very stable. The performance of the microcontroller is excellent.

Software of Bidirectional Counter:

The software of the Bi-directional counter is written in BESCOM, basic language and compiler for the AVR microcontroller. The program code listing is provided at the end of the post.

Reset counting Button:

A push button is also interfaced with the atmega8 Microcontroller to reset the counting at any time.

'*****************************************
'Bi-Directional Production Line Counter
'*****************************************
$regfile = "m8def.dat"
$crystal = 8000000
$prog &HFF , &HE1 , &HD9 , &H00
On Int0 Downcount
On Int1 Upcount
Enable Int0
Enable Int1
Config Int0 = Falling
Config Int1 = Falling
Enable Interrupts
'*****************************************
' outputs  of the Microcntroller Atmega8
'*****************************************
Config Portb.0 = Output : Portb.0 = 0
Config Portb.1 = Output : Portb.1 = 0
Config Portb.2 = Output : Portb.2 = 0
Config Portb.3 = Output : Portb.3 = 0
Config Portb.4 = Output : Portb.4 = 0
Config Portb.5 = Output : Portb.5 = 0
Config Portb.6 = Output : Portb.6 = 0
Config Portb.7 = Output : Portb.7 = 0
Config Portc.0 = Output : Portc.0 = 1
Config Portc.1 = Output : Portc.1 = 1
Config Portc.2 = Output : Portc.2 = 1
Config Portc.3 = Output : Portc.3 = 1
'******************************************
'inputs of the Microcntroller Atmega8
'******************************************
Config Portd.2 = Input : Portd.2 = 1
Config Portd.3 = Input : Portd.3 = 1
Config Portd.7 = Input : Portd.7 = 1
'******************************************
'data for 7 segments
' Codes for common Cathode Type
' Seven Segment Display
'******************************************
Dim Digit(10) As Byte
' Dibit 0
Digit(1) = &B00111111
' Dibit 1
Digit(2) = &B00000110
' Dibit 2
Digit(3) = &B01011011
' Dibit 3
Digit(4) = &B01001111
' Dibit 4
Digit(5) = &B01100110
' Dibit 5
Digit(6) = &B01101101
' Dibit 6
Digit(7) = &B01111101
' Dibit 7
Digit(8) = &B00000111
' Dibit 8
Digit(9) = &B01111111
' Dibit 9
Digit(10) = &B01101111
'*******************************************
'veriables
'*******************************************
Dim Product_count As Integer
Dim Digit_place(4) As Byte
Dim I As Byte
Dim K As Integer
Product_count = 0
Portc.0 = 0 : Portc.1 = 0 : Portc.2 = 0 : Portc.3 = 0
Main:
'**********************************************
' 7seven segment display
'Conversion of the count to digit values
'**********************************************
I = Product_count Mod 10
Digit_place(1) = Digit(i + 1)
K = Product_count / 10

I = K Mod 10
Digit_place(2) = Digit(i + 1)
K = K / 10

I = K Mod 10
Digit_place(3) = Digit(i + 1)
K = K / 10

I = K Mod 10
Digit_place(4) = Digit(i + 1)
K = k / 10
'*********************************************
'Multiplexing the four digits
' Multiplexing seven segment display
'*********************************************
Portb = Digit_place(4)
Portc.0 = 1 : Portc.1 = 0 : Portc.2 = 0 : Portc.3 = 0
Waitus 500
Portc.0 = 0 : Portc.1 = 0 : Portc.2 = 0 : Portc.3 = 0
Portb = Digit_place(3)
Portc.0 = 0 : Portc.1 = 1 : Portc.2 = 0 : Portc.3 = 0
Waitus 500
Portc.0 = 0 : Portc.1 = 0 : Portc.2 = 0 : Portc.3 = 0
Portb = Digit_place(2)
Portc.0 = 0 : Portc.1 = 0 : Portc.2 = 1 : Portc.3 = 0
Waitus 500
Portc.0 = 0 : Portc.1 = 0 : Portc.2 = 0 : Portc.3 = 0
Portb = Digit_place(1)
Portc.0 = 0 : Portc.1 = 0 : Portc.2 = 0 : Portc.3 = 1
Waitus 500
Portc.0 = 0 : Portc.1 = 0 : Portc.2 = 0 : Portc.3 = 0
If Portd.7 = 0 Then Product_count = 0
Goto Main
'****************************************************
Downcount:
If Product_count = 0 then Product_count = 9999
Decr Product_count
Return
'****************************************************
Upcount:
If Product_count = 9999 Then Product_count = 0
 Incr Product_count
 Return

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)