Shop OBEX P1 Docs P2 Docs Learn Events
Can P Basic Math be done on the fly with RC TIME command this is for Tracy All — Parallax Forums

Can P Basic Math be done on the fly with RC TIME command this is for Tracy All

sam_sam_samsam_sam_sam Posts: 2,286
edited 2009-08-11 03:29 in General Discussion
Hi EveryOne

This is a project that I have been ·ask to do·by employer

As of right now I can not give all of the details.......................
................·but when the Project is done I will share with all of you on the Forum


I know that I have·This a another Post but this is a different question
http://forums.parallax.com/showthread.php?p=804156

http://forums.parallax.com/showthread.php?p=804554


Here is the problem that I now have this part resolved but there is a new problem
·
Silo Hold 50,000 Pounds need to keep track of usage need smallest error possible
·
I was using the Seconds */309 to get the Flow Rate··
·
300 Pounds of Sand
248 Seconds to run the·Sand out of hopper
Which give you 1.21 pound per sec or 72.6 per minute
·
So I took 256 x 1.21 = 309.76 rounded to 310

The problem now is that the flow rate changes depending on air flow setting
is there a way to adj the . value on the fly with RC TIME command

.xxxxxxxxxxxx * 65536 base on where RC TIME value is

x value range is from .1xx to .9xx would be nice if this can be done

x is value that want to adj how would I set this up IF this can be done


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

·
·
·
·
Sam

Post Edited (sam_sam_sam) : 8/11/2009 3:15:10 AM GMT

Comments

  • phil kennyphil kenny Posts: 233
    edited 2009-07-31 22:48
    What sort of resolution do you want for X?

    The Stamp only has integer arithmetic. Depending on the
    accuracy you need for the final answer, you may have to
    use double precision arithmetic. Tracy Allen has some of
    these extended math routines posted on his web site.

    You may have to change the Stamp from a BS2 to a BS2P
    in order to have enough room.

    phil
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2009-08-01 22:19
    Sam, I'm not sure from your description what you need to adjust.

    But suppose you have a fraction N/D<1, and what you really want to compute is x*N/D. That is, the result is a certain proportion of x. N and D may be variables (dependent on air flow?) so you have to compute it at run time, not in advance as a constant. The Stamp can calculate a number, f, such that you can replace x*N/D with x ** f. That will be probably the most accurate way to do it on the Stamp. Here is the algorithm that computes f:

    'from http://www.emesys.com/BS2math2.htm#binary_long
    ' enter with N<32768, D<32768, N<D
    '---------binary division loop-----------
    for J=15 to 0               ' 16 bits 
    N=N//D<<1                   ' remainder*2 
    F.bit0(J)=N/D               ' next bit 
    next
       '----------------------------------------
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-08-02 00:24
    Tracy Allen

    Thank You for your help in this Project

    ·I think This is just what I was look for

    I change the value of N and F gave me a roughly the value that would except

    If I use the out put from·the· RC TIME command· which the output from that would be =·N
    D = 1% of 65536 which =·655
    F =· value .1###########· to .9###########····· ·which is what I want to adj on the fly

    I hope that you can understand what I want do

    300 pound / 248 seconds = 1.209677411935...........

    1 +· .209677411935·x 65536 = 13741..>· This is·what I want basicly dial this·
    in so I do not have reprogram the Basic Stamp each time the Flow rate changes

    500 pounds / 348 = 1.436781609195................

    1 +· .436781609195x 65536 = 28625..> ·and so on

    ·Will this work Or am I completely wrong with·what I have here



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

    J·· VAR··· Byte
    N·· VAR··· Word
    D·· VAR··· Word
    F·· VAR··· Word
    ·'from http://www.emesys.com/BS2math2.htm#binary_long
    ' enter with N<32768, D<32768, N<D
    '
    binary division loop
    N = 64000
    D = 655

    FOR J=15 TO 0·············· ' 16 bits
    N=N//D<<1·················· ' remainder*2
    F.BIT0(J)=N/D·············· ' next bit
    NEXT

    ·DEBUG HOME,DEC5 ? N, CR, DEC5 ? D, CR, DEC5 ? F, CR
    ·

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

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 8/2/2009 9:20:21 PM GMT
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2009-08-02 16:50
    Hi Sam, Can you please give it another try at explaining? Lay it out in pseudo-code.

    It won't work as you have it. Note that the comment at the start of the code requires N<32768 and N<D, but you have N=64000 and D=655. Why those values? Also in your example you have 1.21 * 65536 = 13741 and 1.41 * 65536 = 28625, but neither of those is correct, even mod 65536. Huh?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-08-02 20:07
    In the post above I left out a step in·how·I got this value· I edit that post ·for you understand what i am trying to do
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    RC              PIN     7
    result          VAR     Word
    
    Main:
      DO
        HIGH RC                             ' charge the cap
        PAUSE 1                             '   for 1 ms
        RCTIME RC, 1, [color=red]result[/color]                ' measure RC discharge time
        DEBUG HOME, DEC result              ' display value
        PAUSE 50
      LOOP
      END
    

    I want to take the result value and change ** ---- value on the fly if this can be done
    the problem now is that when the flow rate changes I have reload the Basic stamp with the new value I want·to use·a pot to change
    this value·
    Metered:
     
     GOSUB ReadRam
     
    PD = PDsecs + (PDsecs **  [color=red]28625[/color])
    SL = SLsecs + (SLsecs **  [color=red]28625[/color])
    
     
    IF oldsecs <> secs THEN
       oldsecs = secs
     
       PDSecs = PDSecs + 1
       SLSecs = SLSecs + 1
     
    ENDIF
     
    GOSUB WriteRam
     
    RETURN
    

    ·

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

    ·
    ·
    ·
    ·
    Sam
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2009-08-02 22:14
    OK, so the result from RCTIME is somehow related to air flow and then to (pounds per second). Does result have a maximum and a minimum value? Does it need to be calibrated?

    We know that pounds per second is a number around 1.2 or 1.4, but what is the full expected range?
    (pounds) = (seconds) * (pounds per second)

    But how do you figure this:
    (pounds per second) = function_of (result)?

    For example, if result=12345, what is (pounds per second)?
    or if result = 54321, what is it?
    Maybe there is a math formula, or maybe it is empirical, or maybe it needs a table of values to figure it out.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-08-02 23:48
    Tracy Allen

    Does result have a maximum and a minimum value?· Yes

    1.1 to 1.9 pound per seconds is the excepted value

    ·Does it need to be calibrated? Yes some what in that if the pound per second is way·off then the amount in the Silo will be way·off

    So the result from RCTIME is somehow related to air flow and then to (pounds per second).

    ·Yes in·that I would like to adj the Flow rate value

    I will still would have to figure this part·out manually

    Pound / seconds = pounds per seconds then 1 + (. some value) ·x 655365 = P Basic math value

    Then take this value and basically dial this in as the new value

    ·That would be ADJ by RCTIME value so I would not need to reload the Basic Stamp Again with this new pound per second value again
    ·
    ·
    We still have to check the flow rate from the hopper to see if that value· is still right
    I can not change that part


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

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 8/3/2009 12:27:12 AM GMT
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-08-03 01:23
    Tracy Allan

    I wrote this Demo to test the end value of 50,000 pound which is how much the Silo hold to see how far off the actual value versus the Basic Stamp
    value is

    I tried this Demo to see if I could use the RCTIME to do what I have in mind and it seem to work OK

    Please give your thoughts on what·I have here if you see any problems with what I have in the Demo

    Please feel free to let know what changes·need to make this work

    Thank You for all of your help in this Project this has help me a lot I have learned a lot about programing

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

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 8/3/2009 1:35:13 AM GMT
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2009-08-03 02:50
    I see the RCTIME, and there is a capacitor, but what is it hooked up to? What is it measuring?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2009-08-03 22:46
    Okay, after the PM I understand better what is going on. You have a resistor variable from 1 kOhm to 11 kOhm in parallel with a 0.1 uF capacitor. The corresponding RCTIME values will fall approximately in the range of 70 to 740. You need to map that range into a multiplier with a decimal fraction of of 0.0 to 1.0, or in Stampese a ** multiplier from 0 to 65535.

    Here are the calibration steps.
    1) Have PBASIC find the RCTIME value at maximum resistance, call it RTmax
    2) ditto the RCTIME value at minimum resistance, call it RTmin
    Those two values will be approximately 740 and 70.
    3) Have PBASIC calculate the difference RTdiff = RTmax - RTmin, approximately 670.
    4) Turn the dial to an intermediate setting, and have PBASIC measure the RCTIME, call it RCset
    5) run the division algorithm:
    'from http://www.emesys.com/BS2math2.htm#binary_long
    ' enter with N<32768, D<32768, N<D
    '---------binary division loop-----------
    N = RCset - RCmin MAX RCdiff
    D = RCdiff
    for J=15 to 0               ' 16 bits 
    N=N//D<<1                   ' remainder*2 
    F.bit0(J)=N/D               ' next bit 
    next
       '----------------------------------------
    



    Now, the Word value f contains the multiplier you need to use in
    mass = seconds + (seconds ** f)
    The overall result is something in the calculator range of 1.0 to 2.0 as the mass per second conversion.

    You could calibrate the dial of the potentiometer in units from 1.0 to 2.0. If you want to translate the f factor into a decimal fraction to display on your LCD screen, use,
    x = f ** 1000
    DEBUG "1.", DEC3 x ' or the LCD equivalent.

    Note that some of the variables are temporary and can be recycled.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-08-05 02:30
    Here is the problem that I now have this part resolved but there is a new problem
    ·
    Silo Hold 50,000 Pounds need to keep track of usage need smallest error possible
    ·
    I was using the Seconds */309 to get the Flow Rate··
    ·
    300 Pounds of Sand
    248 Seconds to run the·Sand out of hopper
    Which give you 1.21 pound per sec or 72.6 per minute
    ·
    So I took 256 x 1.21 = 309.76 rounded to 310

    The problem now is that the flow rate changes depending on air flow setting
    is there a way to adj the . value on the fly with RC TIME command

    .xxxxxxxxxxxx * 65536 base on where RC TIME value is

    x value range is from .1xx to .9xx would be nice if this can be done

    x is value that want to adj how would I set this up IF this can be done

    This· give me·the range that I want and it tell what the flow rate pounds per seconds

    I want to thank Tracy Allen for all of his help in this project

    and by this doing this project i have learned a lot about programing a Basic Stamp

    I also want to Thank all of·you·that have replied and offer help in this project
    ' =========================================================================
    '
    '   File...... Multiplier with a decimal fraction a value from 0.0 TO 1.0
    '   Purpose... To use a POT to adj a value on the fly from .000 to .999
    '   Author.... Tracy Allen
    '   E-mail.... [url=http://www.emesys.com/]www.emesys.com[/url]
    '   Started... 8-2-09
    '   Updated...
    '
    '   {$STAMP BS2}
    '   {$PBASIC 2.5}
    '
    ' =========================================================================
    'from [url=http:///BS2math2.htm#binary_long]http:///BS2math2.htm#binary_long[/url]
    
    ' -----[noparse][[/noparse] Program Description ]---------------------------------------------
    '
    '
    ' Suppose you have a fraction N/D<1, AND what you really want TO compute is x*N/D.
    ' That is, the result is a certain proportion of x. N AND D may be variables
    ' (dependent ON air flow?) so you have TO compute it at run time, NOT in advance as
    ' a constant. The Stamp can calculate a number, f,
    ' such that you can replace x*N/D with x ** f.
    ' That will be probably the most accurate way TO DO it ON the Stamp.
    ' Here is the algorithm that computes f:
    
    '
    ' Part 1
    '
    ' You have a resistor variable from 1 kOhm TO 11 kOhm in parallel with a 0.1 uF capacitor.
    ' The corresponding RCTIME values will fall approximately in the range of 70 TO 740.
    ' You need TO map that range into a multiplier with a decimal fraction of of 0.0 TO 1.0,
    ' OR in Stampese a ** multiplier from 0 TO 65535.
    'Here are the calibration steps.
    '
    '1) Have PBASIC find the RCTIME value at maximum resistance, call it RTmax
    '2) ditto the RCTIME value at minimum resistance, call it RTmin
    '   Those two values will be approximately 740 AND 70.
    '3) Have PBASIC calculate the difference RTdiff = RTmax - RTmin, approximately 670.
    '4) Turn the dial TO an intermediate setting, AND have PBASIC measure the RCTIME,
    '   call it RCset
    '5) run the division algorithm:
    '
    ' enter with N<32768, D<32768, N<D
    '
    '   Part 2
    '
    ' Now, the Word value f contains the multiplier you need TO use in
    ' mass = seconds + (seconds ** f)
    ' The overall result is something in the calculator range of 1.0 TO 2.0 as
    ' the mass per second conversion.
    ' You could calibrate the dial of the potentiometer in units from 1.0 TO 2.0.
    ' IF you want TO translate the f factor into a decimal fraction TO display ON
    ' your LCD screen, use,
    ' x = f ** 1000
    ' DEBUG CR, DEC RC_Set, TAB, "1.", DEC3 X, CLREOL
    ' Note that is (Tab) to the next column for DEBUG .
    '
    ' -----[noparse][[/noparse] Revision History ]------------------------------------------------
    '
    '
    ' -----[noparse][[/noparse] I/O Definitions ]-------------------------------------------------
     
    RC              PIN     15
                  
    ' -----[noparse][[/noparse] Constants ]-------------------------------------------------------
    
    RC_Diff         CON     600
    RC_Max          CON     613
    RC_Min          CON     13
     
    ' -----[noparse][[/noparse] Variables ]-------------------------------------------------------
    
    J               VAR     Byte
    N               VAR     Word
    D               VAR     Word
    F               VAR     Word
    x               VAR     Word
    RC_Set          VAR     Word
     
    ' -----[noparse][[/noparse] EEPROM Data ]-----------------------------------------------------
    
    ' -----[noparse][[/noparse] Initialization ]--------------------------------------------------
    
    ' -----[noparse][[/noparse] Program Code ]----------------------------------------------------
      DO
    
        Main:
     
        HIGH RC                                            ' charge the cap
        PAUSE 1                                            ' for 1 ms
        RCTIME RC, 1, RC_SET                               ' measure RC discharge time
        PAUSE 50
     
     N = RC_set - RC_min MAX RC_diff                       ' binary division loop
     D = RC_diff
    
    FOR J=15 TO 0               ' 16 bits
    N=N//D<<1                   ' remainder*2
    F.BIT0(J)=N/D               ' next bit
     
    NEXT
     
     DEBUG HOME, DEC RC_Set, TAB, "1.", DEC3 X, CLREOL
     x = f ** 1000
     
      LOOP
    
    ' -----[noparse][[/noparse] Subroutines ]---------------------------------------------------
    

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

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 8/5/2009 3:04:20 AM GMT
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-08-11 03:29
    The new problem is that we are putting a Air Regulator on this Sand Blast Hopper

    Because the·Air Flow Rate now is Controlled with a Ball Value right now

    the Flow Rate is suppose to be 300 CFM @ 120 PSI· MAX·and the compressor that we are using put out 700 CFM @ 140 PSI

    and the Flow Rate may below 1 pound per second What would I need to change to make this work with less than 1 pound per seconds

    I would like to use· **· instead of */ if this can be done

    Just so I know how to do it how would ·you do it if your Flow Rate is more than 2 pounds per second



    The person that works with this Sand Blaster will have find the right flow rate for the best work to be done

    Then I can take this New Flow Rate and go from there


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

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 8/11/2009 3:38:02 AM GMT
Sign In or Register to comment.