Calculating flow rate of infusion pump

Thread Starter

OSOO

Joined Feb 19, 2014
34
llo,
My project is to calculate the flow rate of a medical infusion pump, that is , when the first drop falls there is a infrared pair transmitter and receiver ,when each drop falls the light between the ir pair is interrupted ,and a pulse generated is used to initialize the interrupt service routine ,inside the Interrupt service routine there is the instruction that runs the timer to start measuring the time between the first drop and the second drop, when the second drop falls down another interrupt is occurred ,and there are instructions that stops the timer and display the flow rate according to some calculations that I have made earlier.


This is the code:

#include <reg51.h>
msDelay(unsigned int);
cmd(unsigned char);
dat(unsigned char );



unsigned char a[]="Welcome";
unsigned char b[]="Flow Rate:25ml/hr";
unsigned char c[]="Flow Rate:50ml/hr";
unsigned char d[]="Flow Rate:250ml/hr";
unsigned char e[]="Flow Rate:100ml/hr";


sbit regs=P3^0;
sbit wr=P3^1;
sbit enab=P3^2;


void LCD_write_string(unsigned char *str)
{
int i = 0;
while (str != 0)
{
dat(str);
msDelay(100);
i++;
}
return;
}

unsigned int i,j,k;
void timer0() interrupt 1
{
k--;

}

void timer1() interrupt 2
{
unsigned int k;
i--;
TR0=1;
if(i==1)
{
P1=0xAA;
}

if(i==0)
{
TR0=0;
msDelay(5000);
cmd(0x01);
if(k>=139 || k<=141)
{

LCD_write_string(b);




}
else if(k>=100 || k<139 )
{

LCD_write_string(c);

}

else if(k<=100 || k>=20)
{

LCD_write_string(d);

}

else

{
LCD_write_string(e);


}
k=0;
i=2;
k=141;
msDelay(10000);

TL0=0x00;
TH0=0x00;



}

}




main ()
{
unsigned int k;
// Initialize the LCD
cmd(0x38);
msDelay(1000);
cmd(0x0C);
msDelay(1000);
cmd(0x01);
msDelay(1000);
// *********************
//---------Welcome Message
cmd(0x84);
msDelay(2000);
LCD_write_string(a);
//******************
msDelay(60000);
cmd(0x01);
TMOD=0x01;
IE=0x86;

TL0=0x00;
TH0=0x00;
TCON=0x04;
k=141;
i=4;

while(1);

}

cmd(unsigned char value)
{
P2=value;
regs=0;
wr=0;
enab=0;
msDelay(500);
enab=1;
}

dat(unsigned char info)
{
P2=info;
regs=1;
wr=0;
enab=0;
msDelay(500);
enab=1;
}

msDelay(unsigned int t)
{
unsigned int i,j;
for(i=0;i<=t;i++)
for(j=0;j<=100;j++);
}



This is a picture illustrating the idea of my project:





The problem is that as I think ( if conditions ) are not run ,that is ,all the time the flow rate displayed on the LCD is 25ml/h and is not changed even if I change the time between the drops.
 
Top