原创 YLP2440 PWM 实验

2009-5-21 12:45 2387 7 7 分类: MCU/ 嵌入式
zip

596cc2d4-832e-427d-97e7-0147fdc6506b.jpg

点击看大图

1.初始化TOUTn
设置TOUT0输出功能,并禁止TOUT0口的上啦电阻
    rGPBCON = (rGPBCON & (~(3<<0))) | (2<<0);
    rGPBUP |= 1<<0;
2.设置Timer0,初始化PWM输出
设置Prescaler 0 [7:0]——These 8 bits determine prescaler value for Timer 0 and 1:
    rTCFG0 = rTCFG0 & ~(0xff<<0)|(99<<0);
    //rTCFG0[7:0]=99,预分频0设为100,取....
设置MUX 0——Select MUX input for PWM Timer0:
    rTCFG1 = rTCFG1 & ~(0xf<<0);
    //rTCFG1[3:0]=0,再取1/2
设置TCNTB0和TCMPB0
    rTCMPB0 = duty;
    rTCNTB0 = cycle;
Determine auto reload on[3]、output inverter off[2]、manual update[1] and start for Timer 0[0].
    rTCON = (rTCON & ~(0xf<<0)) | (0xb << 0);
The Timer 0 manual update bit has to be cleared at next writing.
    rTCON &= ~2;
3.跟新rTCMPB0,以获得不同的占空比
            rTCMPB0 = pwm_dac;



PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
7
关闭 站长推荐上一条 /3 下一条