0 - 5 volts to servo positon.
Hi need help
I have adc0838 A/D converter reading 8 pots in single ended mode.
I get 0 - to 5 volts output from the A/D AS 0012 - 0500
I have been able to use some math to get usable pulse with numbers from a variable but not what i want.
How do I trasnlate the output to pulse withs, and·What is offseting
please help any links to reading matiral will help
·
I have adc0838 A/D converter reading 8 pots in single ended mode.
I get 0 - to 5 volts output from the A/D AS 0012 - 0500
I have been able to use some math to get usable pulse with numbers from a variable but not what i want.
How do I trasnlate the output to pulse withs, and·What is offseting
please help any links to reading matiral will help
·
Comments
ADC0838 BASIC Stamp
Maybe it will contain some useful hints:
http://web.bii.a-star.edu.sg/~james/files/A2D_box/program.bs2.old
also 0012 - 0500 is using word size var (close to actual votage)
or I can get 0 - 255 using byte size var
·· While Tracy Allen is normally the math guru here, I was looking at your post, and today for some reason (Maybe because I am not fully awake yet), it made a little sense, and sparked an idea.· If you're getting values of 12-500 from your readings on the ADC, and want to translate them into servo positions, that actually seems easy...
·· Since I am not completely with it I will just try to make sense...On a stock BS2, the PULSOUT command for moving the servo ranges from roughly 500 to 1000...Since you're getting the same range, just off by around 500, then I would try something like:
ServoPos = ADC_Val + 500
PULSOUT Pin, ServoPos
·· Of course, you will need to integrate the PULSOUT·into your refresh loop.· But it seems reasonable to me that this should work, although I have not tried it.· Thought?· Comments?· Caffiene?!?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Knight Designs
324 West Main Street
P.O. Box 97
Montour Falls, NY 14865
(607) 535-6777
Business Page:·· http://www.knightdesigns.com
Personal Page:··· http://www.lightlink.com/dream/chris
Designs Page:··· http://www.lightlink.com/dream/designs
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Post Edited (Jon Williams) : 12/10/2004 4:03:01 PM GMT
·SHIFTIN Dio, Clk, MSBPOST, [noparse][[/noparse]adc0\9]····· ' read selected input
but my adc0 variable is not byte it is word.· Doesent" \9 " aquire 9 bits from the adc
and actualy it works better for what I need. The numbers are easier to work with.· Go figure dumb luck I tried diferent configurations to get digits that were easy.
my servos go from 360 - 1260 and I get almost 180 deg of throw.
now I go from pot( 5k) to servo with little code. here is what I came up with.
see attached.
thanks for every ones help.
what do you think ??
(50k pot has bad voltage fluctuations)
Notice out the output variable is shifted left then the data line is sampled and dumped into BIT0?· If you work through you'll see that the extra bit gets dumped off the MSB end after the 9th clock pulse.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
But like I said my variable is not byte size. It is word size so I get to keep the extra bit.
Again go figure dumb luck, I get a value that is easier to covert for pulse widths.
It might not be a useable value anywhere else but it works here.
I realy am just learning all this as I go along and it is a blast.·Some of it I get and some of it is just a mystery.
It might not make any logical sence but somehow it works.
It is a little touchy when I grab the R/C style joystick but once moving the servos are smooth.
when I try Byte size I don·not get a liniar increase in digits. I get·0-255 then as the pot keeps turning is start at 0 again and then back to 255.
If i need only partial throw I will go back to this·and adjust the math.
This is what I call trial by FIRE·
·
adcVal = adcVal & $00FF
before doing your other calculations.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Knight Designs
324 West Main Street
P.O. Box 97
Montour Falls, NY 14865
(607) 535-6777
Business Page:·· http://www.knightdesigns.com
Personal Page:··· http://www.lightlink.com/dream/chris
Designs Page:··· http://www.lightlink.com/dream/designs
·
Lets say I do it right. Variable goes back to byte size
Now I have the problem that the the byte side variable resets back to 0 half way between 0 and 5 volts from the pot.
I measured the voltag at the pot and I do have 0-5 volts variable.
AGND,·DGND, and COM are all conected Vss
one side of pot is +5v form pin20 other side is at Vss, Center of the pot is at pin 0
Power supply is 12vdc into the regulator.
what should I be getting for·byte values , what is expected?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
ok here is smomething strange, I can get 0-255 out ·with 0-5v in
if I change shiftin to SHIFTIN Dio, Clk, [noparse]/noparse][b]adc0\8[/b
Removing the extra clk pulse lets it work corectly ????
The timing must be diferent on the 0838.
Now I go
·adco=adc0*5
·IF adc0<330 then adc0=330
·if adc0>1230 then adc0=1230
and I get my usable range of 330-1230 if I need to reduce the throw of the pot I only have to change the *5 to a larger value. I lose some resolutin but I guess thats what hapens when you squeeze 180deg of movment into 80 deg of controll lever movment.
·
You want 0 - 255 to become 330 to 1230 ... so try this mx+b equation:
adc = adc */ $388 + 330
How does it work? Well, your output range has a span of 900, so you divide that by 255 (max pot value)·to get the slope (3.5294 -- the 'm' in mx + b). We can use the */ operator to multiply by fractions (in increments of 1/256). To use */ you take your fractional value (3.5294) and multiply it by 256; you 903.5 -- round up to 904.· I like to convert to HEX as I can see the whole part in the upper byte, the fractional part in the lower byte.· 904 in hex is $388.· Of course, we have to add the minimum value; then we're done.·
You can run this little test code to see that it works:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Post Edited (Jon Williams) : 12/11/2004 3:43:07 PM GMT
·Works perfect. That was what I was looking for.
Now On R/C gimbal I only have partal throw of the pot. I see the max value IE 125, the formula incrases the·slope and I get full out put with less pot travel.
Thanks. Now how do I stabalize the voltage form the pot so the servos don't twitch??
PS the timing sheet I have for the 8038 shows·7-0 ·bits for the first MSB
Post Edited (AJI) : 12/11/2004 5:50:57 PM GMT
adcNew = (adcNew / 2) + (adcOld / 2)
adcOld = adcNew
When you do this the proportions (which need to add up to 100%) will control how fast your value moves from old to new. For a slower response, use a larger portion of the old value. This values will give you 25% new, 75% old:
adcNew = (adcNew */ $40) + (adcOld */ $C0)
adcOld = adcNew
As you can see in the examples above, you must save your new "filtered" value before calling your ADC input again.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
That really worked well for my adc...Thanks
now suppose i get something like 10600 - 20250
and i need to convert it to something like 120 - 1100..
..how do i do it..
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
**·ice**
Gerard Sequeira
Machinegrid.com·:: Robots at Work!!
·