Posted: Tue Feb 02, 2010 9:04 pm Post subject: WATCHDOG RESET LOGGER USING MCUCSR and EEPROM
'------------------------------------------------------------------------------
' Free to use - (c) 2010 Benny Aalto
' I must admit that i would be very glad for ANY feedback.
' SUPPORT THIS: http://stopsoftwarepatents.eu
'==============================================================================
' Program for Atmel MEGA16 MCU - DEMO
' Store a log of WATCHDOG resets in MCU EEPROM.
' Durng realtime testing in field it is often an advantage to have a WD-Log.
'==============================================================================
$regfile "M16def.dat" ' Atmel ATMEGA16 used.
$crystal = 4000000 ' CRYSTAL
$hwstack = 32 ' Default 32
$swstack = 10 ' Default 10
$framesize = 40 ' Default 40
$baud = 19200 ' ASCII 0
$programmer = 12 ' USB-ISP I
' $programmer = 4 ' SAMPLE PROGRAMMER
' $programmer = 1 ' STK 200/300
' $INITMICRO ' Call _INIT_MICRO, important initialization
' $sim
' $DBG
wait 1 '5
'==============================================================================
'WATCHDOG RESET COUNTER
' NOTE: On startup MCUCSR is copied to register r0 and then MCUCSR is cleared.
' Set this code at the very start of program!
' You MUST set fusebit 'Preserve EEPROM when chip erase' (=0).
DIM myMCUCSR as byte , WDR_count As Word
myMCUCSR = PEEK(0) ' copy r0 to myMCUCSR
McuCsr = McuCsr AND &B11100000 ' (=224 dec) Reset RESET-flags
'------------------------------------------------------------------------------
' Store the watchdog reset counter in eeram
DIM ERAM_WDR_count AS ERAM Word
WDR_count = ERAM_WDR_count
IF WDR_count > 30000 THEN WDR_count = 0 ' Limit
If myMCUCSR = 8 Then INCR WDR_count ' If WD resetted
ERAM_WDR_count = WDR_count ' Store it in EEPROM
'==============================================================================
PRINT "WDR_count: " ; WDR_count
Config Watchdog = 2048 'Typical Time-out at Vcc = 5.0 V is 2.1 s,
Start Watchdog 'start the watchdog timer
'==============================================================================
MAIN: ' ANY PROGRAM STARTS HERE...
STOP ' STOP does not stop the watchdog timer.
'==============================================================================
End 'end program. This stops also the watchdog timer.
'==============================================================================
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum