Hello David, On 10/12/2013 11:13 AM, David Wallis wrote: > Hi all, > > I'm trying to use the watchdog timer on an ATMega324P for power saving by > sleeping for 8 seconds, and then having the watchdog wake the device. > However, I'm struggling to set the prescaler flags in WDTCSR. > > According to the datasheet, the 'Change Enable' flag (WDCE) must be set to > change the prescaler bits, but this clears after 4 clock cycles*. I'm > thinking that perhaps, this can't be done in forth because changing the > bits will take more than 4 clock cycles (I don't know, I'm guessing). > > Has anyone done this before and have a solution? If not, I guess I have to > write the word in assembler, which I haven't done before. Any pointers on > how to do this? >
Are you sure, you want to do this with the watchdog timer? Isn't the watchdog timer only able to generate a reset? I have a system which sleeps for 8 seconds, then wakes up to do a little work, and then go back to sleep. This requires the sleep function (trunk/core/devices/atmega328p/words/sleep.asm) to be included. It also needs a 32kHz crystal connected to Pins C6,C7. Timer2 is then initialized to a. have the external crystal as clock source (ASSR) b. have a prescaler of 1024 (TCCR2) my code examples are from atmega32! 2variable uptime : .uptime_sec uptime 2@ d.i [char] s emit ; : .uptime uptime 2@ 2dup decimal d.i [char] s emit space &60 ud/mod &60 ud/mod &24 ud/mod d.i [char] d emit space \ days 2 u0.r [char] : emit \ hours 2 u0.r [char] : emit \ minutes 2 u0.r \ seconds ; : ++uptime 1 s>d uptime 2@ d+ uptime 2! ; : tick_isr_uptime 1 ticks +! 8 s>d uptime 2@ d+ uptime 2! ; : +ticks-uptime $07 TCCR2 c! \ clock_ts2/1024 $08 ASSR c! \ source: 32 kiHz crystal \ register interupt service routine ['] tick_isr_uptime TIMER2_OVFAddr int! \ enable timer2 interupt TIMSK c@ $40 or TIMSK c! ; The main loop in my Forth programm looks somewhat like this: : run \ <== initialize everything ... 0 s>d uptime 2! idle.ticks 1+ ticks ! \ run job immediately +ticks-uptime begin \ <== do work only every idle.ticks rounds \ <== e.g. 4 rounds of 8 seconds each ticks @ idle.ticks > if 1 ticks ! \ run job once \ <== here is where the work is done then \ back to power down mode $03 sleep \ <== here we go back to sleep repeat ; I know, I'm not answering your question directly, but hopefully the above can serve as inspiration. Cheers, Erich ------------------------------------------------------------------------------ October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk _______________________________________________ Amforth-devel mailing list for http://amforth.sf.net/ Amforth-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/amforth-devel