Shop OBEX P1 Docs P2 Docs Learn Events
How do you take a value from a Scale doing P Basic Math and from a Flow Meter — Parallax Forums

How do you take a value from a Scale doing P Basic Math and from a Flow Meter

sam_sam_samsam_sam_sam Posts: 2,286
edited 2009-06-21 20:20 in General Discussion
Let say that you have a value from a scale and you take the value which has done with PBasic math
and you get a value................

product·········· VAR···· Word
Water············ VAR···· Word
Pulses··········· VAR···· Word
FMeter·········· VAR···· Word


Which would···· Water = Product */34·········· ·' This will tell you how many gallons of water
···
............You need so many Pulses for so many Gallons of water which has done with PBasic math


· Which would· ·Pulses = Water· */20070····· ' This will tell you how many Pulses you need for so many gallons


This is the part that is taken·from the data from the Scale and use to know how many gallons of water need


Now the Pulses from the Flow Meter are going to be counted with the Basic Stamp

·Would you count the Pulses from the Flow Meter· with the PULSIN Command

I want take the PULSIN value and compare this to the Pulses value and when they are the same then we are done

I am not sure how to write this part of the·routine

Can any one help me with problem


·

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·idea.gif·that you may have and all of your time finding them

·
·
·
·
Sam

Post Edited (sam_sam_sam) : 5/18/2009 1:12:42 AM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-16 04:07
    You can't really do it with PULSIN. PULSIN counts the number of pulses that occur in a specified time interval which is not what you want.

    How long are the pulses and how quickly do they come in? Basically, you are going to have to count them yourself like:
    waitFor1:
       if inputpin = 0 then goto waitFor1   ' Wait for a high
    waitFor0:
       if inputpin = 1 then goto waitFor0   ' Wait for a low
       Pulses = Pulses - 1
       if Pulses > 0 then goto waitFor1   ' More pulses left to count
    ' Here the pulse count has become zero.  We can probably turn off the water.
    
    
  • stamptrolstamptrol Posts: 1,731
    edited 2009-05-16 11:47
    Sam,

    Do you know how many pulses per second you'll be seeing? In my experience, if they get to 30 - 40 pulses per second, the Stamp won't be able to keep up, especially if the program has to do other things.

    What you may have to do is have a dedicated Stamp to count pulses which the other Stamp can interrogate when it wants to check.

    Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • Tracy AllenTracy Allen Posts: 6,667
    edited 2009-05-16 15:53
    Counting for flow meters, anemometers, traffic counters and rain gages can be problematic on the Stamp. I have run into that problem too when several sensors of that type have to be monitored. I made an 8-pin PIC accessory chip, that counts events on 5 of its input pins, complete with debouncing. The Stamp from time to time reads out (SERIN) the 5 words of count data. You can see the instruction sheet here.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • FranklinFranklin Posts: 4,747
    edited 2009-05-16 16:49
    Tracy, nice chip. I've been looking for something like that for a while. I have a tiny13 doing it for one channel now but this is nice.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • stamptrolstamptrol Posts: 1,731
    edited 2009-05-16 16:50
    Tracy's solution is an ideal one for your flowmeter application!

    Tom

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-16 20:48
    Mike

    Thank You for sharing the routine

    waitFor1:
    ···if·inputpin·=·0·then·goto·waitFor1·············· '·Wait·for·a·high
    waitFor0:
    ···if·inputpin·=·1·then·goto·waitFor0············· ·'·Wait·for·a·low


    ···Pulses·=·Pulses·-·1

    ···if·Pulses·>·0·then·goto·waitFor1················· '·More·pulses·left·to·count


    '·Here·the·pulse·count·has·become·zero.··We·can·probably·turn·off·the·water.


    Tom Sisk, ·Stephen

    Thank You for replys this will help alot

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 5/16/2009 8:53:32 PM GMT
  • Tracy AllenTracy Allen Posts: 6,667
    edited 2009-05-17 02:20
    The PIC I have might not be so good for what you want to do. Ii just counts pulses over a fixed time intervals (like the PBASIC COUNT command) and will not automatically flag when the flow has reached a desired limit.

    In PM you told me there will be 78.4 pulses per gallon and you are looking at a flow rate of about 30 gallons per minute. That will be 2352 pulses per minute, or about 40 per second. That gives about 25 milliseconds from pulse to pulse for the Stamp to do processing. That is really quite a bit of time if the Stamp does not have much else to do while counting. Mike's code will work, or for variation here is another kind that uses state machine logic.
    xbit VAR Bit  ' current state of input pin
    x0 VAR Bit   ' previous state
    xx VAR Bit   ' change of state from high to low
    N VAR Word ' number of pulses
    
    N=0
    DO
      xbit = in0
      xx = xbit ^ x0 & x0
      x0 = xbit
      N = N + xx
    LOOP UNTIL N = pulsesNeeded
    



    I figure that loop will execute in about 3 milliseconds, so that is plenty of time within the 25 ms allowed. It actually has to catch both the opening and the closing of the switch, within the 25 millisecond period.

    Some new flowmeters use optical or hall effect sensors that have no bounce, however, some older flowmeters have long reed relays that are notorious for bounce. If bounce is an issue, additional tests have to be put in the loop to be sure that the switch is stable.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-17 15:30
    Here is the link to the Flow Meter that we are thinking about using

    http://www.koboldusa.com/datasheet/DRB-DPE_datasheet.pdf

    Electrical Specifications
    Frequency Output
    Output Type:
    PNP open collector, 25 mA max.
    Power Requirement: 14-28 VDC
    Compact Electronics
    Output Type:
    4-20 mA, 3-wire & PNP switch or 2 PNP switches
    Switch Rating: 300 mA Max. short circuit protected flow switch or frequency transmitter

    6.6-65 DRB-1165 DRB-1265 N8=1-1/2” NPT

    Part Number 807.037=Mating 4-pin Micro-DC plug with 6 ft. cable for output F300, L342, L343 & Z340


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 5/17/2009 3:41:19 PM GMT
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-17 17:26
    Tracy Allen

    Can you Please·explain one line to me so I can understand how this routine works the part in RED Code Wise
    Could you Please give an example like they have in the two example below

    Thank You all of your help in this project

    '·· {$STAMP BS2}
    '·· {$PBASIC 2.5}


    xbit···· VAR··· Bit············································· ··· ·'·current·state·of·input·pin
    x0····· ·VAR··· Bit·················································· '·previous·state
    xx····· ·VAR·· ·Bit·················································· '·change·of·state·from·high·to·low
    N······ ·VAR··· Word··············································· '·number·of·pulses

    N=0
    DO
    ··xbit·=·in0

    ' I understand what they have here as far as the truth table XOR

    '============================================================================================
    '························· ^ Bitwise XOR
    ' The Exclusive OR operator (|) returns the bitwise exclusive OR of two values.
    '· Each Bit of the values is subject TO the following logic:
    '
    '··· 0 ^ 0 = 0
    '··· 0 ^ 1 = 1
    '··· 1 ^ 0 = 1
    '··· 1 ^ 1 = 0
    '
    ' The result returned by ^ will contain 1s in any Bit positions in which one OR the other
    ' (but NOT both) INPUT values contain 1s.

    '
    'Main:
    '· value1 = %00001111
    '· value2 = %10101001
    ' ·result = value1 ^ value2

    '
    ·' DEBUG HOME, BIN8 ? value1,
    ·'··············· · · BIN8 ? value2,
    ·'·············· ··· ·BIN8 ? result······· ' Show OR result (%10100110)


    ·'
    '============================================================================================

    ''& Bitwise AND
    'The AND (&) operator returns the bitwise AND of two values.
    ' Each bit of the values is subject to the following logic:
    '
    '
    '··· 0 & 0 = 0
    '··· 0 & 1 = 0
    '··· 1 & 0 = 0
    '··· 1 & 1 = 1
    '
    '
    'The result returned by & will contain 1s in only those bit
    'positions in which both input values contain 1s.


    value1 = %00001111································································· %00001111
    · value2 = %10101101································································%10101101
    · result = value1 & value2·························································· (%00001101


    · DEBUG HOME, BIN8 ? value1,································ ' Show AND result (%00001101)
    ·················· · BIN8 ? Value2,
    ···················· BIN9 ? result



    '


    '=================================================================================================


    ··xx·=·xbit·^·x0·&·x0

    ··x0·=·xbit
    ··N·=·N·+·xx
    ·················
    ·· DEBUG HOME, DEC ? xbit,
    ···················· ·DEC ? xx,
    ···················· ·DEC ? x0,
    ···················· ·DEC ? N

    LOOP·UNTIL·N·=· 30············································ ··'·pulses Needed



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 5/17/2009 6:38:15 PM GMT
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-17 19:50
    Tracy Allen

    Here Is a Demo From what you have in your Post

    Which work very well

    Thank You for the example

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-17 21:30
    Mike Green

    Here is the Demo that I wrote to use what you have Posted

    Thank You for sharing the code and your help in this Project



    When we order the Flow Meter and come in

    ·I will try both Demo and see which one work the best·for the·Code Routine that·I still have to·write


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 5/17/2009 9:48:31 PM GMT
  • Tracy AllenTracy Allen Posts: 6,667
    edited 2009-05-18 16:03
    That flowmeter, the link you posted, should work fine without any special debouncing. It uses a Hall effect sensor coupled to the magnets in the impeller.

    xx = xbit ^ x0 & x0
    



    The value of xx will be either 1 or 0, depending on the current value of the input (xbit) and the prior value of the input (x0).
    xx will be 1 only if there is a change from prior time to now (xbit ^ x0 = 1) AND the prior time it was high ( & x0). So xx will be 1 only when the input changes from 1 to 0. Note that the statement x0 = xbit subsequently updates the prior value. The DO:LOOP can execute many many times with xx=0. It is only during one time around that it becomes xx=1, when the input transitions from 1-->0.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 5/18/2009 4:47:55 PM GMT
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-19 01:02
    Tracy Allen
    Thank you for taking the time to explain this to me and all of your help in this project

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-06-21 20:20
    Update

    The company that I work for has put this Project on hold for now I will keep you posted if this changes

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam
Sign In or Register to comment.