Anda di halaman 1dari 9

‫بسم اهلل الرمحن الرحيم‬

Palestine Polytechnic University

Microcontroller

Project Title: Fluid Level Control System

‫اعداد‬:

1-‫محمد أنس تفاحة‬

2- ‫مصطفى عبد النبي‬

‫ خالد اطميزي‬.‫ م‬:‫المشرف‬

2011/1/10 :‫تاريخ التسليم‬


Description:

In this project, we display the control of a fluid level measurement system. It is based on a
realistic water system control in an ordinary home. This system enables us to control the volume
of the water in the tank which means knowing how much the tank is full or empty. Therefore, if
the tank is empty, our control gives the opportunity for the pump(water motor) to fill up the
tank again by pumping water from the well and inserting it into the water tank.This will be done
in different speeds according to the “fullness” of the tank. In this control system, we will need the
following to carry out the process:

1- Water level sensor based on conductivity


2- Water tank
3- Well(storage)
4- Voltage source(battery)
5- Potentiometer
6- Switches
7- PIC18F4550
8- Water Pump(motor)
9- Transistors, resistors, etc…

Simply here, the conductive water level sensor in the water tank is connected with the PIC
allowing it to control the input voltage to the DC motor(centrifugal pump). This leads to the
following assumptions:

1- If the tank is empty, the level sensor connected to the tank will open a path for the
current.
2- This will feed the DC pump with power
3- The pump will keep pumping water in different speeds according to the conductive wire
reached which will cause less water pumping as the water level goes up.
4- When the tank is full, the highest conductive wire will cause current to flow that will shut
the pump power system down until the level goes back down and the conduction is no
longer reached.

The following schematic will display the main hardware in this control system:
This is the program used in the PIC18 control system:

#include<p18f4550.h>
#include"gamelinit.h"
#include"timers.h"
#include<pwm.h>
#include<adc.h>

#define verylow PORTBbits.RB0


#define low PORTBbits.RB1
#define high PORTBbits.RB2
#define veryhigh PORTBbits.RB3
#define sw PORTBbits.RB4

void main(void)
{

unsigned int c=0,sum=0;

OSCCON=0b01110011; //using internal osccilator 8MHZ

TRISBbits.TRISB0 =1;
TRISBbits.TRISB1 =1;
TRISBbits.TRISB2 =1;
TRISBbits.TRISB3 =1; //RB0 - RB3 for level detecting
TRISBbits.TRISB4 =1; //for switch

//pulse width modulation


//PWM period =[(period ) + 1] x 4 x TOSC x TMR2 prescaler
OpenTimer2( TIMER_INT_OFF &T2_PS_1_4 & T2_POST_1_1);
OpenPWM1(24);
SetDCPWM1 (0);
TRISCbits.TRISC2 =0; // motor PWM (output)

//ADC for potentiometer analog input


OpenADC(ADC_FOSC_4&ADC_RIGHT_JUST&ADC_4_TAD,ADC_CH0&ADC_INT_OFF&ADC_VREFPLUS_V
DD&ADC_VREFMINUS_VSS,0X0E);

//timer0 for small delay


OpenTimer0(TIMER_INT_OFF & T0_16BIT & T0_SOURCE_INT & T0_EDGE_FALL & T0_PS_1_1
);
WriteTimer0(0);

while(1)
{

if (sw==1)
{

WriteTimer0(250);
while(INTCONbits.TMR0IF==0);

INTCONbits.TMR0IF=0;

sum=verylow+2*low+5*high+25*veryhigh; //explained below

ConvertADC();

while(BusyADC()==1);

c=ReadADC();

//dividing the digital value into 5 levels 1023/5 to obtain values


for (c) see below for more information

if(c<=205)
{
SetDCPWM1 (0);
}

if(c>205 && c<=410)


{
if(sum==0)
{
SetDCPWM1 (100); //PWM 100%
}
if(sum==1)
{
SetDCPWM1 (0); //stop motor
}
}

if(c>410 && c<=615)


{
if(sum==3)
{
SetDCPWM1 (0); //stop motor
}
if(sum==0 || sum==1)
{
SetDCPWM1 (100); //PWM 100%
}
}

if(c>615 && c<=820)


{
if(sum==3)
{
SetDCPWM1 (75); //PWM 75%
}
if(sum==8)
{
SetDCPWM1 (0);
}
if(sum==0 || sum==1)
{
SetDCPWM1 (100);
}
}

if(c>820)
{
if(sum==3)
{
SetDCPWM1 (75);
}
if(sum==8)
{
SetDCPWM1 (50);
}
if(sum==33)
{
SetDCPWM1 (0);
}
if(sum==0 || sum==1)
{
SetDCPWM1 (100);
}

else
{
SetDCPWM1 (0);
}

ClosePWM1();
CloseADC();
CloseTimer0();
}

/* This program does the following:

1-The PIC18 will read a switch connected on the port RB4

2-A small delay will activate in order for the ADC to initialize

3- As for sum, we did that so we can do a single operation without putting too many commands

Very low Low High Very high Sum PWM


1 0 0 0 1 100%
1 1 0 0 3 75%
1 1 1 0 8 50%
1 1 1 1 33 0%

5- We read an input potentiometer where the tank is filled according to potentiometer


reading

Potentiometer reading(c/1023) Level wanted


c<=205 No level(0)
c>205 && c<=410 Very low
c>410 && c<=615 Low
c>615 && c<=820 High
c>820 Very high

6- PWM is not affected by the potentiometer reading


7- Choosing ADC values

*/
We have also worked this semester on the following:

1) JDM based Programmer #1

This programmer did not work because of that the rs232 was serialized.
2) JDM based programmer #2

This was a PIC18 programmer that we tried to build, it did not work because the first leg of the
PIC was broken.
3) IC level sensor

This is a level sensor based on the IC CD4066, it did not work with us because it probably burned
while we where soldering its legs.

Anda mungkin juga menyukai