CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Offsetting Accelerometer outputs
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kein



Joined: 23 Jul 2007
Posts: 103

View user's profile Send private message

Offsetting Accelerometer outputs
PostPosted: Tue Apr 08, 2008 1:18 am     Reply with quote

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!! Embarassed

At the moment I'm feeding adxl320 output directly to pic18f4450 adc pin
kind regards,
s.kein
Matro
Guest







PostPosted: Tue Apr 08, 2008 2:24 am     Reply with quote

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







PostPosted: Tue Apr 08, 2008 3:21 am     Reply with quote

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

View user's profile Send private message

Offsetting Accelerometer outputs
PostPosted: Tue Apr 08, 2008 3:30 am     Reply with quote

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







PostPosted: Tue Apr 08, 2008 3:54 am     Reply with quote

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







PostPosted: Tue Apr 08, 2008 4:01 am     Reply with quote

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







PostPosted: Tue Apr 08, 2008 4:07 am     Reply with quote

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

View user's profile Send private message

I'm abit confused!
PostPosted: Tue Apr 08, 2008 6:07 am     Reply with quote

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







PostPosted: Tue Apr 08, 2008 6:22 am     Reply with quote

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

View user's profile Send private message

It's the voltage will never go negative
PostPosted: Tue Apr 08, 2008 6:43 am     Reply with quote

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







PostPosted: Tue Apr 08, 2008 7:27 am     Reply with quote

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

View user's profile Send private message

What I don't understand
PostPosted: Tue Apr 08, 2008 7:46 am     Reply with quote

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: 1909

View user's profile Send private message

Re: Offsetting Accelerometer outputs
PostPosted: Tue Apr 08, 2008 8:07 am     Reply with quote

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!! Embarassed

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

View user's profile Send private message

PostPosted: Tue Apr 08, 2008 8:12 am     Reply with quote

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 !!!! Very Happy
kein



Joined: 23 Jul 2007
Posts: 103

View user's profile Send private message

Thanks guys
PostPosted: Tue Apr 08, 2008 8:31 am     Reply with quote

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);
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group