NEED HELP URGENTLY! flow meter that displays litres per hour

Status
Not open for further replies.

moad

Newbie level 5
Joined
Jan 30, 2015
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
113
for the past 2 week iv just started my first ever project to make a c program on the software called mikroc where i would get pulses in from the flow meter and calculate the flow rate of how much litres flows every hour which then outputs to the lcd, however, after using a timer of 100ms and an interrupt that occurs that does the calculations and displays on the screen. i get lots of 0's on lcd and when the water flows through the meter...i get a change of 1 . thats all. please guys i would very much appreciate it if i get help on this. also how do i read the input signal becuase i may have done it wrong. the input signal is connected to RB7 as i have chaned the interrupt pin.

pic16f877a datasheet: **broken link removed** water flow meter datasheet: **broken link removed**

this is the code:

Code:
//Prescaler 1:4; TMR1 Preload = 15536; Actual Interrupt Time : 100 ms
volatile unsigned int val;
char num [20];
int calc;
void InitTimer1(){
  T1CON         = 0x21;
  TMR1IF_bit         = 0;
  TMR1H         = 0x3C;
  TMR1L         = 0xB0;
  TMR1IE_bit         = 1;
  INTCON         = 0xC8;
}

void Interrupt(){
  if ((TMR1IF_bit) && (RBIF_bit)){
    TMR1IF_bit = 0;
    RBIF_bit   = 0;
    TMR1H         = 0x3C;
    TMR1L         = 0xB0;
    val= PORTB.F7;                //read the input signal and assign it to val
    Calc = (val * 60 / 7.5);          //calculations for the flow rate per hour
    longinttostrwithzeros(calc,num);       //displaying on screen
    Lcd_Out(1, 3, num );
  }
}


void main() {
     Lcd_Init();
     TRISB=0b10000000;       //initiallizing rb7 as the interrupt
     PORTB=0;
     InitTimer1();            //100ms timer
}
 
Last edited by a moderator:

hello,

you must separate and treat appart the 2 sources of interrupt

With RB7 interrupt, you must cumulate the number of event (pulse) into your variable Nb_of_pulses
and when Timer1 interrupt occurs , read the number of pulse into Nb_of_pulses
save it in another variable, ie into Amount_Pulses_per_100mS , zeroed Nb_of_pulses
and arm a flag ie; Flag to tell to the main program , a calculus is ready

Into your main programme
inside an infinite loop
loop:
just check if Flag is ON
if (FLag==1)
{
display the Amount_pulses_per_100mS on your LCD
Raz the Flag
}
goto loop

maybe you have better to use 1 sec instead of 100mS as timer1 delay...

What is the max frequency of flowmeter pulses ?
if too high, need to use Timer0 counter instead of RB7 ...
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…