这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » LPC213X,PWM LPC213X四路单边PWM模块应用源码

共2条 1/1 1 跳转至

LPC213X,PWM LPC213X四路单边PWM模块应用源码

院士
2006-09-17 18:14:16     打赏
LPC213X,PWM LPC213X四路单边PWM模块应用源码



关键词: LPC213X     四路     单边     模块     应用     源码    

院士
2006-12-22 22:43:00     打赏
2楼
问 /*----------------------------------------------------------------
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 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]