Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
逆着光、寻觅
rt-thread
提交
efc1b058
R
rt-thread
项目概览
逆着光、寻觅
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
efc1b058
编写于
9月 07, 2015
作者:
H
heyuanjie87
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加说明文档
上级
f8012b90
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
101 addition
and
0 deletion
+101
-0
components/drivers/hwtimer/README_CN.md
components/drivers/hwtimer/README_CN.md
+101
-0
未找到文件。
components/drivers/hwtimer/README_CN.md
0 → 100644
浏览文件 @
efc1b058
定时器设备
===
##功能
---
*
时间测量
*
周期或单次执行回调函数
##编译
---
1.
在rtconfig.h添加
`#define RT_USING_HWTIMER`
##使用流程
---
1.
以读写方式打开设备
2.
设置超时回调函数(如果需要)
3.
根据需要设置定时模式(单次/周期)
4.
设置计数频率(可选)
5.
写入超时值,定时器随即启动
6.
停止定时器(可选)
7.
关闭设备(如果需要)
应用参考 [hwtimer_test] (/examples/test/hwtimer
\_
test.c)
##驱动编写指南
---
###操作接口
```
struct rt_hwtimer_ops
{
void (*init)(struct rt_hwtimer_device *timer, rt_uint32_t state);
rt_err_t (*start)(struct rt_hwtimer_device *timer, rt_uint32_t cnt, rt_hwtimer_mode_t mode);
void (*stop)(struct rt_hwtimer_device *timer);
rt_uint32_t (*count_get)(struct rt_hwtimer_device *timer);
rt_err_t (*control)(struct rt_hwtimer_device *timer, rt_uint32_t cmd, void *args);
};
```
*
init - state
<
1
打开设备
0
关闭设备
>
*
start - cnt
<超时值>
- mode
<单次
/
周期
>
*
stop -
<停止计数>
*
count_get -
<读取计数器值>
*
control -
<设置计数频率
>
###定时器特征信息
```
struct rt_hwtimer_info
{
rt_int32_t maxfreq;
rt_int32_t minfreq;
rt_uint32_t maxcnt;
rt_uint8_t cntmode;
};
```
*
maxfreq
<设备支持的最大计数频率>
*
minfreq
<设备支持的最小计数频率>
*
maxcnt
<计数器最大计数值>
*
cntmode
<递增计数
/
递减计数
>
###注册设备
```
static rt_hwtimer_t _timer0;
int stm32_hwtimer_init(void)
{
_timer0.info = &_info;
_timer0.ops = &_ops;
rt_device_hwtimer_register(&_timer0, "timer0", TIM2);
return 0;
}
```
###定时器中断
```
void timer_irq_handler(void)
{
//其它操作
rt_device_hwtimer_isr(&_timer0);
}
```
##注意事项
---
<font
color=
"#FF0000"
>
可能出现定时误差
</font>
误差原因:
假设计数器最大值0xFFFF,计数频率1Mhz,定时时间1秒又1微秒。
由于定时器一次最多只能计时到65535us,对于1000001us的定时要求
就需分15次完成。误差时间: 1000001 - (65535
*
15) = 16976us。
这个误差太大,为了减小误差最理想的情况就是整除。实际中不可能
所有数都被整除(1不合适),所以就只有最大限度逼近理想情况。例如
上式中以 50000us定时20次即可将误差减小到1us(理论值,忽略指令时间)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录