简体   繁体   中英

Can you use FreeRTOS and the hardware watchdog timer at the same time on an Arduino?

I know that FreeRTOS uses the Arduino watchdog timer under the hood to operate. Can I set up my own watchdog reset timer without conflicting with FreeRTOS?

For example, in setup:

#include <avr/wdt.h>
wdt_enable(WDTO_2S);

And to feed:

wdt_reset();

The use of the watchdog timer is specific to the "official" Arduino port at http://www.arduinolibraries.info/libraries/free-rtos and not a feature of FreeRTOS specifically. The implementation is described in detail at https://feilipu.me/2015/11/24/arduino_freertos/ .

The watchdog timer is used as the system tick timer (because all other timers are configured for use by the Arduino framework). In that case you cannot use the watchdog timer for its normal purpose and will surely disturb the scheduler timing if you reset it asynchronously.

This use of the watchdog timer appears to be allow a single port to work an all AVR based Arduino hardware since it is the one timer source that is available on all Arduino devices and which the Arduino framework does not take control over. It is a sub-optimal solution since the on-chip 128KHz oscillator will not be particularly precise or temperature stable.

If you need the watchdog for its intended purpose, then the best solution is probably to modify the port to use an unused (by your application) standard timer. The use of the watchdog was to ensure portability of the port to all Arduinos and all applications regardless of their timer use; however you only need it to work on your hardware and your application, so adapting it to that is entirely legitimate.

An alternative is to abandon the Arduino framework and libraries altogether and just treat it as an unadorned Atmel AVR microcontroller. For example this non-Arduino FreeRTOS port uses Timer 1 on ATMega323, but provides information on changing that to suit other AVR devices.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM