Sonic Depth Meter code & Math problems 12F683


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,627


    Did you find this post helpful? Yes | No

    Default Re: Sonic Depth Meter code & Math problems 12F683

    Hi,
    I'd probably skip dividing the accumulated result by 10 in order to keep the resolution as long as possible.
    It's not perfect but perhaps something like this might work:
    Code:
    newtapsetting = (dist ** 3060) - 42
    IF newtapsetting > 127 THEN newtapsetting = 127
    This will give you a newtapsetting ranging from 0-127 for a dist value ranging from 920-3640. (At least I think it will....)

    /Henrik.

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,175


    Did you find this post helpful? Yes | No

    Default Re: Sonic Depth Meter code & Math problems 12F683

    Also the program runs one time. Is this what you want?

    And on the third paragraph of your post, you say that the sensor gives a value of 92-466 and then 92-364. Which of the two is true?

    Ioannis
    Last edited by Ioannis; - 29th October 2013 at 08:57.

  3. #3
    Join Date
    Jan 2009
    Posts
    34


    Did you find this post helpful? Yes | No

    Default Re: Sonic Depth Meter code & Math problems 12F683

    92 is my rank full value, 466 is zero water in tank, 364 is 8" of water in tank which is my safe empty value.

  4. #4
    Join Date
    Jan 2009
    Posts
    34


    Did you find this post helpful? Yes | No

    Default Re: Sonic Depth Meter code & Math problems 12F683

    Have I defined my variables correctly?

  5. #5
    Join Date
    Jan 2009
    Posts
    34


    Did you find this post helpful? Yes | No

    Default Re: Sonic Depth Meter code & Math problems 12F683

    Sorry, and yes, runs once to establish one depth value based on the average of 10 readings. I have an external system that cycles the power every 5 min ultimately giving me an average reading every 5 min.

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,175


    Did you find this post helpful? Yes | No

    Default Re: Sonic Depth Meter code & Math problems 12F683

    I 'd use what Henrik has posted and maybe with a smaller multiplier, say 3000. Keep your ten average pile. Then Henrik's lines will give you directly the result for your digital pot.

    Code:
    'Main Program  ****************************
    
    'get avg depth
        pause 1000
        for x = 1 to 10
            pulsin gpio.4,1,inputpulse
            dist= dist + inputpulse
            pause 100
        next x
        
        newtapsetting = (dist ** 3060) - 42       'try also a number smaller, 3000
        IF newtapsetting > 127 THEN newtapsetting = 127
    
    serout gpio.0,t9600,[12,"avg :", #avgdist,13]
    serout gpio.0,t9600,["tap :", #newtapsetting]
    
    pause 500
    
    end
    Ioannis
    Last edited by Ioannis; - 29th October 2013 at 19:04.

  7. #7
    Join Date
    Jan 2009
    Posts
    34


    Did you find this post helpful? Yes | No

    Default Re: Sonic Depth Meter code & Math problems 12F683

    Thanks guys. I'm trying to understand the math here, help me out.

    What is the difference between * and **? I can't seem to find something on this forum that explains this. How does the math work.

    For example, Henrik's suggestion above, how did you select 3060 to try and result in a range between 1 and 127? I tried random numbers and 2020 gets me close to my 127 value at full, but gives me 25 at empty. If I subtract 24 to give me 1, then I've also reduced my 127 to 103...Ugg.

    and while I'm at it...how doe the */ and // work?


    I really need the result to provide a linear value between 1 and 127 for this to work properly. So I feel like I need to determine the ratio of the reading (in this case with full reading 92 and emplty reading 364, I would subtract 91 from the values for an adjusted range between 1 and 273) then take the adjusted value and divide by 273 for a multiplier between 0 and 1 and apply that multiplier to 127.
    Last edited by johnnylynx; - 30th October 2013 at 06:01.

  8. #8
    Join Date
    Jan 2009
    Posts
    34


    Did you find this post helpful? Yes | No

    Default Re: Sonic Depth Meter code & Math problems 12F683

    Excuse my last reply...Henrik's number of 3020 gets me a new tap setting of 127 (perfect empty value) but when the tank is full (8" away from the sensor) the new tap reading is 42 (not 0 or 1). If I subtract 42, the full reading gets to 0 or 1, but my empty reading is also reduced...not letting me see the empty value of 127.


Similar Threads

  1. Replies: 0
    Last Post: - 27th March 2011, 21:10
  2. PIC 12f683 AD/PWM Problems:
    By surfer0815 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 7th December 2005, 17:48
  3. math problems (again)
    By lab310 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 28th November 2005, 23:43
  4. 12F683 Comparator Problems
    By morethanenuf in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 9th September 2005, 16:36
  5. math problems - large numbers
    By Tomasm in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th February 2004, 08:48

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