当前位置:网站首页>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;
}
边栏推荐
- Introduction to Totem Pole and Push-Pull Circuits
- MySQL error 1055 solution: [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains
- Comprehensive experiment of MPLS and BGP
- 类型“DropDownList”的控件“ContentPlaceHolder1_ddlDepartment”必须放在具有 runat=server 的窗体标记内。
- 2022-2023 十大应用开发趋势
- Hack The Box - File Transfers Module详细讲解中文教程
- spark架构
- 有点奇怪!访问目的网址,主机能容器却不行
- MySQL-Multiversion Concurrency Control
- CollectionUtil: a collection of functional style tool
猜你喜欢
PLSQL Developer安装和配置
Enterprise training and reproduction guidebook - training and reasoning of the OpenPose model based on Huawei ModelArts platform, realizing the recognition of two behaviors of climbing and climbing ov
flutter 自己写一个组件
HCIP 第八天
mysql操作入门(四)-----数据排序(升序、降序、多字段排序)
Xilinx Constraint Study Notes - Timing Constraints
Conditional constructor ~wapper
Understand Chisel language. 31. Chisel advanced communication state machine (3) - Ready-Valid interface: definition, timing and implementation in Chisel
概率论与数理统计
Compact格式下MySQL的数据如何存储到磁盘
随机推荐
HCIP 第四天
MySQL报错1055解决办法:[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains
HCIP 第十二天
概率论与数理统计
PanGu-Coder:函数级的代码生成模型
Debian 10 dhcp relay (dhcp 中继) dhcp 固定分配
Splunk Field Caculated 计算字段
我与csdn
Compact格式下MySQL的数据如何存储到磁盘
FormData上传二进制文件、对象、对象数组
Data Middle Office: Started in Ali, Prosperous in DaaS
Agile, DevOps and Embedded Systems Testing
LeetCode 2312. 卖木头块
Neural network
(2022 Niu Ke Duo School 5) D-Birds in the tree (tree DP)
Link with Game Glitch
HCIP第三天
LeetCode 283. Shifting Zeros (Simple, Array)
pnpm install出现:ERR_PNPM_PEER_DEP_ISSUES Unmet peer dependencies
OC-error prompt