你好作者大大,我有个疑问。首先不管这个二阶低通滤波器的设计,temp32是ADC-DR的值*(PWM->CMP)/(100*PWM_ONE_PERCENT),到这temp32的量级还是跟ADC-DR的值一样,经过二阶低通滤波器之后temp32 = temp32 +((CurrentNow*55 -LastCurrent*24)>>5); 变成原来temp32大约两倍,此时将CurrentAvg = temp32>>5;相当于直接将temp32缩小了30倍,整个过程都没先将temp32左移5位把高5位当整数,低5位当小数的操作。但是最后比较的时候,我就是觉得CurrentAvg和CURRENT_LIMIT根本就不在一个量级。-
- int32_t temp32 ;
- uint32_t static Turn_ADC = 0 ;
- int32_t static LastCurrent=0, CurrentNow=0 ;
-
- temp32 = ADC->DR & 0xFFFF ;
- switch(ADC->CHER & 0xFF){
- case ADC7_CURRENT :
- temp32 -= Current_Zero ; // 功率管导通时的电流值
- Adc_Current = temp32 ;
- if(temp32 > CURRENT_PEAK){ Duty_Limit -= 1;
- if(temp32 > (CURRENT_PEAK*39>>5)) Duty_Limit -= 40; // 一次减5%, 最快2ms可减80%
- else if(temp32 >(CURRENT_PEAK*35>>5)) Duty_Limit -= 4; // 两次减约0.5%
- TickChangDuty = TIMER1->DR ; // 过流停止加电压,风机类转速上去电流就下来了
- }
- if(temp32 < 0) temp32 = 0 ; // 风机类,若不控制功率就不必测平均电流
- else if(PWM->CMR0 <PWM->CNR0)temp32 =(temp32*PWM->CMR0*Current_Cofficient)>>16; // 周期内均值
- // Current_Cofficient = 65536ul/(100*PWM_ONE_PERCENT); // 电流校正系数
- temp32 = temp32+((CurrentNow*55-LastCurrent*24)>>5); // 二阶低通,转折频率13.8K/2/30= 230Hz
- LastCurrent = CurrentNow; CurrentNow = temp32 ;
- CurrentAvg = temp32>>5;
- break ;
复制代码 |