本帖最后由 nbiot 于 2020-2-20 21:00 编辑
M261芯片,如何用timer capture外部脉冲的个数?
用timer1,PB14,代码如下,是没有捕获到脉冲。请问是什么原因?
SYS->GPB_MFPH &= ~TM1_EXT_PB14_Msk;
SYS->GPB_MFPH |= TM1_EXT_PB14;
TIMER_Open(TIMER1, TIMER_PERIODIC_MODE, 1000000);
/* Update prescale to set proper resolution */
TIMER_SET_PRESCALE_VALUE(TIMER1, 0);
/* Set compare value as large as possible, so don't need to worry about counter overrun too frequently */
TIMER_SET_CMP_VALUE(TIMER1,0xFFFFFF);
/* Configure Timer 0 free counting mode */ //TIMER_COUNTER_EVENT_FALLING
TIMER_EnableCapture(TIMER1, TIMER_CAPTURE_FREE_COUNTING_MODE,TIMER_CAPTURE_EVENT_FALLING);//TIMER_CAPTURE_COUNTER_RESET_MODE, TIMER_CAPTURE_EVENT_RISING);
TIMER1->CTL |= TIMER_CTL_EXTCNTEN_Msk|TIMER_CTL_CNTEN_Msk ;
/* Set capture source from ACMP1 */
//TIMER1->EXTCTL |=TIMER_EXTCTL_CAPIEN_Msk;;//|TIMER_EXTCTL_CAPFUNCS_Msk|TIMER_EXTCTL_ECNTSSEL_Msk ;// TIMER_EXTCTL_ACMPSSEL_Msk;
/* Start Timer 0 */
TIMER_StartCapture(TIMER1);
|