ADC operation questions

Here is the place for all your dsPic or autopilot questions.

Moderator: lukasz

ADC operation questions

Postby Tinus » Sun Oct 31, 2010 10:11 am

Hello,

I am new to the glouonpilot project (awesome job!) I want to adapt the EKF used in the Gluonpilot to work on my own autopilot system, but first I am trying to understand your implementation. I have a couple of questions regarding the ADC operations.

Firstly I will be using two dsPIC30F4011 MCUs interfaced to eachother via SPI. The dsPIC30F4011 does not have the DMA capabilities that the dsPic33FJ256MC71 has so I am unfamiliar with its functions.

1. Could you please explain qualitatively what is being done in the following lines of code (top of adc.c)?
Code: Select all
// Number of locations for ADC buffer = 14 (AN0 to AN13) x 8 = 112 words
// Align the buffer to 128 words or 256 bytes. This is needed for peripheral indirect mode
unsigned int BufferA[MAX_CHNUM][SAMP_BUFF_SIZE]__attribute__((space(dma),aligned(256)));
unsigned int BufferB[MAX_CHNUM][SAMP_BUFF_SIZE]__attribute__((space(dma),aligned(256)));


In function ProcessADCSamples(unsigned int * AdcBuffer):
Code: Select all
return (unsigned int) (((long)(AdcBuffer[0]/4 + AdcBuffer[1]/4 + AdcBuffer[2]/4 + AdcBuffer[3]/4) + (long)(AdcBuffer[4]/4 + AdcBuffer[5]/4 + AdcBuffer[6]/4 + AdcBuffer[7]/4)) / 2);

which is called in adc_get_channel(int i) and returns:
Code: Select all
return ProcessADCSamples(&BufferA[i][0]) / 2 + ProcessADCSamples(&BufferB[i][0]) / 2;

what are the operations doing? Could you maybe explain using an example with a binary number?

2. You have acc_value_g = 6600, where is this value from? What does it represent?

3. Finally, the neutral values (ex. config.sensors.gyro_x_netural). Are they the bias values that are read when the sensors are being held still on a level surface?

Thank you and regards,
Tinus
Tinus
 
Posts: 5
Joined: Sun Oct 31, 2010 9:40 am
Location: South Africa

Re: ADC operation questions

Postby Tinus » Sun Oct 31, 2010 12:53 pm

Hello again,

I might be wrong, but it seems to me that the code I posted is a simple averaging of multiple samples. Am I correct in saying this?

I still however don't understand the difference between the contents of BufferA and BufferB and specifically what is happening here:
Code: Select all
return ProcessADCSamples(&BufferA[i][0]) / 2 + ProcessADCSamples(&BufferB[i][0]) / 2;

Does BufferB contain another 8 samples of the same channel as BufferA? If so, then this is just another averaging?

Also, the ADC is set up for 10-bit sampling, right?

Thank you and regards,
Tinus
Tinus
 
Posts: 5
Joined: Sun Oct 31, 2010 9:40 am
Location: South Africa

Re: ADC operation questions

Postby Tom » Sun Oct 31, 2010 3:30 pm

Hi Tinus,

Yes it is only averaging the samples. This is because the dsPic33 doesn't have a "slow" sample option. This code uses DMA, but the dsPic30 has better alternatives. ADC is 12-bit.

Tom
User avatar
Tom
Site Admin
 
Posts: 1016
Joined: Fri Nov 13, 2009 6:27 pm
Location: Belgium

Re: ADC operation questions

Postby Tinus » Sun Oct 31, 2010 5:04 pm

Hi Tom,

Thank you for your reply. :)

According to the datasheet:
AD12B: 10-Bit or 12-Bit Operation Mode bit
1 = 12-bit, 1-channel ADC operation
0 = 10-bit, 4-channel ADC operation

And from the adc.c file in Gluonpilot_src_v0.5.zip:
AD1CON1bits.AD12B = 0; // 12-bit ADC operation

Doesn't that mean that the ADC is being run in 10-bit mode? Or am I maybe missing something somewhere?

Thank you
Tinus
Tinus
 
Posts: 5
Joined: Sun Oct 31, 2010 9:40 am
Location: South Africa

Re: ADC operation questions

Postby Tinus » Sun Oct 31, 2010 10:40 pm

Hello again,

Regarding the value acc_value_g = 6600.0 .

Is this an approximation for the gravitational constant G (6.673x10^-11 m^3/kg/s^2)?

Sorry for all the questions, I like understanding how everything works :)

Regards
Tinus
Tinus
 
Posts: 5
Joined: Sun Oct 31, 2010 9:40 am
Location: South Africa

Re: ADC operation questions

Postby Tom » Mon Nov 01, 2010 9:55 am

Hi Titus,

Well yes apparently it is 10-bit. I must admit I've changed this ADC code several times because in my opinion it is very critical (sample speed vs. possible vibrations/interferences/moiré). Unfortunately it is too long ago to explain why I took 10-bit (while I took the dsPic33 because it has 12-bit ADC :-) ).

Yes, 6600 is the gravitational constant (9.81m/s^2) expressed in raw ADC values:
From the datasheet:
sensitivity: 300mV/g
ratiometric: (0.3V/g) / 3.3V = 0.091*[total ADC range] / g
[total ADC range] ~= 2^16 - 2^6
5952 / g

I guess I took 6600 because it is what experiments showed to be the best value.
User avatar
Tom
Site Admin
 
Posts: 1016
Joined: Fri Nov 13, 2009 6:27 pm
Location: Belgium

Re: ADC operation questions

Postby Tom » Mon Nov 01, 2010 9:56 am

Btw, feel free to document the code and I'll be happy to include it in the source tree :-)
User avatar
Tom
Site Admin
 
Posts: 1016
Joined: Fri Nov 13, 2009 6:27 pm
Location: Belgium


Return to Firmware

Who is online

Users browsing this forum: No registered users and 2 guests

cron