📄 pwm_init.c
字号:
#include "hw_types.h"
#include "hw_memmap.h"
#include "gpio.h"
#include <hw_sysctl.h>
#include <hw_gpio.h>
#include <sysctl.h>
#include "pwm.h"
#include "pwm_init.h"
#define SysCtlPeriEnable SysCtlPeripheralEnable
#define SysCtlPeriDisable SysCtlPeripheralDisable
#define GPIOPinTypeIn GPIOPinTypeGPIOInput
#define GPIOPinTypeOut GPIOPinTypeGPIOOutput
extern unsigned int ulPeriod;
void pwm_init(void)
{
SysCtlPWMClockSet(SYSCTL_PWMDIV_1);//PWM clock is processor clock /1
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM);
SysCtlPeripheralEnable(motor1_use_pwm_group);
SysCtlPeripheralEnable(motor2_use_pwm_group);
SysCtlPeripheralEnable(motor3_use_pwm_group);
GPIOPinTypePWM(motor1_base, motor1_pwm_forward);
GPIOPinTypePWM(motor1_base, motor1_pwm_reverse);
GPIOPinTypePWM(motor2_base, motor2_pwm_forward);
GPIOPinTypePWM(motor2_base, motor2_pwm_reverse);
GPIOPinTypePWM(motor3_base, motor3_pwm_forward);
GPIOPinTypePWM(motor3_base, motor3_pwm_reverse);
ulPeriod = SysCtlClockGet()/ 1000;
//ulPeriod = 2 0000;
PWMGenConfigure(PWM_BASE, PWM_GEN_0,
PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMGenPeriodSet(PWM_BASE, PWM_GEN_0, ulPeriod);
PWMGenConfigure(PWM_BASE, PWM_GEN_1,
PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMGenPeriodSet(PWM_BASE, PWM_GEN_1, ulPeriod);
PWMGenConfigure(PWM_BASE, PWM_GEN_2,
PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMGenPeriodSet(PWM_BASE, PWM_GEN_2, ulPeriod);
PWMGenEnable(PWM_BASE, PWM_GEN_0);
PWMGenEnable(PWM_BASE, PWM_GEN_1);
PWMGenEnable(PWM_BASE, PWM_GEN_2);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -