Guide on flow sensor application


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223

    Default Guide on flow sensor application

    Hi everyone, I have G1'1/4 Water Flow sensor from (http://www.seeedstudio.com/wiki/inde...er_Flow_sensor). As I understand I have to count the output pulse using RA4/TOCK1 using PIC16F877A(20Mz).
    My question are as follow:
    1. RA4/TOCK1 is using TIMER0 can I use TIMER1 to count up to 65535?
    2. What is the best hardware setup to read pulses of 4 water flow sensors...is it possible 4 sensors in 1 pic16F877A?

    Sorry if my question are not too clear, I really appreciate any help and guide on this..

    Regards,
    tacbanon

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Guide on flow sensor application

    Hi,

    1) Sure, configure TMR1 as a counter and feed the signal to the T1CKI (Timer 1 Clock Input) pin instead of T0CKI.
    2) It's possible for sure but how to do it "the best way" depends on the frequency of the incoming pulses from the sensors and on what else the PIC needs to do. For example, use TMR0 and TMR1 to count pulses from two of the sensors and use two IOC-pins for the other two. Another option is to use four IOC-pins, one for each sensor. Another is to use four external F/V converter chips and feed the output voltage from each to the ADC of the PIC. Yet another is to use the count command on four pins in sequence.

    /Henrik.

    EDIT: OK, just saw that the output frequency is fairly low. ~45Hz at full flow, dutycycle of 40-60%. So, as long as you poll the inputs at at least ~120Hz (timer interrupt for example) you should be able to count pulses in software.
    Last edited by HenrikOlsson; - 8th March 2013 at 10:03.

  3. #3
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Guide on flow sensor application

    Hello Henrik,
    Quote Originally Posted by HenrikOlsson View Post
    Another option is to use four IOC-pins, one for each sensor.
    Is this mean that I can use similar approach like in this link? (http://www.picbasic.co.uk/forum/show...519#post117519)

    Regards,
    tacbanon

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Guide on flow sensor application

    Not sure.
    In that thread it looks like you're using the external interrupts (INT0-INT2) but the 877A only has one "normal" external interrupt (INT0). However it does have four Interrupt on change pins (PortB.4-7) which you could use.

    Or, like I said, you might get away with simply polling the inputs in a loop. As long as you read the inputs atleast ~120 times per second you shouldn't miss any pulses.

    /Henrik.

  5. #5
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Guide on flow sensor application

    Thank you Henrik, I will try to work on it and post here in case I have some inquiries.

    Regards,
    tacbanon

  6. #6
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Guide on flow sensor application

    Hi I'm back...My first attempt for 1 flow sensor is I tried to count the pulse similar to a switch button....but still not really sure if I'm doing it right. If its fine how do I get flow rate?...kindly check the code I'm using.
    Code:
    INCLUDE "MODEDEFS.BAS"       ' Include Shiftin/out modes
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"  ' Include if using PBP interrupts
     
    ;-- Define LCD connections -- (change these to match your hardware) ------------
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 0
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 5
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 4
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50
    PAUSE 100
    
    TRISA = %00000000               ; set PORTA to output pins
    PortA = %00000000               ; set to PORTA low
    TRISB = %10000000               ; set PORTB to B7 input pin rest output pins
    PortB = %00000000               ; set to PORTB low
    TRISC = %10000000               ; set PORTD to output pins
    PORTC = %00000000 
    TRISD = %10000000               ; set PORTD to output pins
    PORTD = %00000000               ; set to PORTD low
    LCDOUT  $FE,1                   ; Initialize the LCD
    pause 200                       ; pause 2 milisec
    
    OPTION_REG = $7f  'enable pull offs
    '--variables init
    flag1 var bit
    flag1 = 0
    c var byte
    c = 0
    cnt1 var word
    cnt1 = 0
    StatLed var PORTA.0
    StatLed = 0
    
    But0 var PortB.7
    But0 = 0
    '--LCD line
    ln1 con $80
    ln2 con $C0
    CS  con 1 
    
    SerialInput var byte[50]  
    Serialdata var byte  
    
    ; setup serial port line for transmition   
    
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 1
    DEFINE HSER_BAUD 9600
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically    
    RCIF       VAR     PIR1.5     ' Receive  interrupt flag (1=full , 0=empty)
    TXIF       VAR     PIR1.4     ' Transmit interrupt flag (1=empty, 0=full)
    '------------------------------------------------------Transmition-------------
    
    ; create the transmition interrupt
            '((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _ToggleLED1,   PBP,  yes
            INT_Handler   RX_INT,    _Getbytes,    PBP,  no
             endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    ;
    T1CON = $31                ; Prescaler = 8, TMR1ON
    @ INT_ENABLE  TMR1_INT     ; enable Timer 1 interrupts
    @ INT_ENABLE  RX_INT
    '((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
    ;------------------------------------------------------------------------
    
    
    
    Hserout ["Flow Sensor Test",13]
    pause 1000
    
    Main:
    PortB.7 = 0 
    LCDOUT $FE,ln1,"Flow Sensor Test"
    LCDOUT $FE,ln2 ,"Cnt: ",dec3 cnt1
    Pause 25
    IF But0 = 0 then
    cnt1 = cnt1+1
       While But0 = 0:Wend   
       If flag1 = 0 then
        HSEROUT ["Counter:",Dec3 cnt1,13]
        flag1 = 1
        else
        flag1 = 0
       Endif
    else
    endif
    Goto main
    
    
    '(((((((((((((((((((((((((This is a preparation for PC interface))))))))))))))))
    
    Getbytes:  
            
           While RCIF = 1     ' clear the buffer
           c = c + 1
           Hserin [Serialdata]
           select case Serialdata          ' What to do with that data???
                                    
               case "A"            ' User selection 
                    HSEROUT ["Option A",13] ' take it out 
               case "B"
                    HSEROUT ["Option B",13] ' take it out 
               case "C"
                    HSEROUT ["Option C",13] ' take it out            
               case "*"
                    'HSEROUT ["This is it! > ",13] ' take it out
                    SerialInput[c] =" "  
               case else                       
                   SerialInput[c] = Serialdata          
             End select            
                
           Wend
    
    @ INT_RETURN
    '*******************************************************************************
    
    
    ToggleLED1:
    
    'Toggle statLed 
    
    @ INT_RETURN
    I also attached some pics about my hardware setup..
    Appreciate any input and time...

    Regards,
    tacbanon
    Attached Images Attached Images   

Similar Threads

  1. Microchip Tips ‘N Tricks Guide
    By Heckler in forum Documentation
    Replies: 1
    Last Post: - 6th January 2015, 05:24
  2. fuel flow sensor?
    By droptail in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 20th May 2009, 04:01
  3. Mass Air Flow Sensor Data
    By jrudd in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st January 2009, 09:35
  4. hot water flow sensor
    By jessey in forum Off Topic
    Replies: 16
    Last Post: - 24th January 2007, 04:05
  5. Windows XP API guide
    By mister_e in forum Off Topic
    Replies: 2
    Last Post: - 9th July 2006, 19:55

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts