Allif Izzat
Newbie level 4
- Joined
- May 25, 2015
- Messages
- 6
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 51
it depends on the flow rate and the number of pules/litre@horace1
How do you calculate liters/minute and liters/hour ?
Do you count pulses for say 1 sec or 10 sec or 1 min and then calculate liters/min and liters/hr ?
@horace1
This is my flow sensor datasheet. How can I write code for it. I need to calculate ltr/min and ltr/hr.
https://www.futurlec.com/FLOW40L0.shtml
depends on your flow rate - do you have sufficent pulses to give you an accurate reading over a shorter periodYou mean I have to wait 1 minute to get the reading ?
My flow is arounf 25 liter per minute and 330 pulses per liter.
the flow meters I have used gave a number of pules per per litre - by feeding this signal into a interrupt on change digital input (I used a PIC24) one can count pulses over a time period and determine flow rate etc
if(INTF_bit) {
INTF_bit = 0;
counter++;
}
Use INT0 pin. Configure INT0 pin to detect low to high transition using INTEDG bit. Now in interrupt routine check like
Code:if(INTF_bit) { INTF_bit = 0; counter++; }
counter holds the value of pulses. Once every minute append the counter value to another unsigned long variable and clear the counter variable.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 // Lcd pinout settings sbit LCD_RS at RB4_bit; sbit LCD_EN at RB5_bit; sbit LCD_D7 at RD7_bit; sbit LCD_D6 at RD6_bit; sbit LCD_D5 at RD5_bit; sbit LCD_D4 at RD4_bit; // Pin direction sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D7_Direction at TRISD7_bit; sbit LCD_D6_Direction at TRISD6_bit; sbit LCD_D5_Direction at TRISD5_bit; sbit LCD_D4_Direction at TRISD4_bit; volatile int NbTopsFan; void rpm(){ NbTopsFan++; //This function measures the rising and falling edge of the } //hall effect sensors signal unsigned int temp_res; char txt1[15]; float calc; void main() { TRISB=0; LCD_Init(); TRISA=0xFF; PORTA=1 ; //Spec :Fosc/64, Use ADC Ch.0 with Ref Vdd&Vss, Right justified ADCON0=0b10001001; //0b10_000_0_x_1 ADCON1=0b11000100; //0b1_1_xx_1110 ADC_Init(); do { temp_res = ADC_Read(0); // Get 10-bit results of AD conversion NbTopsFan = 0; delay_ms(2000); calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate //calculation to show flow per minute floattostr(calc,txt1); lcd_out(1,1,"FLOWRATE: "); lcd_out_cp(txt1); delay_ms(500); lcd_cmd(_lcd_cursor_off); } while(1); }
// Lcd pinout settings
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D4 at RD4_bit;
// Pin direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISD7_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D4_Direction at TRISD4_bit;
volatile int NbTopsFan;
void rpm(){
NbTopsFan++; //This function measures the rising and falling edge of the
} //hall effect sensors signal
unsigned int temp_res;
char txt1[15];
float calc;
void main() {
TRISB=0;
LCD_Init();
TRISA=0xFF;
PORTA=1 ;
//Spec :Fosc/64, Use ADC Ch.0 with Ref Vdd&Vss, Right justified
ADCON0=0b10001001; //0b10_000_0_x_1
ADCON1=0b11000100; //0b1_1_xx_1110
ADC_Init();
do {
temp_res = ADC_Read(0); // Get 10-bit results of AD conversion
NbTopsFan = 0;
delay_ms(2000);
calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate //calculation to show flow per minute
floattostr(calc,txt1);
lcd_out(1,1,"FLOWRATE: ");
lcd_out_cp(txt1);
delay_ms(500);
lcd_cmd(_lcd_cursor_off);
} while(1);
}
#define _LEGACY_HEADERS
#include <htc.h>
// Setup configuration bits
__CONFIG (EC & WDTDIS & PWRTDIS & UNPROTECT & MCLREN & BORDIS & FCMEN & IESOEN);
volatile int tenMillSecCounter=0; // incremented every 10mSec
static volatile int tenMillSecCounter2=0; // incremented every 10mSec - used for delays
static volatile int revolutionTimer=0; // used for counting revs/min or motor
volatile int tenthsSecond=0; // incremented every tenth of a second
volatile int second=0; // incremeneted every second
// Timer 0 is programmed to interrupt every 10mSeconds
// T0 clock is FOSC/4 = 200000
// with 256 prescaler decrements 2000000/256 times / second
// to get an interrupt every T mSec the calculation for TMR0 overflow from 0xFF to 0 is
// count = 255 - T * 2000/256
// i.e. for 10mSec counter is
#define tenMillSec 177
static void interrupt isr(void)
{
if (T0IF) // A TMR0 interupt occurred
{
TMR0=tenMillSec; // increment counters every 10 mSec
tenMillSecCounter2++;
revolutionTimer++;
if((++tenMillSecCounter % 10)==0) tenthsSecond++;
if((tenMillSecCounter % 100)==0) { second++; tenMillSecCounter=0; }
}
T0IF=0; // clear TMR0 interrupt flag
}
// delay for count tenths of a second
void tenthsSecondDelay(int count)
{
tenMillSecCounter2=0; // zero counter
while( tenMillSecCounter2 < (count*10)) ; // wait
}
// delay for count seconds
void secondDelay(int count)
{
tenMillSecCounter2=0; // zero counter
while( tenMillSecCounter2 < (count*100)) ; // wait
}
// initalise clock, set port A for digital input, set up timer 0, etc
void systemInitialise(void)
{
OSCCON=0x70; // Fosc use oscillator 8MHz
ANSEL=0; // set digital inputs
// PORTB PULL-UP DISABLED, TMR0 Timer mode Clock Source Select bit FOSC/4,
// Prescaler is assigned to the Timer0 module & TMR0 RATE 1:256
OPTION=0x87;
TMR0=tenMillSec; // initialise timer 0 counter
T0IE = 1; // enable interrupt on TMR0 overflow from 0xFF to 0
GIE = 1; // Global interrupt enable
}
// initialise Timer 1 to count revolutions of the motor
void REVcounterInitialise(void)
{
TRISC5=1; // RC5 is optical interrupter input
T1CON=0x07; // set Timer 1 prescaler to 1:2, Select external clock source, Timer 1 on
TMR1L=0; // clear timer 1 counter
TMR1H=0;
revolutionTimer=0; // clear rev timer
}
// read timer 1 to get revs/min of motor
int REVperMinute(void)
{
int rpm = (TMR1H << 8) + TMR1L; // read timer 1 counter
// calculate RPM - revolutionTimer is in 1/100's of a second
rpm = (int) (rpm * 6000L / revolutionTimer); // calculate RPM
revolutionTimer=0; // clear REV timer
TMR1L=0; // clear timer 1 counter
TMR1H=0;
return rpm;
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?