From: David W. <ins...@gm...> - 2013-10-12 11:06:01
|
>Are you sure, you want to do this with the watchdog timer? Isn't the >watchdog timer only able to generate a reset? Thanks for your code Erich. I was keen to use the watchdog timer because it works with the lowest power mode (power down) and doesn't need external components. It seems to be a fairly common method. The watchdog can either generate a reset or trigger an interrupt, or both. This interrupt can also be used as a wake up from power down. (At least on the 324P that I'm using). The other way I was considering was with timer 2 in synchronous mode (so I don't need external components) and use power save mode. Did you ever look at synchronous mode? Many thanks, David |
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 ; \ |
From: David W. <ins...@gm...> - 2013-10-12 16:07:45
|
Fantastic. Looks as if this is just what I need. I'll give it a try. Thanks, David |
From: David W. <ins...@gm...> - 2013-10-12 16:44:15
|
Sorry for being dumb, but can you give me a pointer on what to do with the assembler code that you posted? I've never had to use assembler with forth before and can't find a page that describes what to do on the site. Many thanks for your help. David |
From: Matthias T. <mt...@we...> - 2013-10-12 18:01:23
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi David, > Sorry for being dumb, but can you give me a pointer on what to do > with the assembler code that you posted? I've never had to use > assembler with forth before and can't find a page that describes > what to do on the site. You're right, the assembler is very poorly documented. I never used it myself, so I gladly accepted the work Lubos has been made developing it. I wrote an article about it for the German forth society a few years ago, but never spend the time to translate it into English. I just started to write a recipe, but it may take some time to finish. A quick start: It's not rocket science. You need the dict_wl.inc included, load vocabulary.frt and assembler.frt from the lib directory. With that, Vladimir's examples should work. More examples are available behind the link he sent yesterday. I hope your government does not do any harm on you for reading a Russian website ;) Matthias -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iEYEARECAAYFAlJZjmMACgkQ9bEHdGEMFjNllwCgkt1mC1G+SiSyJaYeEOWsuQdj wQYAoOwoyHekjvVTFAH+av23tS8YF+55 =Kcl8 -----END PGP SIGNATURE----- |
From: <vu...@em...> - 2013-10-12 18:08:04
|
> ...can you give me a pointer on what to do with the > assembler code that you posted?... > ... > David You need to use "...\amforth-5.1\lib\assembler.frt" Good luck! moving forth, Vladimir. |
From: David W. <ins...@gm...> - 2013-10-12 18:23:18
|
Thanks to both Vladimir and Matthius for your input. I'll try and get it all up and running on Monday. If I get watchdog sleep running OK I'll send some text and the code to add to your documentation if that's useful. Cheers, David |
From: Matthias T. <mt...@we...> - 2013-10-12 19:05:00
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi David, > If I get watchdog sleep running OK I'll send some text and the code > to add to your documentation if that's useful. Everything that a bloody newby may understand immediatly is fine ;) (I doubt that the watchdog is something in that category, but I may be wrong here ;) ) I just uploaded a very early version: http://amforth.sourceforge.net/TG/recipes/Assembler.html, I'll improve it ASAP (and fix the typos as well, sorry); I hope it is not completely useless in its current state... Matthias -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iEYEARECAAYFAlJZnVMACgkQ9bEHdGEMFjNJbQCgzMhRLYTH+NU1FzHO2WywC6XF mtAAn19rnOIHkLmyIEcpQvhGGKmgKGJS =j4pd -----END PGP SIGNATURE----- |
From: <vu...@em...> - 2013-10-12 18:30:14
|
> ... > A quick start: It's not rocket science. You need the dict_wl.inc > included, load vocabulary.frt and assembler.frt from the lib directory. > ... > Matthias I have loaded: marker.frt postpone.frt vocabulary.frt assembler.frt multitask.frt bitnames.frt atmega328p.frt misc.frt ... and more... moving forth, Vladimir. |
From: <vu...@em...> - 2013-10-12 18:47:46
|
It works! > TimeOuts @ . 0 ok > decimal ok > 1s wdt=prescaler! ok > ?wdt. wdt control&status = 6 ok > &45 TimeOuts ! TimeOuts @ . 45 ok > wdt!interrupt ok > TimeOuts @ . 29 ok > TimeOuts @ . ?wdt. 15 wdt control&status = 46 ok > TimeOuts @ . 0 ok > ?wdt. wdt control&status = 46 ok > ?wdt. wdt!stop ?wdt. wdt control&status = 46 wdt control&status = 6 ok > Vladimir. |
From: Erich W. <ew....@na...> - 2013-10-12 12:44:18
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi David, On 10/12/2013 01:05 PM, David Wallis wrote: >> Are you sure, you want to do this with the watchdog timer? Isn't the >> watchdog timer only able to generate a reset? > > > Thanks for your code Erich. I was keen to use the watchdog timer because it > works with the lowest power mode (power down) and doesn't need external > components. > > It seems to be a fairly common method. The watchdog can either generate a > reset or trigger an interrupt, or both. This interrupt can also be used as > a wake up from power down. (At least on the 324P that I'm using). "or an interrupt". Aha. Looking into the datasheets again: atmega32 (the on I use most often): WDT generates a reset only. atmega644p (of which I have some): WDT generates an interrupt or a reset. So I learned something. Thanks for enlightening me. :-) > The other way I was considering was with timer 2 in synchronous mode (so I > don't need external components) and use power save mode. Did you ever look > at synchronous mode? No, not yet. But maybe I should ... Cheers, Erich -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.15 (GNU/Linux) Comment: Using GnuPG with Icedove - http://www.enigmail.net/ iQIcBAEBAgAGBQJSWUQCAAoJEHx024vXVRNQnboQAIwx9HJnREwP2niJl2z0P7zn dINhPAioYBdyd1PDhZEZn3WphhlApTP5tbHrGJF5Uv9vqsvZPt2jsNrcL7/0e5Js aGFlySF1aUc92/MEK97hNLDjpsXlZ0i3prC2FRrD8dJ5bS3OezB6uB3tNxrWnEJg 2KgttJU3ytSTVZhiqzoodh6VfVY0+9LgHqdQDsDmCN1XtsW4up2m6a9fVCkP9ZOh 8WH50zCCRHL9s8IB1VzfM5i8ixaMfkw70QWREIqTXcFKyNjJWknKzpCfIz5Jg1F8 mjNJERIt3u8R4s1B78nxjgrbTNVE7/D7cHNAhjMTYyXGhXE9BQTi5ONzIhhOWw4p ReOCBkDXR9T4msbBZ/znqjo2MMiSvbXYmYdbDaT8cpnszb2TAzLYbWDZFvNr0AIZ UzkD7PO6L++aSCsUuSPOXUSzDJsq1CLwZgeMkcmNF59drOoU9S+Of64TOo1XLoxP V6AXPx2R/SnLgPK+mu48vpjNdxIyUv51Uu+icMzTdMFuZ+lpV6ckSBB61V+jhK41 kFZOupNS3NLd8CiWc9RWqDwtKuRIqK4Kzs7vFbNETxcKW4q6o36RXmaFmonLWbhY p2LYontLygzPTr7SW6tMcAbMqLLJ89eYei7bIKhc5cM4eNYnUrb6lAITF3bUvfOy Oi7pKtaFzUaSgC5vCnTY =tFuz -----END PGP SIGNATURE----- |