调了一晚上了,想让pwm输出50hz的周期的pwm来驱动舵机,然而pwm时钟就是不分频。我设置的是16分频,但用pmwclkget函数,返回的是“不分频”,示波器测出来的是800hz,求大家解答。
附上pwm代码
#include"main.h"
#include"duoji.h"
#include"pwm.h"
#include "inc/hw_memmap.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/pwm.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
void pwminit(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
PWMClockSet(PWM0_BASE,SYSCTL_PWMDIV_16);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinConfigure(GPIO_PF0_M0PWM0);
GPIOPinConfigure(GPIO_PF1_M0PWM1);
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_1);
PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN |
PWM_GEN_MODE_NO_SYNC);
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 20000);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0|PWM_OUT_1,
1000);
long aw=PWMGenPeriodGet(PWM0_BASE, PWM_GEN_0);
PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT|PWM_OUT_1_BIT, true);
PWMGenEnable(PWM0_BASE, PWM_GEN_0);
}
//然后main是这样的
int main(void)
{
g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 16000000);
pwminit();
uartinit();
adcinit();
IntEnable(INT_PWM0_0|INT_PWM0_1|INT_UART3);
IntMasterEnable();
while(1)
{
pmwclk2333=PWMClockGet(PWM0_BASE);
}
}
xyz549040622:
g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |SYSCTL_OSC_MAIN |SYSCTL_USE_PLL |SYSCTL_CFG_VCO_480), 16000000);
这个最后一个参数,你要把主频配置为16Mhz吗?TM4C129x的最大主频是120Mhz,你这个最后一个参数就设置错误了。
Maka Luo:
Yizhou Chen
调了一晚上了,想让pwm输出50hz的周期的pwm来驱动舵机,然而pwm时钟就是不分频。我设置的是16分频,但用pmwclkget函数,返回的是“不分频”,示波器测出来的是800hz,求大家解答。
附上pwm代码
#include"main.h"#include"duoji.h"#include"pwm.h"#include "inc/hw_memmap.h"#include "driverlib/gpio.h"#include "driverlib/pin_map.h"#include "driverlib/pwm.h"#include "driverlib/sysctl.h"#include "driverlib/uart.h"
void pwminit(void){
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); PWMClockSet(PWM0_BASE,SYSCTL_PWMDIV_16); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinConfigure(GPIO_PF0_M0PWM0); GPIOPinConfigure(GPIO_PF1_M0PWM1);
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_1);
PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 20000);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0|PWM_OUT_1, 1000); long aw=PWMGenPeriodGet(PWM0_BASE, PWM_GEN_0);
PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT|PWM_OUT_1_BIT, true);
PWMGenEnable(PWM0_BASE, PWM_GEN_0);
}
//然后main是这样的
int main(void){ g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 16000000); pwminit(); uartinit(); adcinit(); IntEnable(INT_PWM0_0|INT_PWM0_1|INT_UART3); IntMasterEnable(); while(1) { pmwclk2333=PWMClockGet(PWM0_BASE); }}