AM335x普通定时器配置PWM输出
更新时间:2023-11-19 08:30:01 阅读量: 教育文库 文档下载
- AM335X核心板推荐度:
- 相关推荐
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时,重新装载计数初始值
正在阅读:
AM335x普通定时器配置PWM输出11-19
徒步穿越丛林探险实用指南05-18
2011年影响中医药特色优势发挥和提高中医临床疗效的关键问题调研分析09-06
县卫生局长在县中医院第八次职代会上的讲话10-09
解析美国SAT改革对留学生的影响04-21
高考英语词组搭配分类记忆大全06-20
甲虫介绍02-03
- exercise2
- 铅锌矿详查地质设计 - 图文
- 厨余垃圾、餐厨垃圾堆肥系统设计方案
- 陈明珠开题报告
- 化工原理精选例题
- 政府形象宣传册营销案例
- 小学一至三年级语文阅读专项练习题
- 2014.民诉 期末考试 复习题
- 巅峰智业 - 做好顶层设计对建设城市的重要意义
- (三起)冀教版三年级英语上册Unit4 Lesson24练习题及答案
- 2017年实心轮胎现状及发展趋势分析(目录)
- 基于GIS的农用地定级技术研究定稿
- 2017-2022年中国医疗保健市场调查与市场前景预测报告(目录) - 图文
- 作业
- OFDM技术仿真(MATLAB代码) - 图文
- Android工程师笔试题及答案
- 生命密码联合密码
- 空间地上权若干法律问题探究
- 江苏学业水平测试《机械基础》模拟试题
- 选课走班实施方案
- 定时器
- 输出
- 配置
- 普通
- AM335x
- PWM