我使用这款单片机调速时,占空比不对称分布,10%对应转速为0,45%达到最高转速,请问大侠这是什么原因?
程序:#include"stc12c5a60s2.h"
#include "PWM.h"
void send_PWM1(uchar j_temp);
void pwm_init() ;
//static uint step0 = 0;
//static uint step1 = 0;
//void Set_PWM1(uchar duty);
void send_PWM1(uchar j_temp)
{
CR = 0;
CMOD = 0x00; // CIDL - - - - CPS1 CPS0 ECF Setup PCA Timer
// CPS1 CPS0 = 00, Fosc/12 is PCA/PWM clock
// CPS1 CPS0 = 01, Fosc/2 is PCA/PWM clock CMOD.1,CMOD.2
// 18432000/12/256 = 6000
CL = 0x00;
CH = 0x00;
CCAP1L = j_temp; //Set the initial value same as CCAP0H 00为高电平,FF为低电平
CCAP1H = CCAP1L; //230 10%
CCAPM1 = 0x42; //0100,0010 Setup PCA module 0 in 8BIT PWM,
CR = 1; //启动 PCA/PWM 定时器
}
/*
void pwm_set(unsigned char x,unsigned char y)
{
CCAP0H=x;
CCAP0L=x;
CCAP1H=y;
CCAP1L=y;
}
*/
void pwm_init() //PWM初始化函数,初始占空比为0
{
CR = 0;
CMOD = 0x00; // CIDL - - - - CPS1 CPS0 ECF Setup PCA Timer
CCON = 0x00; // CPS1 CPS0 = 00, Fosc/12 is PCA/PWM clock
// 11952000/256
CCAPM1 = 0x42; // 设置为高速模式,允许中断
// IPH = 0x80; // PCA为最高优先级
// IP = 0x80;
CL = 0x00;
CH = 0x00;
CR = 1; //启动 PCA/PWM 定时器
// EA = 1;
} |