R8C\2K 2L的定时器D的互补PWM模式
使用领域:EBIKE VVVF等三相电机驱动
带死区
三相电机,带死区。
死区:DEAD_TIME
周期:PERIOD
初始化如下:
/************************************************************************
*函数原型: Timer_RD_Init_PWM2
*功能 : 初始化RD 互补PWM模式
************************************************************************/
void Timer_RD_Init_PWM2(void)
{
//trdmr = 0b11101110;
trdstr = 0x0C; // Stop TRD0, TRD1 Count
trd0ic = 0x00; // TRD0 Interrupt disabled
trd1ic = 0x00; // TRD1 Interrupt disabled
cmd0_trdfcr = 0; // Set the CMD1 to CMD0 bits in the TRDFCR register to "00b" */
cmd1_trdfcr = 0;
cmd0_trdfcr = 0; // Combination Mode Selection Bit:Complementary PWM mode("11b") */
cmd1_trdfcr = 1; // (transfer from the Buffer register to the general register at the compare match with */
// the TRD1 registers)
//cmd1,cmd0 11为比较 相等时装入 10为TRD1下溢时装入
sync_trdmr = 0; // Set this bit to "0" (The TRD0 and TRD1 registers operate independently) */
// in complementary PWM mode */
// Set this bit to "0" in complementary PWM mode */
// TRDGRD0 Register:General Register
bfd1_trdmr = 1; //缓冲区
bfd0_trdmr = 1;
bfc1_trdmr = 1;
adtrg_trdfcr = 0; //1:允许AD触发 0:禁止
adeg_trdfcr =0; //0:相同时触发,1:下溢时触发
ols0_trdfcr = 1; // Normal-Phase Output Level Bit:Initial output "H" Active Level"L" */
ols1_trdfcr = 0; // Counter-Phase Output Level Bit:Initial output "H" Active Level"L" */
stclk_trdfcr = 0; /* External clock input disabled */
ea0_trdoer1 = 1; /* Set this bit to "1" in complementary PWM mode */
ec0_trdoer1 = 1; //为普通IO口/* TRDIOC0 Pin Output disable */
eb0_trdoer1 = 1; /* TRDIOB0 Pin Output enable */
ed0_trdoer1 = 1; /* TRDIOD0 Pin Output enable */
ea1_trdoer1 = 1;
eb1_trdoer1 = 1;
ec1_trdoer1 = 1;
ed1_trdoer1 = 1;
pto_trdoer2 = 0; /* INT0 of Pulse output forced cutoff input disabled */
tck2_trdcr0 = 0; /* Count Source Selection Bit:fOCO40M("110") */
tck1_trdcr0 = 0;
tck0_trdcr0 = 1;
tck2_trdcr1 = 0; /* Count Source Selection Bit:fOCO40M("110") */
tck1_trdcr1 = 0;
tck0_trdcr1 = 1;
cclr0_trdcr0 = 0; /* TRD0 Counter Clear Selection Bit: */
cclr1_trdcr0 = 0; /* Set to "000b" in complementary PWM mode */
cclr2_trdcr0 = 0;
trd0 = DEAD_TIME; //死区时间
//trd0 = 0;
trd1 = 0; /* Set this register to "0000h" in complementary PWM mode */
trdgra0 = PERIOD+DEAD_TIME;
trdgrd0 = PERIOD;
trdgrc1 = PERIOD;
trdgrd1 = PERIOD;
trdgrb0 = PERIOD;
trdgra1 = PERIOD;
trdgrb1 = PERIOD;
trdier0 = 0x01; /* TRD0:Disable interrupts, ovie/imied/imiec/imieb/imiea */
trd0ic = 0x06; //优先级为6,TRD0比较中断
trdier1 = 0;
trd1ic =0;
trdstr = 0x0f; /* Start TRD0, TRD1 Count */
}
文章评论(0条评论)
登录后参与讨论