/*******************************************
开发坏境:CCSv5
程序功能:利用PWM模块产生占空比自动从0.1%到100%循环调节的PWM波
程序说明:使用PWM模块0,PWM发生器0,输出为PWM0管脚,PB6 利用PWM中断
********************************************/
#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"
unsigned int PWM_Value=1852; //PWM占空比调节
void PWM0IntHandler(void)
{PWMGenIntClear(PWM0_BASE, PWM_GEN_0, PWM_INT_CNT_LOAD);if((PWMPulseWidthGet(PWM0_BASE, PWM_OUT_0) + 64) <=(PWMGenPeriodGet(PWM0_BASE, PWM_GEN_0) )){PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,PWMPulseWidthGet(PWM0_BASE, PWM_OUT_0) + 64);}else{PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 64);}
}
int main(void)
{SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);SysCtlPWMClockSet(SYSCTL_PWMDIV_1);SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);GPIOPinConfigure(GPIO_PB6_M0PWM0);GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, PWM_Value);//250HZPWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, PWM_Value/2);//占空比0.1%IntMasterEnable();PWMIntEnable(PWM0_BASE, PWM_INT_GEN_0);// Enable the PWM0 LOAD interrupt on PWM0.PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_0, PWM_INT_CNT_LOAD);IntEnable(INT_PWM0_0);PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);PWMGenEnable(PWM0_BASE, PWM_GEN_0);while(1);
}
xyz549040622:
/*******************************************
开发坏境:CCSv5
程序功能:利用PWM模块产生占空比可调的带死区的PWM波
程序说明:使用PWM模块0,PWM发生器0,输出为PWM0和PWM1管脚,分别为PB6,PB7
********************************************/
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/rom.h"
#include "driverlib/gpio.h"
#include "driverlib/pwm.h"
#include "driverlib/fpu.h"
#include "driverlib/pin_map.h"int main (void)
{//long int PWM_Value=12500;//PWM占空比调节//使能FPUFPUEnable();FPULazyStackingEnable();//设置系统时钟为16MHzSysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_OSC|SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ);SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);//使能PWM0模块SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);//使能PWM0和PWM1输出所在GPIOGPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_7);//配置PH0/PH1为PWM功能GPIOPinConfigure(GPIO_PB6_M0PWM0);//#define GPIO_PB6_M0PWM00x00011804GPIOPinConfigure(GPIO_PB7_M0PWM1);//#define GPIO_PB7_M0PWM10x00011C04//驱动电流8MA,推挽输出GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_6,GPIO_STRENGTH_8MA,GPIO_PIN_TYPE_STD);SysCtlPWMClockSet(SYSCTL_PWMDIV_64);// PWM时钟配置:不分频//配置PWM发生器0:加减计数,不同步PWMGenConfigure(PWM0_BASE,PWM_GEN_0,PWM_GEN_MODE_UP_DOWN| PWM_GEN_MODE_NO_SYNC);//设置PWM发生器1的频率,时钟频率/PWM分频数/n,16M/64/5000=50HZPWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 5000);//设置PWM0/PWM1输出的脉冲宽度PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,2500);//50%占空比//PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 500);//25%占空比PWMDeadBandEnable(PWM0_BASE, PWM_GEN_0, 100, 100);//使能PWM0和PWM1的输出PWMOutputState(PWM0_BASE, (PWM_OUT_0_BIT |PWM_OUT_1_BIT), true);//使能PWM发生器PWMGenEnable(PWM0_BASE, PWM_GEN_0);while(1){}
}