AVR Library

I am having difficulty using the watchdog timer (WDT) function. Not specifically with the WDT, I understand how the hardware works, how to use it, and all that. The trouble I am having is understanding the relatively huge AVR library of which wdt.h (and I cannot find wdt.cpp) are a tiny fraction of....

I have read everything I can find (to avoid embarrassing myself with a dopey post and wasting your time).

I have imported multiple libraries into the Libraries Directory and successfully used them, including DX1307RTC, Onewire, etc. They all work great, no issues.

In each of the library directories I have added, I have the requisite .cpp source and .h header file, as well as the examples directory.

I don't understand how to so the same using the huge avr-libc-1.8.0 that I downloaded.

First, there is a ton of stuff in there...and second, I am not sure what the heck I need since the pile of stuff is so huge.

Did I grab the wrong stuff?

I am sure I am missing something - but I need some basic tutorial on how to sort through all this and pick the right stuff....

I have read the Reference material - and I see how to add libraries, as I have stated I do this routinely. But when I go get Onewire or DS1307 or whatever I pick up a relatively small structure that contains the bits that make sense. Doing this with AVR is 18 megabytes of "bits"...

Can anyone help me? I would appreciate it of you have the time.

Thank you,

Mike

Well if you don't mind asking a dumb question then I don't mind either.
Why are you downloading the AVR library. I have been running every kind of arduino program for over six months and have never had to do that. What is the point of that ?

http://www.nongnu.org/avr-libc/user-manual/group__avr__watchdog.html

http://tushev.org/articles/arduino/item/46-arduino-and-watchdog-timer

Avrlibc is already part of the Arduino IDE. You won't find any source files because the library is precompiled. However, the header (.h) files are with the IDE and the wdt stuff is all done with inline macros defined in the header file. And you can have a look at that.

Thank you both.

Not needing it is a big clue - thanks. So when programs have a

#include <avr/wdt.h>

the assumption is in this case that the library is there by default.

The IDE doesn’t look like it recognizes it. For example if I look at a sketch that I used for a temperature controller I have

#include <OneWire.h>

The Orange seeming to indicate it recognizes the stuff I put in the Library. When I include the avr/wdt.h function, I get nothing (all black) which seems to me to indicate it doesn’t “see” the stuff to include. Am I wrong about this? Indeed when I compile I get

sketch_may30ax3000_Working_up.ino:1:9: error: #include expects “FILENAME” or

So I thought perhaps I cobbled up the directory location of the original download of the Arduino IDE?

Would it be correct to locate the avr/wdt.h and plop the entire path name into the include statement then? Or are there assumptions I am making that are incorrect?

When I include include the wdt.h file -

and then enable the timer with

wdt_enable(WDTO_8s);

compiler comes back with an error

sketch…: error: expected constructor, destructor, or type conversion before ‘(’ token

indicating to me that it doesn’t have the avr/wdt.h which of course the error told me above, but just saying…

??

Mike

The highlighting of words is not very important. They get highlighted because they are in some keyword file somewhere.

Anyway, that is the text editor program which recognises those words and colours them in for you, not the compiler.

As far as compilation is concerned, it matters what the compiler recognises, not the text editor.

If the compiler can find that avr header file, that's what it needs. It doesn't need to compile the code, the code is already compiled somewhere already. The necessary parts of the library ( which is already compiled ), is added to the compiled version of your program and any of your own libraries, to create the executable file ( or more specifically, the image of the executable file in the format for downloading to your actual arduino board ).

mikeworkman:
Thank you both.

Not needing it is a big clue - thanks. So when programs have a

#include <avr/wdt.h>

the assumption is in this case that the library is there by default.

The IDE doesn’t look like it recognizes it. For example if I look at a sketch that I used for a temperature controller I have

The IDE text editor doesn’t recognize it as an Arduino library that specified color highlighting.
Which is correct since it isn’t part of the Arduino s/w.
avr/wdt.h is part of the avr-gcc s/w and is specific to the AVR chips.
(see more details below)

#include <OneWire.h>

The Orange seeming to indicate it recognizes the stuff I put in the Library. When I include the avr/wdt.h function, I get nothing (all black) which seems to me to indicate it doesn’t “see” the stuff to include. Am I wrong about this? Indeed when I compile I get

That highlighting is an Arduino IDE thing.
The IDE looks for header files under all the Arduino libraries directories
in the system libraries directory and then under you sketchbook/libraries directory.
When it it finds a header file, in one of those directories, it then does some special things.
One of the things it does is then look for a file called keywords.txt
This controls which strings in your sketch files are highlighted when
displayed in the IDE.

avr/wdt.h is not part of the Arduino system. It is part of the avr-gcc package
(which is bundled with the Arduino IDE)

sketch_may30ax3000_Working_up.ino:1:9: error: #include expects “FILENAME” or

So I thought perhaps I cobbled up the directory location of the original download of the Arduino IDE?

Would it be correct to locate the avr/wdt.h and plop the entire path name into the include statement then? Or are there assumptions I am making that are incorrect?
They are incorrect.

When I include include the wdt.h file -

and then enable the timer with

wdt_enable(WDTO_8s);

compiler comes back with an error

sketch…: error: expected constructor, destructor, or type conversion before ‘(’ token

indicating to me that it doesn’t have the avr/wdt.h which of course the error told me above, but just saying…

??

Mike

Something very odd is happening.

Are you calling

wdt_enable(WDTO_8s);

inside your setup() function?

You should turn on verbose output mode so you can really see what is really happening.
Some versions of the gcc compiler do not consider a missing header file as an error
and simply emit a warning.
Unfortunately, the Arduino team believes that warnings are bad, so by default
the IDE hides all warnings.
If you turn on verbose mode in the IDE, you will see all the warnings.
[file]->[Preferences]

Other than that, I’d suggest that you
post a small full sketch that can demonstrate the problem
so we can replicate what you are seeing.

— bill

mikeworkman:
wdt_enable(WDTO_8s);

Big S…
wdt_enable(WDTO_8S);

compiler comes back with an error
sketch…: error: expected constructor, destructor, or type conversion before ‘(’ token
indicating to me that it doesn’t have the avr/wdt.h which of course the error told me above, but just saying…

Wrong. This is the error produced if the IDE cannot locate wdt.h…

sketch_may19a:5: error: 'WDTO_8s' was not declared in this scope
sketch_may19a:5: error: 'wdt_enable' was not declared in this scope

Which means YOU NEED TO POST YOUR ENTIRE SKETCH if you want any more help.

Thank you all for the help. Attached is an example sketch, and here it is in-line. If I comment out the WDT bits, the sketch works fine. It will not compile do to errors around the wdt_enable and wdt_Rest() functions. It seems to not be properly picking up the avr.h from the include, and thus every function or constant defined by it are “not declared in this scope”. My guess is the installation of aruido ide I did is balled up - that somehow the directory structure it assumes doesn’t match what I have? Is that possibly it?

The output of verify (verbose=true) is:
sketch_wdt_example.ino:1:10: error: #include expects “FILENAME” or
sketch_wdt_example.ino: In function ‘void setup()’:
sketch_wdt_example:23: error: ‘WDTO_8S’ was not declared in this scope
sketch_wdt_example:23: error: ‘WDT_enable’ was not declared in this scope
sketch_wdt_example.ino: In function ‘void loop()’:
sketch_wdt_example:44: error: ‘wdt_reset’ was not declared in this scope

#include (avr/wdt.h)
// Test program for the WDT on an UNO
// Ramps up an LED, then down in sawtooth fashon in 102 steps. Delay between
// steps can be chosen to let the cycles proceed, or if 102 x delay exceeds
// WDT the timer should restart the MPU.
// Uncomment the lines for wdt_enable(WDTO_8), wdt_reset() to try WDT, leave
// comments in to test sketch works fine without the WDT enabled.

/*
Fading modified to ramp up an LED over time, which will be interrupted eventually
by WDT resetting the machine and starting over, ML Workman 5/2014

The circuit:

  • LED attached from digital pin 9 to ground.

Adapted from David A. Mellis Fading (modified 30 Aug 2011 By Tom Igoe)

*/

int ledPin = 9; // LED connected to digital pin 9
int delay_between_steps = 100; // Adjust this to fit or exceed WDT delay (8s)
void setup() {
WDT_enable(WDTO_8S); // Enable WDT when un-commented
Serial.begin(9600); // open the serial port at 9600 bps
Serial.print("…starting up"); //
}

void loop() {
// fade in from min to max in increments of 5 points:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 100 milliseconds to see the dimming effect
delay(100);
}

// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 100 milliseconds to see the dimming effect
delay(100);
}
wdt_reset(); // Uncommented, this should reset the WDT. Since the timer is 8 seconds
// and the previous loops take about 10, this should cause us to restart
// of the fade up and fade down of the LED.
}

sketch_wdt_example.ino (1.88 KB)

Oops - I meant to make the delay in the loops a variable but they are both set to 100mS per step…these could obviously changed so the the entire fade-up/down cycle would fit in the 8 second timer for the Watchdog, and then get reset appropriately. Regardless, the problem isn’t with the functionality of the WDT - it seems to be with the environment I am running the IDE in (at least to me, but if I knew how to fix it I wouldn’t be bothering you guys for help…).

click the MODIFY button in the upper right of the post window.
Highlight all you code.
click the "#" CODE TAGS button on the toolbar above just to the left of the QUOTE button.
click SAVE (at the bottom).
When you post code on the forum, please make a habit of using the code tags "#" button.

#include (avr/wdt.h)

…versus…

#include <avr/wdt.h>