| View previous topic :: View next topic |
| Author |
Message |
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Tue Apr 08, 2008 8:42 am |
|
|
The word offset means different things depending in the context. As to voltage it could mean the zero G reference point. Alternatively since the project will remain earth bound perhaps 1G is the offset and accelerations are references from their deviation to the 1G gravitation field. Now if the max and min voltages from the accelerometer fit inside the PIC voltage rails then
an op amp purely to provide a voltage shift is not needed. The op amp is useful for increasing the resolution via gain. The PIC is constrained to 10 bits over its input range. If _5g to 1g is of no interest then it is possible to map the 10 bit resolution to 1g to 5g. An op amp circuit would amplify the accelerometer out put in the 1G to 5G range so as 1G would be close to the PIC min voltage for ADC and 5G close to the max voltage. The op am has mapped the 1G to 5G out put to the full PIC range. This is only useful if the accelerometer can resolve the 1G 5G range into 10 bits (1024) graduations or approx milliVolt resolution. |
|
 |
Matro Guest
|
|
Posted: Tue Apr 08, 2008 8:47 am |
|
|
OK, so go back to start.
Actually you don't need an offset since it is already included in your sensor.
Now we know that, what you need to do in simple words.
Your acceleration will vary in a range of -5g to +5g.
So the output voltage of the sensor will vary from 0.94V to 4.06V.
This voltage is get by the ADC module of the PIC and convert in a digital value.
Range of digital value is (for 0V to 5V input range):
- 0x0000 to 0xFFC0 if left justified (with step of 0x0040)
- 0x0000 to 0x03FF if right justified (with step of 0x0001)
And then. Is that these values that you want to digitally offset?
And please don't speak in volts when you talk about digital values because it means nothing. ;-)
Try to explain very clearly what should be the complete data flow.
Matro. |
|
 |
horkesley
Joined: 20 Feb 2007 Posts: 48 Location: Essex UK
|
| ADXL320 |
Posted: Tue Apr 08, 2008 8:50 am |
|
|
Regarding the offset, this will vary from one device to another.
I have used a similar device and aranged for a calibration process, either at power up or when the G or tilt is zero.
Are you measuring dynamic or static G ?
Depending on your accuracy requirment you may need to filter the signal or possibly do some averaging. _________________ Horkesley Electronics Limited |
|
 |
Matro Guest
|
| Re: Thanks guys |
Posted: Tue Apr 08, 2008 8:53 am |
|
|
| kein wrote: | 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); |
|
You will need it anyway. The first 2 lines make the ADC 10-bit values to be right justified what is needed if you want to add several values without overflow.
The last line is needed because for adding values you need them to do proportional to "real" acceleration to have a significant result.
The external hardware offset is not needed, but these lines are needed if you want your calculations to be correct.
I don't know if "I never read the datasheet of the chip before but now some people did it for me I know that an external offset is not needed." is a very good argument to be presented to your boss. :-/
Matro. |
|
 |
kein
Joined: 23 Jul 2007 Posts: 103
|
| Very well |
Posted: Tue Apr 08, 2008 9:05 am |
|
|
If ,for example, my accelerometer output voltage were to range from -3.5V to +2.5V (-5g to +5g) then I'll definetly in this case offset the output. This is because :
V- =2.5 - 3.5 = -1V for -5g
V+=2.5 +2.5 =+5V for +5g
My offset voltage then will be +1V and digitally this will be 205 counts. And to remove the offset, the lecturer said I'll have to be inverting the most significant bits of adc counts in order to remove the offset.
This is where my confusion began to surface.
And yes I'm measuring dynamic acceleration
The following is a good lesson to learn for me.
| Quote: | | I don't know if "I never read the datasheet of the chip before but now some people did it for me I know that an external offset is not needed." is a very good argument to be presented to your boss | . |
|
 |
Matro Guest
|
|
Posted: Tue Apr 08, 2008 9:17 am |
|
|
| Quote: |
If ,for example, my accelerometer output voltage were to range from -3.5V to +2.5V (-5g to +5g) then I'll definetly in this case offset the output. This is because :
V- =2.5 - 3.5 = -1V for -5g
V+=2.5 +2.5 =+5V for +5g
|
In this case, the offset is 2.5V and you can't do so beacause the PIC can't have a negative input. So in this case you have to amplify your signal (by 0.75 for example).
I think that now you have understood that an external offset on the analog line is not needed since it is already provided by the sensor.
But where your boss is right is that you have to digitally invert this offset to perform calculations.
So you need to substract half range to the values. And binary laws make that this is equivalent to inverting MSB of the value.
Matro. |
|
 |
horkesley
Joined: 20 Feb 2007 Posts: 48 Location: Essex UK
|
| Offset |
Posted: Tue Apr 08, 2008 9:17 am |
|
|
You have to measure the offset at zero G, sensor level and stationary.
This is the voltage you must offset, make zero, or what ever you want. It will change from one sensor to another if you are to make several of these divices.
This voltage will be near Vcc/2 about 2.5 volts.
This is zero G, no acceleration and no tilt.
This is the method I used, I am sure there are other options. _________________ Horkesley Electronics Limited |
|
 |
kein
Joined: 23 Jul 2007 Posts: 103
|
| Very well |
Posted: Tue Apr 08, 2008 9:24 am |
|
|
Hi horkesley,
Did you mean I measure this voltage at zero G, convert it to digital number and then subtract it from adc count in software i.e. Nadc = ADCval - ZeroG ?
or did you mean after measuring this zero G value I should then design external offset circuitry to offset 2.5V |
|
 |
Matro Guest
|
| Re: Very well |
Posted: Tue Apr 08, 2008 9:27 am |
|
|
| kein wrote: | Hi horkesley,
Did you mean I measure this voltage at zero G, convert it to digital number and then subtract it from adc count in software i.e. Nadc = ADCval - ZeroG ?
|
Yes
| Quote: |
or did you mean after measuring this zero G value I should then design external offset circuitry to offset 2.5V |
No. nothing external is needed!
Matro. |
|
 |
mindstorm88
Joined: 06 Dec 2006 Posts: 102 Location: Montreal , Canada
|
|
Posted: Tue Apr 08, 2008 9:28 am |
|
|
| BTW guys don't forget that 0g is nearly impossible (depending of position) as gravity is always 1g !!!!! |
|
 |
horkesley
Joined: 20 Feb 2007 Posts: 48 Location: Essex UK
|
| Offset |
Posted: Tue Apr 08, 2008 9:30 am |
|
|
Hi Kein,
You don't need any external circuit unless you reguire a filter as the output can be noisy. For offset correction you do not need external circuit. _________________ Horkesley Electronics Limited |
|
 |
Matro Guest
|
|
Posted: Tue Apr 08, 2008 9:30 am |
|
|
| mindstorm88 wrote: | | BTW guys don't forget that 0g is nearly impossible (depending of position) as gravity is always 1g !!!!! |
If the sensor is 1-axe so if this horizontal it will be 0g when idle...
Matro. |
|
 |
kein
Joined: 23 Jul 2007 Posts: 103
|
| Thanks guys |
Posted: Tue Apr 08, 2008 9:37 am |
|
|
Thank you and thank you. Here is a section of my code.
| Code: | #include <18F4450.h>
#device *=16
#device adc=10
#BIT ADFM = 0xFC0.7
/*<<<<< Main function >>>>>>>>>>>>>>>>>>>>>>*/
void main()
{
//INT16U *data;
int8 k;
setup_adc_ports(AN0_AN1_AN2_AN4_AN5_VSS_VREF);
setup_adc(ADC_CLOCK_DIV_64); // setup_adc(ADC_OFF);
ADFM = 1;
set_adc_channel(0)
// TODO: USER CODE!!
while(1)
{
signed int16 res = 0L;
set_adc_channel(chan); // select the required channel
delay_us(10);
for(i = 0; i < 16; i++)
{
res += (signed int16)(read_adc()^ 0x0200);
}
res = (res >> 4); // Vs/2 = 2.5*1023/5 =512=i0x0200 s zero Gvalue
printf("\t%0Ld",res);
}
}
|
|
|
 |
Matro Guest
|
| Re: Thanks guys |
Posted: Tue Apr 08, 2008 9:53 am |
|
|
The variable "k" is not used.
The variable "chan" isn't defined.
The 2nd set_adc_channel() isn't needed if you always use the same channel (0).
The >>4 at the end is not needed anymore since the read values are already right justified.
Matro. |
|
 |
kein
Joined: 23 Jul 2007 Posts: 103
|
|
Posted: Tue Apr 08, 2008 10:04 am |
|
|
Sorry about that.
| Code: | #include <18F4450.h>
#device *=16
#device adc=10
#BIT ADFM = 0xFC0.7
signed int16 ReadAVerADC(char chan);
/*<<<<< Main function >>>>>>>>>>>>>>>>>>>>>>*/
void main()
{
//INT16U *data;
setup_adc_ports(AN0_AN1_AN2_AN4_AN5_VSS_VREF);
setup_adc(ADC_CLOCK_DIV_64); // setup_adc(ADC_OFF);
ADFM = 1;
//set_adc_channel(0)
// TODO: USER CODE!!
while(1)
{
signed int16 result=0L;
result = ReadAVerADC(0);
printf("\t%0Ld",result);
delay_ms(100);
}
}
signed int16 ReadAVerADC(char chan)
{
signed int16 res = 0L;
int i;
set_adc_channel(chan); // select the required channel
delay_us(10);
for(i = 0; i < 16; i++)
{
res += (signed int16)(read_adc()^ 0x0200);
}
return (res = res>> 4) //return average
}
|
| Code: | | The >>4 at the end is not needed anymore since the read values are already right justified. |
I''m getting the average of the results i.e. res /=16; |
|
 |
|