Page 1 of 1

RESET

Posted: Tue Jan 22, 2008 7:58 pm
by ALAN_26
IS THERE A WAY TO RESET AN AVR ( ATMEGA8 ) PROGRAMMATICALY WITH A COSTOM C ? AND IF YES HOW CAN I DO IT ?

Re: RESET

Posted: Wed Jan 23, 2008 10:59 am
by Sean
Hello Alan.

There seem to be two ways to reset an ATMEGA8 from within a program.

1. Connect an unused output to the /RESET input and control it from the program.

2. Allow the watchdog to time-out.
If the watchdog is not being used during normal program execution it can be turned on when a reset is required, and the main program can execute a loop until the reset is forced. This will take a minimum of 15ms.

The following C code should enable the watchdog function. Note: the watchdog enable fuse should be left un-programmed in this case (default condition) to prevent the watchdog from being enabled permanently.

wdt_enable(WDT0_15MS);

If the watchdog is being used, the reset can be forced by failing to execute the wdt_reset() instruction within the time-out period.

If you want to look at the WinAVR watchdog commands they are defined in the wdt.h file in the Tools\avr\include\avr\ folder of the Flowcode installation.

Re: RESET

Posted: Wed Jan 23, 2008 5:09 pm
by ALAN_26
hello sean

thanks very much for your help i will try it tomorrow

Thank again
Regars Alan

Re: RESET

Posted: Thu Jan 24, 2008 10:51 am
by Sean
One additional requirement for the reset functions to work; the wdt.h file must be included in the compilation.

Add the following code to the 'Definitions and function declarations' panel in the 'Edit->Supplementary Code...' menu:

#include <avr\wdt.h>

Re: RESET

Posted: Thu Jan 24, 2008 7:11 pm
by ALAN_26
hello sean

there seem to be some kind of problem it's not compiling to hex

ile name: C:\Documents and Settings\ALAN\Desktop\test\test.c
Generated by: Flowcode v3.3.4.44
Date: Thursday, January 24, 2008 19:10:35
Licence: Professional
Registered to: Alan Cilia


http://www.matrixmultimedia.com



Launching the compiler...

C:\Program Files\Matrix Multimedia\Flowcode_AVR\Tools\MX_bats\avra.bat atmega8 "C:\DOCUME~1\ALAN\Desktop\test\test.elf" "C:\DOCUME~1\ALAN\Desktop\test\test.c" "C:\DOCUME~1\ALAN\Desktop\test\test.lst"


C:\Documents and Settings\ALAN\Desktop\test>"C:\PROGRA~1\MATRIX~1\FLOWCO~2\Tools\MX_bats\..\bin\avr-gcc.exe" -mmcu=atmega8 -Os -funsigned-char -o "C:\DOCUME~1\ALAN\Desktop\test\test.elf" "C:\DOCUME~1\ALAN\Desktop\test\test.c"
C:\DOCUME~1\ALAN\Desktop\test\test.c: In function 'main':
C:\DOCUME~1\ALAN\Desktop\test\test.c:104: error: 'WDT0_15MS' undeclared (first use in this function)
C:\DOCUME~1\ALAN\Desktop\test\test.c:104: error: (Each undeclared identifier is reported only once
C:\DOCUME~1\ALAN\Desktop\test\test.c:104: error: for each function it appears in.)

Error returned from [avr-gcc.exe]

Return code = 1

Flowcode was unable to compile the flowchart's C code due to the following errors:


If your flowchart contains C code, please review this carefully. If your flowchart contains no C-code or you have thoroughly reviewed the code, contact Technical Support.

FINISHED

Re: RESET

Posted: Fri Jan 25, 2008 10:24 am
by Sean
A correction to the spelling of the watchdog timer definition names.

The prefixes contain the letter 'O', not the number '0'.

The command to set the minimum watchdog timer period should be:
wdt_enable(WDTO_15MS);
not
wdt_enable(WDT0_15MS);

If #include <avr/wdt.h> has been added to the supplementary code this definition will be available to the program.