diff --git a/trunk/accero.c b/trunk/accero.c index d277b34..105089e 100644 --- a/trunk/accero.c +++ b/trunk/accero.c @@ -101,53 +101,72 @@ task_status_immed tsk_cbk_accero( ) // if( ( vreg_ctr[VREG_C_ACC_CONFIG] & VREG_BITMASK_ACC_CONF_HOSU ) != 0x00 ) { static s16 th_H = 0x3300; // 閾値。暫定。動的変更とかしたい…ので変数 - static s16 th_L = 0x2A00; + static s16 th_L = 0x2C00; static u16 acc_norm[3]; // 加速度の大きさのヒストリ。数字が大きい方が古い - static u16 interval_hh; // 山-山間の時間。短過ぎたらはじく。 - static u16 time_l; // 前回の極小からの経過時間 - + static u8 interval_hh; // 山-山間の時間。短過ぎたらはじく。 + static u8 time_l; // 前回の極小からの経過時間 + static u16 peak_l; // 谷の深さ + static u16 peak_h; // 山の高さ + static u16 norm_avg[8]; u16 sx16 = abs( (u16)vreg_ctr[VREG_C_ACC_XH] * 256 + vreg_ctr[VREG_C_ACC_XL] ); u16 sy16 = abs( (u16)vreg_ctr[VREG_C_ACC_YH] * 256 + vreg_ctr[VREG_C_ACC_YL] ); u16 sz16 = abs( (u16)vreg_ctr[VREG_C_ACC_ZH] * 256 + vreg_ctr[VREG_C_ACC_ZL] ); - acc_norm[2] = acc_norm[1]; - acc_norm[1] = acc_norm[0]; - // そのうちローコストな方法を考える、かも - acc_norm[0] = sqrt( (long)sx16 * ( sx16 / 2 ) + + norm_avg[7] = norm_avg[6]; // 最近8サンプルの移動平均 + norm_avg[6] = norm_avg[5]; + norm_avg[5] = norm_avg[4]; + norm_avg[4] = norm_avg[3]; + norm_avg[3] = norm_avg[2]; + norm_avg[2] = norm_avg[1]; + norm_avg[1] = norm_avg[0]; + norm_avg[0] = sqrt( (long)sx16 * ( sx16 / 2 ) + (long)sy16 * ( sy16 / 2 ) + (long)sz16 * ( sz16 / 2 ) ); + acc_norm[2] = acc_norm[1]; // 移動平均結果のヒストリ + acc_norm[1] = acc_norm[0]; + acc_norm[0] = + // norm_avg[7] /8 + norm_avg[6] /8 + norm_avg[5] /8 + norm_avg[4] /8 + + norm_avg[3] /4 + norm_avg[2] /4 + norm_avg[1] /4 + norm_avg[0] /4; + +// ここから共通 + + if( acc_norm[2] <= acc_norm[1] && acc_norm[1] > acc_norm[0] && acc_norm[0] > th_H ) // 極大で、閾値を超えていた { - if(( 20 < interval_hh ) && ( interval_hh < 200 )) + if(( 15 < interval_hh ) && ( interval_hh < 80 )) // 前回の極大からの間隔がほどよい { if( time_l < interval_hh ) // 谷を挟んでいる { - // 一歩増えました - hosu_increment(); + if( acc_norm[0] - peak_l > 4000 ){ + // 一歩増えました + hosu_increment(); + } } } interval_hh = 0; } else { - interval_hh += ( interval_hh != 65535 ) ? 1: 0; // 飽和加算って楽に書けたらいいのに + interval_hh += ( interval_hh != 255 ) ? 1: 0; // 飽和加算って楽に書けたらいいのに } // (2) 直近の極小からの時間 if( acc_norm[2] >= acc_norm[1] && acc_norm[1] < acc_norm[0] && acc_norm[0] < th_L ) { + // 極小を検出 time_l = 0; + peak_l = acc_norm[0]; } else { - time_l += ( time_l != 65535 ) ? 1: 0; + time_l += ( time_l != 255 ) ? 1: 0; } { @@ -158,16 +177,20 @@ task_status_immed tsk_cbk_accero( ) vreg_ctr[VREG_C_ACC_DBG_1] = (u8)( acc_norm[0] / 256 & 0x00FF ); vreg_ctr[VREG_C_ACC_DBG_2] = (u8)( acc_norm[0] & 0x00FF ); - vreg_ctr[VREG_C_ACC_DBG_3] = (u8)( interval_hh / 256 & 0x00FF ); - vreg_ctr[VREG_C_ACC_DBG_4] = (u8)( interval_hh & 0x00FF ); + vreg_ctr[VREG_C_ACC_DBG_3] = 0; + vreg_ctr[VREG_C_ACC_DBG_4] = interval_hh; - vreg_ctr[VREG_C_ACC_DBG_5] = (u8)( time_l / 256 & 0x00FF ); - vreg_ctr[VREG_C_ACC_DBG_6] = (u8)( time_l & 0x00FF ); + vreg_ctr[VREG_C_ACC_DBG_5] = 0; + vreg_ctr[VREG_C_ACC_DBG_6] = time_l; vreg_ctr[VREG_C_ACC_DBG_7] = vreg_ctr[ VREG_C_ACC_HOSU_L ]; + vreg_ctr[VREG_C_ACC_DBG_8] = (u8)( peak_l / 256 & 0x00FF ); + vreg_ctr[VREG_C_ACC_DBG_9] = (u8)( peak_l & 0x00FF ); + vreg_ctr[VREG_C_ACC_DBG_A] = (u8)( norm_avg[0] / 256 & 0x00FF ); + vreg_ctr[VREG_C_ACC_DBG_B] = (u8)( norm_avg[0] & 0x00FF ); } - +// ここまで } diff --git a/trunk/i2c_ctr.c b/trunk/i2c_ctr.c index 1159e6b..40ff5b1 100644 --- a/trunk/i2c_ctr.c +++ b/trunk/i2c_ctr.c @@ -69,7 +69,7 @@ __interrupt void int_iic_ctr( ) static u8 tx_buf; u8 rx_buf; - EI(); +// EI(); // 読み出し終了 if( !ACKD ) // 割り込み要因はNAK(データ送信の最後) diff --git a/trunk/vreg_ctr.c b/trunk/vreg_ctr.c index 4a8be55..f4d92b6 100644 --- a/trunk/vreg_ctr.c +++ b/trunk/vreg_ctr.c @@ -281,6 +281,8 @@ void vreg_ctr_write( u8 adrs, u8 data ) // リードされたらクリアなどは気をつける u8 vreg_ctr_read( u8 adrs ) { + static u16 rsub_temp; + // RTCは読み出し途中に繰り上がるのを避けるため if( ( VREG_C_RTC_SEC <= adrs ) && ( adrs <= VREG_C_RTC_YEAR ) ) { @@ -296,11 +298,12 @@ u8 vreg_ctr_read( u8 adrs ) } else if( adrs == VREG_C_ACC_DBG_E ) { - return( (u8)( ( RSUBC >> 8 ) & 0xFF ) ); + rsub_temp = RSUBC; + return( (u8)( ( rsub_temp >> 8 ) & 0xFF ) ); } else if( adrs == VREG_C_ACC_DBG_F ) { - return( (u8)( RSUBC & 0xFF ) ); + return( (u8)( rsub_temp & 0xFF ) ); } #if 1 diff --git a/trunk/yav_mcu_bsr.plg b/trunk/yav_mcu_bsr.plg index 631f6d5..b99f447 100644 --- a/trunk/yav_mcu_bsr.plg +++ b/trunk/yav_mcu_bsr.plg @@ -1,16 +1,12 @@ C:\WINDOWS\system32\cmd.exe /c touch magic.c +"C:\Program Files\NEC Electronics Tools\CC78K0R\W2.10\bin\cc78k0r.exe" -c9F0104 -y"C:\Program Files\NEC Electronics Tools\DEV" -_msgoff -irenge -i"C:\Program Files\NEC Electronics Tools\FSL78K0R_Type02ES\V1.20\inc78k0r" -ms -quvjl3wt -sainter_asm -zp -no i2c_ctr.c +Compilation complete, 0 error(s) and 0 warning(s) found. +"C:\Program Files\NEC Electronics Tools\RA78K0R\W1.31\bin\ra78k0r.exe" -c9F0104 -y"C:\Program Files\NEC Electronics Tools\DEV" -_msgoff inter_asm\i2c_ctr.asm +Assembly complete, 0 error(s) and 0 warning(s) found. "C:\Program Files\NEC Electronics Tools\CC78K0R\W2.10\bin\cc78k0r.exe" -c9F0104 -y"C:\Program Files\NEC Electronics Tools\DEV" -_msgoff -irenge -i"C:\Program Files\NEC Electronics Tools\FSL78K0R_Type02ES\V1.20\inc78k0r" -ms -quvjl3wt -sainter_asm -zp -no magic.c Compilation complete, 0 error(s) and 0 warning(s) found. "C:\Program Files\NEC Electronics Tools\RA78K0R\W1.31\bin\ra78k0r.exe" -c9F0104 -y"C:\Program Files\NEC Electronics Tools\DEV" -_msgoff inter_asm\magic.asm Assembly complete, 0 error(s) and 0 warning(s) found. -"C:\Program Files\NEC Electronics Tools\CC78K0R\W2.10\bin\cc78k0r.exe" -c9F0104 -y"C:\Program Files\NEC Electronics Tools\DEV" -_msgoff -irenge -i"C:\Program Files\NEC Electronics Tools\FSL78K0R_Type02ES\V1.20\inc78k0r" -ms -quvjl3wt -sainter_asm -zp -no adc.c -adc.c(76) : CC78K0R warning W0745: Expected function prototype -adc.c(78) : CC78K0R warning W0401: Conversion may lose significant digits -adc.c(106) : CC78K0R warning W0401: Conversion may lose significant digits -adc.c(257) : CC78K0R warning W0401: Conversion may lose significant digits -Compilation complete, 0 error(s) and 4 warning(s) found. -"C:\Program Files\NEC Electronics Tools\RA78K0R\W1.31\bin\ra78k0r.exe" -c9F0104 -y"C:\Program Files\NEC Electronics Tools\DEV" -_msgoff inter_asm\adc.asm -Assembly complete, 0 error(s) and 0 warning(s) found. "C:\Program Files\NEC Electronics Tools\RA78K0R\W1.31\bin\lk78k0r.exe" -y"C:\Program Files\NEC Electronics Tools\DEV" -_msgoff -obsr.lmf "..\..\Program Files\NEC Electronics Tools\CC78K0R\W2.10\lib78k0r\s0rm.rel" -go85h,0FC00h,1024 -gi0FFFFFFFFFFFFFFFFFFFFh -pbsr_k0r.map -nkd -kp -gb7EFBFFh -b"C:\Program Files\NEC Electronics Tools\FSL78K0R_Type02ES\V1.20\lib78k0r\fsl.lib" -bcl0rdm.lib -bcl0rm.lib -bcl0rmf.lib -i"C:\Program Files\NEC Electronics Tools\CC78K0R\W2.10\lib78k0r" -dbsr_mcu.dr -s -w0 loader.rel pm.rel i2c_ctr.rel main.rel magic.rel WDT.rel i2c_mcu.rel i2c_twl.rel ini_VECT.rel led.rel rtc.rel vreg_ctr.rel vreg_twl.rel adc.rel renge.rel accero.rel self_flash.rel reboot.rel sw.rel task_debug.rel task_misc.rel task_sys.rel Link complete, 0 error(s) and 0 warning(s) found. "C:\Program Files\NEC Electronics Tools\RA78K0R\W1.31\bin\oc78k0r.exe" -y"C:\Program Files\NEC Electronics Tools\DEV" -_msgoff -o.\bsr.hex -nu -ki bsr.lmf @@ -21,4 +17,4 @@ intel-HEX to bsr bin converter file converted! -Build Total error(s) : 0 Total warning(s) : 4 +Build Total error(s) : 0 Total warning(s) : 0 diff --git a/trunk/yav_mcu_bsr.pri b/trunk/yav_mcu_bsr.pri index 4eb02e9..ba0b93b 100644 --- a/trunk/yav_mcu_bsr.pri +++ b/trunk/yav_mcu_bsr.pri @@ -4,7 +4,7 @@ Target=IDK0R32G [Configuration] Chip=uPD79F0104 Internal Rom=32KB -Internal Ram=1536KB +Internal Ram=1536B Clock=Target Sub Clock=Target Peripheral Break=0x2 @@ -23,7 +23,7 @@ SubClock=None Count=0 [Main] Geometry=113, 17, 1467, 1110 -Window=Normal +Window=Max MDI_MAX=OFF Button=ON Mode=Auto @@ -78,10 +78,10 @@ Symbol Type=OFF Language=C Kanji=SJIS [Source] -Geometry=155, 80, 1012, 920 +Geometry=43, 209, 1012, 920 Window=Normal -DispStart=46 -CaretPos=95,0 +DispStart=276 +CaretPos=277,0 Mode=Normal DispFile= Address1= @@ -142,8 +142,8 @@ Accumulative=ON [Assemble] Geometry=605, 2, 600, 400 Window=Normal -DispStart=685 -CaretPos=685,27 +DispStart=17244 +CaretPos=17226,27 Address1= Address2= Address3= @@ -858,34 +858,44 @@ Count=0 Geometry=1232, 6, 354, 910 Window=Normal Boundary=13762700 -0=.adc_raw_vol,P,N,A,+,1 -1=.vol_old,P,N,A,+,1 -2=.vol,P,N,A,+,1 -3=.direction,P,N,A,+,1 -4=.temp,P,N,A,+,1 -Line=5 +0=.iics1,P,S,A,+,1 +1=.iicf1,P,S,A,+,1 +2=.iicctl11,P,S,A,+,1 +3=.iicctl01,P,S,A,+,1 +4=.SUBCUD,P,S,A,+,1 +5=.tx_buf,P,N,A,+,1 +6=.adc_raw_vol,P,N,A,+,1 +7=.vol_old,P,N,A,+,1 +8=.vol,P,N,A,+,1 +9=.direction,P,N,A,+,1 +10=.temp,P,N,A,+,1 +Line=11 [Quick Watch] -0=pu0,P,A,1 -1=p5,B,A,1 -2=P7,B,A,1 -3=cmd_BL,P,A,1 -4=vreg_ctr,P,A,1 -5=pool,P,A,1 -6=if2,P,A,1 -7=if2h,P,A,1 -8=new_task,P,A,1 +0=if2,P,A,1 +1=if2h,P,A,1 +2=new_task,P,A,1 +3=iic_mcu_busy,P,A,1 +4=adc_raw_vol,P,A,1 +5=direction,P,A,1 +6=vol,P,A,1 +7=temp,P,A,1 +8=vol_old,P,A,1 9=tx_buf,P,A,1 -10=iic_mcu_busy,P,A,1 -11=adc_raw_vol,P,A,1 -12=direction,P,A,1 -13=vol,P,A,1 -14=temp,P,A,1 -15=vol_old,P,A,1 +10=SUBCUD,P,A,1 +11=iicas1,P,A,1 +12=iics1,P,A,1 +13=iicf1,P,A,1 +14=iicctl01,P,A,1 +15=iicctl11,P,A,1 [Software Break] Geometry=1204, 674, 500, 428 Window=Normal Width=150 30 200 100 -Count=0 +Name0=Swb00003 +Address0=i2c_ctr.c#_int_iic_ctr+0xc0 +Window0=ASM +Status0=ON +Count=1 [Reset] Debugger=ON Symbol=OFF diff --git a/trunk/yav_mcu_bsr.prk b/trunk/yav_mcu_bsr.prk index 53593d4..3e24b2d 100644 --- a/trunk/yav_mcu_bsr.prk +++ b/trunk/yav_mcu_bsr.prk @@ -1,18 +1,20 @@ [ProjectManager] FrameMax=0 -FrameX=63 -FrameY=123 +FrameX=82 +FrameY=140 FrameCX=1299 FrameCY=1044 OpenFile1=renge\renge.h,0,502,637,1746,1394,29,16,29,0 OpenFile2=pm.c,0,154,154,1133,791,0,792,0,0 -OpenFile3=adc.c,0,132,132,1111,769,34,98,34,0 -OpenFile4=self_flash.c,0,154,154,1133,791,44,112,0,0 -OpenFile5=config.h,0,289,54,1268,691,0,19,19,0 -OpenFile6=adc.c,0,198,198,1177,835,0,114,0,0 -OpenFile7=ProjectWindow +OpenFile3=self_flash.c,0,154,154,1133,791,44,112,0,0 +OpenFile4=vreg_ctr.h,0,220,220,1464,977,20,214,29,0 +OpenFile5=ProjectWindow PrjPos=0,2,754,3,253 -OpenFile8=OutputWindow +OpenFile6=vreg_ctr.c,0,198,198,1442,955,27,303,22,0 +OpenFile7=accero.c,0,132,132,1133,760,70,186,69,0 +OpenFile8=adc.c,0,242,242,1486,999,0,116,25,0 +OpenFile9=config.h,0,268,24,1247,661,0,33,29,0 +OpenFile10=OutputWindow OutputPos=0,421,829,388,1497 ActivePRJ=yav_mcu_bsr.prj [ProjectWindow] diff --git a/trunk/yav_mcu_bsr.sdb b/trunk/yav_mcu_bsr.sdb index 45a404f..698e03d 100644 --- a/trunk/yav_mcu_bsr.sdb +++ b/trunk/yav_mcu_bsr.sdb @@ -32,7 +32,7 @@ T=4b68d913 6=led.h 7=adc.h [magic.c] -T=4b721c34 +T=4b7bd688 1=config.h [WDT.c] T=4afd21ca @@ -56,7 +56,7 @@ T=4b4438bb T=4b6a6fa4 1=incs.h [vreg_ctr.c] -T=4b721c07 +T=4b724017 1=incs.h 2=vreg_ctr.h 3=rtc.h @@ -73,7 +73,7 @@ T=4b6907de 4=vreg_ctr.h 5=renge\renge_task_intval.h [adc.c] -T=4b6bd936 +T=4b723615 1=incs.h 2=adc.h 3=pm.h @@ -88,7 +88,7 @@ T=4b5d73b9 6=user_define.h 7=bsr_system.h [accero.c] -T=4b6a666a +T=4b7bd680 1=incs.h 2=..\..\Program Files\NEC Electronics Tools\CC78K0R\W2.10\inc78k0r\math.h [self_flash.c] @@ -148,7 +148,7 @@ T=4b023fdb [user_define.h] T=4b690aa2 [config.h] -T=4b7217b7 +T=4b7cf1c7 [bsr_system.h] T=4b3064de [renge\renge.h]