Subversion Repositories NaviCtrl

Rev

Rev 330 | Rev 339 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 330 Rev 338
Line 73... Line 73...
73
#define MAG_TYPE_NONE           0
73
#define MAG_TYPE_NONE           0
74
#define MAG_TYPE_HMC5843        1
74
#define MAG_TYPE_HMC5843        1
75
#define MAG_TYPE_LSM303DLH      2
75
#define MAG_TYPE_LSM303DLH      2
76
u8 NCMAG_MagType = MAG_TYPE_NONE;
76
u8 NCMAG_MagType = MAG_TYPE_NONE;
Line 77... Line 77...
77
 
77
 
78
#define CALIBRATION_VERSION 1
78
#define CALIBRATION_VERSION                     1
-
 
79
#define EEPROM_ADR_MAG_CALIBRATION              50
Line 79... Line 80...
79
#define EEPROM_ADR_MAG_CALIBRATION 50
80
#define MAG_CALIBRATION_COMPATIBEL              0xA1
80
 
81
 
81
#define NCMAG_MIN_RAWVALUE -2047
82
#define NCMAG_MIN_RAWVALUE -2047
Line 175... Line 176...
175
#define LSM303DLH_CRA_RATE_3_0HZ        0x08
176
#define LSM303DLH_CRA_RATE_3_0HZ        0x08
176
#define LSM303DLH_CRA_RATE_7_5HZ        0x0C
177
#define LSM303DLH_CRA_RATE_7_5HZ        0x0C
177
#define LSM303DLH_CRA_RATE_15HZ         0x10    //default
178
#define LSM303DLH_CRA_RATE_15HZ         0x10    //default
178
#define LSM303DLH_CRA_RATE_30HZ         0x14
179
#define LSM303DLH_CRA_RATE_30HZ         0x14
179
#define LSM303DLH_CRA_RATE_75HZ         0x18
180
#define LSM303DLH_CRA_RATE_75HZ         0x18
-
 
181
 
180
// bit mask for gain
182
// bit mask for gain
181
#define LSM303DLH_CRB_GAIN_XXGA         0x00
183
#define LSM303DLH_CRB_GAIN_XXGA         0x00
182
#define LSM303DLH_CRB_GAIN_13GA         0x20    //default
184
#define LSM303DLH_CRB_GAIN_13GA         0x20    //default
183
#define LSM303DLH_CRB_GAIN_19GA         0x40
185
#define LSM303DLH_CRB_GAIN_19GA         0x40
184
#define LSM303DLH_CRB_GAIN_25GA         0x60
186
#define LSM303DLH_CRB_GAIN_25GA         0x60
185
#define LSM303DLH_CRB_GAIN_40GA         0x80
187
#define LSM303DLH_CRB_GAIN_40GA         0x80
186
#define LSM303DLH_CRB_GAIN_47GA         0xA0
188
#define LSM303DLH_CRB_GAIN_47GA         0xA0
187
#define LSM303DLH_CRB_GAIN_56GA         0xC0
189
#define LSM303DLH_CRB_GAIN_56GA         0xC0
188
#define LSM303DLH_CRB_GAIN_81GA         0xE0
190
#define LSM303DLH_CRB_GAIN_81GA         0xE0
189
// self test value
191
// self test value
190
#define LSM303DLH_TEST_XSCALE   655
192
#define LSM303DLH_TEST_XSCALE   495
191
#define LSM303DLH_TEST_YSCALE   655
193
#define LSM303DLH_TEST_YSCALE   495
192
#define LSM303DLH_TEST_ZSCALE   630
194
#define LSM303DLH_TEST_ZSCALE   470
Line 193... Line 195...
193
 
195
 
194
// the i2c ACC interface
196
// the i2c ACC interface
195
#define ACC_SLAVE_ADDRESS               0x30    // i2c slave for acc. sensor registers
197
#define ACC_SLAVE_ADDRESS               0x30    // i2c slave for acc. sensor registers
196
// register mapping
198
// register mapping
Line 249... Line 251...
249
volatile s16vec_t MagRawVector;
251
volatile s16vec_t MagRawVector;
Line 250... Line 252...
250
 
252
 
251
 
253
 
252
u8 NCMag_CalibrationWrite(void)
254
u8 NCMag_CalibrationWrite(void)
253
{
255
{
254
        u8 i, crc = 0xAA;
256
        u8 i, crc = MAG_CALIBRATION_COMPATIBEL;
Line 255... Line 257...
255
        EEPROM_Result_t eres;
257
        EEPROM_Result_t eres;
256
        u8 *pBuff = (u8*)&Calibration;
258
        u8 *pBuff = (u8*)&Calibration;
Line 267... Line 269...
267
        return(i);     
269
        return(i);     
268
}
270
}
Line 269... Line 271...
269
 
271
 
270
u8 NCMag_CalibrationRead(void)
272
u8 NCMag_CalibrationRead(void)
271
{
273
{
272
        u8 i, crc = 0xAA;
274
        u8 i, crc = MAG_CALIBRATION_COMPATIBEL;
Line 273... Line 275...
273
        u8 *pBuff = (u8*)&Calibration;
275
        u8 *pBuff = (u8*)&Calibration;
274
 
276
 
275
        if(EEPROM_SUCCESS == EEPROM_ReadBlock(EEPROM_ADR_MAG_CALIBRATION, pBuff, sizeof(Calibration)))
277
        if(EEPROM_SUCCESS == EEPROM_ReadBlock(EEPROM_ADR_MAG_CALIBRATION, pBuff, sizeof(Calibration)))
Line 331... Line 333...
331
               
333
               
332
                case 5:
334
                case 5:
333
                        // Save values
335
                        // Save values
334
                        if(Compass_CalState != OldCalState) // avoid continously writing of eeprom!
336
                        if(Compass_CalState != OldCalState) // avoid continously writing of eeprom!
335
                        {
337
                        {
-
 
338
//                              #define MIN_CALIBRATION    256
336
                                #define MIN_CALIBRATION    256
339
                                #define MIN_CALIBRATION    450
337
                                Calibration.MagX.Range = Xmax - Xmin;
340
                                Calibration.MagX.Range = Xmax - Xmin;
338
                                Calibration.MagX.Offset = (Xmin + Xmax) / 2;
341
                                Calibration.MagX.Offset = (Xmin + Xmax) / 2;
339
                                Calibration.MagY.Range = Ymax - Ymin;
342
                                Calibration.MagY.Range = Ymax - Ymin;
340
                                Calibration.MagY.Offset = (Ymin + Ymax) / 2;
343
                                Calibration.MagY.Offset = (Ymin + Ymax) / 2;
Line 620... Line 623...
620
//----------------------------------------------------------------
623
//----------------------------------------------------------------
621
void InitNC_MagnetSensor(void)
624
void InitNC_MagnetSensor(void)
622
{
625
{
623
        s16 xscale, yscale, zscale;
626
        s16 xscale, yscale, zscale;
624
        u8 crb_gain, cra_rate;
627
        u8 crb_gain, cra_rate;
625
        u8 i = 0, retval = 1;
628
//      u8  retval = 1;
Line 626... Line 629...
626
 
629
 
627
        switch(NCMAG_MagType)
630
        switch(NCMAG_MagType)
628
        {
631
        {
629
                case MAG_TYPE_HMC5843:
632
                case MAG_TYPE_HMC5843:
Line 633... Line 636...
633
                        yscale = HMC5843_TEST_YSCALE;
636
                        yscale = HMC5843_TEST_YSCALE;
634
                        zscale = HMC5843_TEST_ZSCALE;
637
                        zscale = HMC5843_TEST_ZSCALE;
635
                        break;
638
                        break;
Line 636... Line 639...
636
 
639
 
637
                case MAG_TYPE_LSM303DLH:
640
                case MAG_TYPE_LSM303DLH:
638
                        crb_gain = LSM303DLH_CRB_GAIN_13GA;
641
                        crb_gain = LSM303DLH_CRB_GAIN_19GA;
639
                        cra_rate = LSM303DLH_CRA_RATE_75HZ;
642
                        cra_rate = LSM303DLH_CRA_RATE_75HZ;
640
                        xscale = LSM303DLH_TEST_XSCALE;
643
                        xscale = LSM303DLH_TEST_XSCALE;
641
                        yscale = LSM303DLH_TEST_YSCALE;
644
                        yscale = LSM303DLH_TEST_YSCALE;
642
                        zscale = LSM303DLH_TEST_ZSCALE;
645
                        zscale = LSM303DLH_TEST_ZSCALE;
Line 643... Line 646...
643
                        break;
646
                        break;
644
 
647
 
645
                default:
648
                default:
Line 646... Line 649...
646
                return(0);
649
                return;
647
        }
650
        }
648
 
651
 
Line 711... Line 714...
711
                        yscale = HMC5843_TEST_YSCALE;
714
                        yscale = HMC5843_TEST_YSCALE;
712
                        zscale = HMC5843_TEST_ZSCALE;
715
                        zscale = HMC5843_TEST_ZSCALE;
713
                        break;
716
                        break;
Line 714... Line 717...
714
 
717
 
715
                case MAG_TYPE_LSM303DLH:
718
                case MAG_TYPE_LSM303DLH:
716
                        crb_gain = LSM303DLH_CRB_GAIN_13GA;
719
                        crb_gain = LSM303DLH_CRB_GAIN_19GA;
717
                        cra_rate = LSM303DLH_CRA_RATE_75HZ;
720
                        cra_rate = LSM303DLH_CRA_RATE_75HZ;
718
                        xscale = LSM303DLH_TEST_XSCALE;
721
                        xscale = LSM303DLH_TEST_XSCALE;
719
                        yscale = LSM303DLH_TEST_YSCALE;
722
                        yscale = LSM303DLH_TEST_YSCALE;
720
                        zscale = LSM303DLH_TEST_ZSCALE;
723
                        zscale = LSM303DLH_TEST_ZSCALE;