杰理AD150+AD140

AD14N定时器0/1做输入捕获功能,在捕获端口计数按按键的次数。目前的想法是PA8做输入口。但是配置后发现不能用。需要如何配置这个输入捕获功能?

void timer0_init(void)    //输出入捕获初始化设置
{
    HWI_Install(IRQ_TIME0_IDX,(u32)timer0_isr,IRQ_TIMER0_IP) ;
    JL_TMR0->CON &= ~BIT(3) ; //设置PA8输入源
    JL_TMR0->CON |= BIT(2) ; //设置PA8输入源
    JL_IOMC->IOMC0 &= ~BIT(13) ; //IO_PA8
    JL_TMR0->CNT = 0 ;           //初值为0
    JL_TMR0->CON |= BIT(6);    //清中断
    JL_TMR0->CON |= BIT(1) ; //设置下降沿捕获
    JL_TMR0->CON |= BIT(0) ; //设置下降沿捕获 打开定时器

    log_info("timer0_init_ok!") ;
}

    static u32 cnt = 0 ;
SET(interrupt(""))
static void timer0_isr(void)
{
    JL_TMR0->CON |= BIT(6) ;
    cnt = JL_TMR0->PRD ;
    log_info("in_cnt = %d \n",cnt) ;
}

问题已经自己解决,可以分享给大家!
输入捕获计数功能不需要定时器中断,只要按规格书配置Timer0/Timer1,然后配置PA8,PA10为输入,就可以在JL_TMRx->CNT寄存器读到输入的上升或者下降沿个数。上代码:

void timer0_init(void)    //输出入捕获初始化设置
{
    JL_TMR0->CON &= ~BIT(3) ; //设置PA8输入源
    JL_TMR0->CON |= BIT(2) ; //设置PA8输入源
    JL_IOMC->IOMC0 &= ~BIT(13) ; //IO_PA8
    JL_TMR0->CON &= ~BIT(5);
    JL_TMR0->CON &= ~BIT(4);    //1分频
    JL_TMR0->CNT = 0 ;           //初值为0
    JL_TMR0->CON |= BIT(1) ; //设置下降沿捕获
    JL_TMR0->CON |= BIT(0) ; //设置下降沿捕获 打开定时器
    log_info("io_int =  %d \n",JL_TMR0->CNT) ;
    log_info("timer0_init_ok!") ;
}
void timer1_init(void)    //输出入捕获初始化设置
{
    JL_TMR1->CON &= ~BIT(3) ; //设置PA10输入源
    JL_TMR1->CON |= BIT(2) ; //设置PA10输入源
    JL_IOMC->IOMC0 &= ~BIT(14) ; //IO_PA10
    JL_TMR1->CON &= ~BIT(5);
    JL_TMR1->CON &= ~BIT(4);    //1分频
    JL_TMR1->CNT = 0 ;           //初值为0
    JL_TMR1->CON |= BIT(1) ; //设置下降沿捕获
    JL_TMR1->CON |= BIT(0) ; //设置下降沿捕获 打开定时器
    log_info("io_int =  %d \n",JL_TMR1->CNT) ;
    log_info("timer1_init_ok!") ;
}

//输入捕获端口
gpio_set_direction(IO_PORTA_08,1); //配置输入
gpio_set_die(IO_PORTA_08,1); //普通输入
gpio_set_pull_up(IO_PORTA_08,1); //配置上拉
gpio_set_pull_down(IO_PORTA_08,0); //不下拉

//输入捕获端口
gpio_set_direction(IO_PORTA_10,1); //配置输入
gpio_set_die(IO_PORTA_10,1); //普通输入
gpio_set_pull_up(IO_PORTA_10,1); //配置上拉
gpio_set_pull_down(IO_PORTA_10,0); //不下拉