void PWM_init(uint32_t period ){
////设置系统时钟为16MHZ//定时都要初始化始终;
////SysCtlClockSet(SYSCTL_SYSDIV_1 |SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
//设置系统时钟为80MHZ//定时都要初始化始终;
SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_MAIN_OSC_DIS | SYSCTL_OSC_INT |SYSCTL_USE_PLL);
//一分频
SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
//使能//使能函数都是同一个
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
////SysCtlClockSet(SYSCTL_SYSDIV_1 |SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
//设置系统时钟为80MHZ//定时都要初始化始终;
SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_MAIN_OSC_DIS | SYSCTL_OSC_INT |SYSCTL_USE_PLL);
//一分频
SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
//使能//使能函数都是同一个
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
//配置相应的管脚
GPIOPinConfigure(GPIO_PB6_M0PWM0);
GPIOPinConfigure(GPIO_PB7_M0PWM1);
GPIOPinTypePWM(GPIO_PORTB_BASE,GPIO_PIN_6|GPIO_PIN_6|GPIO_PIN_7) ;
//配置PWM发生器
PWMGenConfigure(PWM0_BASE, PWM_GEN_0,PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);//设置周期PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, period);//设置输出高电平时间
//PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 100);//PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 300);//使能PWM的发生器
PWMGenEnable(PWM0_BASE, PWM_GEN_0);PWMGenEnable(PWM0_BASE, PWM_GEN_1);
GPIOPinConfigure(GPIO_PB6_M0PWM0);
GPIOPinConfigure(GPIO_PB7_M0PWM1);
GPIOPinTypePWM(GPIO_PORTB_BASE,GPIO_PIN_6|GPIO_PIN_6|GPIO_PIN_7) ;
//配置PWM发生器
PWMGenConfigure(PWM0_BASE, PWM_GEN_0,PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);//设置周期PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, period);//设置输出高电平时间
//PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 100);//PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 300);//使能PWM的发生器
PWMGenEnable(PWM0_BASE, PWM_GEN_0);PWMGenEnable(PWM0_BASE, PWM_GEN_1);
PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_0,PWM_TR_CNT_ZERO );
PWMGenIntRegister(PWM0_BASE, PWM_GEN_0,count_step);
IntMasterEnable();
//使能输出PWMOutputState(PWM0_BASE, (PWM_OUT_0_BIT | PWM_OUT_1_BIT), true);
//PWMOutputState(PWM0_BASE, (PWM_OUT_0_BIT | PWM_OUT_1_BIT),false);禁止
PWMGenIntRegister(PWM0_BASE, PWM_GEN_0,count_step);
IntMasterEnable();
//使能输出PWMOutputState(PWM0_BASE, (PWM_OUT_0_BIT | PWM_OUT_1_BIT), true);
//PWMOutputState(PWM0_BASE, (PWM_OUT_0_BIT | PWM_OUT_1_BIT),false);禁止
}
Susan Yang:
您现在使用的是EK-TM4C123GXL?
您可以看一下
http://www.ti.com/lit/ug/spmu296/spmu296.pdf 给出的说明
您现在使用的是PB6 PB7,若是想正常使用该引脚的PWM的话,您需要移除R9 R10这两个0欧姆的电阻
所以建议您使用其他的PWM通道
user5925053:
回复 Susan Yang:
谢谢
Susan Yang:
回复 user5925053:
很高兴能帮到您