【AT32】AT32定时器
at32的定时器
使用work Bench 启动一个基本的定时器 6 使用
生成的代码如下
void wk_tmr6_init(void)
{/* add user code begin tmr6_init 0 *//* add user code end tmr6_init 0 *//* add user code begin tmr6_init 1 *//* add user code end tmr6_init 1 *//* configure counter settings */tmr_cnt_dir_set(TMR6, TMR_COUNT_UP);tmr_period_buffer_enable(TMR6, FALSE);tmr_base_init(TMR6, 999, 95);/* configure primary mode settings */tmr_primary_mode_select(TMR6, TMR_PRIMARY_SEL_OVERFLOW);/* configure overflow event */tmr_overflow_request_source_set(TMR6, TRUE);tmr_counter_enable(TMR6, TRUE);/*** Users need to configure TMR6 interrupt functions according to the actual application.* 1. Call the below function to enable the corresponding TMR6 interrupt.* --tmr_interrupt_enable(...)* 2. Add the user's interrupt handler code into the below function in the at32f425_int.c file.* --void TMR6_GLOBAL_IRQHandler(void)*//* add user code begin tmr6_init 2 *//* add user code end tmr6_init 2 */
}
启动 此定时器调用注释的
--tmr_interrupt_enable(...)
tmr_interrupt_enable(TMR6, TMR_OVF_INT, TRUE); //启动定时器
然后在定时器回调函数里面调用用户函数
void TMR6_GLOBAL_IRQHandler(void)
{/* add user code begin TMR6_GLOBAL_IRQ 0 *//* add user code end TMR6_GLOBAL_IRQ 0 *//* add user code begin TMR6_GLOBAL_IRQ 1 *//* add user code end TMR6_GLOBAL_IRQ 1 */
}
注意要在 回调 添加 清除 中断标志位 否则会一直卡在 定时器当中
if (tmr_flag_get(TMR6, TMR_OVF_FLAG) != RESET) {
tmr_flag_clear(TMR6, TMR_OVF_FLAG);}