|
- void Pwm_Init(void)
- {
- u8 buff[4] = {0x5A,0x01,(u8)(PWM_HIGH_MAX>>8),(u8)PWM_HIGH_MAX}; //01是分频系数,
- // u8 buff[4] = {0x5A,0x01,0x81,0x06}; //01是分频系数,
- sys_write_vp(PWM0_SET_ADDR,buff,2); //设置PWM0 通道
- }
复制代码 这是参考熊老师的例程,上面是设置分辨率,- //设置占空比
- void pwm_set_duty(u16 duty)
- {
- // #define PWM0_OUT_ADDR 0x92
-
- // if(duty>100)
- // duty = 100;
-
- // duty = (u16)((float)duty/100.0f*PWM_ACCURACY+0.5f);
- sys_write_vp(PWM0_OUT_ADDR,(u8*)&duty,1);
- }
复制代码 先设置占空比再转为高电平脉冲数duty = (u16)((float)duty/100.0f*PWM_ACCURACY+0.5f);可以正常输出,但是// duty = (u16)((float)duty/100.0f*PWM_ACCURACY+0.5f);注释掉后,直接设置高电平脉冲数,用示波器测量没有PWM波形,这是为啥?
|
|