Arduino ATTINY 85-首次重置后睡眠看门狗时间发生变化
我正在我的阁楼上写一个简单的程序。该程序应该在芯片处于唤醒状态时点亮LED引脚,并在芯片处于休眠状态时将其关闭。 然而,当我将看门狗定时器设置为在0.5秒后重置时,它会在第一次重置时重置,然后在大约100毫秒后重置。 我用示波器检查过,prinstcreen在这个链接下: 代码如下:Arduino ATTINY 85-首次重置后睡眠看门狗时间发生变化,arduino,sleep,watchdog,attiny,Arduino,Sleep,Watchdog,Attiny,我正在我的阁楼上写一个简单的程序。该程序应该在芯片处于唤醒状态时点亮LED引脚,并在芯片处于休眠状态时将其关闭。 然而,当我将看门狗定时器设置为在0.5秒后重置时,它会在第一次重置时重置,然后在大约100毫秒后重置。 我用示波器检查过,prinstcreen在这个链接下: 代码如下: /* * Sketch for testing sleep mode with wake up on WDT. * Donal Morrissey - 2011. * ATTINY85 */ #incl
/*
* Sketch for testing sleep mode with wake up on WDT.
* Donal Morrissey - 2011.
* ATTINY85
*/
#include <TinyWireM.h> // I2C Master lib for ATTinys which use USI - comment this out to use with standard arduinos
#include <LiquidCrystal_attiny.h> // for LCD w/ GPIO MODIFIED for the ATtiny85
#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>
//uwaga na numer pinu! nie używać tego z resetem
#define OUT_PIN 3
#define GPIO_ADDR 0x27
LiquidCrystal_I2C lcd(GPIO_ADDR, 16, 2); // set address & 16 chars / 2 lines
volatile int f_wdt=1;
/***************************************************
* Name: ISR(WDT_vect)
*
* Returns: Nothing.
*
* Parameters: None.
*
* Description: Watchdog Interrupt Service. This
* is executed when watchdog timed out.
*
***************************************************/
ISR(WDT_vect){
if(f_wdt == 0){
f_wdt=1;
}
else{
// lcd.clear();
// lcd.print("WDT overrun");
// delay(500);
}
}
/***************************************************
* Name: enterSleep
*
* Returns: Nothing.
*
* Parameters: None.
*
* Description: Enters the arduino into sleep mode.
*
***************************************************/
void enterSleep(void)
{
// lcd.clear();
// lcd.print("Asleep...");
set_sleep_mode( SLEEP_MODE_PWR_DOWN ); /* EDIT: could also use SLEEP_MODE_PWR_DOWN for lowest power consumption. */
sleep_enable();
/* Now enter sleep mode. */
sleep_mode();
/* The program will continue from here after the WDT timeout*/
sleep_disable(); /* First thing to do is disable sleep. */
/* Re-enable the peripherals. */
power_all_enable();
}
/***************************************************
* Name: setup
*
* Returns: Nothing.
*
* Parameters: None.
*
* Description: Setup for the serial comms and the
* Watch dog timeout.
*
***************************************************/
void setup()
{
/* Setup the LCD */
lcd.init(); // initialize the lcd
lcd.backlight(); // Print a message to the LCD.
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Initializing...");
delay(500);
/*** Setup the WDT ***/
/* Clear the reset flag of watchdog interrupts, so that they are available again. */
MCUSR &= ~(1<<WDRF);
/* Enable configuration changes
*/
WDTCR |= (1<<WDCE) | (1<<WDE);
/*
WDP3 WDP2 WDP1 WDP0 Number of WDT Typical Time-out at
Oscillator Cycles VCC = 5.0V
0 0 0 0 2K (2048) cycles 16 ms
0 0 0 1 4K (4096) cycles 32 ms
0 0 1 0 8K (8192) cycles 64 ms
0 0 1 1 16K (16384) cycles 0.125 s
0 1 0 0 32K (32768) cycles 0.25 s
0 1 0 1 64K (65536) cycles 0.5 s
0 1 1 0 128K (131072) cycles 1.0 s
0 1 1 1 256K (262144) cycles 2.0 s
1 0 0 0 512K (524288) cycles 4.0 s
1 0 0 1 1024K (1048576) cycles 8.0 s
*/
/* set new watchdog timeout prescaler value */
WDTCR = 0<<WDP3 | 1<<WDP2 | 0<<WDP1 | 1<<WDP0 ;
/* Enable the WD interrupt (note no reset). */
WDTCR |= (1<<WDIE);
lcd.clear();
lcd.print("Initialisation complete.");
delay(100);
}
/***************************************************
* Name: enterSleep
*
* Returns: Nothing.
*
* Parameters: None.
*
* Description: Main application loop.
*
***************************************************/
void loop()
{
if(f_wdt == 1)
{
// lcd.clear();
// lcd.print("Awake!");
digitalWrite( OUT_PIN, HIGH );
delay(1000);
/* Don't forget to clear the flag. */
f_wdt = 0;
digitalWrite( OUT_PIN, LOW );
/* Re-enter sleep mode. */
enterSleep();
}
else
{
/* Do nothing. */
}
}
/*
*WDT上带唤醒的睡眠模式测试示意图。
*多纳尔·莫里西-2011。
*阁楼85
*/
#包括//用于使用USI的ATTinys的I2C主库-将其注释为与标准arduinos一起使用
#包括//用于修改了ATtiny85的GPIO的LCD
#包括
#包括
#包括
#包括
//uwaga na numer pinu!nie używaćtego z resetem
#定义输出引脚3
#定义GPIO_地址0x27
液晶I2C液晶显示器(GPIO地址,16,2);//设置地址和16个字符/2行
volatile int f_wdt=1;
/***************************************************
*名称:印度标准行业协会(WDT_vect)
*
*返回:没有。
*
*参数:无。
*
*描述:看门狗中断服务。这
*在看门狗超时时执行。
*
***************************************************/
行业特殊风险(WDT_vect){
如果(f_wdt==0){
f_wdt=1;
}
否则{
//lcd.clear();
//lcd.打印(“WDT超限”);
//延迟(500);
}
}
/***************************************************
*姓名:enterSleep
*
*返回:没有。
*
*参数:无。
*
*描述:进入arduino睡眠模式。
*
***************************************************/
无效进入睡眠(无效)
{
//lcd.clear();
//lcd.打印(“睡眠…”);
设置睡眠模式(睡眠模式下);/*编辑:也可以使用睡眠模式下以获得最低功耗*/
sleep_enable();
/*现在进入睡眠模式*/
睡眠模式();
/*WDT超时后,程序将从此处继续*/
sleep_disable();/*首先要做的是禁用睡眠*/
/*重新启用外围设备*/
电源全部启用();
}
/***************************************************
*名称:安装程序
*
*返回:没有。
*
*参数:无。
*
*说明:设置串行通信和
*看门狗超时。
*
***************************************************/
无效设置()
{
/*设置LCD*/
lcd.init();//初始化lcd
lcd.backlight();//将消息打印到lcd。
lcd.clear();
lcd.setCursor(0,0);
打印(“初始化…”);
延迟(500);
/***设置WDT***/
/*清除看门狗中断的重置标志,使其再次可用*/
MCUSR&=~(1)如果你自己找到了答案,那么帖子就是一个答案。不要把它放在问题中。为什么不简单地感谢有人发布了解决方案而不是走开呢?你想让他也把他的问题标记为答案吗(怀疑它是否有效)…有些人…tsssss如果你自己找到了答案,post就是一个答案。不要把它放在问题中。为什么不简单地感谢有人发布了解决方案而不是离开呢?你想让他把他的问题也标记为答案(怀疑它是否有效)…有些人…tsssss
void enterSleep(void)
{
lcd.clear();
lcd.print("Asleep...");
/* Enable the WD interrupt (note no reset). */
WDTCR |= (1<<WDIE);
set_sleep_mode( SLEEP_MODE_PWR_DOWN ); /* EDIT: could also use SLEEP_MODE_PWR_DOWN for lowest power consumption. */
sleep_enable();
/* Now enter sleep mode. */
sleep_mode();
/* The program will continue from here after the WDT timeout*/
sleep_disable(); /* First thing to do is disable sleep. */
/* Re-enable the peripherals. */
power_all_enable();
/* Disable the WD interrupt */
WDTCR &= ~_BV(WDIE);
}
WDTCR |= (1<<WDIE);