/*---------------------------------------------------------------- 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; } }
|
文章评论(0条评论)
登录后参与讨论