Math help please!!!


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Oops again.

    That won't work either, it'll overflow less than half way thru the range.

    Still playing with it.

    Can you use just Hundredths, instead of Thousanths. (2 decimal places)?
    <br>
    DT

  2. #2
    Join Date
    Dec 2003
    Location
    WI
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    I really don't need that kind of resolution so tenths is fine. I was thinking about this before that the thousands digit is in the mud anyway. I might just add a FPU chip to this project and call it done.......

    Jason

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I might just add a FPU chip to this project and call it done.......
    No, No don't do that. Just a few modifications and you're there.

    OK, let's start with the Amp routine.
    The way is is now, it takes 10 samples, averages them by dividing the total by 10.
    Then after multiplying by Quanta (convert to voltage) it multiplies the result by 10 again.

    So the last digit (1mv) would always be zero.

    Instead, let's let the accumulation of the 10 samples be the * 10. Then you don't need to divide and multiply later.

    10 samples of 1023 would be 10230 max.
    *1250 (quanta) / 256 = 54946 max (54.946 VDC). So it's still within the Word limit.

    So now it looks like ...
    Code:
    Amp:
        Average=0                         ' Clear the Average variable befor use
        For Samples=0 to 9                ' We will take 10 samples of the ADC
            ADCIN 0,AD_Raw                ' Place the conversion of channel0 into AD_RAW
            Average=Average+AD_Raw        ' Build up the Average result	
        Next                              ' Close the loop
    ;    Average=Average/10                ' Calculate the average by dividing by the number of samples taken
        AD_Result1=(Average) */ Quanta    ' Quantasize the result
    ;    AD_Result1=AD_Result1*10
        amps= AD_Result1/1000             ' Calculate the Amps part of the result
        Milliamps=AD_Result1//1000        ' Calculate the Milliamps part of the result
        IF Milliamps < 60 THEN
            Milliamps=Milliamps-Milliamps
        ENDIF
    RETURN
    Now for the volts, it's a similar situation, except the multiplier is 11.
    So if you take 11 samples, instead of 10, then again, it doesn't need to divide and multiply later.
    Code:
    Volt:
        Average=0				' Clear the Average variable befor use
        For Samples=0 to 10			' We will take 11 samples of the ADC
            ADCIN 1,AD_Raw                  ' Place the conversion of channel0 into AD_RAW
            Average=Average+AD_Raw            ' Build up the Average result	
        Next                    ' Close the loop
    ;    Average=Average/10			' Calculate the average by dividing by the number of samples taken
        AD_Result=(Average) */ Quanta        ' Quantasize the result
    ;    AD_Result=AD_Result*11
        Volts= AD_Result/1000               ' Calculate the Volts part of the result
        Millivolts=AD_Result//1000          ' Calculate the Millivolts part of the result
    RETURN
    And finally to get Watts, we need to drop one of the values down (/10), I chose amps, no particular reason.
    At the maximum values, Amps will be 4995 (49.95 amps), and Volts will be 54946 (54.946 V).
    Multiply those 2 together, then DIV32 by 10,000 and the maximum result is 27445 (2744.5 Watts).

    Here's the last part.
    Code:
    Watt:
        AD_Result1 = AD_Result1 / 10    ' Scale amps down to 2 decimals
        AD_Raw=AD_Result*AD_Result1
        AD_Raw = DIV32 10000            
        W = AD_Raw / 10                ' Calculate the watts part of the result
        Milliwatts=AD_Raw//10          ' Calculate the Milliwatts part of the result
    	                           ' resolution is 100 milliwatts (0.1W)
    	                           ' max = 2744.5 Watts
    Return
    This time I tested it.

    HTH,
    DT

Similar Threads

  1. Resolution integer math assistance?
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 14th January 2010, 04:01
  2. Line Graph, math problem...
    By TerdRatchett in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th May 2009, 05:20
  3. Pulsin Math question
    By ruijc in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 2nd April 2008, 17:15
  4. PBPL Math...new math takes more cycles...Always?
    By skimask in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th February 2008, 11:22
  5. not quite understanding the MATH function
    By Rhatidbwoy in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 17th January 2006, 21:20

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