Hallo,
ist zwar nicht taufrisch, aber im Prinzip wie hier im Tread schon beschrieben:
https://arduino-projekte.webnode.at/...ecken-mit-wdt/
Gruß André
Hallo,
ist zwar nicht taufrisch, aber im Prinzip wie hier im Tread schon beschrieben:
https://arduino-projekte.webnode.at/...ecken-mit-wdt/
Gruß André
Hallo,
ich habe ein Bascom Demo Programm gemacht. Leider bin ich in C nicht so fit, daß ich das schnell hinbekomme. Habe aber versucht, möglichst gut zu kommentieren. Programm ist auf Tiny44 getestet. Auf Tiny13 heißen, so meine ich, nur zwei relevante Bits anders. Ist im Programm kommentiert.
Gruß
Searcher
Code:'################################################### ' 'ATtiny44 ' 'WATCHDOG DEMO ' 'IMPORTANT prerequisite: 'WDTON fuse is default (unprogrammed = 1, watchdog timer interrupt function is enabled) ' 'three LEDs are used to visually monitor the success of sleep mode pauses ' 1. after start of program (or a reset) all three leds lit for one second ' 2. 8 seconds wdt pause ' 3. wdt led flash, life led flash ' 4. 8 seconds pause ' 5. wdt led flash, life led flash ' 6. 8 seconds pause ' 7. wdt led flash, life led flash ' 8. directly after 7. action led flash ' 9 5 seconds pause in action sub, another action led flash ' 10. continue step 2. with 8 sconds pause ' ' control overall sleep duration by value in watchdog_ovf ' '####################################################### $regfile = "attiny44.dat" $framesize = 24 $swstack = 24 $hwstack = 38 $crystal = 8000000 'internal oscillator Config Portb.0 = Output 'WDT LED, switched in watchdog isr (200ms flash) Config Porta.3 = Output 'Action LED indicates action after watchdog controlled sleep Config Porta.7 = Output 'Life LED, monitor wether sleep mode ist entered Rem : all LEDs for 1 second ON (check for program begin and/or µC reset) portb.0 = 1 porta.3 = 1 porta.7 = 1 wait 1 portb.0 = 0 porta.3 = 0 porta.7 = 0 Rem : check end for program begin and/or µC reset dim watchdog_action_flag as byte 'set in watchdog interrupt, indicates end of sleep pause dim watchdog_ovf as word 'counts watchdog timer overflows before action set mcucr.sm1 'prepare sleepmode as power down, SM1 Bit in MCUcR on wdt isr_watchdog 'watchdog interrupt vector to watchdog isr wdtcsr = bits(wdp0 , wdp3) 'set wdp0,wdp3 bits, watchdog prescaler to 8 seconds Rem : ### !wdr 'asm instruction "wdr" resets the watchdog timer set WDTCSR.wdie 'watchdog interrupt enable Rem attiny13 : set WDTCSR.wdtie 'watchdog interrupt enable enable interrupts 'global interrupt enable (sei) Rem : ############################################################################### Rem : ### main loop Do set mcucr.se 'enable following sleep command, SE Bit in MCUCR !sleep 'asm sleep command. enters sleepmode which is prepared in MCUCR by SM bits reset mcucr.se 'disable sleep commands: recomended in datasheet porta.7 = 1 'Life LED ON waitms 200 '200ms flash, monitor sleep state porta.7 = 0 'Life LED OFF Rem : ### if sleepmode ist not entered , Life LED OFF is not noticable (to fast, LED appears continiously on exept during action) if watchdog_action_flag = 1 then gosub sub_watchdog_action watchdog_action_flag = 0 end if Loop Rem : main loop end Rem : ############################################################################### Rem : ############################################################################### Rem : ### in subroutine do whatever to be done after watchdog controlled long sleep break sub_watchdog_action: porta.3 = 1 'Action LED ON waitms 200 '200ms flash porta.3 = 0 'Action LED OFF wait 5 '5 seconds do nothing, just wait porta.3 = 1 'Action LED ON waitms 200 '200ms flash porta.3 = 0 'Action LED OFF Rem : ### !wdr 'asm instruction "wdr" resets the watchdog timer set WDTCSR.wdif 'clear eventually set interrupt flag before enabling wdt interrupt set WDTCSR.wdie 'watchdog interrupt enable Rem attiny13 : set WDTCSR.WDTIF 'clear eventually set interrupt flag before enabling wdt interrupt Rem attiny13 : set WDTCSR.WDTIE 'watchdog interrupt enable return Rem : ############################################################################### isr_watchdog: 'controls invoking of "sub_watchdog_action" portb.0 = 1 waitms 200 '200ms flash - monitor watchdog interrupt portb.0 = 0 watchdog_ovf = watchdog_ovf + 1 'count wdt timer overflows/interrupts if watchdog_ovf >= 3 then reset WDTCSR.wdie 'watchdog interrupt disable Rem attiny13 : reset WDTCSR.wdtie 'watchdog interrupt disable watchdog_action_flag = 1 'flag will be processed in main loop watchdog_ovf = 0 end if return end 'end program
Geändert von Searcher (14.01.2022 um 10:03 Uhr) Grund: Kommentare im PRG berichtigt
Hoffentlich liegt das Ziel auch am Weg
..................................................................Der Wegzu einigen meiner Konstruktionen
Danke Euch für die konstruktiven Hinweise.
Danke Gnom67 - jaaa, das ist DER Hinweis! .. steht auf den an die zwanzig Seiten Datenblatt die ich (noch) nie gelesen, nicht mal überflogen hatte. Sprich: bins selber schuld. Ich geh die nächsten Tage dran (jetzt erstmal an die Kletterwand - in der Halle - weils draussen deutlich unter Null ist *brrrr* aber der Himmel ist uni bayerisch-blau)m Datenblatt DS40002307A Kapitel 8.4 kannst du nachlesen . . .
@André : ach jee, und die Arduinohilfen gehören auch nicht zu meiner üblichen Literatur. Schade wie ich sehe!
@Searcher : danke für Deine Mühe. PS: haste im Postfach nachgesehen?
Danke nochmal für Eure Hilfen. Ich werde berichten.
Ciao sagt der JoeamBerg
Es geht weiter? Ja, blos funktionieren tuts nicht :-/ Da muss ich mal (noch) gründlich (..er) drüberschauen.
Wird im main aufgerufen :Code:// ============================================================================= = // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // N E U Basis "alter" SLEEP1, Adaption aus searcher´s tiny44_WDT_Demo-in-BAS // ============================================================================= = // Dok D:\D_pro-fi...blätter\atmel-controller_Datenblätter_App-Notes // \ATtiny13_doc2535J_08-10-akt-neueste-13-13V_13neu_13-13Vneu_13-13Vneu.pdf // ============================================================================= = // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void SLP0init (void) // Ruhemodus vorbereiten / initialisieren { // // __watchdog_reset(); // Siehe https://arduino-projekte.webnode.at // /meine-projekte/attiny-im-schlafmodus/wecken-mit-wdt/ // Setzen des Registers fuer Watchdog Time-out Interrupt cli(); wdt_reset(); // Reset Watchdog Timer MCUSR &= ~(1 << WDRF); //Ruecksetzen des Watchdog System Reset Flag MCUCR |= (1 << SM1); // SM1: Power Down 46 /* Set new prescaler(time-out) */ WDTCR |= (1<<WDE) | (1<<WDCE) | (1<<WDP3); // WDTCR |= (1 << WDTIE); // Watchdog Timer Interrupt Enable 41 WDTCR |= (1 << WDTE); // Watchdog Timer Interrupt Enable setzen 41 // sei(); return; } // Ende void SLEEP1 (void) -- Ruhemodus ein, wake up dur // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ============================================================================= = // ============================================================================= = // Dok D:\D_pro-fi...blätter\atmel-controller_Datenblätter_App-Notes // \ATtiny13_doc2535J_08-10-akt-neueste-13-13V_13neu_13-13Vneu_13-13Vneu.pdf // Dann - neu: D:\D_pro-fi...blätter\atmel-controller_Datenblätter_App-Notes // \ATtiny13A-Data-Sheet-DS40002307A-2021_neu-Microchip // ============================================================================= = // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void SLEEP0 (void) // Ruhemodus SLEEP0 starten { // MCUCR |= (1<<SM1)|(1<<SE); // SM1: Power Down, SE: Sleep enable 46 sei(); // asm volatile ("sleep"); // Inline-Assembler MCUCR &= ~(1<<SM1)|(1<<SE); // => alten Zustand / zurücksetzen WDTCR &= ~(1<<WDE); // Watchdog Timer Interrupt D I S able 41 WDTCR |= (1<<WDTIE); // Watchdog Timer Interrupt Enable 41 // - - - - - - - - - - - - - - - - return; } // Ende void SLEEP1 (void) -- Ruhemodus ein, wake up dur // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ============================================================================= =*grübel*Code:.. SetBit (PORTB, kLED); wms ( 5 ); // Port für/mit PB0/rLED SLP0init ( ); // Ruhemodus SLEEP0 vorbereiten / initialisieren ClrBit (PORTB, kLED); wms ( 5 ); // Port für/mit PB0/rLED while ( 1 ) // Hier folgt das eigentliche Hauptprogramm { // SetBit (PORTB, kLED); wms ( 10 ); // SLEEP0 ( ); // Ruhemodus SLEEP0 // ClrBit (PORTB, kLED); wms ( 10 ); // LED aus // // SLEEP0 ( ); // Ruhemodus SLEEP0 // } // Ende while ( 1 ) ..
Ciao sagt der JoeamBerg
Hallo,
ich finde keine Interrupt Routine. Springt der µC ins Leere?
Die Zeile "WDTCR &= ~(1<<WDE); // Watchdog Timer Interrupt D I S able 41" ist unnötig und wird vermutlich auch nicht ausgeführt.
Gruß
Searcher
Hoffentlich liegt das Ziel auch am Weg
..................................................................Der Wegzu einigen meiner Konstruktionen
Danke! Richtig, ich finde auch keine WDT-ISR. Hab ich nachgetragen. Die genannte Zeile gelöscht . . ... ich finde keine Interrupt Routine. Springt der µC ins Leere?
..
Die Zeile "WDTCR &= ~(1<<WDE); // Watchdog Timer Interrupt D I S able 41" ist unnötig und wird vermutlich auch nicht ausgeführt
Noch immer gibts nur so ´n Blinzeln im Oskar (klick).
Geändert von oberallgeier (24.01.2022 um 08:02 Uhr)
Ciao sagt der JoeamBerg
Diese Zeile hatte ich eben auch übersehen. WDE setzt den Watchdog RESET. Du möchtest aber den Watchdog Interrupt. Muß also auch weg zusammen mit WDCE.Code:WDTCR |= (1<<WDE) | (1<<WDCE) | (1<<WDP3);
MIT WDP3 wird der Timer auf 4 Sekunden eingestellt. OK.
Bleibt nur WDTCR |= (1<<WDP3); von der Zeile übrig.
Hoffentlich liegt das Ziel auch am Weg
..................................................................Der Wegzu einigen meiner Konstruktionen
Danke - läuft. Anfangs mit Stolpersteinen. Ausführlich erst morgen.. . Bleibt nur WDTCR |= (1<<WDP3); von der Zeile übrig . .
Ciao sagt der JoeamBerg
Lesezeichen