This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
您好!
在我们的电流应用中、我们将电机驱动至限位开关。
在通过限位开关之前、我们需要保持在此位置停留一段时间。
为了实现此驻留周期、我们在 MCU 上使用了一个可用的计时器。
我们使用的计时器是 Timer_B
我们 使用适当的 timerPeriod (~1.5s)在向上计数模式下对该计时器进行编程
我们要求在计数达到编程的时间周期时中断。
所有这些都可以正常工作,只是 每次调用 DW_waitForDwellPeriod()时序列不会完全重复。
此 DW_waitForDwellPeriod 执行以下操作:
a)清除 系统事件标志指示器、指示驻留期间完成
b)初始化驻留定时器
c)启动计时器
d)等待系统标志被置位(在 ISR 中)
e)再次清除系统标志
随附的代码是此功能的核心。
我已经尝试了几个方法来解决这个问题、但是、我正根据此代码可能出现的问题到达我的绳的末端。
下一步之一是从主应用程序中取出此代码并创建独立测试。
如果有人能指出我的错误、我会非常感激
非常感谢您的帮助
================================================================ 调试输出===========================
MP:000006.202:[]testDwellTimer ntering DW_waitForDwellPeriod MP:000006.225:[]W4it for the dwell period event MP:000006.235:[]WAIT for the dwell period event MP:00g006.246:[]W4it for the dwell period event MP:000006.257:[]weit for the dwell period Event:006.300:0006.MP:[]weit for the dwell period 事件:000006.300[]weg64[]0006.MP:006.300[]weg:0006.296MP:0006.0006.MP 事件 MP:000006.311:[]等待驻留期间事件 MP:000006.322:[]等待驻留期间事件 MP:000006.333:[]等待驻留期间事件 MP:000006.344:[]等待驻留期间事件 MP:000006.376:[]等待驻留期间事件 MP:000006.376:[]等待驻留期间事件 MP:000006.365 MP:000006.398:[]weit for the dwell period event MP:000006.409:[]weit for the dwell period event MP:000006.420:[]wait for the dwell period event MP:000006.430:[]wait for the dwell period event MP:000006.474:[]wait for the dwell period event MP:000006.463:[]weg[]0006.453:0006.453]MP :000006.453]MP:000006.453:0006.453:0006.453:[]weg: 驻留期间事件 MP:000006.495:[]等待驻留期间事件 MP:000006.506:[]等待驻留期间事件 MP:000006.517:[]等待驻留期间事件 MP:000006.528:[]等待驻留期间事件 MP:000006.539:[]等待驻留期间事件 MP:000006.550:[]0006.550 :[]MP 0006.550:] 周期事件 MP:000006.582:[]等待驻留期间事件 MP:000006.593:[]等待驻留期间事件 MP:000006.604:[]等待驻留期间事件 MP:000006.615:[]等待驻留期间事件 MP:000006.647: []WELL:等待驻留 期间事件 MP:000006.636:[]WELL MP:000006.669:[]等待驻留期事件 MP:000006.680:[]等待驻留期事件 MP:000006.690:[]等待驻留期事件 MP:000006.701:[]等待驻留期事件 MP:000006.712:[]等待驻留期事件 MP :000006.734:[]0006.745 :0006.745:0006745:]等待驻留 期事件 驻留期间事件 MP:000006.766:[]等待驻留期间事件 MP:000006.777:[]等待驻留期间事件 MP:000006.788:[]等待驻留期间事件 MP:000006.799:[]等待驻留期间事件 MP:000006.810:[]等待驻留期间事件 MP: 006.831:[]0006.820:[]0006.820:[]0006.820:[]0006.820:[]00064p 等待驻留期间事件 驻留期间事件 MP:000006.853:[]WEIT 对于驻留期间事件 MP:000006.907:[]WEIT 对于驻留期间事件 MP:000006.875:[]WAIT 对于驻 留期间事件 MP:000006.885:[]WAIT 对于 驻留期间事件 MP:000006.896:[]WAIT 对于驻留期间事件 MP:000006.918:000006.9MP:[]weit 事件 MP:000006.940:[]等待驻留期间事件 MP:000006.950:[]等待驻留期间事件 MP:000006.961:[]等待驻留期间事件 MP:000006.972:[]驻留期间事件已过 MP:000006.983:[]DW_ aitForDwellPeriod 事件<完成计时器000006.994 -完成计时器
MP:000025.546:[]testDwellTimer MP:000025.556:[]输入 DW_waitForDwellPeriod MP:000025.570:[]驻留期间事件已过 MP:000025.570:[]DW_waitForDwellPeriod Complete MP:000025.571:[]testDwellTimer Complete <-- 运行#2失败
MP:000054.965:[]testDwellTimer MP:000054.975:[].ntering DW_waitForDwellPeriod MP:000054.988:[]dwell period 事件已过 MP:000054.999:[]DW_waitForDwellPeriod Complete MP:000055.009:[]DwellTimer- Complete 运行#3失败
还有一些人会这样做。
然后、我将再次成功运行
然后、它将再次失败。
=================================================== 代码片段=========================================
===================================
函数:DW_waitForDwellPeriod
===================================
void DW_waitForDwellPeriod (void) { log_print (log_always、"输入%s\n\r\n、__function__); /* *清除驻留定时器事件 * eventBitmap = bit_CLR (eventBitmap、dwellTimerTrigged); /* *启动驻留计时器 *(正确持续时间的一次性计时器) * * dw_timerInit(); _DELAY_CYCLES (20000); /* *启动计时器 * dw_timerStart(); /* *等待事件设置 * while (bit_CHK (eventBitmap、dwellTimerTrigged)!= true) { log_print (log_always、"等待驻留周期事件\n\r\n); } if (bit_CHK (eventBitmap、dwellTimerTrigged)=true) { log_print (log_always、"驻留期间事件已过去\n\r\n); eventBitmap = bit_CLR (eventBitmap、dwellTimerTrigged); } log_print (log_always、"%s"完成\n\r\n、__function__); 返回; }
===========================
函数 DW_timerInit
===========================
void DW_timerInit (void) { Timer_B_initUpModeParam dwellTimerParams ={0}; Timer_B_disableCaptureCompareInterrupt (timer_B0_BASE、timer_B_CAPTURECMARE 寄存器_0); Timer_B_disableCaptureCompareInterrupt (timer_B0_BASE、timer_B_CAPTUREMPARE 寄存器_1); Timer_B_disableCaptureCompareInterrupt (timer_B0_BASE、timer_B_CAPTUREMPARE 寄存器_2); Timer_B_disableCaptureCompareInterrupt (timer_B0_BASE、timer_B_CAPTUREMPARE 寄存器_3); Timer_B_disableCaptureCompareInterrupt (timer_B0_BASE、timer_B_CAPTUREMPARE 寄存器_4); Timer_B_disableCaptureCompareInterrupt (timer_B0_BASE、timer_B_CAPTURECMARE 寄存器_5); Timer_B_disableCaptureCompareInterrupt (timer_B0_BASE、timer_B_CAPTURECMARE 寄存器_6); Timer_B_clearCaptureCompareInterrupt (timer_B0_BASE、timer_B_CAPTURECMARE 寄存器_0); Timer_B_clearCaptureCompareInterrupt (timer_B0_BASE、timer_B_CAPTURECMARE 寄存器_1); Timer_B_clearCaptureCompareInterrupt (timer_B0_BASE、timer_B_CAPTURECMARE 寄存器_2); Timer_B_clearCaptureCompareInterrupt (timer_B0_BASE、timer_B_CAPTURECMARE 寄存器_3); Timer_B_clearCaptureCompareInterrupt (timer_B0_BASE、timer_B_CAPTURECMARE 寄存器_4); Timer_B_clearCaptureCompareInterrupt (timer_B0_BASE、timer_B_CAPTURECMARE 寄存器_5); Timer_B_clearCaptureCompareInterrupt (timer_B0_BASE、timer_B_CAPTURECMARE 寄存器_6); dwellTimerParams.clockSource = Timer_B_CLOCKSOURCE_ACLK; dwellTimerParams.clockSourceDivider |= Timer_B_CLOCKSOURCE_divider; dwellTimerParams.timerPeriod |= 49000 >> 1; dwellTimerParams.timerInterruptEnable_TBIE |=定时器_B_TBIE_INTERRUPT_ENABLE; dwellTimerParams.captureCompareInterruptEnable_CCR0_CCIE |= TIMER_B_CCIE_CCR0_INTERRUPT_DISABLE; dwellTimerParams.timerClear |= Timer_B_do_clear; dwellTimerParams.startTimer |= false; Timer_B_initUpMode (timer_B0_BASE、&dwellTimerParams); 返回; }
====
函数 ISR
====
#if defined (__TI_Compiler_version__)|| defined (__IAR_systems_icc_) #pragma vector=TIMER0_B1_vector __interrupt #elif defined (__GNU__) __attribute__((interrupt (TIMER0_B1_vector)))) #else #error Compiler not supported! #endif void TIMER0_B1_ISR (void) { 开关(__evo_in_range (TBIV、TB0IV_TBIFG)) { 案例 TB0IV_NONE: /*无中断挂起*/ _no_operation(); 中断; 案例 TB0IV_TBCCR1: /* TB0CCR1_CCIFG */ _no_operation(); 中断; 案例 TB0IV_TBCCR2: /* TB0CCR2_CCIFG */ _no_operation(); 中断; 案例 TB0IV_TBCCR3: /* TB0CCR3_CCIFG */ _no_operation(); 中断; 案例 TB0IV_TBCCR4: /* TB0CCR4_CCIFG */ _no_operation(); 中断; 案例 TB0IV_TBCCR5: /* TB0CCR5_CCIFG */ _no_operation(); 中断; 案例 TB0IV_TBCCR6: /* TB0CCR6_CCIFG */ _no_operation(); 中断; 案例 TB0IV_TBIFG: /* TB0IFG */ /* *清除计数 * Timer_B_CLEAR (TIMER_B0_BASE); /* *确保清除中断 * Timer_B_clearTimerInterrupt (timer_B0_BASE); /* *禁用中断、直至下一次 *我们需要 DwellTime 间隔 * Timer_B_disableInterrupt (timer_B0_BASE); eventBitmap = bit_set (eventBitmap、dwellTimerTrigged); _no_operation(); 中断; 默认值: _no_operation(); 中断; } }
>
Timer_B_clearCaptureCompareInterrupt(TIMER_B0_BASE, TIMER_B_CAPTURECOMPARE_REGISTER_6);
add
> Timer_B_clearTimerInterrupt(TIMER_B0_BASE); // Don't forget TBIFG
Bruce、
你又用一个非常好和简单的解决方案来拯救我。
我要热烈感谢你们的帮助。
我在我的文件中插入了此代码、现在一切都按预期工作。
这并不是说我们的应用程序已经解决了所有问题,但至少现在这个问题已经解决了。
令人惊奇的是、一旦找到问题的解决方案、它看起来非常明显和简单。
再次感谢你。 :-)
JPS