Guide on flow sensor application


Results 1 to 9 of 9

Threaded View

  1. #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 : 0

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