|
发表于 2012-9-2 03:17:31
|
显示全部楼层
本帖最后由 john800422 于 2012-9-2 03:19 编辑
/* Different PWM Cycle */
#define PWM_Cycle // PWM Cycle
#define DeltaT // Interrupt Time
u16 PWM_H; // PWM High Time
u8 PWM_Sta = 0; // Initial State
Times += DeltaT;
switch(PWM_Sta) {
case 0:
PWM = 1;
if(Times >= PWM_H) {
PWM_Sta = 1;
Times = 0;
}
break;
case 1:
PWM = 0;
if(Times >= (PWM_Cycle-PWM_H)) {
PWM_Sta = 0;
Times = 0;
}
break;
}
/* Same PWM Cycle */
#define PWM_Cycle // PWM Cycle
u16 Interrupt_Time // Interrupt Time
u16 PWM1_H; // PWM1 High Time
u16 PWM2_H; // PWM2 High Time
u8 PWM_Sta = 0; // Initial State
switch(PWM_Sta) {
case 0:
Interrupt_Time = PWM1_H;
PWM1 = 1;
PWM_Sta = 1;
break;
case 1:
Interrupt_Time = PWM2_H;
PWM1 = 0;
PWM2 = 1;
PWM_Sta = 2;
break;
case 2:
Interrupt_Time = PWM_Cycle-(PWM1_H+PWM2_H);
PWM1 = 0;
PWM2 = 0;
PWM_Sta = 0;
break;
}
// Set Timer Interrupt Time
若是调亮度, 应该同周期也可以吧?
因为使用相同周期的PWM会比较简单
不同周期就必须分开做,
或是像"yangshichang110"
使用两个PWM之关系做处理 |
|