EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / Calculating flow rate of an infusion pump

Calculating flow rate of an infusion pump

|

Microcontroller › 8051 › Calculating flow rate of an infusion pump

  • This topic has 10 replies, 5 voices, and was last updated 11 years, 2 months ago by Ashutosh Bhatt.
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • May 14, 2014 at 9:27 am #4883
    Osama Mohammed
    Participant
    Hello, 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.
     
    I am using Proteus simulation software.
     
    May 15, 2014 at 3:52 pm #11733
    Ashutosh Bhatt
    Participant

    r u getting pulses when there is a drop?

    if yes then anything else is very simple

    you just count number of pulses (that means drops) per unit time (1 sec, 10 sec etc) 

    do some calibration like in 10 sec 100 drops falls that means 50 ml liquid flowed like wise. then calculate flow rate as ml / sec or ml / minute etc.

    May 15, 2014 at 7:54 pm #11734
    Osama Mohammed
    Participant

    Thanks, 

    The problem is solved 

    but now I have another problem, 

    I don’t know how to display decimal numbers on LCD , for example 244 how if I want to display on LCD ?

    Also how to display a number preserved inside a variable ,for instance if k is a variable and k=200; , how to display this value of k ????

    May 16, 2014 at 4:25 am #11735
    AJISH ALFRED
    Participant

    Hi Mohammed,

     

    It is very simple. Tell you the logic!

    Take another variable, say ‘m’,

     

    step : 1; m = k % 10, you will get the unit place value of k in m,

    step : 2; now m = m + ‘0’, you will get the ascii value of that unit place, which you can display on the LCD.

    step : 3; display m on LCD

    step : 4; Now k = k / 10 and, continue these 4 steps until k becomes zero at step 4.

    May 16, 2014 at 5:04 pm #11737
    venkateshwaran
    Participant

    Hi mohammed,

    this is the code for you.

     

    void convert (void)
    {
    if(sourse<=9) { b = sourse;
    c = 0;
    d = 0;}
    else if(( sourse>= 10) && (sourse<20) ) {
    b = sourse – 10 ;
    c = 1 ;
    d = 0 ; }
    else if( (sourse>= 20) && (sourse<30) ) {
    b = sourse – 20 ;
    c = 2 ;
    d = 0 ; }
    else if(( sourse>= 30) && (sourse<40) ) {
    b = sourse – 30 ;
    c = 3 ;
    d = 0 ; }

    else if(( sourse>= 40) &&( sourse<50 )) {
    b = sourse – 40 ;
    c = 4 ;
    d = 0 ; }
    else if( (sourse>= 50) &&(sourse<60) ) {
    b = sourse – 50 ;
    c = 5 ;
    d = 0 ; }
    else if( (sourse>= 60) && (sourse<70 )) {
    b = sourse – 60 ;
    c = 6 ;
    d = 0 ; }
    else if(( sourse>= 70) &&(sourse<80) ) {
    b = sourse – 10 ;
    c = 7 ;
    d = 0 ; }
    else if( sourse>= 80 && sourse<90 ) {
    b = sourse – 10 ;
    c = 8 ;
    d = 0 ; }
    else { b = sourse – 10 ;
    c = 9 ;
    d = 0 ; }
    b=0x30|b;
    c=0x30|c;
    d=0x30|d;}

    b is first digit c and d are second and third digits,

    this code works only  sourse value is below 100, you can edit this code for

    more values. 

    May 18, 2014 at 4:26 am #11739
    SHAH DISHANT H.
    Participant

    Hi,

     

    This function will help you. In this whatever the number you want to display, pass it as a parameter and it will be displayed on LCD.

     

    void DisplayDigit(unsigned int dat)
    {
    unsigned int temp,i=0, buf[10];
     
    while(dat>=10)
    {
    buf=dat%10;
    dat=dat/10;
    i++;
    } 
     
    buf=dat;
     
    for(temp=0;temp<=i;temp++)
    {
    LCDWriteData(buf[i-temp]+’0′);
    }
     
    }
     
     
    All the best…!!!
     
    May 18, 2014 at 12:08 pm #11742
    Ashutosh Bhatt
    Participant

    congrets for getting solution.

    pls write in detail how ur system works now. how problem is solved?

    this will help many other students, hobbysists etc 

    May 18, 2014 at 8:53 pm #11744
    Osama Mohammed
    Participant

    Hi,

     

     

    Thank you all,

     

    the problem is solved :)

     

    the if statement argument was wrong ,that is all !! 

     

     

     

     

     

    SHAH DISHANT H. thank you for posting this function I will try it 

    May 18, 2014 at 8:53 pm #11745
    Osama Mohammed
    Participant

    Hi,

     

     

    Thank you all,

     

    the problem is solved :)

     

    the if statement argument was wrong ,that is all !! 

     

     

     

     

     

    Dishant 

     thank you for posting this function I will try it 

    May 18, 2014 at 9:45 pm #11746
    Osama Mohammed
    Participant

    Please I hgave another question 

     

    my hex code file is 9 kilo bytes in size

     

    can it be used with 89C52 ?

    May 20, 2014 at 5:47 pm #11749
    Ashutosh Bhatt
    Participant

    try to limit the code size less then 8 KB.

  • Author
    Posts
Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Sump pit water alarm - Kicad 9 July 18, 2025
  • Pic18f25q10 osccon1 settings swordfish basic July 17, 2025
  • Anyone jumped from Easyeda std to Easyeda pro? July 17, 2025
  • turbo jet fan - feedback appreciated. July 17, 2025
  • More fun with ws2812 this time XC8 and CLC July 17, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise