ADC-Negative values!!

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ADC-Negative values!!

6,675 Views
fredycolombia
Contributor I
Hi all,
I have already adc in gp32 and  works fine, but I need to obtain binary negative values when I put a analog  signal with positive a negative values, I only can see de positve side.
Somebody knows how I can represent negative values??

Regards,
fredy.
Labels (1)
0 Kudos
6 Replies

1,578 Views
PeterHouse
Contributor I
Fredy,

If the analog signal goes negative and is centered around the ground to your CPU It will only be able to see the excursions above ground which is only the top half of your analog signal.  You will probably need an op-amp for scaling and offfset correction.  This will allow your signal to be centered in the middle of the range of your ADC so your ADC can see the entire AC waveform.

Peter
0 Kudos

1,578 Views
bigmac
Specialist III
Hello Fredy,
 
To further elaborate on the comments of Peter -
 
There seems to be two possibilities using a single op amplifier for each channel, one using an inverting configuration, and the other using a non-inverting configuration.  If you are not already familiar with these terms, most text books on analog topics should cover these basic configurations.  To keep things simple, the op amp will need to be of the output "rail-to-rail" type, and operate from the same supply as the MCU.
 
For the non-inverting configuration, the input signal would be applied to the non-inverting :smileyplus: input.  There will be a feedback resistor between output and inverting :smileyminus: input, plus a source resistor typically returned to ground.  However, to provide the necessary voltage offset in this case, the source resistor will need to be returned to a fixed, negative reference voltage, equal to one half the positive Vdd value, assuming equal resistor values.  Because the non-inverting input will swing negative, the amplifier will need a negative supply voltage.
 
For the inverting configuration, the input signal will be applied to the source resistor. and a fixed, positive reference voltage would be applied to the non-inverting :smileyplus: input.  Again, assuming equal value resistors, the reference voltage would be one half the Vdd voltage.  For this method, your code will need to allow for the ADC input voltage swing towards zero as the input voltage increases above zero, and vice versa.  This method also has the disadvantage of a lower input resistance (the source resistor value) compared with the non-inverting method.  However, I prefer this method, where possible, because the reference voltage can be derived directly from Vdd, using a voltage divider.  Additionally, the amplifier does not require a negative supply voltage.
 
For either method, since the resistor values will have a tolerance (1 percent resistors should be used), the input voltage level may differ slightly from one-half Vdd, when the input voltage is zero.  If the offset error can be predetermined, and a correction value stored in non-volatile memory, the firmware can compensate for the error.
 
Regards,
Mac
 


Message Edited by bigmac on 2008-01-14 11:26 PM
0 Kudos

1,578 Views
fredycolombia
Contributor I
hi,

ahhh, I understand, I need to add a dc level to my analog signal.
So if I use inverting configuratión,  the output is conected to one channel and I don´t need more channels ¿right?
When the analog  signal  go  to a  level under 2.5v (my offset), the adc in CPU give me  a negative values or  I have to do something with my code  to obtain this values ?

regards.


Message Edited by fredycolombia on 2008-01-14 08:53 PM
0 Kudos

1,578 Views
PeterHouse
Contributor I
Fredy,

Configured this way, the ADC will give you a reading of 1/2 full scale when your input signal is at 0 (2.5v), the ADC will read 0 for a full scale signal excursion (0v) in the negative range, and will read full scale for a full scale excursion (5v) in the positive direction.

If you want positive and negative numbers you will have to subtract half of the adc full scale reading from all of your input readings.  If you are using an inverting amplifier and want the "true" polarity of your input signal, you could then swap the signs with a only little more numerical manipulation.

Good Luck,

Peter
0 Kudos

1,578 Views
bigmac
Specialist III
Hello Fredy,
 
If using the inverted configuration, and assuming an 8-bit result, the ADC reading would need to be manipulated as follows.  I have assumed a fixed offset value, but this could alternatively be a variable, subject to calibration for zero input.  The offset value is subtracted from the ones complement of the reading.
 
#define OFFSET  0x80
 
signed char result;
 
result = (~AD1RL) - OFFSET;
 
The manipulation is slightly more complex if using a 10-bit result, which must be handled as a 16-bit value.
 
#define OFFSET  0x200
 
int result;
 
result = (~(AD1R | 0xFC00)) - OFFSET;
 
Regards,
Mac
 
0 Kudos

1,578 Views
fredycolombia
Contributor I
hi all,
this is a very useful information for my project with usb, I really be so thankful.

regards,
fredy
0 Kudos