-
N32G455定时器捕获偶尔会丢一个沿的问题
[i=s] 本帖最后由 通讯不上 于 2024-2-21 14:02 编辑 [/i] 使用定时器一个通道捕获频率时偶尔出现频率只有一半的问题。检查重复捕获标志位没有异常。信号源和电路应该没有问题,用pwm模式捕获的话是正常的,求助!!!部分代码: void inline pwm_compute(uint8_t idx) { // uint32_t first_val = 0; uint16_t cap_val = 0u; //进来先读值 uint8_t i = 0; //避免在处理这个中断时update没来得及处理导致计算不准确 switch (idx) { case 0: cap_val = TIM_GetCap1(TIM5); break; case 1: cap_val = TIM_GetCap2(TIM5); break; case 2: cap_val = TIM_GetCap3(TIM5); break; case 3: cap_val = TIM_GetCap4(TIM5); break; default: break; } if(ic_info[idx].ic_capnum == 0) { /* Get the Input Capture value */ ic_info[idx].ic_freq_delval = cap_val; //TIM_ConfigOc1Polarity(TIM5,TIM_IC_POLARITY_FALLING); ic_info[idx].ic_capnum = 2; // 1是有占空比 ic_info[idx].ic_overcnt = 0; } else if(ic_info[idx].ic_capnum == 1) { /* Get the Input Capture value */ ic_info[idx].ic_duty_delval = ic_info[idx].ic_overcnt * 65535 + cap_val - ic_info[idx].ic_freq_delval; TIM_ConfigOc1Polarity(TIM5,TIM_IC_POLARITY_RISING); ic_info[idx].ic_capnum = 2; } else if(ic_info[idx].ic_capnum == 2) { /* Get the Input Capture value */ // first_val = ic_info[idx].ic_freq_delval; if(cap_val < ic_info[idx].ic_freq_delval && ic_info[idx].ic_overcnt == 0) { i = 1; } ic_info[idx].ic_freq_delval = (ic_info[idx].ic_overcnt +i)* 65535 + cap_val - ic_info[idx].ic_freq_delval; //dev_printf("del1 =%d",ic_info[idx].ic_freq_delval); //TIM_ConfigOc1Polarity(TIM5,TIM_IC_POLARITY_RISING); ic_info[idx].ic_freq = (uint32_t) (18000000 * 1.0 / ic_info[idx].ic_freq_delval + 0.5); ic_info[idx].ic_duty = (uint32_t) ((float)ic_info[idx].ic_duty_delval * 1.0 / ic_info[idx].ic_freq_delval)*1000; //ic_info[idx].ic_capnum = 0; if(ic_info[idx].ic_freq < 480) { dev_printf("freq =%d\n",ic_info[idx].ic_freq); // first_val = 0; } //全波形测量 ic_info[idx].ic_freq_delval = cap_val; ic_info[idx].ic_overcnt = 0; } void PI_IRQHandlerCallback(void) { uint8_t i = 0; if(TIM_GetIntStatus(TIM5, TIM_INT_UPDATE) == SET) { for(i = 0;i<4;i++) { if(TIM_GetIntStatus(TIM5, (TIM_INT_CC1<pi1) { dev_pi_get_fd(bd_r->pi1,ic_info[0].ic_freq,ic_info[0].ic_duty); } } if(TIM_GetIntStatus(TIM5, TIM_INT_CC2) == SET) { /* Clear TIM2 Capture compare interrupt pending bit */ TIM_ClrIntPendingBit(TIM5, TIM_INT_CC2); pwm_compute(1); if(bd_r && bd_r->pi2) { dev_pi_get_fd(bd_r->pi2,ic_info[1].ic_freq,ic_info[1].ic_duty); } } if(TIM_GetIntStatus(TIM5, TIM_INT_CC3) == SET) { /* Clear TIM2 Capture compare interrupt pending bit */ TIM_ClrIntPendingBit(TIM5, TIM_INT_CC3); pwm_compute(2); if(bd_r && bd_r->pi3) { dev_pi_get_fd(bd_r->pi3,ic_info[2].ic_freq,ic_info[2].ic_duty); } } if(TIM_GetIntStatus(TIM5, TIM_INT_CC4) == SET) { /* Clear TIM2 Capture compare interrupt pending bit */ TIM_ClrIntPendingBit(TIM5, TIM_INT_CC4); pwm_compute(3); if(bd_r && bd_r->pi4) { dev_pi_get_fd(bd_r->pi4,ic_info[3].ic_freq,ic_info[3].ic_duty); } } } } [/i]
1159浏览量 1回复量 关注量 -
N32G455的RTC断电复位问题
硬件上,CR2032直接对VBAT供电。软件初始化没有主动改写日历。 多次通断电会导致日历被清零,时间正常往前走。 请问这是什么原因导致的。谢谢
687浏览量 1回复量 关注量