Subversion Repositories NaviCtrl

Rev

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

Rev 395 Rev 397
Line 263... Line 263...
263
// axis anable flags                    
263
// axis anable flags                    
264
#define ACC_CRTL1_XEN                   0x01
264
#define ACC_CRTL1_XEN                   0x01
265
#define ACC_CRTL1_YEN                   0x02
265
#define ACC_CRTL1_YEN                   0x02
266
#define ACC_CRTL1_ZEN                   0x04
266
#define ACC_CRTL1_ZEN                   0x04
Line 267... Line 267...
267
 
267
 
268
#define ACC_CRTL2_FILTER8       0x00
268
#define ACC_CRTL2_FILTER8       0x10
269
#define ACC_CRTL2_FILTER16      0x01
269
#define ACC_CRTL2_FILTER16      0x11
270
#define ACC_CRTL2_FILTER32      0x02
270
#define ACC_CRTL2_FILTER32      0x12
Line 271... Line 271...
271
#define ACC_CRTL2_FILTER64      0x03
271
#define ACC_CRTL2_FILTER64      0x13
272
 
272
 
273
#define ACC_CTRL4_BDU                   0x80 // Block data update, (0: continuos update; 1: output registers not updated between MSB and LSB reading)
273
#define ACC_CTRL4_BDU                   0x80 // Block data update, (0: continuos update; 1: output registers not updated between MSB and LSB reading)
274
#define ACC_CTRL4_BLE                   0x40 // Big/little endian, (0: data LSB @ lower address; 1: data MSB @ lower address)
274
#define ACC_CTRL4_BLE                   0x40 // Big/little endian, (0: data LSB @ lower address; 1: data MSB @ lower address)
Line 499... Line 499...
499
        }
499
        }
500
}
500
}
501
// rx data handler  for acceleration raw data
501
// rx data handler  for acceleration raw data
502
void NCMAG_UpdateAccVector(u8* pRxBuffer, u8 RxBufferSize)
502
void NCMAG_UpdateAccVector(u8* pRxBuffer, u8 RxBufferSize)
503
{       // if number of byte are matching
503
{       // if number of byte are matching
-
 
504
static s32 filter_z;
504
        if(RxBufferSize == sizeof(AccRawVector) )
505
        if(RxBufferSize == sizeof(AccRawVector) )
505
        {
506
        {
506
                memcpy((u8*)&AccRawVector, pRxBuffer,sizeof(AccRawVector));
507
                memcpy((u8*)&AccRawVector, pRxBuffer,sizeof(AccRawVector));
507
        }
508
        }
508
        DebugOut.Analog[16] = AccRawVector.X;
509
        DebugOut.Analog[16] = AccRawVector.X;
509
        DebugOut.Analog[17] = AccRawVector.Y;
510
        DebugOut.Analog[17] = AccRawVector.Y;
-
 
511
filter_z = (filter_z * 7 + AccRawVector.Z) / 8;
-
 
512
 
510
        DebugOut.Analog[18] = AccRawVector.Z;
513
        DebugOut.Analog[18] = filter_z;
511
DebugOut.Analog[19] = (DebugOut.Analog[19] * 3 + AccRawVector.Z) / 4;
514
        DebugOut.Analog[19] = AccRawVector.Z;
512
}
515
}
513
// rx data handler for reading magnetic sensor configuration
516
// rx data handler for reading magnetic sensor configuration
514
void NCMAG_UpdateMagConfig(u8* pRxBuffer, u8 RxBufferSize)
517
void NCMAG_UpdateMagConfig(u8* pRxBuffer, u8 RxBufferSize)
515
{       // if number of byte are matching
518
{       // if number of byte are matching
516
        if(RxBufferSize == sizeof(MagConfig) )
519
        if(RxBufferSize == sizeof(MagConfig) )
Line 718... Line 721...
718
 
721
 
719
//----------------------------------------------------------------
722
//----------------------------------------------------------------
720
u8 NCMAG_Init_ACCSensor(void)
723
u8 NCMAG_Init_ACCSensor(void)
721
{
724
{
722
        AccConfig.ctrl_1 = ACC_CRTL1_PM_NORMAL|ACC_CRTL1_DR_50HZ|ACC_CRTL1_XEN|ACC_CRTL1_YEN|ACC_CRTL1_ZEN;
725
        AccConfig.ctrl_1 = ACC_CRTL1_PM_NORMAL|ACC_CRTL1_DR_50HZ|ACC_CRTL1_XEN|ACC_CRTL1_YEN|ACC_CRTL1_ZEN;
723
        AccConfig.ctrl_2 = ACC_CRTL2_FILTER64;
726
        AccConfig.ctrl_2 = 0;//ACC_CRTL2_FILTER32;
724
        AccConfig.ctrl_3 = 0x00;
727
        AccConfig.ctrl_3 = 0x00;
725
        AccConfig.ctrl_4 = ACC_CTRL4_BDU|ACC_CTRL4_FS_8G;
728
        AccConfig.ctrl_4 = ACC_CTRL4_BDU | ACC_CTRL4_FS_8G;
726
        AccConfig.ctrl_5 = ACC_CTRL5_STW_OFF;
729
        AccConfig.ctrl_5 = ACC_CTRL5_STW_OFF;
727
        return(NCMAG_SetAccConfig());
730
        return(NCMAG_SetAccConfig());
728
}
731
}
729
// --------------------------------------------------------
732
// --------------------------------------------------------
Line 762... Line 765...
762
                                        NCMAG_GetMagVector();
765
                                        NCMAG_GetMagVector();
763
                                        delay = 20;
766
                                        delay = 20;
764
                                        break;
767
                                        break;
765
                                case TYPE_LSM303DLH:
768
                                case TYPE_LSM303DLH:
766
                                case TYPE_LSM303DLM:
769
                                case TYPE_LSM303DLM:
-
 
770
                                        NCMAG_GetMagVector();
-
 
771
                                        delay = 20;
767
                                        if(s){ NCMAG_GetMagVector(); s = 0;}
772
/*                                      if(s){ NCMAG_GetMagVector(); s = 0;}
768
                                        else { NCMAG_GetAccVector(); s = 1;}
773
                                        else { NCMAG_GetAccVector(); s = 1;}
769
                                        delay = 10;
774
                                        delay = 10;
-
 
775
*/
770
                                        break;                           
776
                                        break;                           
771
                        }
777
                        }
772
                        if(send_config == 24) TimerUpdate = SetDelay(5);    // next event is the re-configuration
778
                        if(send_config == 24) TimerUpdate = SetDelay(5);    // next event is the re-configuration
773
                        else TimerUpdate = SetDelay(delay);    // every 20 ms are 50 Hz
779
                        else TimerUpdate = SetDelay(delay);    // every 20 ms are 50 Hz
774
                }
780
                }