From: <vu...@em...> - 2013-10-12 15:16:03
|
> Message: 1 > Date: Sat, 12 Oct 2013 12:05:53 +0100 >From: David Wallis <ins...@gm...> > Subject: Re: [Amforth] Watchdog prescalers > To: amf...@li... > > ... > ... I was keen to use the >watchdog timer because it > works with the lowest power mode (power down) and >doesn't need external > components. > ... > > David > Hello, David. I have Freaduino Pro Mini ( atmega328p @16MHz) http://www.hwkitchen.com/products/freaduino-pro-328-5v-16mhz/ I used WatchDog Timer as 1s Interval timer with this code \ \ WDTON Fuse unprogrammed marker =wdt-timeouts= \ Watchdog Timer Control Register bits: \ WDIF WDIE WDP3 WDCE WDE WDP2 WDP1 WDP0 \ am4th51 constants: \ WDTCSR_WDE WDTCSR_WDCE WDTCSR_WDP WDTCSR_WDIE WDTCSR_WDIF WDTCSR WDTCSR WDTCSR_WDIF bitmask: wdt.if WDTCSR WDTCSR_WDIE bitmask: wdt.ie WDTCSR WDTCSR_WDCE bitmask: wdt.ce WDTCSR WDTCSR_WDE bitmask: wdt.e WDTCSR WDTCSR_WDP bitmask: wdt.psc \ \ also assembler code wdtcsr! ( # --- ) R16 SREG lds, cli, R25 WDTCSR lds, R25 WDTCSR_WDCE WDTCSR_WDE or ori, WDTCSR R25 sts, WDTCSR R24 sts, R24 Y+ ld, \ poptos R25 Y+ ld, SREG R16 sts, end-code previous \ \ Watchdog Timer Prescale Select \ \ WDTCSR_WDP bits mask $0 constant 1/64s $1 constant 1/32s $2 constant 1/16s $3 constant 1/8s $4 constant 1/4s $5 constant 1/2s $6 constant 1s $7 constant 2s $8 constant 4s $9 constant 8s : wdt=prescaler! ( n -- ) 8s over < if .x abort" illegal" then dup 2 lshift $20 ( wdp3 ) and or wdt.psc drop and wdtcsr! ; \ \ mode action \ wdt-stop none \ wdt-interrupt interrupt \ wdt-reset system reset : wdt!interrupt wdt.ie high ; : wdt!reset wdt.e c@ or wdtcsr! ; : wdt!stop wdt.e wdt.ie drop rot or invert swap c@ and wdtcsr! ; \ \ variable TimeOuts variable StopWatch : 0TimeOuts! 0 TimeOuts ! ; : 0StopWatch! 0 StopWatch ! ; \ \ waiting for downcounter \ : time?out begin pause TimeOuts @ 0= until ; \ \ variable decrement \ : ?--! ( a --- ) dup @ ?dup if 1- swap ! else drop then ; \ \ wdt interrupt service routine \ : tick-tack wdt.if high \ очень жаль тактов... TimeOuts ?--! ; \ \ : interval ( n --- ) TimeOuts ! wdt!interrupt time?out wdt!stop ; \ \ ----------------------------------------------- \ wdt info : ?wdt. WDTCSR c@ ." wdt control&status = " .x cr ; \ |