织梦CMS - 轻松建站从此开始!

欧博ABG官网-欧博官方网址-会员登入

Uno R4 Wifi WDG游戏atchdog Timer

时间:2025-09-17 00:21来源: 作者:admin 点击: 0 次
Hey, i want to use the Watchdog Timer on my new Uno R4 Wifi. I've tried using the avr/wdt.h libary, but i got an error "No such file

I used this article to create a timer that runs once a second:
https://www.pschatzmann.ch/home/2023/07/01/under-the-hood-arduino-uno-r4-timers/

This timer even runs when Arduino is busy doing cloud stuff. So inside this timer I kick the watchdog to keep it alive.
Inside my main loop I set a counter to millis() so I can check inside the timer how long it's been since the main loop ran.

#include "FspTimer.h" #include "WDT.h" FspTimer background_timer; unsigned long TimeoutCounter = 0; void setup() { if (WDT.begin(5000)) { WDT.refresh(); } else { Serial.println("Error initializing watchdog"); } beginTimer(1); } void loop() { TimeoutCounter = millis(); // Kick the timeout counter to avoid reset. } void timer_callback(timer_callback_args_t __attribute((unused)) *p_args) { WDT.refresh(); if (millis() > (TimeoutCounter + (1000 * 60 * 5))) NVIC_SystemReset(); // More than 5 minutes unresponsive } bool beginTimer(float rate) { uint8_t timer_type = GPT_TIMER; int8_t tindex = FspTimer::get_available_timer(timer_type); if (tindex < 0) { tindex = FspTimer::get_available_timer(timer_type, true); } if (tindex < 0) { return false; } FspTimer::force_use_of_pwm_reserved_timer(); if (!background_timer.begin(TIMER_MODE_PERIODIC, timer_type, tindex, rate, 0.0f, timer_callback)) { return false; } if (!background_timer.setup_overflow_irq()) { return false; } if (!background_timer.open()) { return false; } if (!background_timer.start()) { return false; } return true; }

(责任编辑:)
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:
发布者资料
查看详细资料 发送留言 加为好友 用户等级: 注册时间:2025-09-17 22:09 最后登录:2025-09-17 22:09
栏目列表
推荐内容