AM335x普通定时器配置PWM输出

更新时间:2023-11-19 08:30:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

1、AM335X 裸机下,配置TIMER4输出PWM,输出IO为GPIO_19,即XDMA_EVENT_INTR0,主要配置代码如下:

#include \ #include \ #include \ #include \ #include \ #include \ #include \ #include \ #include \ #include \

/******************************************************************************

** INTERNAL MACRO DEFINITIONS

*******************************************************************************/

#define DMTIMER_INSTANCE (SOC_DMTIMER_4_REGS) #define TIMER_INITIAL_COUNT (0xFFFFC000) #define TIMER_RLD_COUNT (0xFFFFC000) #define TIMER_DUTY_COUNT

int main(void) {

/*将A15(即XDMA_EVENT_INTR0)引脚配置成 MODE2,即为TIMER4的PWM输出模式*/ HWREG(SOC_CONTROL_REGS + CONTROL_CONF_XDMA_EVENT_INTR(0)) = ((0x00000020u) + CONTROL_CONF_MUXMODE(2));

/* This function will enable clocks for the DMTimer2 instance */ DMTimer4ModuleClkConfig();

/* Perform the necessary configurations for DMTimer */ DMTimerSetUp();

/* Start the DMTimer */

DMTimerEnable(DMTIMER_INSTANCE);

while(1); } /*

** Setup the timer for one-shot and compare mode.

(0xFFFFE000)

*/

static void DMTimerSetUp(void) {

/* Load the counter with the initial count value */ DMTimerCounterSet(DMTIMER_INSTANCE, TIMER_INITIAL_COUNT);

/* Load the load register with the reload count value */ DMTimerReloadSet(DMTIMER_INSTANCE, TIMER_RLD_COUNT);

/*Set the match register with the compare value */ DMTimerCompareSet(DMTIMER_INSTANCE, TIMER_DUTY_COUNT);

/* Configure the DMTimer for Auto-reload and compare mode */

DMTimerModeConfigure(DMTIMER_INSTANCE,0x000018C2);//DMTIMER_AUTORLD_NOCMP_ENABLE); }

在dmtimer.c中修改的地方

void DMTimerModeConfigure(unsigned int baseAdd, unsigned int timerMode) {

/* Wait for previous write to complete */

DMTimerWaitForWrite(DMTIMER_WRITE_POST_TCLR, baseAdd);

/* Clear the AR and CE field of TCLR */

HWREG(baseAdd + DMTIMER_TCLR) &= ~(DMTIMER_TCLR_AR | DMTIMER_TCLR_CE | DMTIMER_TCLR_TRG);// ~(DMTIMER_TCLR_AR | DMTIMER_TCLR_CE);

/* Wait for previous write to complete */

DMTimerWaitForWrite(DMTIMER_WRITE_POST_TCLR, baseAdd);

/* Set the timer mode in TCLR register */

HWREG(baseAdd + DMTIMER_TCLR) |= timerMode;//(timerMode & (DMTIMER_TCLR_AR |

// DMTIMER_TCLR_CE | // DMTIMER_TCLR_TRG)); }

2、需要注意的地方

XDMA_EVENT_INTR0在MODE2模式下为TIMER4的PWM输出,配置方式 HWREG(SOC_CONTROL_REGS + CONTROL_CONF_XDMA_EVENT_INTR(0)) = ((0x00000020u) + CONTROL_CONF_MUXMODE(2));

3、计数方式需要注意

#define TIMER_INITIAL_COUNT (0xFFFFC000) #define TIMER_RLD_COUNT (0xFFFFC000)

#define TIMER_DUTY_COUNT (0xFFFFE000)

计数从0xFFFFC000开始,当计数到0xFFFFE000时,产生边沿跳变,计数到0xFFFFFFFF时,重新装载计数初始值

本文来源:https://www.bwwdw.com/article/vixv.html

Top