Author Topic: Scaling of ADC input  (Read 5181 times)

0 Members and 1 Guest are viewing this topic.

Offline paul23

  • Regular Contributor
  • *
  • Posts: 91
  • Country: es
Scaling of ADC input
« on: July 04, 2013, 03:10:51 pm »
I am working on a circuit and I am a bit stuck on how to do the ADC part.  I am using an ATTINY85 and using the internal ADC to take a measurement. 

There are 3 inputs to the circuit, VIN, Signal and GND.  VIN can be a voltage between 4.5 - 12VDC, Signal is a voltage between 0-100% of VIN, this what I want to read, and GND is obvious.

VIN goes through an LDO to power the ATTiny at 3.3V, so I need to turn my signal into a 0-3.3V value.  For example, say VIN is 9V and Signal is 4.5V, then I need the input to the ADC to be 1.65V.  How do I do that?  If VIN was a fixed value I could do it easily, but I can´t figure out how to do it when VIN can change.

Any help kindly appreciated.

 
 

Offline Marco

  • Super Contributor
  • ***
  • Posts: 4416
  • Country: nl
Re: Scaling of ADC input
« Reply #1 on: July 04, 2013, 03:47:56 pm »
You could just measure both ... but if you absolutely want to do it in a single measurement, then you can divide VIN by ~4 and use it as an external voltage reference for the ADC.
 

Offline Dave

  • Super Contributor
  • ***
  • Posts: 1210
  • Country: si
  • I like to measure things.
Re: Scaling of ADC input
« Reply #2 on: July 04, 2013, 03:49:01 pm »
What resolution are you looking for? If you don't require a very high resolution, you could just use a voltage divider (factor of 3.7, 10k and 27k resistor, 12V gets scaled down to 3.24V) for both the input voltage and input signal. You then mathematically calculate (just a simple division) the ratio of the input signal to input voltage. But yes, while this solution will work, your resolution will suffer.
<fellbuendel> it's arduino, you're not supposed to know anything about what you're doing
<fellbuendel> if you knew, you wouldn't be using it
 

Offline paul23

  • Regular Contributor
  • *
  • Posts: 91
  • Country: es
Re: Scaling of ADC input
« Reply #3 on: July 04, 2013, 04:12:50 pm »
Resolution doesn´t really matter, I can get away with quite a low resolution, I only really need a 3 bit value from the ADC, so accuracy and resolution are not critical.

The ATTINY uses VCC as its reference, i think.  I am pretty sure there isn´t an AREF pin on that chip. 

With the voltage divider method, that works great at 12V, but doesn´t work at lower voltages, say 5V.  If Vin was a fixed value then I would have done it with a voltage divider, but I don´t how to do it with a dynamic range, without an AREF pin.
 

Offline Dave

  • Super Contributor
  • ***
  • Posts: 1210
  • Country: si
  • I like to measure things.
Re: Scaling of ADC input
« Reply #4 on: July 04, 2013, 04:46:21 pm »
Why would it not work at 5V?
5V / 3.7 = 1.35V
1.35V on the input of a 10-bit ADC with 3.3V reference should read 419.

So your full scale for the input signal at 5V supply would be 419, which is much better than your required 3 bits. :-+

Also, if your input signal would have a high impedance (for example if you had a potentiometer as the input), you should add a RRIO opamp on the input connected as a voltage buffer.
<fellbuendel> it's arduino, you're not supposed to know anything about what you're doing
<fellbuendel> if you knew, you wouldn't be using it
 

Offline paul23

  • Regular Contributor
  • *
  • Posts: 91
  • Country: es
Re: Scaling of ADC input
« Reply #5 on: July 04, 2013, 05:05:41 pm »
Why would it not work at 5V?
5V / 3.7 = 1.35V
1.35V on the input of a 10-bit ADC with 3.3V reference should read 419.

Yes, but the value should be 1023 at 5V (if Vin is 5V too).  The ADC has no way to know what the full scale value is.

Quote
So your full scale for the input signal at 5V supply would be 419, which is much better than your required 3 bits. :-+

That´s fine, but how do I set that automatically?  That is what I am stuck on.

Maybe I did not explain clear enough what the problem is.  Vin can change, it´s not a fixed value, so it´s not always 5V or always 12V or whatever.  I need a way to detect what Vin in and scale the measurements accordingly so that the signal (0-Vin) == 0-3.3V, but it has to be automatic and not user programmable/settable.  I can´t figure out how to do that, maybe it is not possible?
 

Offline Dave

  • Super Contributor
  • ***
  • Posts: 1210
  • Country: si
  • I like to measure things.
Re: Scaling of ADC input
« Reply #6 on: July 04, 2013, 05:22:56 pm »
I understood exactly what your requirement is, maybe I didn't explain my suggestion well enough.

You would be measuring 2 voltages: the supply voltage and the signal you are trying to quantize.
Both these voltages would be divided by 3.7 and both of them then measured with an ADC.
The reading you are getting from the signal voltage would be mathematically compared to the reading you are getting from the supply voltage. It's just division (signal/supply; you could also multiply the signal reading first, so you can avoid floating point calculations, which take more processing).

So basically, you are measuring both unknown voltages and comparing the two. It doesn't matter if the supply voltage is 5, 7 or 12 volts, you are always able to calculate the ratio of the two.
<fellbuendel> it's arduino, you're not supposed to know anything about what you're doing
<fellbuendel> if you knew, you wouldn't be using it
 

Offline fcb

  • Super Contributor
  • ***
  • Posts: 1275
  • Country: gb
  • designer/manufacturer of test instruments
    • Electron Plus
Re: Scaling of ADC input
« Reply #7 on: July 04, 2013, 05:23:34 pm »
I'm not familar with the ATTiny, but some ideas:

1. Use the ADC reference input.  Feed your signal to a potential divider on the ADC input, and feed your DC rail into another potential divider on the ADC REF input. That will give you a ratiometric ADC (depending somewhat on the way the ADC works!).

2. Use 2x ADC channels with potential dividers on them (one for signal and one for rail) - and then do a bit of scaling maths.

3. Build a primitive multiplier and scale your signal according to the DC rail - you could probably do this with three-four transistors. Look-up voltage controlled amplifiers (VCA) - it's not qoing to be quick to design.

I'd probably go for 2. But I don't know what your pin budget is like.

Offline Marco

  • Super Contributor
  • ***
  • Posts: 4416
  • Country: nl
Re: Scaling of ADC input
« Reply #8 on: July 04, 2013, 05:39:12 pm »
I am pretty sure there isn´t an AREF pin on that chip.
Not dedicated, but it is one of the many potential functions of PB0.
 

Offline 4to20Milliamps

  • Regular Contributor
  • *
  • Posts: 248
  • Country: us
Re: Scaling of ADC input
« Reply #9 on: July 04, 2013, 06:15:38 pm »
I'm not sure exactly what your application is, but it seems like if you know your resolution and your voltages you should be able to use a look up table to grab the adjusted value, there are folks here that are way more competent at figuring stuff out in software than I am so if there's an easier way to do it I'm sure they will point it out.

References and example:

http://www.eetimes.com/document.asp?doc_id=1276974< paragraph on software calibration.

http://www.ni.com/white-paper/4806/en/

http://www.phanderson.com/picaxe/picaxe_thermistor.html
« Last Edit: July 04, 2013, 08:06:57 pm by 4to20Milliamps »
 

Offline paul23

  • Regular Contributor
  • *
  • Posts: 91
  • Country: es
Re: Scaling of ADC input
« Reply #10 on: July 04, 2013, 06:59:08 pm »
I understood exactly what your requirement is, maybe I didn't explain my suggestion well enough.

You would be measuring 2 voltages: the supply voltage and the signal you are trying to quantize.
Both these voltages would be divided by 3.7 and both of them then measured with an ADC.
The reading you are getting from the signal voltage would be mathematically compared to the reading you are getting from the supply voltage. It's just division (signal/supply; you could also multiply the signal reading first, so you can avoid floating point calculations, which take more processing).

So basically, you are measuring both unknown voltages and comparing the two. It doesn't matter if the supply voltage is 5, 7 or 12 volts, you are always able to calculate the ratio of the two.

Thanks, I am such a spaz, I get what you mean and that is such an obvious solution, I should have thought of that myself. I didn´t realise you were meant using 2 ADC channels.  But that would be a good solution.  Thanks.

1. Use the ADC reference input.  Feed your signal to a potential divider on the ADC input, and feed your DC rail into another potential divider on the ADC REF input. That will give you a ratiometric ADC (depending somewhat on the way the ADC works!).

As I said, there is no ADC REF on the tiny85
Quote

2. Use 2x ADC channels with potential dividers on them (one for signal and one for rail) - and then do a bit of scaling maths.

That´s the winner
Quote

3. Build a primitive multiplier and scale your signal according to the DC rail - you could probably do this with three-four transistors. Look-up voltage controlled amplifiers (VCA) - it's not qoing to be quick to design.

Too much mucking about, it´s easier  with 2 ADC channels.  Thanks for your suggestions
I am pretty sure there isn´t an AREF pin on that chip.
Not dedicated, but it is one of the many potential functions of PB0.
Well done, I hadn´t noticed that. 
 

Offline Dave

  • Super Contributor
  • ***
  • Posts: 1210
  • Country: si
  • I like to measure things.
Re: Scaling of ADC input
« Reply #11 on: July 04, 2013, 07:26:49 pm »
Thanks, I am such a spaz, I get what you mean and that is such an obvious solution, I should have thought of that myself. I didn´t realise you were meant using 2 ADC channels.  But that would be a good solution.  Thanks.
You are very welcome.

When doing the calculation, I think the fastest and simplest solution will be to put your signal reading into a long variable (long being the 32-bit variable type, not an adjective) and then shifting it 10 bits to the left. You then divide this variable by the reading you get from your supply voltage. You then shift the result to the right by 10-N places, where N represents the number of digits you want your final result to have. I'd say you have 6 reliable bits tops, but then again, you said you only need 3, so that should be fine.
<fellbuendel> it's arduino, you're not supposed to know anything about what you're doing
<fellbuendel> if you knew, you wouldn't be using it
 

Offline richcj10

  • Supporter
  • ****
  • Posts: 201
  • Country: us
Re: Scaling of ADC input
« Reply #12 on: July 05, 2013, 12:51:39 am »
Resolution doesn´t really matter, I can get away with quite a low resolution, I only really need a 3 bit value from the ADC, so accuracy and resolution are not critical.

The ATTINY uses VCC as its reference, i think.  I am pretty sure there isn´t an AREF pin on that chip. 

With the voltage divider method, that works great at 12V, but doesn´t work at lower voltages, say 5V.  If Vin was a fixed value then I would have done it with a voltage divider, but I don´t how to do it with a dynamic range, without an AREF pin.

There is an optional Aref pin. But, I would use the internal reference tho.
The voltage divider will work at "all" voltages.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf