Arduino函数中config printk timetime()怎么理解呢?

arduino基本函数_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
arduino基本函数
&&arduino基本函数
阅读已结束,下载文档到电脑
想免费下载更多文档?
定制HR最喜欢的简历
下载文档到电脑,方便使用
还剩16页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢【JoyTag Arduino 教程】如何使用Watchdog (看门狗) | 卓泰科技
› 【JoyTag Arduino 教程】如何使用Watchdog (看门狗)
【JoyTag Arduino 教程】如何使用Watchdog (看门狗)
*: WordPress代码高亮控件有BUG,明明是”,复制出来就变成“,导致示例程序无法在Arduino IDE里正常编译。
请到此处复制代码:/thread-30-1-1.html
何谓Watchdog?
ATmega48A/PA/88A/PA/168A/PA/328/P has an Enhanced Watchdog Timer (WDT). The WDT is a timer counting
cycles of a separate on-chip 128kHz oscillator. The WDT gives an interrupt or a system reset when the counter
reaches a given time-out value. In normal operation mode, it is required that the system uses the WDR – Watchdog
Timer Reset – instruction to restart the counter before the time-out value is reached. If the system doesn’t restart
the counter, an interrupt or system reset will be issued.
如何在Arduino中使用?
//example by Joytag
#include &avr/wdt.h&
void setup ()
wdt_enable (WDTO_1S);
} // end of setup
void loop ()
wdt_reset ();
} // end of loop
可以选择的定时时长:
(请参考avr/wdt.h获取更详细信息)
Threshold value
Constant name
Supported on
ATMega 8, 168, 328,
ATMega 8, 168, 328,
ATMega 8, 168, 328,
WDTO_120MS
ATMega 8, 168, 328,
WDTO_250MS
ATMega 8, 168, 328,
WDTO_500MS
ATMega 8, 168, 328,
ATMega 8, 168, 328,
ATMega 8, 168, 328,
ATMega 168, 328,
ATMega 168, 328,
目的:启用看门狗,不喂狗,观察Arduino重启
结论:通过串口监视器,我们会看到每五组数据后会输出一个”restart”,亦即看门狗起作用了。
//example by Joytag
#include &avr/wdt.h&
void setup() {
Serial.begin(9600);
wdt_enable(WDTO_4S);
Serial.println(“restart”);
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
delay(1000);
目的:启用看门狗,并喂狗,了解喂狗的作用
结论:我们在loop中不断的喂狗,狗吃饱了,所以Arduino不重启。通过串口监视器,我们看到Arduino持续输出数据。
//example by Joytag
#include &avr/wdt.h&
void setup() {
Serial.begin(9600);
wdt_enable(WDTO_4S);
Serial.println(“restart”);
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
delay(1000);
wdt_reset();
国外论坛上有不少关于Arduino使用看门狗的讨论,其实一个有意思的地方就是说wdt_enable是对寄存器进行操作,而掉电后寄存器的值依然保存。
假设这样一种情况:我们在一段arduino代码中启用了2秒的看门狗并下载执行。然后我们去下载并执行另外一个程序,这个新程序中没有使用看门狗,也没有喂狗,那么因为之前的寄存器配置依然存在,看门狗还是会起作用的,arduino会2秒重置一次。
实际情况是,因为我们平时使用arduino,是通过bootloader下载和启动的,而新版本的bootloader中已经对这个情况做了修复,查看bootloader的代码,我们会发现类似部分:
void appStart() {
watchdogConfig(WATCHDOG_OFF);
亦即在启动我们的程序之前,关掉watchdog.
(需要注意的是,可能部分版本的bootloader,没有对此问题进行修复)
感兴趣的朋友,可以使用ISP工具直接对arduino下载应用,来测试watchdog的这个特点。本人比较懒,就不测试了。
关于禁用watchdog
继续假设上一种情况,我们启用的看门狗,bootloader中又没禁用,在我们的新程序中,我们又不想使用看门狗,该如何操作。
为了这个问题,我走了一些弯路:
(1)查找芯片的技术手册,找到了一个函数来关掉看门狗:
void WDT_off(void)
__disable_interrupt();
__watchdog_reset();
/* Clear WDRF in MCUSR */
MCUSR &= ~(1&&WDRF);
/* Write logical one to WDCE and WDE */
/* Keep old prescaler setting to prevent unintentional time-out */
WDTCSR |= (1&&WDCE) | (1&&WDE);
/* Turn off WDT */
WDTCSR = 0x00;
__enable_interrupt();
(2)编译代码时,无法找到以下函数,
__disable_interrupt(); __watchdog_reset(); __enable_interrupt();
即便我包含了这个文件:#include &avr/interrupt.h&
为此我查找了avr-libc手册,分别使用cli();wdt_reset();sei();来替换对应的函数
(3)编译通过,测试也通过。使用WDT_off(),可以关闭watchdog功能。
按说这是一件令人高兴的事,可是吐血的是,我浏览avr/wdt.h的时候,发现这个函数:wdt_disable
(注:实际上是一个宏定义,为了方便,就都叫函数了)
In Interrupt mode, the WDT gives an interrupt when the timer expires. This interrupt can be used to wake the
device from sleep-modes, and also as a general system timer. One example is to limit the maximum time allowed
for certain operations, giving an interrupt when the operation has run longer than expected. In System Reset mode,
the WDT gives a reset when the timer expires. This is typically used to prevent system hang-up in case of runaway
code. The third mode, Interrupt and System Reset mode, combines the other two modes by first giving an interrupt
and then switch to System Reset mode. This mode will for instance allow a safe shutdown by saving critical parameters
before a system reset.
(问题:Arduino中如何使用Interrupt mode?)
The Watchdog always on (WDTON) fuse, if programmed, will force the Watchdog Timer to System Reset mode.
With the fuse programmed the System Reset mode bit (WDE) and Interrupt mode bit (WDIE) are locked to 1 and 0
respectively.
If the Watchdog is accidentally enabled, for example by a runaway pointer or brown-out condition, the device
will be reset and the Watchdog Timer will stay enabled. If the code is not set up to handle the Watchdog, this might
lead to an eternal loop of time-out resets. To avoid this situation, the application software should always clear the
Watchdog System Reset Flag (WDRF) and the WDE control bit in the initialization routine, even if the Watchdog is
not in use.
文成仓促,错漏难免,欢迎各位行家批评指导。
转载请注明出处。
Recent Posts
Categories
d’d’d
powered byArduino 语法手册函数部分_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
Arduino 语法手册函数部分
阅读已结束,下载文档到电脑
想免费下载本文?
定制HR最喜欢的简历
下载文档到电脑,方便使用
还剩33页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢Arduino 语言常用语句_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
Arduino 语言常用语句
阅读已结束,下载文档到电脑
想免费下载本文?
定制HR最喜欢的简历
下载文档到电脑,方便使用
还剩10页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢arduino时间计算方法?_百度知道
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。
arduino时间计算方法?
int Atime = 0;
int Btime = 0;
void setup()
void loop(){
/**********事件一处理************
************************************/
if(Atime & 10)
/**********事件二处理************
这个方法参考下:uns
unvoid loop(){
starttime = millis();//你的代码stoptime = millis();looptime = stoptime -}
采纳率:77%
来自团队:
用到了Arduino 中的 millis()函数,这是个不断更新时间值的函数。分别取不同的记录点,就可以得出不同记录点间的时间差。很方便。但这个函数根本停不下来,哈哈.com/link?url=oqNMcbYjPHTjUKEbozEIvpUCVrYMtNluk-WOStHkSb_ZnBzFJ7N0kTqEagXY5oQbUYZ3lCF9AtT23M42qFuEXq" target="_blank">http.baidu?url=oqNMcbYjPHTjUKEbozEIvpUCVrYMtNluk-WOStHkSb_ZnBzFJ7N0kTqEagXY5oQbUYZ3lCF9AtT23M42qFuEXq去看看这个:///link<a href="http://zhidao
如果我要显示五个数{10,2, 3,4,5},并且每三秒显示一个数字,如何做到呢?
那就delay(3000)吧,呵呵
本回答被提问者和网友采纳
可以修改这个数字,这个的时间值只是一个近视值,不包括你的程序执行时间,程序如果不是很复杂,基本或略其它时间; 10) 中的10就是时间,= 程序每10Ms 执行一次,1秒钟=1000MS/秒(执行次数)如果你想要执行是次数快点或者慢点;10ms=100次&#47if(Atime &gt
程序每10Ms执行一次,是与下面的delay(1)有关么,如果delay(10),时间会变么?
当然了。如果是delay(1),上面就设定10,delay(10)上面就设定1,还是10ms一次
为您推荐:
其他类似问题
arduino的相关知识
&#xe675;换一换
回答问题,赢新手礼包&#xe6b9;

我要回帖

更多关于 tp5 的config函数 的文章

 

随机推荐