Showing posts with label 18f452. Show all posts
Showing posts with label 18f452. Show all posts

Solar Tracking System Microcontroller PIC 18F452

Solar Energy Tracking System using microcontroller

Abstract of Solar Tracking System:

The goal of the project is to develop and implement a solar energy tracking system using a microcontroller. To find out alternative sources of energy and get maximum efficiency from such non-conventional energy source is the need of present and future. This project involves around the requirement that how we can design an efficient solar panel system to acquire maximum solar energy from it. This is the reason we are try to design this project.

Introduction of Efficient Solar Penal System:

As the energy costs are increasing with the decreasing supplies of conventional fuels, the need arises to find out sustainable alternative forms of power. These energy source shall be such that to protect the environment from the harmful releases of gases. The Solar energy is one of the big sources which is being implemented. The Solar panels are usually fixed at certain angle, although a reasonable amount of energy is produced from these panels. But production of electricity can even be increase with the use of an intelligent solar panel tracking system which control the direction solar electrical panel in a way to face the sun at the maximum time. If we design a system which control the solar electrical panels such that it always faces the sun, then we will be able to get maximum advantage from sun light with the use of existing solar panels.  This microcontroller project involves a solar tracking system which is designed with a microcontroller, optical sensors and motors. The position of sun and panel is checked and best suitable direction is calculated then the panels are moved in such direction that panel should face the sun exactly. The position or directional angle with respect earth of the Sun is not fixed. Therefore the angle at which sunlight strikes the earth surface also varies through the day. Therefore the solar panel will have variable amount of light whole the day. The production of electrical energy will also be not constant. So the direction of solar panel need readjustment through the day in order to have sun facing angle, so that maximum light may fall on solar panels. All this happening due to the rotation of the Earth around the sun in our sun solar system. The Solar-electrical panels shall absorb sunlight maximum to give maximum electrical energy. It can only be achieved if the solar-electrical panels are incessantly moved and placed inline with direction of the Sun to have maximum sunlight all the time. Therefore the solar-electrical panel will be constantly subject to adjustment-readjustment rotational angle as a function of direction of Sun. This microcontroller project is designed to obtain the desired goal for having maximum efficiency from existing solar-electrical system with applying tracking algorithm.

Solar Panel for Maximum Electrical Energy Tracking System Objectives:

The main objective of the project is to design a solar tracking system using pic microcontroller. However besides this we will achieves some associated advantages like we will be able to learn about the working of the solar energy panels tracking system, implementation of a microcontroller from PIC family to achieve the target, the needs of a solar energy tracking system, the appropriate methods of tracking the solar energy generating panels used, the design methodology and constraints in the development of efficient solar panel tracking system, the designing of schematic circuit diagram of tracking system using microcontroller from the PIC family, writing the software and code listing for the PIC microcontroller in the construction of an efficient solar panel electrical tracking system.

The Philosophy of Solar tracking system:

The solar energy converting electrical panels tracking system works with on an idea to get the maximum energy from the existing solar to electrical panels with implementation of a smart electronics controller with the solar panels. It is already in understanding that the solar panels are installed at the roof of the house or any other building with the intension to get the electrical power from the light and heat of the sun energy with the help of these solar-to-electrical panels. It is worth mentioned that the solar-electrical panels convert solar energy into electrical energy with an effective implantation of photovoltaic principle. It is very obvious that the intensity of light from the sun plays the important role in the production of electrical energy from the panels, more electrical power with higher intensity of light.  Is there any other factor which can serve to obtain more electrical power from the solar-electrical panels? Yes the direction of placement of panels is much important, the panel shall be placed in a suitable direction that maximum light from sun can fall directly on the panels. This project is designed for the controlling the position and direction of solar-electrical panel in such a way that the light from the sun fall directly on panels and maximum energy may be converted and obtained. Therefore here we will be developing a controller of panels to rotate them accordingly with the hanging the position of sun.

By using this tracking system, we will be able to expose solar panel for the maximum time in front of sunlight and thus we will be able to get the maximum power from the existing solar panels. There are two well pronounced methods which are used for the Solar tracking system. These are the Sun-Solar tracking system and Time-Solar tracking system. These two methods are briefly explain below.

Time solar tracking system:

The information of time and season is additionally gathered from the database to find out the exact direction where the sun light is maximum. In this method time plays an important rule to decode the rotation of earth around the sun. The use of real time clock in the control circuitry of solar tracking system with microcontroller will do the purpose. As the season give different angles of direction where sunlight is more than usual. Therefore the tow parameters together will decide it.

Sun Solar tracking system:

The solar tracking system, as its name indicates that it will track the sun. The solar panels rotated with the help of motors in the direction of sun. As the quantity of light changes with the rotation of earth around the sun, therefore it is necessary to measure the intensity of light. The Light dependent resistor (LDR) or photo diode are used for this purpose. The electrical signal generated by optical sensor is processed and command to motors is issued in response. As a result the solar panels gain the direction where the light is maximum.

The optical sensors which will be either the LDR or the photo diode or photo transistor will measure the intensity of light. There are two optical sensors used which are separated by an insulator of light, so that each may work independently. Initially both sensors are calibrated when same amount of light is given to each of them. After their installment at the panels, now the light intensity from each of optical sensor is measured using the microcontroller. In ideal conditions when same amount of light falls on both sensor, they should give same amount of electrical output and the motor shall not move in any direction unless one of the sensor start giving less or grater light. With the start of day, the output of sensors will not balance each other therefore microcontroller will generate command to motors to bring the panels in the direction of sun, where the light is maximum and both optical sensor read equal amount of light. Following are test cases of project:

Case # 1: When the electrical signal from both sensor is same, reflecting that the intensity of light is same at both optical sensors. In this case the solar-electrical panels will be assumed that the direction is perfect and there is no need to rotate in any direction. Solar panel will remain in this position.

Case # 2: When the output of the optical sensor is not equal. The optical sensor # 1, which is on left side of panel reads more intensity than the sensor # 2 which is at right side of the solar panel. It will happened usually in the morning time, left optical light sensor will be on higher intensity. Then solar panel will start rotating will the help of stepper motor to left direction where the two sensors get same reading of intensity. It will be the point where maximum solar light will fall on the solar panel and out optimum direction.

Case # 3: When the output of the optical sensor is not equal. The optical sensor # 2, which is on right side of panel reads more intensity than the sensor # 1 which is at left side of the solar panel. It will happened normally afternoon, when the right side optical light sensor will be on higher intensity as compared to the left side optical sensor. Then solar panel will start rotating will the help of stepper motor to right direction till the two sensors have same response. Then we get our desire direction where maximum solar light will fall on the solar panel.

The 2-D solar tracking System:

The Solar energy is also called free source of energy that’s why it has gain more popularity as compared to other renewable energy resources. Moreover the emission of burned fossil fuel bi-products and hydrocarbon which are destroy our environment are not associated with the power generation from the solar system. The Solar-electrical named as Photovoltaic (PV) panels are the devices which convert the sun light into electricity energy. Once a solar system is planned to installed anywhere for the generation electricity from sunlight, then the point of concern come that the maximizing electrical shall be acquired to increase the efficiency of solar system at the available resources. To achieve this goal the solar or photovoltaic panels must be kept aligned with the direction of sunlight through the use of a tracking system which will focus on the direction of the sun.

 Usually the fixed type PV panels don’t follow the sun direction that’s why their efficiency overall remain at lower side. On the other hand the sun tracker which work on single axis principle, the solar panel are adjusted and re-adjusted in East-West direction. The solar tracking system which work on the principle of two-axis tracking  have more precise adjustment of direction of solar panel by moving the panel into two direction. The up -down and left – right movement of solar panel in order to have maximum output will increase the efficiency even more. Thus a solar tracking system consisting of two axis tracking using microcontroller will be more efficient.

It is learnt that the efficiency of PV panels is a function of various parameters like environmental temperature, humidity, rain, status of cloud and dust level on panels. This project is a Microcontroller based two axis Solar Tracking system which adjust the direction of solar panel so that the efficiency of solar panel is increased considerably.

Components used in the development of general purpose one axis solar tracking system.

If we wish to develop a low cost general purpose one dimensional solar tracking system then we will have to build a few components like Solar panel, PIC18F452 microcontroller, Optical sensor based on Photo Transistors or photo diode, A set of resistor, Servo Motor, 8MHz Crystal, 22pF Ceramic Capacitors, Connecting Wires, Stepper motor, ULN2003, Oscillator, Resistors, Capacitors etc.

Construction of Two Axises Solar Tracking System:

On the implementation of the tracking system, we will be considering the direction of the sun which will be varying in two directions up-down and left-right. The horizontal direction from the observer to the sun is called the azimuth angle. Whereas the vertical direction from the observer to the sun is called altitude angle.

Schematic Circuit diagram of the Two-Axis Solar Panel Tracking system using microcontroller PIC 18F452:

The Schematic Circuit diagram for double axis solar tracking system has been designed, prepared and analyzed in Proteus ISIS software. The full circuit of 2-D solar panel tracking system is shown in Figure # 1. 

Complete Circuit diagram of 2-D Solar Tracking System
Figure # 1: Complete Circuit diagram of 2-D Solar Tracking System


The whole schematic circuit diagram of the project is consisting of following main sections:

1.     The central processing Unit Board CPU consisting of PIC Microcontroller 18F452

2.     The Sensor Boards consisting of Temperature sensor LM35 and optical sensor LDR.

3.     The Keyboard consisting of four push switches and a latched button.

4.     The LCD based display Unit Board

5.     The Motors controller boards

6.     The LED status board

7.     The power supply section

     The details of component and construction of each section and its board is discussed as below. The functionality of whole project will be explored step by step as under.

Solar Tracking System Central processing Unit Board (CPU)

For the processing of information gathered from the sensors and obtaining the useful results for the effective control of DC motors, the CPU boards is designed, as shown in the diagram (Figure # 2) below. 

Microcontroller PIC18F458 Connection with circuit diagram of solar Tracking system
Figure # 2: Microcontroller PIC18F458 Connection with circuit diagram of solar Tracking system

The tasks done under this brain board of the solar tracking system developed using Microcontroller are listed as under:

1.    Measuring the signal from the optical sensors (04 Nos). The four optical sensors (LDR) are required to mount on each side of solar panel i.e to detect the light intensity at Upper side, lower side, right side and left side. The Light intensity signal is processed by converting the analog voltage level to digital by using built-in ADCs of the Microcontroller. The digital number corresponding to light intensity levels at each side are formatted properly to be utilized effectively in the logic decision section of program.

2.  Measuring the analog signal from Temperature sensors (QTY: 04 Nos). The four Temperature sensors (The Integrated Analog Temperature Sensors LM35) are required to be mounted on each side of solar panel i.e to detect the Temperature at Upper side, lower side, right side and left side. The analog signal from LM 35 is processed by converting the analog voltage level to digital by using built-in ADCs of the Microcontroller. The digital number corresponding to the degree of Temperature at each side are formatted properly to be utilized effectively in the logic decision section of program.

3.  The sensing to keyboard which is consisting four directional keys i.e. up-ward, down-ward, left and right side keys. These keys are used to the manual motion of solar panel (if required).

4.    The scanning of a logical latched button which used for the selection of Logical decision, whether the decision should be based on results of Temperature sensors or optical sensors, or otherwise the logical decision will be based on results of Temperature sensors and optical sensors. This selection is very important in decision matrix. Because there will be location where we will be preferring to utilized the optical sensors as input only for the implementation of proper direction of solar panel. In this case the temperature reading will be ignored in making the decision of motion. In other condition we will preferably utilized the results from both type of sensors and if logic from both sensors is in same sense, then motor will be operated accordingly to adjust the direction of solar panel.

5.  Updating the LCD display with the current measured values of the four temperature sensors and four LDR, the optical sensors at the LCD. The user will have to look if he wants to know what are the temperature and light intensity levels at various sides of the solar panel. Is the controller is working perfectly or algorithm shall be modified.

6.    The issuance of movement commands for each motor separately when required for the adjustment of solar panel UP-DOWN (Vertical Movement) direction and Left-right direction (Horizontal Movement). There are two motors which are responsible for the 2D axis adjustment of the solar panel in right direction and angle.

7. The main program will be performing the calculations and producing the proper commands for motor control (if required). It will be discussed in more details in the Logical decision making section.

The components used in the CPU boards, the brain and heart of the solar tracking system, which is the main processing board and act as the essential electronics board of project are listed as below:

1.    The PIC Microcontroller 18F452. It is selected for three reason that the ADCs results of this microcontroller are stable. Secondly, the number of IO lines required for this project meets by using the PIC 18F452 Microcontroller. Third reason for the selection of this microcontroller is that it has sufficient RAM, ROM to support the software requirements of this solar tracking system.

2.  Crystal 8 MHz: The 8 MHz crystal is very optimum choice, how ever the project can easily work on the 20MHz crystal as well. There is any number in between 8 and 20 MHz crystal will efficiently work.

3.     Capacitor 33pF (QTY: 02 Nos)

4.     Resistor 10k Ohm

5.     Capacitor 104 mounted on power supply lines. Although it is not shown in the schematic diagram, but is sued because the Power supply are not visible or shown in circuit diagram prepared in the software Proteus ISIS.

6.  Capacitor 100uF 16V mounted on power supply lines. Although it is shown in the apparent circuit diagram, but it is recommended to be used in parallel with the power supply lines to have a good filter power supply to microcontroller.

Sensor Boards:

There are four sensor boards used in the project of solar tracking system using microcontroller PIC 18f452. Each board has one temperature sensor and one Optical sensor as shown in figure # 3. The temperature sensor we are using in project is an integrated analog temperature sensor LM35 which is good for general purpose applications and its response is also acceptable. It gives analog output signal 10mV/degree C. The optical sensor is LDR, whose resistance varies with the intensity of light. When light strikes on the LDR sensor, then the resistance of the photo sensor decreases. It means that during day time its resistance will be low in the order of a few hundred Ohms (400 to 500 Ohms) and in night its resistance will be high in the order of a few kilo Ohms (1400 to 1500 Ohms). In the day time its resistance will be function of amount of light falling on it in the range of say 150 Ohm to 700 Ohms. Thus potential difference across the LDR will be direct presentation of the intensity of light. If there is less light strike on it, its resistance will be high and voltage drop across it will be lower and vice versa. The two analog signals from each board are feed to the ADC (Analog PINS) of the Microcontroller PIC 18F452. Where the analog signal is then converted to digital signal and processed accordingly.

 

Placement of sensor at solar panel for sun tracking system using Microcontroller PIC18F452
Figure # 3: Placement of sensor at solar panel for sun tracking system using Microcontroller PIC18F452

Keyboard

A small keyboard consisting of four push buttons and latches button is designed and attached with the microcontroller board to accept the input from users. The reason of this keyboard is to facilitate the user of solar tracking system to give manual commands to microcontroller for the proper fixing of location or direction of solar panel. The circuit diagram of the keyboard is presented in figure # 4 as below.

It is consisting of simple push button which are pull-up with 10kOhm resistor for the generation of proper logical signal. When any of the key is press, a corresponding logic “0” is obtained otherwise due to pull-up resistors the logic “1” will be on each switch output line. The four push button corresponds to provision of input for movement in four direction like up, down, left or right direction of solar panel for the fine adjustment if required by user.

Key Board Interfacing Circuit diagram with Microcontroller for Solar tracking System
Figure # 4: Key Board Interfacing Circuit diagram with Microcontroller for Solar tracking System


One latch switch or button is provided at keyboard front panel for the selection user intension for logical decision regarding the direction of panel. The facility is provided to use optical sensor input with logical or with temperature input. At the other position of switch, it will logical and the inputs of the temperature sensor and optical sensor. Thus in this selection case, the decision will consider the input from both sensors, if it is coincide then movement command will be generated.

LCD based display Unit Board

An LCD of four line and twenty characters is used for the display of the current temperature and intensity levels on the screen front panel. The LCD is interfaced with microcontroller using four bit mode. The total six IOs lines of Microcontroller are used for the data and command communication between LCD and microcontroller as shown in figure # 5 below. Four IOs lines are for data and two IOs lines for control line to give LCD enable signal, and RS signal to LCD. The LCD is used in fixed write mode. The contrast of LCD is controlled using a potentiometer, variable resistor, of 10kOhm. The LCD will work on DC 5V power supply which will be shred from microcontroller board power supply section.

LCD Display Connection with circuit diagram for solar tracking System
Figure # 5: LCD Display Connection with circuit diagram for solar tracking System


Motors controller boards

There are two DC Motors required to be used in this project of solar tracking system using microcontroller PIC 18F452. Therefore there are two motor control board designed to control one DC motor by each motor controller board. Each Motor control board I consisting of four transistors, two PNP and two NPN transistors. The Four transistors are configured to make the well know H Bridge type control of DC motor as shown in figure # 6 below. The PNP transistors are responsible for the provision of positive power supply connection to motor one terminal. On the other hand the NPN transistors are responsible for the provision of ground level voltage to the other terminal of the DC motor. As we know that the PNP transistor is active or start conduction when operated as switch on the availability of logic “0” on its base terminal. Whereas the NPN transistor when configured in switch configuration will be active on the provision of logic “1” at its base. One PNP and one NPN transistor share one IO line. Therefore at a time only one transistor will be active. Thus for the effective control the direction of motion of DC motor, two control IOs of microcontroller are used. At idle time, both IOS will have same logic level. But for motion in particular direction i.e. clockwise or anticlockwise, the logic level on one IO line will be high whereas logic level on the second IO line will be low. Therefore at this time one PNP and one NPN transistor from opposite in diagonal when conduct, as result one terminal of DC motor will receive positive supply and other end of motor will receive ground level. Then the motor will start rotating till the change of status of IO lines. The Four PN junction protection diode are also used in the motor controller board to nullify the reverse emf generation problem of DC motor. These diode are for the safety of transistor because otherwise transistor may burn out on the generation of reverse emf at the terminal of motor.

MOTOR DIRVE CONTROL Circuit diagram of Solar Panel Tracking System
Figure # 6: MOTOR DIRVE CONTROL Circuit diagram of Solar Panel Tracking System


It may be noted that the specific number of PNP and NPN transistor and diodes are not being mentioned with the intension that the user may select the components to meet the requirement of load, DC motor specifications etc. Therefore the power supply of DC motor will also be appropriately selected on the basic of requirement of DC motor.

LED status board

A board is designed to show the movement of solar penal if any motor is operated at any time with the help of four LEDs which corresponded to the movement of direction in four side. The same IOs lines used for the control of direction of rotation of motor used by motor controller boards are used here to glow the respective LED with the utilization of TTL IC, 7408 and 7404, AND gate logic IC and NOT gate logic IC respective as shown in the figure # 7 below.

LED Status Board for Motor Motion Indication
Figure # 7: LED Status Board for Motor Motion Indication


Power Supply Section

Apparently the microcontroller and associated boards works with regulated DC 05V power supply which is consisting of a step down transformer, rectified diodes, filter capacitor and an analog voltage regulator LM7805 IC. As the overall current consumption of the circuits is not high and remains in the range of about 100mAs to 150mAs. Therefore use of LM7805 IC is enough which is usually cable to provide 1000mAs regulated power supply. However the DC motors selected for this prototype project works on DC12V and may draw current in the range of 1Amp. Therefore a spate power supply for the motors will be required to match the requirement of motors. As we are not fixing the selection of motor at this stage therefore the user or developer is responsible for the section of appropriate DC motors and their power supply along with the proper selection of PNP & NPN transistor pairs in the motor controller board. This end is kept open and component can be selected based on the actual requirements.

Software of the 2-D solar Tracking System Using Microcontroller PIC 18F452:

The program coding of the 2-D solar tracking system is written and compiled using Proton Plus Basic Complier for PIC Microcontroller. Its code listing is provided in the next post. Please visit the Post " Program for Solar Tracking System".

The other microcontroller based degree projects and many hobby projects of Microcontroller are available here.

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

Popular Post (All Time)