使用函数 PWMClockSet() 不能给 PWM 分频,可能是哪边没有配置好啊 。急等。
大神们,有没有例程啊。跪求。
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
你这个函数就不对吧。正确的应该是SysCtlPWMClockSet,给你个完整的PWM的例程看看
//PWM实验程序解析 //头文件 #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) { //使能FPU FPUEnable(); FPULazyStackingEnable(); //设置系统时钟为50MHz SysCtlClockSet(SYSCTL_SYSDIV_4 |SYSCTL_USE_PLL |SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ); //使能PWM模块 ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM); //使能PWM2和PWM3输出所在GPIO ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); //配置PH0/PH1为PWM功能 ROM_GPIOPinTypePWM(GPIO_PORTH_BASE, GPIO_PIN_0); ROM_GPIOPinTypePWM(GPIO_PORTH_BASE, GPIO_PIN_1); // PWM时钟配置:不分频 ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_1); //配置PWM发生器1:加减计数 ROM_PWMGenConfigure(PWM_BASE, PWM_GEN_0,PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC); //设置PWM发生器1的周期 ROM_PWMGenPeriodSet(PWM_BASE, PWM_GEN_0, 6000); //设置PWM2/PWM3输出的脉冲宽度 ROM_PWMPulseWidthSet(PWM_BASE, PWM_OUT_0, 4200); ROM_PWMPulseWidthSet(PWM_BASE, PWM_OUT_1, 1800); //使能PWM2和PWM3的输出 ROM_PWMOutputState(PWM_BASE, (PWM_OUT_0_BIT | PWM_OUT_1_BIT), true); //使能PWM发生器1 ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_0); while(1); { } }
peng xue 说:您好 谢谢您的回答。
我用的芯片是TM4C1924 用 ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_1); 这个函数没有用
不能给PWM 分�。
官网外设库手册貌似必须用 PWMClockSet()才对。---
大神求助。。研究研究啊 帮帮我 要交货。
//*****************************************************************************
//
//! Sets the PWM clock configuration.
//!
//! \param ui32Config is the configuration for the PWM clock; it must be one of
//! \b SYSCTL_PWMDIV_1, \b SYSCTL_PWMDIV_2, \b SYSCTL_PWMDIV_4,
//! \b SYSCTL_PWMDIV_8, \b SYSCTL_PWMDIV_16, \b SYSCTL_PWMDIV_32, or
//! \b SYSCTL_PWMDIV_64.
//!
//! This function configures the rate of the clock provided to the PWM module
//! as a ratio of the processor clock. This clock is used by the PWM module to
//! generate PWM signals; its rate forms the basis for all PWM signals.
//!
//! \note This function should only be used with TM4C123 devices. For
//! other TM4C devices, the PWMClockSet() function should be used.
//!
//! \note The clocking of the PWM is dependent on the system clock rate as
//! configured by SysCtlClockSet().
//!
//! \return None.
//
//*****************************************************************************
void
SysCtlPWMClockSet(uint32_t ui32Config)
{
//
// Check the arguments.
//
ASSERT((ui32Config == SYSCTL_PWMDIV_1) ||
(ui32Config == SYSCTL_PWMDIV_2) ||
(ui32Config == SYSCTL_PWMDIV_4) ||
(ui32Config == SYSCTL_PWMDIV_8) ||
(ui32Config == SYSCTL_PWMDIV_16) ||
(ui32Config == SYSCTL_PWMDIV_32) ||
(ui32Config == SYSCTL_PWMDIV_64));
//
// Check that there is a PWM block on this part.
//
ASSERT(HWREG(SYSCTL_DC1) & (SYSCTL_DC1_PWM0 | SYSCTL_DC1_PWM1));
//
// Set the PWM clock configuration into the run-mode clock configuration
// register.
//
HWREG(SYSCTL_RCC) = ((HWREG(SYSCTL_RCC) &
~(SYSCTL_RCC_USEPWMDIV | SYSCTL_RCC_PWMDIV_M)) |
ui32Config);
}
//*****************************************************************************
///
//! Sets the PWM clock configuration.
//!
//! \param ui32Base is the base address of the PWM module.
//! \param ui32Config is the configuration for the PWM clock; it must be one of
//! \b PWM_SYSCLK_DIV_1, \b PWM_SYSCLK_DIV_2, \b PWM_SYSCLK_DIV_4,
//! \b PWM_SYSCLK_DIV_8, \b PWM_SYSCLK_DIV_16, \b PWM_SYSCLK_DIV_32, or
//! \b PWM_SYSCLK_DIV_64.
//!
//! This function sets the PWM clock divider as the PWM clock source. It also
//! configures the clock frequency to the PWM module as a division of the
//! system clock. This clock is used by the PWM module to generate PWM
//! signals; its rate forms the basis for all PWM signals.
//!
//! \note This function should not be used with TM4C123 devices. For
//! TM4C123 devices, the SysCtlPWMClockGet() function should be used.
//!
//! \note The clocking of the PWM is dependent upon the system clock rate as
//! configured by SysCtlClockFreqSet().
//!
//! \return None.
//
//*****************************************************************************
void
PWMClockSet(uint32_t ui32Base, uint32_t ui32Config)
{
//
// Check the arguments.
//
ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
ASSERT((ui32Config == PWM_SYSCLK_DIV_2) ||
(ui32Config == PWM_SYSCLK_DIV_4) ||
(ui32Config == PWM_SYSCLK_DIV_8) ||
(ui32Config == PWM_SYSCLK_DIV_16) ||
(ui32Config == PWM_SYSCLK_DIV_32) ||
(ui32Config == PWM_SYSCLK_DIV_64));
//
// Set the PWM clock configuration into the PWM clock configuration
// register.
//
HWREG(ui32Base + PWM_O_CC) = ((HWREG(ui32Base + PWM_O_CC) &
~(PWM_CC_USEPWM | PWM_CC_PWMDIV_M)) |
ui32Config);
}
Maka 说:您好 谢谢您的回答。
我用的芯片是TM4C1924 用 ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_1); 这个函数没有用
�能给PWM 分�。
官网外设库手册貌似必须用 PWMClockSet()才对。---
大神求助。。研究研究啊 帮帮我 要交货。
//*****************************************************************************
//
//! Sets the PWM clock configuration.
//!
//! \param ui32Config is the configuration for the PWM clock; it must be one of
//! \b SYSCTL_PWMDIV_1, \b SYSCTL_PWMDIV_2, \b SYSCTL_PWMDIV_4,
//! \b SYSCTL_PWMDIV_8, \b SYSCTL_PWMDIV_16, \b SYSCTL_PWMDIV_32, or
//! \b SYSCTL_PWMDIV_64.
//!
//! This function configures the rate of the clock provided to the PWM module
//! as a ratio of the processor clock. This clock is used by the PWM module to
//! generate PWM signals; its rate forms the basis for all PWM signals.
//!
//! \note This function should only be used with TM4C123 devices. For
//! other TM4C devices, the PWMClockSet() function should be used.
//!
//! \note The clocking of the PWM is dependent on the system clock rate as
//! configured by SysCtlClockSet().
//!
//! \return None.
//
//*****************************************************************************
void
SysCtlPWMClockSet(uint32_t ui32Config)
{
//
// Check the arguments.
//
ASSERT((ui32Config == SYSCTL_PWMDIV_1) ||
(ui32Config == SYSCTL_PWMDIV_2) ||
(ui32Config == SYSCTL_PWMDIV_4) ||
(ui32Config == SYSCTL_PWMDIV_8) ||
(ui32Config == SYSCTL_PWMDIV_16) ||
(ui32Config == SYSCTL_PWMDIV_32) ||
(ui32Config == SYSCTL_PWMDIV_64));
//
// Check that there is a PWM block on this part.
//
ASSERT(HWREG(SYSCTL_DC1) & (SYSCTL_DC1_PWM0 | SYSCTL_DC1_PWM1));
//
// Set the PWM clock configuration into the run-mode clock configuration
// register.
//
HWREG(SYSCTL_RCC) = ((HWREG(SYSCTL_RCC) &
~(SYSCTL_RCC_USEPWMDIV | SYSCTL_RCC_PWMDIV_M)) |
ui32Config);
}
//*****************************************************************************
///
//! Sets the PWM clock configuration.
//!
//! \param ui32Base is the base address of the PWM module.
//! \param ui32Config is the configuration for the PWM clock; it must be one of
//! \b PWM_SYSCLK_DIV_1, \b PWM_SYSCLK_DIV_2, \b PWM_SYSCLK_DIV_4,
//! \b PWM_SYSCLK_DIV_8, \b PWM_SYSCLK_DIV_16, \b PWM_SYSCLK_DIV_32, or
//! \b PWM_SYSCLK_DIV_64.
//!
//! This function sets the PWM clock divider as the PWM clock source. It also
//! configures the clock frequency to the PWM module as a division of the
//! system clock. This clock is used by the PWM module to generate PWM
//! signals; its rate forms the basis for all PWM signals.
//!
//! \note This function should not be used with TM4C123 devices. For
//! TM4C123 devices, the SysCtlPWMClockGet() function should be used.
//!
//! \note The clocking of the PWM is dependent upon the system clock rate as
//! configured by SysCtlClockFreqSet().
//!
//! \return None.
//
//*****************************************************************************
void
PWMClockSet(uint32_t ui32Base, uint32_t ui32Config)
{
//
// Check the arguments.
//
ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
ASSERT((ui32Config == PWM_SYSCLK_DIV_2) ||
(ui32Config == PWM_SYSCLK_DIV_4) ||
(ui32Config == PWM_SYSCLK_DIV_8) ||
(ui32Config == PWM_SYSCLK_DIV_16) ||
(ui32Config == PWM_SYSCLK_DIV_32) ||
(ui32Config == PWM_SYSCLK_DIV_64));
//
// Set the PWM clock configuration into the PWM clock configuration
// register.
//
HWREG(ui32Base + PWM_O_CC) = ((HWREG(ui32Base + PWM_O_CC) &
~(PWM_CC_USEPWM | PWM_CC_PWMDIV_M)) |
ui32Config);
}
[/quote]
TM4C123X 和TM4C129X在配置PWM 时钟函数有不一样。
1294就用void PWMClockSet(uint32_t ui32Base, uint32_t ui32Config) 是对的。
peng xue 说:您好 谢谢您的回答。
我用的芯片是TM4C1924 用 ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_1); 这个函数没有用
不能给PWM 分频。
官网外设库手册貌似必须用 PWMClockSet()才对。---
大神求助。。研究研究啊 帮帮我 要交货。
TM4C1294用PWMClockSet(uint32_t ui32Base, uint32_t ui32Config) 是正确的,但是还是建议把代码上传上来分析。