I'm trying to work out a better way of converting a voltage into something I can sample on an ADC.
I need to measure a voltage that goes up to 48V (its an LED dimmable power supply) but I only need to measure it down to around 30V - In other words I need to convert a 30-48v signal into a 0-3.3v signal.
At the moment I just use a potential divider and sample it with the 10 bit ADC, then subtract out of the ADC reading a value equal to 30V. My problems is that it doesn't give me enough resolution because I am ditching most of the signal.
I don't want to use an external ADC if I can help it but I can't figure out a simple way to convert the analog voltages into a useful range.
One way of doing this is with an op-amp to subtract a fixed voltage from what you're trying to measure before it goes into the ADC. So let's say you had a voltage divider on the signal that divides the input by 6, giving you a span of 5 - 8V, the op-amp would be configured to subtract a fixed 5V from that signal, providing 0-3V at the output which is safe for an Arduino.
The problem is that doing this properly requires good quality references (for the offset subtraction) and precision resistors matched to a high degree if you want to ensure accuracy. It will work, but in the end the result may have been achieved much easier by using an external higher resolution ADC. This is one of many reasons that measurements are typically done digitally as much as possible these days.
You could use an operational amplifier (OP-AMP) to subtract the 30 volts. Unfortunately this may require more external circuitry than an external 12 bit ADC. Another option would be to measure current since that is the real determinant of LED brightness.
Or you could satisfy yourself with the approximately 380 discreet useful values that your current circuit allows. This results in about 0.05 volts per step. Are you sure you need higher resolution than that?
EDIT: it seems @cedarlakeinstruments and I were answering at the same time. Same advice though.
You'll still need a divider (1k resistor from R1 to ground), but assuming that the voltage changes very slowly, your resolution is basically only limited by how much time you allocate to it.
I have just realised I can swap to a different device (I'm using TinyAVR's) and get 12 bits of ADC which will give me plenty of resolution so I'll try that before going for anything more complicated.