BMA223調試記錄
一、運動中斷檢測
1.斜率運動
寄存器: 參數設置:
0x00 BMA2x2_CHIP_ID_REG
0x0f BMA2x2_RANGE_SEL_REG: 0x03 //量程(+-)2g
0x10 BMA2x2_BW_SEL_REG: 0x0f //帶寬1000Hz
0x16 BMA2x2_INT_ENABLE1_REG: 0x07 //在組0中使能斜率中斷
0x19 BMA2x2_INT1_PAD_SEL_REG: 0x04 //斜率中斷信號映射到 INT1 引腳
0x1b BMA2x2_INT2_PAD_SEL_REG: 0x04 //斜率中斷信號映射到 INT2 引腳
0x20 BMA2x2_INT_SET_REG: 0x05 //設置INT1/INT2 引腳空閑高電平
0x21 BMA2x2_INT_CTRL_REG: 0x8e //設置中斷延時50ms后 復位
0x27 BMA2x2_SLOPE_DURN_REG: 0x03 //設置中斷連續樣本數據點個數
0x28 BMA2x2_SLOPE_THRES_REG: 0x14 //設置中斷閾值 20*3.91mg = 78.2 mg
slope(t 0 + Δ t)= acc(t 0 + Δ t) - acc(t 0 )
使用連續加速度信號之間的斜率來檢測運動的變化。當斜率(加速度差的絕對值)超過預設閾值時,產生中斷。一旦斜率降到閾值以下,中斷被清除
2.1慢/無運動之慢運動
SLOW_NO_MOTION :*15.63 mg (8-g range)--:threshold->5(78mg)~8(125 mg)
寄存器: 參數設置:
0x00 BMA2x2_CHIP_ID_REG
0x0f BMA2x2_RANGE_SEL_REG: 0x03 //量程(+-)8g
0x10 BMA2x2_BW_SEL_REG: 0x0f //帶寬1000Hz
0x18 BMA2x2_INT_SLO_NO_MOT_REG: 0x07 //在組2中使能慢/無運動中斷
0x19 BMA2x2_INT1_PAD_SEL_REG: 0x08 //斜率中斷信號映射到 INT1 引腳
0x1b BMA2x2_INT2_PAD_SEL_REG: 0x08 //斜率中斷信號映射到 INT2 引腳
0x20 BMA2x2_INT_SET_REG: 0x05 //設置INT1/INT2 引腳空閑高電平
0x21 BMA2x2_INT_CTRL_REG: 0x8e //設置中斷延時50ms后 復位
0x27 BMA2x2_SLO_NO_MOT_THRES_REG: 0x28 //設置中斷連續樣本數據點個數
0x28 BMA2x2_SLO_NO_MOT_THRES_REG: 0x14 //設置中斷閾
在慢動作模式中,當至少一個使能軸的測量斜率超過可編程數量的樣本的可編程斜率閾值時,觸發中斷。 因此,引擎的行為類似于任意運動中斷,但具有不同的參數集。 為了抑制誤觸發,如果一定數量N的連續斜率數據點大于(小于)由(0x27)slo_no_mot_dur <1:0>給出的斜率閾值,則僅產生(清除)中斷。 數字是N =(0x27)slo_no_mot_dur <1:0> + 1
2.2慢/無運動之無運動
NO_MOTION :*15.63 mg
0x00 BMA2x2_CHIP_ID_REG
0x0f BMA2x2_RANGE_SEL_REG: 0x08 //(+-)8g
0x10 BMA2x2_BW_SEL_REG: 0x0f //1000Hz
0x18 BMA2x2_INT_SLO_NO_MOT_REG:0x0F //*在組2中使能慢/無運動中斷0x19 BMA2x2_INT1_PAD_SEL_REG: 0x08 //斜率中斷信號映射到 INT1 引腳
0x1b BMA2x2_INT2_PAD_SEL_REG: 0x08 //斜率中斷信號映射到 INT2 引腳
0x20 BMA2x2_INT_SET_REG: 0x05 //設置INT1/INT2 引腳空閑高電平
0x21 BMA2x2_INT_CTRL_REG: 0x8e //設置中斷延時50ms后 復位
0x27 BMA2x2_SLO_NO_MOT_THRES_REG:0x08 //設置中斷觸發條件持續時間
0x28 BMA2x2_SLO_NO_MOT_THRES_REG: 0x10 //設置中斷閾值
在非運動模式下,如果所有選定軸上的斜率在可編程延遲時間內保持小于可編程閾值,則會產生中斷。閾值的縮放與慢動作中斷的縮放相同。 但是,在無運動模式寄存器(0x27)中,slo_no_mot_dur定義了觸發無運動中斷之前的延遲時間。 表19列出了使用寄存器(0x27)slo_no_mot_dur調整的延遲時間。 計時器滴答周期為1秒。 因此,使用短延遲時間會導致相當大的時序不確定性。
3.1HIGH_G 運動中斷:
0x00 BMA2x2_CHIP_ID_REG
0x0f BMA2x2_RANGE_SEL_REG: 0x03 //(+-)2g
0x10 BMA2x2_BW_SEL_REG: 0x0f //1000Hz
0x17 BMA2x2_INT_ENABLE1_REG: 0x07 //在組2中使能HIGH_G運動中斷
0x19 BMA2x2_INT1_PAD_SEL_REG: 0x04 //斜率中斷信號映射到 INT1 引腳0x1b BMA2x2_INT2_PAD_SEL_REG: 0x04 //斜率中斷信號映射到 INT2 引腳
0x20 BMA2x2_INT_SET_REG: 0x05 //設置INT1/INT2 引腳空閑高電平
0x21 BMA2x2_INT_CTRL_REG: 0x1e //設置中斷延時50ms后 復位
0x24 BMA2x2_LOW_HIGH_HYST_REG 0x41 //high-g 中斷滯后:*125 mg
0x25 BMA2x2_HIGH_DURN_REG : 0x18 //設置中斷觸發條件持續時間[0x18+1] * 2 ms
0x26 BMA2x2_HIGH_THRES_REG: 0xC0 //設置中斷閾值
threshold:0xC0->192 (default) 192*7.81mg = 1499 mg
如果使能的三個軸(或關系)里至少有一個的加速度絕對值高于閾值,并且至少持續寄存器(0x25)high_dur里定義的時間,則產生高g中斷。
如果使能的三個軸(與關系,也就是全部軸)的加速度絕對值低于閾值,并且至少持續寄存器(0x25)high_dur里定義的時間,則高g中斷產生復位。在位(0x09)high_int中存儲中斷狀態。
3.2LOW_G 運動中斷:
0x00 BMA2x2_CHIP_ID_REG
0x0f BMA2x2_RANGE_SEL_REG: 0x03 //(+-)2g
0x10 BMA2x2_BW_SEL_REG: 0x0f //1000Hz
0x17 BMA2x2_INT_ENABLE1_REG: 0x07 //在組2中使能HIGH_G運動中斷
0x19 BMA2x2_INT1_PAD_SEL_REG: 0x04 //斜率中斷信號映射到 INT1 引腳0x1b BMA2x2_INT2_PAD_SEL_REG: 0x04 //斜率中斷信號映射到 INT2 引腳
0x20 BMA2x2_INT_SET_REG: 0x05 //設置INT1/INT2 引腳空閑高電平
0x21 BMA2x2_INT_CTRL_REG: 0x1e //設置中斷延時50ms后 復位
0x24 BMA2x2_LOW_HIGH_HYST_REG 0x41 //high-g 中斷滯后:*125 mg
0x25 BMA2x2_HIGH_DURN_REG : 0x18 //設置中斷觸發條件持續時間[0x18+1] * 2 ms
0x26 BMA2x2_HIGH_THRES_REG: 0xC0 //設置中斷閾值
threshold:0xC0->192 (default) 192*7.81mg = 1499 mg
如果所有軸的加速度的絕對值(在單模式下為'and'關系)或它們的總和(在和模式的情況下)至少在定義的時間內低于閾值,則產生低g中斷 通過(0x22)low_dur寄存器。
如果至少一個軸的加速度的絕對值(在單模式的情況下為'or'關系)或絕對值的總和(在和模式的情況下)至少一次的數據采集中高于閾值加滯后,則重置中斷。 在位(0x09)low_int中存儲中斷狀態。
4.1雙擊檢測
0x00 BMA2x2_CHIP_ID_REG
0x0f BMA2x2_RANGE_SEL_REG: 0x08 //(+-)8g
0x10 BMA2x2_BW_SEL_REG: 0x0f //1000Hz
0x16 BMA2x2_INT_SLO_NO_MOT_REG: 0x10 //在組0中使能雙擊運動中斷
0x19 BMA2x2_INT1_PAD_SEL_REG: 0x10 //斜率中斷信號映射到 INT1 引腳
0x1b BMA2x2_INT2_PAD_SEL_REG: 0x10 //斜率中斷信號映射到 INT2 引腳
0x20 BMA2x2_INT_SET_REG: 0x05 //設置INT1/INT2 引腳空閑高電平
0x21 BMA2x2_INT_CTRL_REG: 0x8e //設置中斷延時50ms后 復位
0x2A BMA2x2_TAP_PARAM_REG: 0x07 //設置中斷第二擊的時間窗口
0X06-->500ms,0x07-->700ms
0x2B BMA2x2_TAP_THRES_REG: 0x14 //設置中斷閾值
threshold*250 mg (8-g range)--:threshold->2(500mg)~10(2500mg)
4.2單擊檢測
0x00 BMA2x2_CHIP_ID_REG
0x0f BMA2x2_RANGE_SEL_REG: 0x08 //(+-)8g
0x10 BMA2x2_BW_SEL_REG: 0x0f //1000Hz
0x16 BMA2x2_INT_SLO_NO_MOT_REG: 0x10 //在組0中使能雙擊運動中斷
0x19 BMA2x2_INT1_PAD_SEL_REG: 0x10 //斜率中斷信號映射到 INT1 引腳
0x1b BMA2x2_INT2_PAD_SEL_REG: 0x10 //斜率中斷信號映射到 INT2 引腳
0x20 BMA2x2_INT_SET_REG: 0x05 //設置INT1/INT2 引腳空閑高電平
0x21 BMA2x2_INT_CTRL_REG: 0x8e //設置中斷延時50ms后 復位
0x2A BMA2x2_TAP_PARAM_REG: 0x07 //設置中斷第二擊的時間窗口
0X06-->500ms,0x07-->700ms
0x2B BMA2x2_TAP_THRES_REG: 0x14 //設置中斷閾值
threshold:0x14->20 (default) 20*3.91mg = 78.2 mg
如果超過至少一個軸的加速度的預定義斜率,則檢測到輕敲事件。區分兩個不同的點擊事件:“單擊”是特定時間內的單個事件,然后是某個安靜時間。 “雙擊”包括第一個這樣的事件,然后是在規定的時間范圍內的第二個事件。
二、靜態特殊方向檢測:
1.在靜止的情況下三軸加速度數據,其中兩個軸的數據幾乎接近0(>0mg&&<60mg),另一個軸數據接近1000mg。
- if((GsensorDataHX<14) && (GsensorDataHX >0))
- {
- if((GsensorDataHY<14) && (GsensorDataHY>0))
- {
- if((GsensorDataHZ<80) && (GsensorDataHZ>28) && (GsensorDataZ ==0))
- printf("positive\r\n");
- else if((GsensorDataHZ<80) && (GsensorDataHZ>28) && (GsensorDataZ ==1))
- printf("negative \r\n");
- }
- }
- if((GsensorDataHX<14) && (GsensorDataHX >0))
- {
- if((GsensorDataHZ<14) && (GsensorDataHZ>0))
- {
- if((GsensorDataHY<80) && (GsensorDataHY>28) && (GsensorDataY ==0))
- printf("Left\r\n");
- else if((GsensorDataHY<80) && (GsensorDataHY>28) && (GsensorDataY ==1))
- printf("Right \r\n");
- }
- }
- if((GsensorDataHY<14) && (GsensorDataHY >0))
- {
- if((GsensorDataHZ<14) && (GsensorDataHZ>0))
- {
- if((GsensorDataHX<80) && (GsensorDataHX>28) && (GsensorDataX ==0))
- printf("Front\r\n");
- else if((GsensorDataHX<80) &&(GsensorDataHX>28) && (GsensorDataX ==1))
- printf("Back \r\n");
- }
- }
復制代碼
三、加速度數據的運動檢測
三軸的合加速度G =重力加速度G0+動態加速度Gv
靜止時,SVM約等于重力加速度,運動時,G的幅值SVM圍繞著重力加速度G=G0上下浮動,此時Gv的幅值SS(i)會大于0。
1.對當前數據點進行動態與靜態識別:SVM>1050 --->動態點
2.對動態點的各軸數據進行幅值測試分析
- for(jtemp=x_flag;jtemp<=z_flag;jtemp++)
- {
- array3[jtemp]=array2[jtemp];
- array2[jtemp]=array1[jtemp];
- array1[jtemp]=array0[jtemp];
- array0[jtemp]= GsensorData [jtemp]; adresult[jtemp]=array0[jtemp]+array1[jtemp]
- +array2[jtemp]+array3[jtemp];
- GsensorData_tem_devi[jtemp]=(sumdata-adresult[jtemp)/4;
- }
-
復制代碼
四、計步器
1. 滑動窗口采樣濾波,找出最大小值
- for(jtemp=x_flag;jtemp<=z_flag;jtemp++)
- {
- array3[jtemp]=array2[jtemp];
- array2[jtemp]=array1[jtemp];
- array1[jtemp]=array0[jtemp];
- array0[jtemp]= GsensorData [jtemp]; adresult[jtemp]=array0[jtemp]+array1[jtemp]
- +array2[jtemp]+array3[jtemp];
- adresult[jtemp]=adresult[jtemp]>>2;
- if(adresult[jtemp]>max[jtemp])
- max[jtemp]=adresult[jtemp];
- if(adresult[jtemp]<min[jtemp])
- min[jtemp]=adresult[jtemp];
- }
復制代碼
2. 計算動態門限和動態精度,采集四五十次數據調整一次
門限值vpp[jtemp]: 30
中值dc[jtemp]: 500
精度precision[jtemp]: 5
- if(sampling_counter>=40)
- {
- sampling_counter=0;
- for(jtemp=0;jtemp<=2;jtemp++)
- {
- vpp[jtemp]=max[jtemp]-min[jtemp];
- dc[jtemp] =min[jtemp]+(vpp[jtemp]>>1);
- max[jtemp]=0;
- min[jtemp]=1023;
- bad_flag[jtemp]=0;
- if(vpp[jtemp]>=160)
- {
- precision[jtemp]=vpp[jtemp]/32; //8
- }
- else if((vpp[jtemp]>=50)&& (vpp[jtemp]<160))
- {
- precision[jtemp]=4;
- }
- else if((vpp[jtemp]>=15) && (vpp[jtemp]<50))
- {
- precision[jtemp]=3;
- }
- else
- {
- precision[jtemp]=2;
- bad_flag[jtemp]=1;
- }
- }
- }
復制代碼
3. 線性移位寄存器,找出最近兩次采集數據之間差異最大的值
- for(jtemp=0;jtemp<=2;jtemp++)
- {
- old_fixed[jtemp]=new_fixed[jtemp];
- if(adresult[jtemp]>=new_fixed[jtemp]){
- if((adresult[jtemp]-new_fixed[jtemp])>=precision[jtemp]) new_fixed[jtemp]=adresult[jtemp];
- }
- else if(adresult[jtemp]<new_fixed[jtemp]){
- if((new_fixed[jtemp]-adresult[jtemp])>=precision[jtemp])
- new_fixed[jtemp]=adresult[jtemp];
- }
- }
復制代碼
4. 動態門限判決,找出兩次數據間最大門限值,并判斷是否在窗口內進行計步。
- if((vpp[0]>=vpp[1])&&(vpp[0]>=vpp[2])){
- if((old_fixed[0]>=dc[0])&&(new_fixed[0]<dc[0])&&(bad_flag[0]==0)) {
- printf("X STEP+1 \r\n ");
- Time_Window();
- }
- }
- else if((vpp[1]>=vpp[0])&&(vpp[1]>=vpp[2])){
- if((old_fixed[1]>=dc[1])&&(new_fixed[1]<dc[1])&&(bad_flag[1]==0)) {
- printf("Y STEP+1 \r\n ");
- Time_Window();
- }
- }
- else if((vpp[2]>=vpp[1])&&(vpp[2]>=vpp[0])){
- if((old_fixed[2]>=dc[2])&&(new_fixed[2]<dc[2])&&(bad_flag[2]==0)) {
- printf("Z STEP+1 \r\n ");
- Time_Window();
- }
- }
復制代碼 5.時間窗口
- /*------------------------------------------------------------------------------------------------------------------------
- #define TIMEWINDOW_MIN 10 //0.2s
- #define TIMEWINDOW_MAX 100 //2s
- #define REGULATION 4 //
- #define INVALID 2 //
- unsigned char Interval=0; //
- unsigned char TempSteps=0; //
- unsigned char InvalidSteps=0; //
- unsigned char ReReg=2; //
- // 2-
- // 1-
- // 0-
- *------------------------------------------------------------------------------------------------------------------------*/
- void Time_Window(void)
- {
- Interval=time_win_value;
- time_win_value=0;
- if(ReReg==2) //
- {
- TempSteps++;
- Interval=0;
- ReReg=1;
- InvalidSteps=0;
- }
- else //
- {
- printf("Interval:----%d --- \r\n ",Interval);
- if((Interval>=TIMEWINDOW_MIN)&&(Interval<=TIMEWINDOW_MAX)) //
- {
- InvalidSteps=0;
- if(ReReg==1) //
- {
- TempSteps++; //
- if(TempSteps>=REGULATION) //
- {
- ReReg=0; //
- STEPS=STEPS+TempSteps; //
- TempSteps=0;
- printf("STEPS+tempstep:%d \r\n\r\n ",STEPS);
- }
- Interval=0;
- }
- else if(ReReg==0) //
- {
- STEPS++;
- TempSteps=0;
- Interval=0;
- printf("STEPS:%d \r\n\r\n ",STEPS);
- }
- printf("timer is ok ! \r\n\r\n ");
- }
- else if(Interval<TIMEWINDOW_MIN) //
- {
- if(ReReg==0) //
- {
- InvalidSteps++; //
- if(InvalidSteps>=INVALID) //
- {
- InvalidSteps=0;
- ReReg=1;
- TempSteps=1;
- Interval=0;
- }
- else //
- Interval=0;
- }
- else if(ReReg==1) //
- {
- InvalidSteps=0;
- ReReg=1;
- TempSteps=1;
- Interval=0;
- }
- printf("timer is smaler ! \r\n\r\n ");
- }
- else if(Interval>TIMEWINDOW_MAX) //
- {
- InvalidSteps=0;
- ReReg=1;
- TempSteps=1;
- Interval=0;
- printf("timer is bigger ! \r\n\r\n ");
- }
- }
- }
復制代碼
完整的Word格式文檔51黑下載地址:
8.16.1調試記錄.docx
(48.29 KB, 下載次數: 36)
2018-9-3 15:49 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|