Chinaunix首页 | 论坛 | 博客
  • 博客访问: 843363
  • 博文数量: 213
  • 博客积分: 5048
  • 博客等级: 大校
  • 技术积分: 1883
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-14 10:14
文章分类

全部博文(213)

文章存档

2011年(4)

2010年(55)

2009年(47)

2008年(107)

我的朋友

分类: 嵌入式

2010-04-18 23:30:19

msp430用一段时间,可是有些问题只有在测试中才会发现。
msp430 timer的datasheet中有下面这样一个note

Note: Modifying Timer_A Registers
It is recommended to stop the timer before modifying its operation (with
exception of the interrupt enable, interrupt flag, and TACLR) to avoid errant
operating conditions.
When the timer clock is asynchronous to the CPU clock, any read from TAR
should occur while the timer is not operating or the results may be
unpredictable. Alternatively, the timer may be read multiple times while
operating, and a majority vote taken in software to determine the correct
reading. Any write to TAR will take effect immediately.

注意全红的那句话,当timer的始终和cpu始终是异步的时候,timer工作状态下从tar中都timer计数值是不确定的。是的,是不确定,我遇到这样一个问题才注意这句话的。

我的系统16M,内部dco,我的timer始终32k晶振。这两者可以说异步的。
我原来的延迟程序这样做:
1,记录下开始时tar的值
2,不停读tar值,减去开始值再和delayclk数比较,确定是否延时完了

不停读tar,问题就在这,在这很有可能读出来的tar值是不正确的,导致延迟出错。

我是这样解决的:
1,开timer32k的中断,在中断中把一个全局变量myTAR自加,
2,原来延迟读的tar值,都改为读这个myTAR的值
这样就不会出现上面的问题了
阅读(1629) | 评论(0) | 转发(0) |
0

上一篇:buildroot

下一篇:wsn项目总结

给主人留下些什么吧!~~