adc value for IMU

Digital Fiber, Photoelectric, Laser Range, Optical, Temperature, Rotary Encoder, Ultrasonic, Gas, Gyro, Accelerometer, FlexiBend, Flexiforce, Compass......

adc value for IMU

Postby watisthis » Wed Jan 20, 2010 2:30 pm

i'm testing IMU for static condition,,
means the value when the board is in flat surface/not moving
currently measuring raw value from adc for x & y axis...
CODE: SELECT_ALL_CODE
float accelero_x()
{
   set_ADC_channel(0);
   delay_us(20);
   return read_adc();
}

float accelero_y()
{
   set_ADC_channel(5);
   delay_us(20);
   return read_adc();
}

this is what i do..
but the value moved a lot,, it is not static at all, also the range quite big
it can be 100++ to full masurement 1023....
how can get the value?
watisthis
Newbie
 
Posts: 10
Joined: Sun Jan 03, 2010 3:28 pm

Re: adc value for IMU

Postby A380 » Thu Jan 21, 2010 3:28 pm

I ever use IMU but I didn't face this problem before. May be your ADC configuration problem. Make sure IMU is supplied at 3.3V. According to its datasheet, the axis output might around 3.3V/2 = 1.65V in 0 gravity which is 1023/2 = 512 in your ADC value if the Vref connected to 3.3V.
User avatar
A380
Discoverer
 
Posts: 120
Joined: Tue May 19, 2009 2:44 pm
Location: Malaysia

Re: adc value for IMU

Postby watisthis » Thu Jan 21, 2010 6:46 pm

when you said Vref did you mean one on the PIC or IMU...
i connected the RA3 pin on PIC to 3.3V as ref. voltage,,
as for IMU the Vref pin is not connected to anywhere...

or did i get the wrong idea here?

my setup for adc
CODE: SELECT_ALL_CODE
   setup_adc_ports( ANALOG_RA3_REF );
   setup_adc( ADC_CLOCK_DIV_32 );


i'm using PIC16f877a with 20M osc..
watisthis
Newbie
 
Posts: 10
Joined: Sun Jan 03, 2010 3:28 pm

Re: adc value for IMU

Postby mk99011 » Thu Jan 21, 2010 11:12 pm

hi a380,may i hav ur full programming?thanks
mk99011
Fledgling
 
Posts: 1
Joined: Thu Jan 21, 2010 11:08 pm

Re: adc value for IMU

Postby A380 » Fri Jan 22, 2010 11:15 am

watisthis WROTE:when you said Vref did you mean one on the PIC or IMU...
i connected the RA3 pin on PIC to 3.3V as ref. voltage,,
as for IMU the Vref pin is not connected to anywhere...

or did i get the wrong idea here?


Ya, you are right. I mean the PIC Vref.

mk99011 WROTE:hi a380,may i hav ur full programming?thanks


Sorry, I didn't keep the programming. Last time I used dsPIC6012A as my controller.
Something is like this
CODE: SELECT_ALL_CODE
unsigned int read_adc(unsigned int channel)
{
   unsigned int i;
   ADCHS=channel;            //select channel
   ADCON1bits.SAMP=1;         //start sampling adc
   for(i=700;i>0;i-=1);              //sampling delay
   ADCON1bits.SAMP=0;         //stop sampling, start conversion
   while(ADCON1bits.DONE==0);           //wait for conversion to finish
   i=ADCBUF0;
   return i;   
}


This code is for dsPIC which I used last time and not suitable for 16F877A. The sampling delay is quite important for ADC sampling capacitor (C hold) charging.
For correct A/D conversions, the A/D conversion clock (TAD) must be selected to ensure minimum TAD time of 1.6 μs. (Page 131 of PIC16F877A datasheet, under section 11.2 Selecting the A/D Conversion Clock)
So, I think you can try to change the ADCS2:ADCS1:ADCS0, may be 32Tosc or 64Tosc.

Good Luck!
User avatar
A380
Discoverer
 
Posts: 120
Joined: Tue May 19, 2009 2:44 pm
Location: Malaysia

Re: adc value for IMU

Postby watisthis » Fri Jan 22, 2010 5:21 pm

so what i'm doing is right..
then, what might be the problem?
watisthis
Newbie
 
Posts: 10
Joined: Sun Jan 03, 2010 3:28 pm

Re: adc value for IMU

Postby aurora » Sat Jan 23, 2010 1:08 pm

Try change the variable type for accelero_x and accelero_y from float to int16/long. See if it works and do let us know the result.
aurora
Discoverer
 
Posts: 126
Joined: Sun Jun 07, 2009 4:52 pm

Re: adc value for IMU

Postby watisthis » Sun Jan 24, 2010 12:08 pm

CODE: SELECT_ALL_CODE
void main ()
{
   lcd_init();

   setup_adc_ports( ANALOG_RA3_REF );
   setup_adc( ADC_CLOCK_DIV_32 );

   while (1)
   {
      printf(lcd_putc,"\fX:%Ld   Y:%Ld\nz:%Ld",accelero_x(),accelero_y(),accelero_z());
      delay_ms(350);
     
   }
}

int16 accelero_x()
{
   set_ADC_channel(0);
   delay_us(20);
   return read_adc();
}

int16 accelero_y()
{
   set_ADC_channel(5);
   delay_us(20);
   return read_adc();
}

int16 accelero_z()
{
   set_ADC_channel(6);
   delay_us(20);
   return read_adc();
}

still the value "jumpy"
watisthis
Newbie
 
Posts: 10
Joined: Sun Jan 03, 2010 3:28 pm

Re: adc value for IMU

Postby aurora » Sun Jan 24, 2010 1:28 pm

I have never seen anyone use printf with function declared inside it.
CODE: SELECT_ALL_CODE
printf(lcd_putc,"\fX:%Ld   Y:%Ld\nz:%Ld",accelero_x(),accelero_y(),accelero_z());

Try something like this:
CODE: SELECT_ALL_CODE
x = accelero_x;
y = accelero_y;
z = accelero_z;
printf(lcd_putc,"\fX:%Ld   Y:%Ld\nz:%Ld",x,y,z);
aurora
Discoverer
 
Posts: 126
Joined: Sun Jun 07, 2009 4:52 pm

Re: adc value for IMU

Postby watisthis » Sun Jan 24, 2010 6:00 pm

still, not doing any better..
but i realized now that my Vref varies a bit from 3.3v~3.29v
watisthis
Newbie
 
Posts: 10
Joined: Sun Jan 03, 2010 3:28 pm

Next

Return to Sensor

Who is online

Users browsing this forum: No registered users and 7 guests

cron