Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Congratulations !
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> AR7212
View previous topic :: View next topic  
Author Message
Kiedro

Bascom Member



Joined: 08 Mar 2006
Posts: 81

germany.gif
PostPosted: Tue Jun 07, 2011 11:32 am    Post subject: Reply with quote

Here is a code snippet for differential ADC on an AT128 - AT2560 is similar:
Code:

'-------------------- OLD 2DOF READING BY DIFFERENTIAL ADC Begin ---------------
Accelerometer:
            '';**** Analog to Digital Converter ****
            ''.equ ADEN = 7  ; ADCSR                 ADC ENABLE
            ''.equ ADSC = 6                          ADC START CONVERSION
            ''.equ ADFR = 5                          ADC FREE RUNNING SELECT (0 = single, 1 = free)
            ''.equ ADIF = 4                          ADC INTERRUPT FLAG (is set after conversion)
            ''.equ ADIE = 3                          ADC INTERRUPT ENABLE (set to enable)
            ''.equ ADPS2 = 2                         ADC PRESCALER SELECT BITS (000 = Prescaler 2
            ''.equ ADPS1 = 1                         ADC PRESCALER SELECT BITS      to..
            ''.equ ADPS0 = 0                         ADC PRESCALER SELECT BITS  111 = Prescaler 128)
            '
            ''.equ    REFS1   =7  ; ADMUX            ADC REFERENCE SELECT BITS (00 for AREF = voltage externally connected, to)
            ''.equ    REFS0   =6                     ADC REFERENCE SELECT BITS (11 for AREF = internal 2.56V reference)
            ''.equ    ADLAR   =5                     ADC LEFT ADJUST RESULT (0 = right adjusted, 1 = left adjusted result in ADSL und ADSH word)
            ''.equ    MUX4    =4                     ADC ANALOG CHANNEL AND GAIN SELECTION BITS (00000 - 00111 for normal to AGND)
            ''.equ    MUX3    =3                     ADC ANALOG CHANNEL AND GAIN SELECTION BITS (01001 for ADC1 - ADC0, gain = 10)
            ''.equ    MUX2    =2                     ADC ANALOG CHANNEL AND GAIN SELECTION BITS (01101 for ADC3 - ADC2, gain = 10)
            ''.equ    MUX1    =1                     ADC ANALOG CHANNEL AND GAIN SELECTION BITS
            ''.equ    MUX0    =0                     ADC ANALOG CHANNEL AND GAIN SELECTION BITS
            '
            ''     Admux = &B00001101
            ''     '         --             00 = AREF = VCC
            ''     '           -             0 = ADLAR left justify
            ''     '            -----    01101 = (VADC03-VADC02) * Gain * 512/VCC, Gain = 10
            ''     '                             gives for VADC03 - VADC02 = 312 mV max:
            ''     '                             0.312 * 10 * 512/5 = +319 to -320
            ''     Adcsra = &B11100000
            ''     '          -              1 = Enable ADC
            ''     '           -             1 = Start  ADC
            ''     '            -            1 = Free running conversion
            ''     '             -           0 = ADC interrupt flag (GETBIT)
            ''     '              -          0 = Enable ADC interrupt (SETBIT)
            ''     '               ---     000 = ADC prescaler = 2
            ''     '
            ''     '
            Admux = &B00001001                              ' configure for differential input ADC1-ADC0, Gain = 10
            Waitus 125                                      ' wait for setting
            Set Adcsr.aden                                  ' enable ADC
            Set Adcsr.adsc                                  ' start  ADC
            Do
            Loop Until Adcsr.adif = 1                       ' loop until conversion complete
            Set Adcsr.adif                                  ' Set flag again
            Lby = Adcl                                      ' Read low byte first
            Hby = Adch                                      'then high byte
            Iin = 256 * Hby                                 'convert into integer
            Iin = Iin + Lby
            If Iin => 512 Then Iin = Iin - 1024             'center to -512 ... +511
            Xacc(LoopKby) = Iin + Xaccoffin                     'correct offset
           
            Admux = &B00001101                              'configure for differential input ADC3-ADC2, Gain = 10
            Waitus 125
            Set Adcsr.aden                                  ' enable ADC
            Set Adcsr.adsc                                  ' start  ADC
            Do
            Loop Until Adcsr.adif = 1                       ' loop until conversion complete
            Set Adcsr.adif                                  ' Set flag again
            Lby = Adcl                                      ' Read low byte first
            Hby = Adch                                      'then high byte
            Iin = 256 * Hby                                 'convert into integer
            Iin = Iin + Lby
            If Iin => 512 Then Iin = Iin - 1024             'center to -512 ... +511
            Yacc(LoopKby) = Iin + Yaccoffin                     'correct offset
           
           
            ''If Autonomousservocontrolflag = 0 Then
            ''   'just a Test routine which is not active on direct steering
            ''   Adxxacc = 0
            ''   Adxyacc = 0                                  'moving average from last 10 conversions
            ''   For Lby = 1 To 10
            ''       Adxxacc = Adxxacc + Xacc(lby)
            ''       Adxyacc = Adxyacc + Yacc(lby)            'max. Adx.acc is 3200 (10 x 320) in theory
            ''   Next Lby
            ''
            ''   Isi = Adxxacc
            ''   Isi = Isi * .3                               'from *3/10 for a almost full servomove of 960 (= 3 X 320) in each direction
            ''   Pulse_rudder = Isi
            ''   Pulse_rudder = Pulse_rudder + 3000
            ''
            ''   Isi = Adxyacc
            ''   Isi = Isi * .3
            ''   Pulse_elevator = Isi
            ''   Pulse_elevator = Pulse_elevator + 3000
            ''End If
            '
Return
'-------------------- OLD 2DOF READING BY DIFFERENTIAL ADC END ---------------
 
Back to top
View user's profile
Matrixx

Bascom Member



Joined: 30 Nov 2005
Posts: 154

mexico.gif
PostPosted: Wed Jun 08, 2011 7:08 am    Post subject: Reply with quote

Thank you Kiedro,

I have been reading the M2560 datasheet and dig some on differential inputs. I'm kinda slow to understand Embarassed
However I don't see how I will use differential input on Gyro signal as it is singe ended. I mean the gyro axis output is going from say 0.9V to 1.6V so there is no differential output.

Maybe if I put a load resistors and attach the diff inputs to the ends of one of them..? and set gain of 200?

Or using a opamp.


Well, Looks my budget is geting fine so I will order some low scale gyros from sparkfun. I'm in doubt to order 30deg/sec or 60deg/sec gyros. I think a gyro under 100deg/sec will be fine for my application.
Back to top
View user's profile
Kiedro

Bascom Member



Joined: 08 Mar 2006
Posts: 81

germany.gif
PostPosted: Wed Jun 08, 2011 12:43 pm    Post subject: Reply with quote

Oh, I forgot to mention this: The gyros have a Vref output, 1.? V. I would just feed Vref to a voltage divider, e.g. two 10k resistors:

Vref---R---ADC0---R---GND. Have ADC0 connected to ADC0 and ADC2, gyro x to ADC1 and gyro y to ADC3. Differential ADC needs a little work on calibration/offsetting (described in the data sheet) - but it pays back. I would start using gain 10, with 200 you might run into a saturation problem.

Natalius
Back to top
View user's profile
Matrixx

Bascom Member



Joined: 30 Nov 2005
Posts: 154

mexico.gif
PostPosted: Mon Apr 23, 2012 4:23 pm    Post subject: Reply with quote

Hello!!

Time has been passed. I continued this year with my hobby projects left due to lack of time.

I'm getting again to the vehicle and driving forces. Now I have built a IMU unit using 3 Gyros and 3 Accelerometers. For automotive application I choose XV-8000 single axis gyros, and ADXL202 +/-2G accelerometers.

I mounted the sensors in a 3D configuration. Form my past experience the Gyro range was big enough for my application so now I bough +/-60 degs'sec range ones. In my corners I expect +/-30 Deg/sec.

I'm now using a Arduino M2560 R3 but just the hardware, all the current and new firmware is written in Bascom.

I tested the IMU with both Lauzus Kalman algorythm and complementary filter as well (Ported Luzus algorythm to Delphi to avoid reflashing the M2560) so the Atmel just send ADC values thru serial port.

I would like to test with DCM.

This is new for me, I have the IMU running, but now I'm looking what to do with... Razz


My original target is 'separating' the gravity forces from the accelerometer but as one of you mentioned, with the anterior 5DOF I was lacking the Yaw. Altough I have now Z gyro, I realized I need more DOF (Zgyro + Compass). In one chance I will get a compass to complement the IMU.
Back to top
View user's profile
Per Svensson

Bascom Member



Joined: 03 Oct 2004
Posts: 164
Location: Gothenburg, Sweden

sweden.gif
PostPosted: Fri Jan 10, 2014 5:13 pm    Post subject: Reply with quote

Kiedro,

After a very long time with other matters I return to the Inertial sensor world of problems.
I read your threads again and I must say I'm amazed how much work and insights you have dug down into
this forum when it comes to sensor fusing and all math involved. I am truly impressed

I remember that I wrote a thread about Kalman filters some time ago
( http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=11265&highlight=dummies )
and maybe it is time to contribute with something else soon...

Anyway, as some time has passed and new sensor devices has been introduced at an unstoppable pace.
I now wonder if someone here (perhaps you Kiedro) have evaluated the Invensense 9250 http://www.invensense.com/mems/gyro/mpu9250.html
It incorporate 3D Accel+Gyro plus input for 3D Magnetometers. And it also contains software for 9DOF sensor fusion.
All on the same chip (4x4mm) !!!
I have not yet read all the documentation, and I'm particularly interested to see if the firmware have support for Soft-iron calibration
of the magnetometers.

My current interest is to design a full 3D compass solution with hard and soft iron compensation ON THE FLY.
That is, adaptive recognition and elimination of offsets and non-linear flux for full 3D use.
The idea is that the device shall successively learn the distortion of the surrounding magnetic field lines due to magnetic objects attached to the
sensor frame, and eliminate it.
There are many many academic articles written about this problem and I have read most of them but still not found an engineering approach to the problem.
Many of them can do a static calibration with the use of massive matrix math, but few or none can do it as a natural part of the device operation.

The thing is that if you make a device that MUST be calibrated AFTER the device was mounted on the target equipment, then the procedure must
be simple enough for an unskilled person to perform it.
In practice, this doesn't work. End-users don't even want to get involved in these delicate matters. It should simply work out_of_the_box.

So the only solution for good sensor solutions today rely on two corner stones as i see it:
1: Multiple sensor fusion (and perhaps redundant sensors)
2. Adaptive calibration algorithms (Preferably no special modes. Just plain run)

So if you who bothered to read this far. Perhaps you could also give some thoughts or experience from how to turn academic
fire-flies into real embedded solutions...


Friday afternoon now. Time for a glass of wine and drift away from sensors and ugly software.
Cheers

/Per


Some links about magnetometer calibration:
----------------------------------------------
http://www.roboticsproceedings.org/rss09/p50.pdf
http://www.sgp.geodezja.org.pl/ptfit/wydawnictwa/krakow2011/APCRS%20vol.%2022%20pp.%209-23.pdf
http://www.ignss.org/LinkClick.aspx?fileticket=7oH5%2FnHXZyY%3D&tabid=88&mid=424
http://sailboatinstruments.blogspot.se/2011/08/improved-magnetometer-calibration.html <- I have tested this with good results, but it offers static calibration only
http://sailboatinstruments.blogspot.se/2011/09/improved-magnetometer-calibration-part.html
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> AR7212 All times are GMT + 1 Hour
Goto page Previous  1, 2, 3
Page 3 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
You cannot attach files in this forum
You cannot download files in this forum