NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » can nerdkit produce variable voltages??
May 30, 2009 by andy_b1986 |
hello i need to send variable votlages out of two pins from the nerdkit. is this possible? i need to send between 2.2v and 2.9v on both pins. i am basically doing th rc car project but my controller uses a variable resistor in order to send a resulting votlage to an onboard chip. it is this voltage which tells the motors where to move. If i can get this to work this way it would save me a lot of bother but ofcourse i could be approaching it from the wrong angle and PWM could still be a good solution. just need a bit of guidance i guess! |
---|---|
September 14, 2009 by kevinmullican |
Hey there. What you want is a digital potentiometer. You could use something like: http://www.analog.com/en/digital-to-analog-converters/digital-potentiometers/ad8400/products/product.html This is an SPI controlled digital potentiometer. You would need to learn how to use the SPI interface on the ATMEGA128, but that is not too hard. Good luck. |
September 14, 2009 by rusirius |
actually you could whip up a little integrator circuit if you have an op-amp... Basically it's a cap and resistor in parallel as a feedback loop coming back from the output. The resulting output will be proportional to the integral of the input... Do a google on "integrator circuit" and I'm sure you'll find loads of examples... |
September 14, 2009 by rusirius |
Slap DOH... I just realized your voltages were below what you're probably running the atmel at. In that case you can actually use just a simple low pass filter... Just a resistor in series with the PWM and a cap tying it to ground. Just choose an RC combo with a time constant about 100 times the period of your PWM... In other words, if your period is 100us you'd want a time constant of about 10ms... (a 1k resistor and 10uF cap) Keep in mind that it's not going to be an "instant" change when the PWM is changed... It'll have a delay before the voltage stabilizes at the new value... |
September 14, 2009 by rusirius |
Just had another thought... I'm just starting to mess around with microcontrollers so take this for what it's worth, but since the atmel has an ADC onboard, you could actually feed the output voltage back into it as a way to monitor the actual voltage that is being output... If nothing else you could use this as a way to make sure your voltages never went out of spec, if they did you could shut down the PWM to prevent damage, etc... |
September 15, 2009 by rusirius |
One last thing I'll throw out there... Sorry I was kinda in a rush last night and didn't have time... If you need a much quicker control on the voltages, then there is another way you could do this... The disadvantage is going to be using a lot of i/o pins depending on the amount of "resolution" you want (how fine of an adjustment you want to be able to make...) Basically you can create a pretty simple DAC... If you use this method you'll need to figure out how much resolution you want... If you use 8 i/o pins you'll have very fine resolution (on a 5V scale)... (It'll be an 8-bit DAC)... You'll need some resistors... Two values... Values just depend on how much current you want out of it, but chances are that really won't apply in your case since you're probably just driving an input... What DOES matter is the ratio between the resistors... You'll need two different values... A "base" value and a 2x value... In other words, let's say you have a bunch of 1k resistors laying around... Then you'll just need some 2k (2.2k should work fine and will be easier to find)... Or you could use 10k and 20k (22k), etc... Basically you'll start with a 2x value resistor followed by 7 (in the case of 8-bit) of your base resistors all in series... Then each of your i/o pins will have a 2x resistor in series that then ties into the nodes between each of your series resistors from above... In other words, it'll look something like this...
You may still want to pass the output to an opamp to buffer it and make it a bit more linear... (as you get towards the upper range of the supply voltage the linearity will begin to roll off... If you use Kirchoff's voltage law you can easily see what's going on here... Each bit literally represents a "value" that get's added into the output based on it's significance. |
September 15, 2009 by rusirius |
One last note... If you're not sure how many bits to use, just figure out what size "steps" you need to be able to control the voltage... For example, if the above circuit is driven with 5V, since it's 8-bit (max value of 8 bits is 255 or 256 "values") then you can divide 5V by 256 to get an approx. idea of the value of each "bit"... In this case, about 2 hundreths of a volt... (.02 volts)... If you made a 4-bit dac, the max value would be be 15... therefore each "step" would be about 1/3rd of a volt... Hope that helps! |
Please log in to post a reply.
Did you know that you can control multiple LEDs from one microcontroller output? Learn more...
|