Author Topic: ADC with no ADC  (Read 5768 times)

0 Members and 1 Guest are viewing this topic.

Offline blewisjrTopic starter

  • Frequent Contributor
  • **
  • Posts: 301
ADC with no ADC
« on: May 04, 2013, 03:06:59 pm »
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?
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: ADC with no ADC
« Reply #1 on: May 04, 2013, 03:22:34 pm »
Why do you need an ADC??
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline SeanB

  • Super Contributor
  • ***
  • Posts: 16358
  • Country: za
Re: ADC with no ADC
« Reply #2 on: May 04, 2013, 03:27:29 pm »
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.
 

Offline blewisjrTopic starter

  • Frequent Contributor
  • **
  • Posts: 301
Re: ADC with no ADC
« Reply #3 on: May 04, 2013, 03:41:48 pm »
Ultimately I want to use the ADC to control the voltage going to a peizo to adjust the volume of its output.
 

Offline McMonster

  • Frequent Contributor
  • **
  • Posts: 413
  • Country: pl
    • McMonster's blog
Re: ADC with no ADC
« Reply #4 on: May 04, 2013, 03:43:08 pm »
Or you can use NE555 as VCO and just measure the frequency.
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: ADC with no ADC
« Reply #5 on: May 04, 2013, 04:15:22 pm »
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.  :-//
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline blewisjrTopic starter

  • Frequent Contributor
  • **
  • Posts: 301
Re: ADC with no ADC
« Reply #6 on: May 04, 2013, 04:33:25 pm »
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.
 

Offline Rufus

  • Super Contributor
  • ***
  • Posts: 2095
Re: ADC with no ADC
« Reply #7 on: May 04, 2013, 04:34:43 pm »
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.
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: ADC with no ADC
« Reply #8 on: May 04, 2013, 04:37:07 pm »
If you're using a pot to dim LEDs what do you even need a microcontroller for?

You can charge a capacitor through a variable resistance and measure the time taken for the voltage on the capacitor to reach some threshold.

Yep. Ramp up a capacitor voltage as one comparator input, and the pot output voltage as the other input.
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline ivan747

  • Super Contributor
  • ***
  • Posts: 2046
  • Country: us
Re: ADC with no ADC
« Reply #9 on: May 04, 2013, 04:56:17 pm »
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
 

Offline blewisjrTopic starter

  • Frequent Contributor
  • **
  • Posts: 301
Re: ADC with no ADC
« Reply #10 on: May 04, 2013, 05:10:29 pm »
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?
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: ADC with no ADC
« Reply #11 on: May 04, 2013, 05:18:16 pm »
So I should be able to pot the vref and compair that against the charging cap correct?

Yep. 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.)
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline blewisjrTopic starter

  • Frequent Contributor
  • **
  • Posts: 301
Re: ADC with no ADC
« Reply #12 on: May 04, 2013, 05:24:03 pm »
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.
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: ADC with no ADC
« Reply #13 on: May 04, 2013, 05:31:39 pm »
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.
« Last Edit: May 04, 2013, 05:37:13 pm by c4757p »
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline blewisjrTopic starter

  • Frequent Contributor
  • **
  • Posts: 301
Re: ADC with no ADC
« Reply #14 on: May 04, 2013, 05:36:32 pm »
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.
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: ADC with no ADC
« Reply #15 on: May 04, 2013, 05:37:49 pm »
Why? Is there any reason you need to be able to shut off that voltage? Save pins - you don't have many.
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline blewisjrTopic starter

  • Frequent Contributor
  • **
  • Posts: 301
Re: ADC with no ADC
« Reply #16 on: May 04, 2013, 05:45:27 pm »
According to the atmel app note that is how it is done not sure why they do not say.
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: ADC with no ADC
« Reply #17 on: May 04, 2013, 07:45:28 pm »
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...  :P
No longer active here - try the IRC channel if you just can't be without me :)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf