共2条
1/1 1 跳转至页
LPC213X,PWM LPC213X四路单边PWM模块应用源码
问
/*----------------------------------------------------------------
ARM水鸟 HotPower@126.com
2006.06.26 23:55 于西安大雁塔村队部
-----------------------------------------------------------------*/
void PwmObj::OpenPwm(unsigned int worknum)
{
worknum &= 3;
PWM->PWM_PR = 0x00;
PWM->PWM_MCR = (1 << PWMMCRR0);
switch (worknum) {
case 0://CD1
PINSEL->PIN_SEL0 |= (P0_7_PWM2 << P0_7_PINSEL);// P0.7连接到PWM2
PWM->PWM_PCR |= (1 << PWMENA2);
PWM->PWM_MR0 = PwmSize;//16KHz (周期数=864)
PWM->PWM_MR2 = PwmStartSize;
PWM->PWM_LER = (1 << PWMLER2) | (1 << PWMLER0);
break;
case 1://CD2
PINSEL->PIN_SEL0 |= (P0_8_PWM4 << P0_8_PINSEL);// P0.8连接到PWM4
PWM->PWM_PCR |= (1 << PWMENA4);
PWM->PWM_MR0 = PwmSize;//16KHz (周期数=864)
PWM->PWM_MR4 = PwmStartSize;
PWM->PWM_LER = (1 << PWMLER4) | (1 << PWMLER0);
break;
case 2://CD3
PINSEL->PIN_SEL0 |= (P0_9_PWM6 << P0_9_PINSEL);// P0.9连接到PWM6
PWM->PWM_PCR |= (1 << PWMENA6);
PWM->PWM_MR0 = PwmSize;//16KHz (周期数=864)
PWM->PWM_MR6 = PwmStartSize;
PWM->PWM_LER = (1 << PWMLER6) | (1 << PWMLER0);
break;
case 3://CD4
PINSEL->PIN_SEL1 |= (P0_21_PWM5 << P0_21_PINSEL);// P0.21连接到PWM5
PWM->PWM_PCR |= (1 << PWMENA5);
PWM->PWM_MR0 = PwmSize;//16KHz (周期数=864)
PWM->PWM_MR5 = PwmStartSize;
PWM->PWM_LER = (1 << PWMLER5) | (1 << PWMLER0);
break;
}
PWM->PWM_TCR = 0x02;
PWM->PWM_TCR = 0x09;
}
void PwmObj::ClosePwm(unsigned int worknum)
{
worknum &= 3;
switch (worknum) {
case 0:
PWM->PWM_MR2 = 0;//PWM2
CDPORT->IOCLR = (1 << P0_7);
CDPORT->IODIR |= (1 << P0_7);
PINSEL->PIN_SEL0 &= ~(3 << P0_7_PINSEL);// P0.7连接到GPIO
break;
case 1:
PWM->PWM_MR4 = 0;//PWM4
CDPORT->IOCLR = (1 << P0_8);
CDPORT->IODIR |= (1 << P0_8);
PINSEL->PIN_SEL0 &= ~(3 << P0_8_PINSEL);// P0.8连接到GPIO
break;
case 2:
PWM->PWM_MR6 = 0;//PWM6
CDPORT->IOCLR = (1 << P0_9);
CDPORT->IODIR |= (1 << P0_9);
PINSEL->PIN_SEL0 &= ~(3 << P0_9_PINSEL);// P0.9连接到GPIO
break;
case 3:
PWM->PWM_MR5 = 0;//PWM5
CDPORT->IOCLR = (1 << P0_21);
CDPORT->IODIR |= (1 << P0_21);
PINSEL->PIN_SEL1 &= ~(3 << P0_21_PINSEL);// P0.21连接到GPIO
break;
}
}
void PwmObj::IncPwm(unsigned int worknum)
{
worknum &= 3;
switch(worknum) {
case 0:
if ((PWM->PWM_MR2 + 1) < (PWM->PWM_MR0 * 70 / 100)) {
PWM->PWM_MR2 += 1;
PWM->PWM_LER = (1 << PWMLER2) | (1 << PWMLER0);
}
break;
case 1:
if ((PWM->PWM_MR4 + 1) < (PWM->PWM_MR0 * 70 / 100)) {
PWM->PWM_MR4 += 1;
PWM->PWM_LER = (1 << PWMLER4) | (1 << PWMLER0);
}
break;
case 2:
if ((PWM->PWM_MR6 + 1) < (PWM->PWM_MR0 * 70 / 100)) {
PWM->PWM_MR6 += 1;
PWM->PWM_LER = (1 << PWMLER6) | (1 << PWMLER0);
}
break;
case 3:
if ((PWM->PWM_MR5 + 1) < (PWM->PWM_MR0 * 70 / 100)) {
PWM->PWM_MR5 += 1;
PWM->PWM_LER = (1 << PWMLER5) | (1 << PWMLER0);
}
break;
}
}
void PwmObj::DecPwm(unsigned int worknum)
{
worknum &= 3;
switch(worknum) {
case 0:
if (PWM->PWM_MR2 >= 1) {
PWM->PWM_MR2 -= 1;
PWM->PWM_LER = (1 << PWMLER2) | (1 << PWMLER0);
}
break;
case 1:
if (PWM->PWM_MR4 >= 1) {
PWM->PWM_MR4 -= 1;
PWM->PWM_LER = (1 << PWMLER4) | (1 << PWMLER0);
}
break;
case 2:
if (PWM->PWM_MR6 >= 1) {
PWM->PWM_MR6 -= 1;
PWM->PWM_LER = (1 << PWMLER6) | (1 << PWMLER0);
}
break;
case 3:
if (PWM->PWM_MR5 >= 1) {
PWM->PWM_MR5 -= 1;
PWM->PWM_LER = (1 << PWMLER5) | (1 << PWMLER0);
}
break;
}
}
答 1: 好大哥,让弟弟见识了。支持 答 2: 有没有C的代码啊???? 答 3: 能说一说其实现什么功能吗????它的方波频率是多少?
它的四路输出的频率是一样的吗???
你是怎么实现脉冲输出个数的计数的??
ARM水鸟 HotPower@126.com
2006.06.26 23:55 于西安大雁塔村队部
-----------------------------------------------------------------*/
void PwmObj::OpenPwm(unsigned int worknum)
{
worknum &= 3;
PWM->PWM_PR = 0x00;
PWM->PWM_MCR = (1 << PWMMCRR0);
switch (worknum) {
case 0://CD1
PINSEL->PIN_SEL0 |= (P0_7_PWM2 << P0_7_PINSEL);// P0.7连接到PWM2
PWM->PWM_PCR |= (1 << PWMENA2);
PWM->PWM_MR0 = PwmSize;//16KHz (周期数=864)
PWM->PWM_MR2 = PwmStartSize;
PWM->PWM_LER = (1 << PWMLER2) | (1 << PWMLER0);
break;
case 1://CD2
PINSEL->PIN_SEL0 |= (P0_8_PWM4 << P0_8_PINSEL);// P0.8连接到PWM4
PWM->PWM_PCR |= (1 << PWMENA4);
PWM->PWM_MR0 = PwmSize;//16KHz (周期数=864)
PWM->PWM_MR4 = PwmStartSize;
PWM->PWM_LER = (1 << PWMLER4) | (1 << PWMLER0);
break;
case 2://CD3
PINSEL->PIN_SEL0 |= (P0_9_PWM6 << P0_9_PINSEL);// P0.9连接到PWM6
PWM->PWM_PCR |= (1 << PWMENA6);
PWM->PWM_MR0 = PwmSize;//16KHz (周期数=864)
PWM->PWM_MR6 = PwmStartSize;
PWM->PWM_LER = (1 << PWMLER6) | (1 << PWMLER0);
break;
case 3://CD4
PINSEL->PIN_SEL1 |= (P0_21_PWM5 << P0_21_PINSEL);// P0.21连接到PWM5
PWM->PWM_PCR |= (1 << PWMENA5);
PWM->PWM_MR0 = PwmSize;//16KHz (周期数=864)
PWM->PWM_MR5 = PwmStartSize;
PWM->PWM_LER = (1 << PWMLER5) | (1 << PWMLER0);
break;
}
PWM->PWM_TCR = 0x02;
PWM->PWM_TCR = 0x09;
}
void PwmObj::ClosePwm(unsigned int worknum)
{
worknum &= 3;
switch (worknum) {
case 0:
PWM->PWM_MR2 = 0;//PWM2
CDPORT->IOCLR = (1 << P0_7);
CDPORT->IODIR |= (1 << P0_7);
PINSEL->PIN_SEL0 &= ~(3 << P0_7_PINSEL);// P0.7连接到GPIO
break;
case 1:
PWM->PWM_MR4 = 0;//PWM4
CDPORT->IOCLR = (1 << P0_8);
CDPORT->IODIR |= (1 << P0_8);
PINSEL->PIN_SEL0 &= ~(3 << P0_8_PINSEL);// P0.8连接到GPIO
break;
case 2:
PWM->PWM_MR6 = 0;//PWM6
CDPORT->IOCLR = (1 << P0_9);
CDPORT->IODIR |= (1 << P0_9);
PINSEL->PIN_SEL0 &= ~(3 << P0_9_PINSEL);// P0.9连接到GPIO
break;
case 3:
PWM->PWM_MR5 = 0;//PWM5
CDPORT->IOCLR = (1 << P0_21);
CDPORT->IODIR |= (1 << P0_21);
PINSEL->PIN_SEL1 &= ~(3 << P0_21_PINSEL);// P0.21连接到GPIO
break;
}
}
void PwmObj::IncPwm(unsigned int worknum)
{
worknum &= 3;
switch(worknum) {
case 0:
if ((PWM->PWM_MR2 + 1) < (PWM->PWM_MR0 * 70 / 100)) {
PWM->PWM_MR2 += 1;
PWM->PWM_LER = (1 << PWMLER2) | (1 << PWMLER0);
}
break;
case 1:
if ((PWM->PWM_MR4 + 1) < (PWM->PWM_MR0 * 70 / 100)) {
PWM->PWM_MR4 += 1;
PWM->PWM_LER = (1 << PWMLER4) | (1 << PWMLER0);
}
break;
case 2:
if ((PWM->PWM_MR6 + 1) < (PWM->PWM_MR0 * 70 / 100)) {
PWM->PWM_MR6 += 1;
PWM->PWM_LER = (1 << PWMLER6) | (1 << PWMLER0);
}
break;
case 3:
if ((PWM->PWM_MR5 + 1) < (PWM->PWM_MR0 * 70 / 100)) {
PWM->PWM_MR5 += 1;
PWM->PWM_LER = (1 << PWMLER5) | (1 << PWMLER0);
}
break;
}
}
void PwmObj::DecPwm(unsigned int worknum)
{
worknum &= 3;
switch(worknum) {
case 0:
if (PWM->PWM_MR2 >= 1) {
PWM->PWM_MR2 -= 1;
PWM->PWM_LER = (1 << PWMLER2) | (1 << PWMLER0);
}
break;
case 1:
if (PWM->PWM_MR4 >= 1) {
PWM->PWM_MR4 -= 1;
PWM->PWM_LER = (1 << PWMLER4) | (1 << PWMLER0);
}
break;
case 2:
if (PWM->PWM_MR6 >= 1) {
PWM->PWM_MR6 -= 1;
PWM->PWM_LER = (1 << PWMLER6) | (1 << PWMLER0);
}
break;
case 3:
if (PWM->PWM_MR5 >= 1) {
PWM->PWM_MR5 -= 1;
PWM->PWM_LER = (1 << PWMLER5) | (1 << PWMLER0);
}
break;
}
}
答 1: 好大哥,让弟弟见识了。支持 答 2: 有没有C的代码啊???? 答 3: 能说一说其实现什么功能吗????它的方波频率是多少?
它的四路输出的频率是一样的吗???
你是怎么实现脉冲输出个数的计数的??
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
vscode+cmake搭建雅特力AT32L021开发环境被打赏30分 | |
【换取逻辑分析仪】自制底板并驱动ArduinoNanoRP2040ConnectLCD扩展板被打赏47分 | |
【分享评测,赢取加热台】RISC-V GCC 内嵌汇编使用被打赏38分 | |
【换取逻辑分析仪】-基于ADI单片机MAX78000的简易MP3音乐播放器被打赏48分 | |
我想要一部加热台+树莓派PICO驱动AHT10被打赏38分 | |
【换取逻辑分析仪】-硬件SPI驱动OLED屏幕被打赏36分 | |
换逻辑分析仪+上下拉与多路选择器被打赏29分 | |
Let'sdo第3期任务合集被打赏50分 | |
换逻辑分析仪+Verilog三态门被打赏27分 | |
换逻辑分析仪+Verilog多输出门被打赏24分 |