View previous topic :: View next topic |
Author |
Message |
kein
Joined: 23 Jul 2007 Posts: 103
|
Offsetting Accelerometer outputs |
Posted: Tue Apr 08, 2008 1:18 am |
|
|
My project supervisor is driving me nut! He said that the output from adxl320 (+-5g) accelerometer must be offsetted in order to obtain acceleration and deceleration(dynamic acceleration). My supply voltage to adxl320 is 5V.
I've not seen anywhere where this is done! The question is, is this necessary? Can someone suggest some calculations for this?
The following is what this nutty Dr. demanded
when
Vacc= +2.5V---------------Vo =+5.0V
Vacc= 0V --------------Vo= +2.5V
Vacc= -2.5V --------------Vo= +0.0V
Vacc is the Voutput from the accelerometer
Vo is the Voutput from the opam or offsetting circuit and should be fed to pic18F4450 ADC pin.
He suggest that I should invert the most significant bit of ADC values in software in order to get correct values(remove offset) plus convert values to signed int16. How do I do this given the fact CCS C compiler uses read_adc(chan)?
Please help I'm running nut!!
At the moment I'm feeding adxl320 output directly to pic18f4450 adc pin
kind regards,
s.kein |
|
|
Matro Guest
|
|
Posted: Tue Apr 08, 2008 2:24 am |
|
|
Sorry but your question can't be understood since we don't know what are Vacc and Vo.
What is the voltage range of the sensor?
If Vacc is the real voltage range so you can't measure it since there are negative values.
You wrote "read_adc(chan)", but what is the configuration of your ADC?
8 bits or 10 bits?
In case of 10 bits, right aligned or left aligned?
Post your adc configuration for further help.
Matro. |
|
|
Ttelmah Guest
|
|
Posted: Tue Apr 08, 2008 3:21 am |
|
|
If you are feeding the accelerometer output 'directly to the PIC pin', you risk damaging the chip.... The PIC has input protection diodes, that will clamp any voltage going more than about 0.6v below ground.
Use the op-amp as you show. So now you get:
+5g = +2.5v -> op-amp 5v out
0g = 0v -> op-amp 2.5v out
-5g = -2.5v - op-amp 0v out.
Then feed this into the PIC.
If you set the ADC to be working in 10bit mode, so now you get:
+5g = 1023
0g = 512
-5g = 0
Ensure that the value you put this into, is a _signed_ int16 value.
Then simply subtract 512 from this.
Done. |
|
|
kein
Joined: 23 Jul 2007 Posts: 103
|
Offsetting Accelerometer outputs |
Posted: Tue Apr 08, 2008 3:30 am |
|
|
Sorry Matro for the unclarity plus my broken english.
The adxl320 accelerometer is +-5g and the input voltage,Vin, for accelerometer is 5V, the output sensitivity is typically 312 mV/g. Which means +1g = 0.312V/g and for
+5g , +Vomax= + 0.312 * 5(g/g ) = +1.56V at maximum +5g
- 5g , -Vomax=+ 0.312*-5 (g/g ) = -1.56V at maximum -5g
are these correct?
and because the dynamic acceleration swing between positive and negative which is sinusoidal, the Dr. Said i should provide an offset circuitry before connecting the adxl320 to pic. The above values are to be amplified usign lm741 i.e Vo/Vi =gain and Vo = 5V. R2/R1 =gain. in this case I'll be measuring both acceleration and deceleration.
He said I should then invert the most significant bit of adc values to remove the offset and assigned the results to a signed variable. How do I do below is a section of my code?
Vacc is the output signal (voltage) from adxl320 accelerometer which is either from y or x pin.
below is the configuration of my adc
Code: | #include <18F4450.h>
#device *=16
#device adc=10
...........................
void main()
{
signed int16 result =0L;
unsigned in32 res=0;
setup_adc_ports(AN0_AN1_AN2_AN4_AN5_VSS_VREF);
setup_adc(ADC_CLOCK_DIV_64); // setup_adc(ADC_OFF);
set_adc_channel(0);
// TODO: USER CODE!!
while(1)
{
set_adc_channel(0);
delay_us(10);
for(i = 0; i < 16; i++)
{
results += (unsigned int16)read_adc();
}
result = (signed int16)(results >> 4);
printf("%0Ld\n",result);
delay_ms(100);
}
} |
|
|
|
Matro Guest
|
|
Posted: Tue Apr 08, 2008 3:54 am |
|
|
Now this is clear.
Concerning the hardware offset to add you will need to implement an operational amplifier in summing configuration that will add 2.5V to the sensor output.
Concerning your code you are doing a sum of some results. The problem here is that the default behavior of ADC module is to left-justified the values. So you will quickly trigger an overflow and have a wrong value.
To right justified the values, you have to had these lines to your code :
Code: |
#BIT ADFM = 0xFC0.7
...
ADFM = 1;
|
You have to remove the offset before summing the values. To do so, replace
Code: |
results += (unsigned int16)read_adc();
|
by
Code: |
results += (unsigned int16) (read_adc() ^ 0x0200);
|
For a secure result never sum more than 32 values.
Matro. |
|
|
Matro Guest
|
|
Posted: Tue Apr 08, 2008 4:01 am |
|
|
Matro wrote: |
You have to remove the offset before summing the values. To do so, replace
Code: |
results += (unsigned int16)read_adc();
|
by
Code: |
results += (unsigned int16) (read_adc() ^ 0x0200);
|
|
Sorry but a mistake here :
Replace
Code: |
results += (unsigned int16)read_adc();
|
by
Code: |
results += (unsigned int16) (read_adc() - 0x200);
|
Matro |
|
|
Matro Guest
|
|
Posted: Tue Apr 08, 2008 4:07 am |
|
|
Final add :
Actually both ways are equivalent and will give the same result.
Maybe even prefer the first one for optimization reason, but if the compiler is good both will give the same ASM code.
Still sorry for this "hesitation".
Matro. |
|
|
kein
Joined: 23 Jul 2007 Posts: 103
|
I'm abit confused! |
Posted: Tue Apr 08, 2008 6:07 am |
|
|
Thanks alot Matro for your contribution.
I'm a bit confused about accelerometer range voltage calculation. I understand that zero Gs voltage is Vs/2 =2.5V approxim (Vs is supply voltage to the accelerometer) while the accelerometer sits on flat surface.
However, at Vs 5V, the output sensitivity is typically 312 mV/g meaning 1g is 0.312V And +-5g = +-1.56V.
How can we combine this with zero G voltage to workout offset voltage? I'm very confused.
Will I be correct to say:
Vs/2+-1.56 to Vs/2 + 1.56 = 2.5-1.56 to 2.5 +1.56 =0.44V to 4.06V
But then this calculation shows no negative voltage and I would wonder why we need to offset the accelerometer output?
S.kein |
|
|
Matro Guest
|
|
Posted: Tue Apr 08, 2008 6:22 am |
|
|
At now your right except a calculation mistake :
2.5-1.56 = 0.94V
Of course this calculation shows no negative value. That is the goal since the PIC ADC can only acquire positive voltage.
Once the A-to-D conversion is done, you can recover the true values by substracting the digital value of the analog offset that has been added.
That's what is done in the previous example. :-)
I'm not sure to well understand your question.
But as I already explained, the accelerometer output shall be offset because the PIC only accept (and convert) values that are in its power voltage range (Vss - Vdd). In this case 0 to 5V.
Matro. |
|
|
kein
Joined: 23 Jul 2007 Posts: 103
|
It's the voltage will never go negative |
Posted: Tue Apr 08, 2008 6:43 am |
|
|
Hi Matro, My confusion only arises from the fact that adxl320 output will never go negative if:
1) -5g gives -1.56V and at zero G this voltage reduces to 0.94V because zero G voltage =Vs/2 = 5/2 =2.5.
Why then bother add a voltage offset if Vaccelerometer never goes negative?
The voltage will only be negative inside the processor when zero G is subtracted i.e.
Vadc = Vacc - VzeroG
= Vacc - 2.5 depending on the orientation.
S.Kein |
|
|
Matro Guest
|
|
Posted: Tue Apr 08, 2008 7:27 am |
|
|
The accelerometer output WILL be negative. But the voltage in input of the PIC will never be thanks to an op-amp circuitry.
The op-amp will just create a offset that will do that :
sensor value --> sensor output --> op-amp output
-5g --> -1.56V --> 0.94V
0g --> 0V --> 2.5V
+5g --> +1.56V --> 4.06V
The PIC input will never be negative THANKS TO the offset.
I really can't see clearly where is the locking point for you and what you don't clearly understand. ;-)
Matro. |
|
|
kein
Joined: 23 Jul 2007 Posts: 103
|
What I don't understand |
Posted: Tue Apr 08, 2008 7:46 am |
|
|
Sorry Matro if I'm becoming more bothering.
What I don't understand is why I should provide an additional external offset circuitry?
When you mentioned "But the voltage in input of the PIC will never be thanks to an op-amp circuitry. The op-amp will just create a offset that will do that : ", did you mean the pic16f4450 internal Op-amp circuitry?
kind regards,
S.Kein |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1908
|
Re: Offsetting Accelerometer outputs |
Posted: Tue Apr 08, 2008 8:07 am |
|
|
kein wrote: | My project supervisor is driving me nut! He said that the output from adxl320 (+-5g) accelerometer must be offsetted in order to obtain acceleration and deceleration(dynamic acceleration). My supply voltage to adxl320 is 5V.
I've not seen anywhere where this is done! The question is, is this necessary? Can someone suggest some calculations for this?
The following is what this nutty Dr. demanded
when
Vacc= +2.5V---------------Vo =+5.0V
Vacc= 0V --------------Vo= +2.5V
Vacc= -2.5V --------------Vo= +0.0V
Vacc is the Voutput from the accelerometer
Vo is the Voutput from the opam or offsetting circuit and should be fed to pic18F4450 ADC pin.
He suggest that I should invert the most significant bit of ADC values in software in order to get correct values(remove offset) plus convert values to signed int16. How do I do this given the fact CCS C compiler uses read_adc(chan)?
Please help I'm running nut!!
At the moment I'm feeding adxl320 output directly to pic18f4450 adc pin
kind regards,
s.kein |
I don't mean to burst your bubble, but you really need to read the datasheet again. In particular, look at page 10: http://www.analog.com/UploadedFiles/Data_Sheets/84033828ADXL320_0.pdf. The output of this chip NEVER goes negative. |
|
|
mindstorm88
Joined: 06 Dec 2006 Posts: 102 Location: Montreal , Canada
|
|
Posted: Tue Apr 08, 2008 8:12 am |
|
|
Kein , have read the datasheet ???? according to it , you'll never get negative voltages , at 0 g you'll be at half vcc in your case 2.5 vdc .
at vcc 5v you have 312mv per G so -5g should be about 0.94vdc and 5g about 4.06 vdc !!!!!!
OUPSSS newguy you were faster than me !!!! |
|
|
kein
Joined: 23 Jul 2007 Posts: 103
|
Thanks guys |
Posted: Tue Apr 08, 2008 8:31 am |
|
|
Thanks alot guys. I now have a strong argument to put forward to my bloody nutty Dr...
Because the transfer function for adxl320 is V = (Vs/2 + Coal )+ (0.312*g)
= 2.5 +Coal + (0.312*g)
where Coal is calibration constant
As discussed:
-5g =0.94V
+5g =4.06V
0.0g =2.5V
Then I don't need an external offset circuitry
and because the values never go negative i don't need to use the following as well:
Code: |
#BIT ADFM = 0xFC0.7
...
ADFM = 1;
results += (unsigned int16) (read_adc() ^ 0x0200); |
|
|
|
|