R8C\2K 2L的定时器D的PWM模式
用于,N个PWM输出,此例程仅2路输出,2路不同步
使用中请按照自己的要求更改部分设置。
R8C\2K 2L的定时器的PWM模式:
此程序仅有TRDIOB1和TRDIOD1输出,不同步,周期相同。
其他端口是普通IO,没有使用中断
周期:PERIOD
初始化代码如下:
/************************************************************************
*函数原型: Timer_RD_Init_PWM
*功能 : 初始化RD PWM模式
************************************************************************/
void Timer_RD_Init_PWM(void)
{
trdstr = 0x0C; // Stop TRD0, TRD1 Count
trd0ic = 0x00; // TRD0 Interrupt disabled
trd1ic = 0x00; // TRD1 Interrupt disabled
sync_trdmr = 0; // The TRD0 and TRD1 独立运行
bfc0_trdmr=0;
bfd0_trdmr=0;
bfc1_trdmr=0;
bfd1_trdmr=0; // trdgxi寄存器选择位
pwmb0_trdpmr=0;
pwmc0_trdpmr=0;
pwmd0_trdpmr=0;
pwmb1_trdpmr=1; // B1 pwm
pwmc1_trdpmr=0;
pwmd1_trdpmr=1; // D1 pwm
cmd0_trdfcr=0;
cmd1_trdfcr=0; //PWM 模式必须设置为00
pwm3_trdfcr=1; //PWM 模式必须设置为1
ea0_trdoer1 = 1; /* Set this bit to "1" in PWM mode */
ec0_trdoer1 = 1; // TRDIOC0 Pin Output disable */
eb0_trdoer1 = 1; /* TRDIOB0 Pin Output disable */
ed0_trdoer1 = 1; /* TRDIOD0 Pin Output disable */
ea1_trdoer1 = 1; /* Set this bit to "1" in PWM mode */
eb1_trdoer1 = 0;
ec1_trdoer1 = 1;
ed1_trdoer1 = 0;
pto_trdoer2 = 0; /* INT0 of Pulse output forced cutoff input disabled */
toa0_trdocr = 0; /* Set this bit to "0" in PWM mode */
tob0_trdocr = 0;
toc0_trdocr = 0;
tod0_trdocr = 0;
toa1_trdocr = 0; /* Set this bit to "1" in PWM mode */
tob1_trdocr = 1;
toc1_trdocr = 0; /* 初始输出非有效电平 */
tod1_trdocr = 1;
tck2_trdcr1 = 0; /* Count Source Selection Bit:fOCO40M("110") */
tck1_trdcr1 = 0;
tck0_trdcr1 = 1;
cclr0_trdcr1 = 1; /* 001 PWM模式时 */
cclr1_trdcr1 = 0; /* 在trdgai比较匹配时清除trdi寄存器 */
cclr2_trdcr1 = 0;
polb_trdpocr1 = 1;
pold_trdpocr1 = 1;
trd1=PERIOD;
trdgra1=PERIOD;
trdgrb1=PERIOD/2;
trdgrd1=PERIOD/3;
trdstr = 0x0f; /* Start TRD0, TRD1 Count */
}
文章评论(0条评论)
登录后参与讨论