ADC with no ADC - Page 1
Forum section: electronics / beginners

author: blewisjr
author_rank: Frequent Contributor
timestamp: May 04, 2013, 03:06:59 pm
content: I have a few uCs that I want to use up in a project. The issue is I need to control a pwm like you would for dimming a led. Normally you would use an adc to do this. The issue is these chips only have an analog comparator. I know I can use a digital pin with a resistor to charge a cap to use the comparator as an adc (thanks google) however I have no idea where the pot needs to go. Any ideas?

author: c4757p
author_rank: Super Contributor
timestamp: May 04, 2013, 03:22:34 pm
content: Why do you need an ADC??

author: SeanB
author_rank: Super Contributor
timestamp: May 04, 2013, 03:27:29 pm
content: If you have a few digital port pins spare just use a R/2R network on them and make a low resolution stepped ADC with the internal comparator. You can easily get 5 bits of resolution, and this is quite enough to dim LED's with.

author: blewisjr
author_rank: Frequent Contributor
timestamp: May 04, 2013, 03:41:48 pm
content: Ultimately I want to use the ADC to control the voltage going to a peizo to adjust the volume of its output.

author: McMonster
author_rank: Frequent Contributor
timestamp: May 04, 2013, 03:43:08 pm
content: Or you can use NE555 as VCO and just measure the frequency.

author: c4757p
author_rank: Super Contributor
timestamp: May 04, 2013, 04:15:22 pm
content: I'm lost - what does an ADC have to do with dimming LEDs? What do you have to measure? Just output the PWM signal directly.

author: blewisjr
author_rank: Frequent Contributor
timestamp: May 04, 2013, 04:33:25 pm
content: It does not measure you use the ADC converted value which is modified by a pot that controls the voltage going into the ADC. This allows you to use the conveyed value to scale the pwm which means when you turn the pot the led gets brighter or dimmer.

author: Rufus
author_rank: Super Contributor
timestamp: May 04, 2013, 04:34:43 pm
content: You can charge a capacitor through a variable resistance and measure the time taken for the voltage on the capacitor to reach some threshold.That threshold voltage might just be the logic level threshold of a digital input or the voltage on the other side of one of the internal comparators. You can probably configure the same pin as an output to discharge the capacitor before making the measurement.An alternative is to make a kind of delta sigma converter. Drive an RC network with an output and compare the capacitor voltage with the unknown voltage you are measuring. At a regular rate look at the comparator and set the output to drive the capacitor voltage towards the unknown. The capacitor voltage will follow the unknown voltage (with some ripple) and the ratio of highs and lows you drive the RC with is proportional to the unknown voltage.

author: c4757p
author_rank: Super Contributor
timestamp: May 04, 2013, 04:37:07 pm
content: If you're using a pot to dim LEDs what do you even need a microcontroller for?Quote from: Rufus on May 04, 2013, 04:34:43 pmYep. Ramp up a capacitor voltage as one comparator input, and the pot output voltage as the other input.

author: ivan747
author_rank: Super Contributor
timestamp: May 04, 2013, 04:56:17 pm
content: Why not using a rotary encoder? Or why don't you switch to a microcontroller that has an ADC. You can get these almost for free.This chip has 2 ADC channels and costs 60 cents:http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en023672

author: blewisjr
author_rank: Frequent Contributor
timestamp: May 04, 2013, 05:10:29 pm
content: I have chips with ADC but when I got these I thought they did so I figure why not learn something. So I should be able to pot the vref and compair that against the charging cap correct?

author: c4757p
author_rank: Super Contributor
timestamp: May 04, 2013, 05:18:16 pm
content: Quote from: blewisjr on May 04, 2013, 05:10:29 pmYep. That's a very common, basic "roll-your-own" ADC. I've actually played around with it before just for fun and managed to get usable four-digit precision - it works quite well. You just need a small current source to ramp up the capacitor and a switch to dump off the charge - a resistor as the current source and just switching the comparator input to output-zero should suffice for this. Then just set the comparator output as a timer trigger input and you're done. (Or if this MCU doesn't allow that, poll it in code, but you'll need to run more slowly.)

author: blewisjr
author_rank: Frequent Contributor
timestamp: May 04, 2013, 05:24:03 pm
content: ATtiny2313A. The cap is getting charged through a resistor and a digital pin do I should be able to just flip the digital Io pin to input to drain the cap.

author: c4757p
author_rank: Super Contributor
timestamp: May 04, 2013, 05:31:39 pm
content: Not unless I've misunderstood how it's connected. Here's how I would do it - just flip AIN1 to an output and set it to zero. It will absorb both the charge current through the resistor and the existing charge on the capacitor, pulling it down to 0V.Edit: you should probably put a small resistor between the series RC circuit and AIN1, to limit the discharge current. A ceramic or film capacitor can deliver quite large peak currents for a brief moment if you directly short it.

author: blewisjr
author_rank: Frequent Contributor
timestamp: May 04, 2013, 05:36:32 pm
content: Ok I see. The only difference is that ain1's vcc is coming from a digital Io pin and v ref's vcc is coming from the main voltage rail.

author: c4757p
author_rank: Super Contributor
timestamp: May 04, 2013, 05:37:49 pm
content: Why? Is there any reason you need to be able to shut off that voltage? Save pins - you don't have many.

author: blewisjr
author_rank: Frequent Contributor
timestamp: May 04, 2013, 05:45:27 pm
content: According to the atmel app note that is how it is done not sure why they do not say.

author: c4757p
author_rank: Super Contributor
timestamp: May 04, 2013, 07:45:28 pm
content: You mean AVR400? I believe they're doing that so the charging can be started with more precise timing than if you just switch the comparator pin back to an input - useful for a more accurate conversion, but not really necessary if you're just trying to read a pot. Sadly the app note doesn't really explain much - a Jim Williams app note it ain't...