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
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 07:57.
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.
Have I defined my variables correctly?
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.
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.
IoannisCode:'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
Last edited by Ioannis; - 29th October 2013 at 18:04.
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 05:01.
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.
![]()
Hi,
I guess I'm a bit confused by your somewhat "conflicting" numbers.
In your original post you said that the input value ranged from 92 from to 466 but that a full scale output (127) should be reached with an input value of 364.
Think of the ** operator as kind of like multiplying by units of 1/65536. With an input value of 920 (given we stick with the times ten accumulated result) the output value would (should) be 920 * (3060/65536) = 42 and with an input value of 3640 the output value will be 3640 * (3060/65536) = 169. Subtract 42 from the two numbers and you'll get 0 and 127 respectively. Note that it's 3060, not 3020.So, I need to convert the 92 and 364 to 1% or 100% respectively and apply to 127 to get a new tap setting
Is that not what you wanted? Or is that what you wanted but it doesn't actually give you those results - which is possible as I haven't tested it here. Please clarify.
The */ operator is similar to the ** operator but instead of units of 1/65536 it's units of 1/256. The // operator is modolus or remainder. If you do 123//10 you'll get 3 which is the "left over" from 123/10. They have been covered multiple times on the forum and they are covered in the manual.
/Henrik.
Bookmarks