本文主要是介绍电子烟开发【恒压、恒有效算法】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
恒压算法
pwm是通过软件模拟的 pwm满值运行是250全占空比
#define D_TARGET_AVERAGE_VOLTAGE 3500
//R_ADC1_Vout :发热丝两端AD值
//R_ADC_FVR :电池电压AD值
//FVR_VOLTAGE :电池AD参考电压 满电值AD
//R_Smk1Duty :最后得出的占空比
void CAL1_ConstantVoltage(void)
{R_Temp32 = (vu32)D_TARGET_AVERAGE_VOLTAGE * 250 * R_ADC_FVR; //电压* duty =3.5V; R_Temp32 = R_Temp32 / R_ADC1_Vout;R_Temp32 = R_Temp32/FVR_VOLTAGE;if(R_Temp32 > 250) R_Smk1Duty = 250;else R_Smk1Duty = R_Temp32 & 0xff;
}
恒有效值表对应AD值
AD值 = (功率 * 负载阻值 * (电池参考电压)^2 ) 开方
=SQRT(A9988988B9)
=SQRT(A910001000B9)
恒有效算法
//VoltageTab :恒有效对应输出功率AD值
//R_Power_Num :输出的功率 1-30W
//R_ADC1_Vout :发热丝两端AD值
//R_ADC_FVR :电池电压AD值
//FVR_VOLTAGE :电池AD参考电压 满电值AD
//R_Smk1Duty :最后得出的占空比
const vu16 VoltageTab[31] = {0,// 699 ,988 ,1210,1397,1562,1711,1848,1976,2096,2209, //1-10w -0.5R// 2317,2420,2519,2614,2706,2794,2880,2964,3045,3124, //11-20w -0.5R// 3201,3277,3350,3423,3493,3562,3630,3697,3762,3827 //21-30w -0.5R699 ,988 ,1210,1397,1562,1711,1848,1976,2096,2079, //1-10w -0.5R2190,2300,2400,2500,2585,2664,2730,2814,2900,2985, //11-20w -0.5R3061,3137,3210,3285,3353,3562,3630,3697,3762,3827 //21-30w -0.5R};void ConstantValidVoltage(void)
{R_Temp32 = (vu32)R_ADC_FVR * VoltageTab[R_Power_Num];R_Temp32 = R_Temp32 / R_ADC1_Vout;R_Temp32 = R_Temp32 << 8;R_Temp32 = R_Temp32 / FVR_VOLTAGE;R_Temp32 = R_Temp32 * R_Temp32;R_Temp32 = R_Temp32 >> 8;if (R_Temp32 > 250)R_Smk1Duty = 250;elseR_Smk1Duty = R_Temp32 & 0xff;
}
定时器处理
此函数8ms打开一次mos管 一个占空比周期为8ms 通过控制Timer2定时器去关mos实现调整mos管输出占空比实现调整发热丝输出
SMOKE1_MOS_ON;
//定时器2 通道1R_Smk1Duty_Valid = ((vu16)R_Smk1Duty + R_Smk1Duty_Valid) >> 1; // re-initial TIMER2// re-initial TIMER2PR2H = R_Smk1Duty_Valid >> 7;PR2L = (R_Smk1Duty_Valid & 0x7F) << 1;TMR2H = 0;TMR2L = 0;TMR2IF = 0;TMR2IE = 1;
中断函数处理
//低优先级中断服务函数
void interrupt low_priority ISR_l (void)
{if(TMR2IE == 1 && TMR2IF == 1) //一个PWM周期关MOS时间到;{ TMR2IF = 0;CMP1IE = 0;//关比较器中断TMR2IE = 0;//禁止中断SMOKE1_MOS_OFF;}
}
这篇关于电子烟开发【恒压、恒有效算法】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!