本人新手,根据手把手教你学DSP课本的输出占空比固定的PWM波形实例,程序运行正确,但是在示波器上显示的时间与计算的时间正好差一半!
检查了几遍程序也没发现有问题,
void InitEv(void)
{
//EVA模块
EvaRegs.T1CON.bit.TMODE = 2; //连续增模式
EvaRegs.T1CON.bit.TPS = 1; //T1CLK=HSPCLK/2=37.5MHz
EvaRegs.T1CON.bit.TENABLE = 0; //暂时禁止T1计数
EvaRegs.T1CON.bit.TCLKS10 = 0; //使用内部时钟T1CLK
EvaRegs.T1CON.bit.TECMPR = 1; //使能定时器比较操作
EvaRegs.T2CON.bit.TMODE = 2; //连续增模式
EvaRegs.T2CON.bit.TPS = 1; //T2CLK=HSPCLK/2=37.5MHz
EvaRegs.T2CON.bit.TENABLE = 0; //暂时禁止T2计数
EvaRegs.T2CON.bit.TCLKS10 = 0; //使用内部时钟T2CLK
EvaRegs.T2CON.bit.TECMPR = 1; //使能定时器比较操作
EvaRegs.GPTCONA.bit.TCOMPOE =1; //定时器比较输出T1PWM_T1CMPR和T2PWM_T2CMPR
//由各自的定时器比较逻辑驱动
EvaRegs.GPTCONA.bit.T1PIN =1; //低电平有效
EvaRegs.GPTCONA.bit.T2PIN =2; //高电平有效
EvaRegs.T1PR =0x927B; //1KHz的PWM,周期为1ms
EvaRegs.T1CMPR =0x3A98; //占空比为40%,低电平有效
EvaRegs.T1CNT =0;
EvaRegs.T2PR =0x927B; //1KHz的PWM,周期为1ms
EvaRegs.T2CMPR =0x57E4; //占空比为40%,高电平有效
EvaRegs.T2CNT =0;
EvaRegs.COMCONA.bit.CENABLE =1; //使能比较单元的比较操作
EvaRegs.COMCONA.bit.FCOMPOE =1; //全比较输出,PWM1~6引脚均由相应的比较逻辑驱动
EvaRegs.COMCONA.bit.CLD =2; //立即中断
//死去时间为:4.7us
EvaRegs.DBTCONA.bit.DBT =10; //死区定时器周期,m=10
EvaRegs.DBTCONA.bit.EDBT1 =1; //死区定时器1使能位
EvaRegs.DBTCONA.bit.EDBT2 =1; //死区定时器2使能位
EvaRegs.DBTCONA.bit.EDBT3 =1; //死区定时器3使能位
EvaRegs.DBTCONA.bit.DBTPS =4; //死区定时器预定标因子Tab=37.5MHz/16=2.34MHz
EvaRegs.ACTR.all =0x0999; //设定引脚PWM1~6的动作属性,PWM1、3、5为低电平,PWM2、4、6为低电平
EvaRegs.CMPR1 =0x3A98; //PWM1占空比为40%
EvaRegs.CMPR2 =0x3A98; //PWM3占空比为40%
EvaRegs.CMPR3 =0x3A98; //PWM5占空比为40%
//EVB模块
EvbRegs.T3CON.bit.TMODE = 1; //连续增/减模式
EvbRegs.T3CON.bit.TPS = 1; //T3CLK=HSPCLK/2=37.5MHz
EvbRegs.T3CON.bit.TENABLE = 0; //暂时禁止T3计数
EvbRegs.T3CON.bit.TCLKS10 = 0; //使用内部时钟T3CLK
EvbRegs.T3CON.bit.TECMPR = 1; //使能定时器比较操作
EvbRegs.T4CON.bit.TMODE = 1; //连续增/减模式
EvbRegs.T4CON.bit.TPS = 1; //T4CLK=HSPCLK/2=37.5MHz
EvbRegs.T4CON.bit.TENABLE = 0; //暂时禁止T4计数
EvbRegs.T4CON.bit.TCLKS10 = 0; //使用内部时钟T4CLK
EvbRegs.T4CON.bit.TECMPR = 1; //使能定时器比较操作
EvbRegs.GPTCONB.bit.TCOMPOE =1; //定时器比较输出T3PWM_T3CMPR和T4PWM_T4CMPR
//由各自的定时器比较逻辑驱动
EvbRegs.GPTCONB.bit.T3PIN =1; //低电平有效
EvbRegs.GPTCONB.bit.T4PIN =2; //高电平有效
EvbRegs.T3PR =0x493E; //1KHz的PWM,周期为1ms
EvbRegs.T3CMPR =0x1D4C; //占空比为40%,低电平有效
EvbRegs.T3CNT =0;
EvbRegs.T4PR =0x493E; //1KHz的PWM,周期为1ms
EvbRegs.T4CMPR =0x2BF2; //占空比为40%,高电平有效
EvbRegs.T4CNT =0;
EvbRegs.COMCONB.bit.CENABLE =1; //使能比较单元的比较操作
EvbRegs.COMCONB.bit.FCOMPOE =1; //全比较输出,PWM7~12引脚均由相应的比较逻辑驱动
EvbRegs.COMCONB.bit.CLD =2;
//死去时间为:4.7us
EvbRegs.DBTCONB.bit.DBT =10; //死区定时器周期,m=10
EvbRegs.DBTCONB.bit.EDBT1 =1; //死区定时器1使能位
EvbRegs.DBTCONB.bit.EDBT2 =1; //死区定时器2使能位
EvbRegs.DBTCONB.bit.EDBT3 =1; //死区定时器3使能位
EvbRegs.DBTCONB.bit.DBTPS =4; //死区定时器预定标因子Tab=37.5MHz/16=2.34MHz
EvbRegs.ACTRB.all =0x0999; //设定引脚PWM7~12的动作属性
EvbRegs.CMPR4 =0x1D4C; //PWM7占空比为40%
EvbRegs.CMPR5 =0x1D4C; //PWM9占空比为40%
EvbRegs.CMPR6 =0x1D4C; //PWM11占空比为40%
}
我测的是PWM1和PWM2的波形。显示的死去时间为2.几微秒,而计算值是4.7微秒,差不多少了一半!
mangui zhang:
计算公式 如果是确定的2倍 那就是你的时钟没有计算对
死区时间=DB定时器周期*DB预定标系数*CPUCLK周期
本人新手,根据手把手教你学DSP课本的输出占空比固定的PWM波形实例,程序运行正确,但是在示波器上显示的时间与计算的时间正好差一半!
检查了几遍程序也没发现有问题,
void InitEv(void)
{
//EVA模块
EvaRegs.T1CON.bit.TMODE = 2; //连续增模式
EvaRegs.T1CON.bit.TPS = 1; //T1CLK=HSPCLK/2=37.5MHz
EvaRegs.T1CON.bit.TENABLE = 0; //暂时禁止T1计数
EvaRegs.T1CON.bit.TCLKS10 = 0; //使用内部时钟T1CLK
EvaRegs.T1CON.bit.TECMPR = 1; //使能定时器比较操作
EvaRegs.T2CON.bit.TMODE = 2; //连续增模式
EvaRegs.T2CON.bit.TPS = 1; //T2CLK=HSPCLK/2=37.5MHz
EvaRegs.T2CON.bit.TENABLE = 0; //暂时禁止T2计数
EvaRegs.T2CON.bit.TCLKS10 = 0; //使用内部时钟T2CLK
EvaRegs.T2CON.bit.TECMPR = 1; //使能定时器比较操作
EvaRegs.GPTCONA.bit.TCOMPOE =1; //定时器比较输出T1PWM_T1CMPR和T2PWM_T2CMPR
//由各自的定时器比较逻辑驱动
EvaRegs.GPTCONA.bit.T1PIN =1; //低电平有效
EvaRegs.GPTCONA.bit.T2PIN =2; //高电平有效
EvaRegs.T1PR =0x927B; //1KHz的PWM,周期为1ms
EvaRegs.T1CMPR =0x3A98; //占空比为40%,低电平有效
EvaRegs.T1CNT =0;
EvaRegs.T2PR =0x927B; //1KHz的PWM,周期为1ms
EvaRegs.T2CMPR =0x57E4; //占空比为40%,高电平有效
EvaRegs.T2CNT =0;
EvaRegs.COMCONA.bit.CENABLE =1; //使能比较单元的比较操作
EvaRegs.COMCONA.bit.FCOMPOE =1; //全比较输出,PWM1~6引脚均由相应的比较逻辑驱动
EvaRegs.COMCONA.bit.CLD =2; //立即中断
//死去时间为:4.7us
EvaRegs.DBTCONA.bit.DBT =10; //死区定时器周期,m=10
EvaRegs.DBTCONA.bit.EDBT1 =1; //死区定时器1使能位
EvaRegs.DBTCONA.bit.EDBT2 =1; //死区定时器2使能位
EvaRegs.DBTCONA.bit.EDBT3 =1; //死区定时器3使能位
EvaRegs.DBTCONA.bit.DBTPS =4; //死区定时器预定标因子Tab=37.5MHz/16=2.34MHz
EvaRegs.ACTR.all =0x0999; //设定引脚PWM1~6的动作属性,PWM1、3、5为低电平,PWM2、4、6为低电平
EvaRegs.CMPR1 =0x3A98; //PWM1占空比为40%
EvaRegs.CMPR2 =0x3A98; //PWM3占空比为40%
EvaRegs.CMPR3 =0x3A98; //PWM5占空比为40%
//EVB模块
EvbRegs.T3CON.bit.TMODE = 1; //连续增/减模式
EvbRegs.T3CON.bit.TPS = 1; //T3CLK=HSPCLK/2=37.5MHz
EvbRegs.T3CON.bit.TENABLE = 0; //暂时禁止T3计数
EvbRegs.T3CON.bit.TCLKS10 = 0; //使用内部时钟T3CLK
EvbRegs.T3CON.bit.TECMPR = 1; //使能定时器比较操作
EvbRegs.T4CON.bit.TMODE = 1; //连续增/减模式
EvbRegs.T4CON.bit.TPS = 1; //T4CLK=HSPCLK/2=37.5MHz
EvbRegs.T4CON.bit.TENABLE = 0; //暂时禁止T4计数
EvbRegs.T4CON.bit.TCLKS10 = 0; //使用内部时钟T4CLK
EvbRegs.T4CON.bit.TECMPR = 1; //使能定时器比较操作
EvbRegs.GPTCONB.bit.TCOMPOE =1; //定时器比较输出T3PWM_T3CMPR和T4PWM_T4CMPR
//由各自的定时器比较逻辑驱动
EvbRegs.GPTCONB.bit.T3PIN =1; //低电平有效
EvbRegs.GPTCONB.bit.T4PIN =2; //高电平有效
EvbRegs.T3PR =0x493E; //1KHz的PWM,周期为1ms
EvbRegs.T3CMPR =0x1D4C; //占空比为40%,低电平有效
EvbRegs.T3CNT =0;
EvbRegs.T4PR =0x493E; //1KHz的PWM,周期为1ms
EvbRegs.T4CMPR =0x2BF2; //占空比为40%,高电平有效
EvbRegs.T4CNT =0;
EvbRegs.COMCONB.bit.CENABLE =1; //使能比较单元的比较操作
EvbRegs.COMCONB.bit.FCOMPOE =1; //全比较输出,PWM7~12引脚均由相应的比较逻辑驱动
EvbRegs.COMCONB.bit.CLD =2;
//死去时间为:4.7us
EvbRegs.DBTCONB.bit.DBT =10; //死区定时器周期,m=10
EvbRegs.DBTCONB.bit.EDBT1 =1; //死区定时器1使能位
EvbRegs.DBTCONB.bit.EDBT2 =1; //死区定时器2使能位
EvbRegs.DBTCONB.bit.EDBT3 =1; //死区定时器3使能位
EvbRegs.DBTCONB.bit.DBTPS =4; //死区定时器预定标因子Tab=37.5MHz/16=2.34MHz
EvbRegs.ACTRB.all =0x0999; //设定引脚PWM7~12的动作属性
EvbRegs.CMPR4 =0x1D4C; //PWM7占空比为40%
EvbRegs.CMPR5 =0x1D4C; //PWM9占空比为40%
EvbRegs.CMPR6 =0x1D4C; //PWM11占空比为40%
}
我测的是PWM1和PWM2的波形。显示的死去时间为2.几微秒,而计算值是4.7微秒,差不多少了一半!
mangui zhang:
http://www.deyisupport.com/question_answer/microcontrollers/c2000/f/56/t/86477.aspx
时间管理器详细讲解 你看看