#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/pwm.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
//*****************************************************************************
//主程序
int
main(void)
{
//
// 设置系统时钟16M
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
//
// PWM不分频
//
SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
//使能M1PWM外设
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
//使能M1PWM用到的PF,和RESET对应的PB
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);//使能B端口,PB2、PB3分别对应RESET_AB,RESET_CD
GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_2|GPIO_PIN_3);//配置2,3管脚为输出
//配置PF0,PF1分别为M1PWM4,M1PWM5
GPIOPinConfigure(GPIO_PF0_M1PWM4);
GPIOPinConfigure(GPIO_PF1_M1PWM5);
// 配置PF0,PF1为PWM的输出管脚
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_1);
//
// Configure the PWM1 to count down without synchronization.
//配置GEN2递减计数模式不同步模式
PWMGenConfigure(PWM1_BASE, PWM_GEN_2,
PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
//
// Set the PWM period to 250Hz. To calculate the appropriate parameter
// use the following equation: N = (1 / f) * SysClk. Where N is the
// function parameter, f is the desired frequency, and SysClk is the
// system clock frequency.
// In this case you get: (1 / 250Hz) * 16MHz = 64000 cycles. Note that
// the maximum period you can set is 2^16.
//设置PWM周期
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2,100);
//
// For this example the PWM0 duty cycle will be variable. The duty cycle
// will start at 0.1% (0.01 * 64000 cycles = 640 cycles) and will increase
// to 75% (0.5 * 64000 cycles = 32000 cycles). After a duty cycle of 75%
// is reached, it is reset to 0.1%. This dynamic adjustment of the pulse
// width is done in the PWM0 load interrupt, which increases the duty
// cycle by 0.1% everytime the reload interrupt is received.
//设置PWM占空比
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_4, 100/2);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, 100/2);
//使能PWM输出状态
PWMOutputState(PWM1_BASE, PWM_OUT_4_BIT| PWM_OUT_5_BIT, true);
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2, 0x1<<2);//H2管脚置高 对应RESETAB
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_3, 0x1<<3);//H3管脚置高 对应RESETCD
//
// 使能PWM发生器
PWMGenEnable(PWM1_BASE, PWM_GEN_2);
//循环等待响应
while(1)
{
}
}
PF1能输出PWM,PF0不能输出PWM
zhetao xu:
回复 Ken Wang:
Hi Ken,
谢谢你的答复。