当前位置:网站首页>I.MX6U-ALPHA开发板(EPIT定时器实验)
I.MX6U-ALPHA开发板(EPIT定时器实验)
2022-08-02 07:20:00 【*﹏ℳ๓无情*】
一、EPIT简介
1、EPIT是32位的一个向下计数器。
2、EPIT的时钟源可以选择,我们选择ipg_clk=66MHz。
3、可以对时钟源进行分频,12位的分频器,0~4095
分别代表1~4096分频。
4、开启定时器以后,计数寄存器会每个时钟减1,如果和比较寄存器里面的值相等的话就会触发中断。
EPIT有两种工作模式:
Set-add-forget,一个是free-runing
5、6ULL有两个EPIT定时器。
EPIT_CR寄存器用于配置EPIT。
二、实验原理简介
EPIT_CR bit0为1,设置EPIT使能,bit1为1,设置计数器的初始值为记载寄存器的值。Bit2为1使能比较中断,bit3为1设置定时器工作在set-and-forget模式下。Bit15~bit4设置分频值。Bit25:24设置时钟源的选择,我们设置为1,那么EPIT的时钟源就为ipg_clock=66MHz
EPIT_SR寄存器,只有bit0有效,表示中断状态,写1清零。当OCIF位为1的时候表示中断发生,为0的时候表示中断未发生。我们处理完定时器中断以后一定要清除中断标志位。
EPIT_LR寄存器设置计数器的加载值。计数器每次计时到0以后就会读取LR寄存器的值重新开始计时。
CMPR比较计数器,当计数器的值和CMPR相等以后就会产生比较中断。
使用EPIT实现500ms周期的定时器。我们在EPIT中断服务函数里面让LED灯亮灭。
// bsp_epittimer.h
#ifndef _BSP_EPITTIMER_H
#define _BSP_EPITTIMER_H
#include "imx6ul.h"
/* 函数声明 */
void epit1_init(unsigned int frac, unsigned int value);
void epit1_irqhandler(void);
#endif
//bsp_epittimer.c
#include "bsp_epittimer.h"
#include "bsp_int.h"
#include "bsp_led.h"
void epit1_init(unsigned int frac, unsigned int value)
{
if(frac > 0XFFF)
frac = 0XFFF;
EPIT1->CR = 0; /* 先清零CR寄存器 */
/* * CR寄存器: * bit25:24 01 时钟源选择Peripheral clock=66MHz * bit15:4 frac 分频值 * bit3: 1 当计数器到0的话从LR重新加载数值 * bit2: 1 比较中断使能 * bit1: 1 初始计数值来源于LR寄存器值 * bit0: 0 先关闭EPIT1 */
EPIT1->CR = (1<<24 | frac << 4 | 1<<3 | 1<<2 | 1<<1);
EPIT1->LR = value; /* 倒计数值 */
EPIT1->CMPR = 0; /* 比较寄存器,当计数器值和此寄存器值相等的话就会产生中断 */
/* 使能GIC中对应的中断 */
GIC_EnableIRQ(EPIT1_IRQn);
/* 注册中断服务函数 */
system_register_irqhandler(EPIT1_IRQn, (system_irq_handler_t)epit1_irqhandler, NULL);
EPIT1->CR |= 1<<0; /* 使能EPIT1 */
}
//EPIT中断处理函数
void epit1_irqhandler(void)
{
static unsigned char state = 0;
state = !state;
if(EPIT1->SR & (1<<0)) /* 判断比较事件发生 */
{
led_switch(LED0, state); /* 定时器周期到,反转LED */
}
EPIT1->SR |= 1<<0; /* 清除中断标志位 */
}
66MHZ=1s 66000000次
// mian.c
#include "bsp_clk.h"
#include "bsp_delay.h"
#include "bsp_led.h"
#include "bsp_beep.h"
#include "bsp_key.h"
#include "bsp_int.h"
#include "bsp_epittimer.h"
int main(void)
{
int_init(); /* 初始化中断(一定要最先调用!) */
imx6u_clkinit(); /* 初始化系统时钟 */
clk_enable(); /* 使能所有的时钟 */
led_init(); /* 初始化led */
beep_init(); /* 初始化beep */
key_init(); /* 初始化key */
epit1_init(0, 66000000/2); //初始化EPIT1定时器,1分频计数值为:66000000/2,也就是定时周期为500ms。
while(1)
{
delay(500);
}
return 0;
}
边栏推荐
- MySQL error 1055 solution: [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains
- Splunk Filed Alias 字段改名
- The best interests of buying and selling stocks with handling fees [What is missing in the definition of DP status?]
- MySQL-索引详解
- Compact格式下MySQL的数据如何存储到磁盘
- Thesis understanding: "Cross-Scale Residual Network: A GeneralFramework for Image Super-Resolution, Denoising, and "
- (2022 Niu Ke Duo School 5) B-Watches (two points)
- MySQL-执行流程+缓存+存储引擎
- 2022-2023 十大应用开发趋势
- flutter解决键盘和输入框不适配问题
猜你喜欢
随机推荐
Install Metasploitable2 on VMware
研发创新编码器霍尔板,引领企业高质量发展
机器学习笔记--数学库
typescript学习
regular expression
静态路由综合实验
MySQL-慢查询日志
Introduction to mysql operation (4) ----- data sorting (ascending, descending, multi-field sorting)
Azure Synapse Analytics上创建用户并赋予权限
Kind of weird!Access the destination URL, the host can container but not
postgres groupby 合并字符串
Thesis understanding: "Cross-Scale Residual Network: A GeneralFramework for Image Super-Resolution, Denoising, and "
View port number occupancy
Mysql error 2003 solution Can 't connect to Mysql server on' localhost '(10061).
Inverter insulation detection detection function and software implementation
HCIP 第十三天
Introduction to Totem Pole and Push-Pull Circuits
用户身份标识与账号体系实践
神经元网络
Inverter Phase Locking Principle and DSP Implementation