你好,
我在調(diào)試代碼時(shí)發(fā)現(xiàn)有一處T2自動(dòng)重載中斷比理論值長5%。經(jīng)反復(fù)測試,似乎是中斷里的代碼會(huì)影響T2的周期。我寫了一個(gè)測試代碼,可在多片CH552上復(fù)現(xiàn)此問題。暫時(shí)代碼用Arduino框架執(zhí)行。
void?Timer2Interrupt(void)?__interrupt?(INT_NO_TMR2) { ??timer2IntrHandler();//debugwire?related } void?timer2IntrHandler()?{ ??// ??if?(TF2)?{ ????TF2?=?0; ????P1_4?=?0; ????????P1_4=0; ????????P1_4=0; ????????P1_4=0; ????????P1_4=0; ????????P1_4=0; ????????P1_4=0; ????????P1_4=0; ????????P1_4=0; ????????P1_4=0; ????????P1_4=0; ????????P1_4=0; ????????P1_4=0; ????????P1_4=0; ????????P1_4=0; ????????P1_4=0; ????????P1_4=0; ????????P1_4=0; ????????P1_4=0; ????????P1_4=0; ????????P1_4=0; ????????P1_4=0; //????__asm__("nop"); //????__asm__("nop"); //????__asm__("nop"); //????__asm__("nop"); //????__asm__("nop"); //????__asm__("nop"); //????__asm__("nop"); //????__asm__("nop"); //????__asm__("nop"); //????__asm__("nop"); //????__asm__("nop"); //????__asm__("nop"); //????__asm__("nop"); //????__asm__("nop"); //????__asm__("nop"); //????__asm__("nop"); //????__asm__("nop"); //????__asm__("nop"); //????__asm__("nop"); //????__asm__("nop"); ???? ????P1_4?=?1; ??} } void?setup()?{ ??//?put?your?setup?code?here,?to?run?once: ??TR2?=?0; ??// ??RCLK?=?0; ??TCLK?=?0;???????????//?clear?RCLK,TCLK?in?T2CON ??C_T2?=?0;???????????//?clear?C_T2?in?T2CON?for?using?internal?clk ??EXEN2?=?0;??????????//?clear?EXEN2?in?T2CON?to?disable?T2EX ??T2MOD?|=?(bT2_CLK)?|?bTMR_CLK;?//?set?bT2_CLK,?for?fast?clk.Using?Fsys/4 ??CP_RL2?=?0;?????????//?clear?CP_RL2?in?T2CON?for?16bit?timer,?reload?mode ??RCAP2?=?65536?-?128; ??TF2?=?0; ??EXF2?=?0; ??TR2?=?1;?//?start?timer ??TL2?=?0x00;?//?seem?only?work?when?timer?is?on? ??TH2?=?0xFF; ??ET2?=?1; } void?loop()?{ ??//?put?your?main?code?here,?to?run?repeatedly: }
16M時(shí)鐘下中斷應(yīng)該是125K的頻率,一次8us。
但是如果我寫一大堆P1_4=0,中斷就會(huì)變慢。
如果我把多余的P1_4=0換成nop,就正常許多。
請問這是我對定時(shí)器理解不對還是芯片Bug?