Mostafa
i have a made a little code to show you the concept ..
In my application in order to save the max energy, i have disable all clocks to save maximum energy thats why you have the loop count down.
Everything does work fine out of the
;
; test 1.asm
;
; Created: 28/01/2024
; Author : Tic & Tac
;
; REGISTER USAGE
; | sbr/cbr | sbrs/sbrc | Comment
; R16 | | |
; R17 | | |
; R18 | | |
; R19 | | |
; R20 | | |
; R21 | | |
; R22 | | |
; R23 | | |
; R24 | | |
; R25 | | |
; R26 | | |
; R27 | | |
; R28 | | |
; R29 | | |
; R30 | | |
; R31 | | |
; R32 | | |
; R33 | | |
; R34 | | |
; R35 | | |
.include "tn25def.inc" ;Include bibliotheque
;========================================================================= Interrupt Watchdog- Vector Table - DEBUT ==========================================================================================================================
.cseg
.org $0000 ;External Pin, Power-on Reset, Brown-out Reset, Watchdog system Reset
RESET: nop
rjmp START
.org $000D ;WDT Timeout interrupt vector
reti
.org $0010 ;application space
;========================================================================= Interrupt Watchdog- Vector Table - FIN ==========================================================================================================================
;========================================================================= Port Parameter +Value - DEBUT ==========================================================================================================================
START: ;init PORTB
sbi DDRB,PB0 ;PB/0 OUT. all others port IN (charge pump entree)
sbi DDRB,PB1 ;PB/1 OUT. all others port IN (Half bridge)
sbi DDRB,PB2 ;PB/2 OUT. all others port IN (Half bridge)
sbi DDRB,PB3 ;PB/3 OUT. all others port IN (charge pump sortie)
sbi DDRB,PB4 ;PB/4 OUT. all others port IN (Light)
cbi DDRB,PB5 ;PB/5 INPUT.
cbi portb,pb0 ; OFF alimentation Charge pump (verification)
cbi portb,pb1 ; OFF alimentation Charge pump (verification)
cbi portb,pb2 ; OFF alimentation Charge pump (verification)
cbi portb,pb3 ; OFF alimentation Charge pump (verification)
cbi portb,pb4 ; OFF alimentation Charge pump (verification)
cbi portb,pb5 ; set pulldown input
ldi R17,0x32 ; EEprom Adress Low
ldi R24,0x04 ; pulse lengh setting
ldi R26,0x02 ; compteur signal court / long (si R26=0 alors long
ldi R27,0x0a ; ( avant b) Valeur du nombre de relative JUMP dans R25 (19 hexa = 25 decimal)
;==============================================================================================
; Start - flash PB0 - 2 times
;==============================================================================================
;loop count down (used as timer)
sbi PORTB,PB4 ; light ON PB4
ldi R20,0x20
Tempo_EEPROM_311:
ldi R19,0xff
Tempo_EEPROM_031:
dec R19 ; Dec value R -1
brne Tempo_EEPROM_031 ; Compare Valu and loop till = 0
dec R20 ; Dec value R -1
brne Tempo_EEPROM_311 ; Compare Valu and loop till = 0
cbi PORTB,PB4 ; light OFF PB4
;loop count down (used as timer)
ldi R20,0xff
Tempo_EEPROM_3111:
ldi R19,0xff
Tempo_EEPROM_03111:
dec R19 ; Dec value R -1
brne Tempo_EEPROM_03111 ; Compare Valu and loop till = 0
dec R20 ; Dec value R -1
brne Tempo_EEPROM_3111 ; Compare Valu and loop till = 0
sbi PORTB,PB4 ; light ON PB4
;loop count down (used as timer)
ldi R20,0x20
Tempo_EEPROM_3113:
ldi R19,0xff
Tempo_EEPROM_03112:
dec R19 ; Dec value R -1
brne Tempo_EEPROM_03112 ; Compare Valu and loop till = 0
dec R20 ; Decrememnte 1 a R(egistre)20 a chaque passage
brne Tempo_EEPROM_3113 ; Compare Valeur R(egristre)20 et boucle tant que pas egal a 0
cbi PORTB,PB4 ; light OFF PB4
;==============================================================================================
; Watch dog - setting
;==============================================================================================
out SREG,R15 ; load SREG
;init brown out detection desealble for sleep mode
;ldi r23, (1<<BODSE) ; En 2 fois 1- pour autoriser ecriture (1<<BODSE)|(1<<BODS)
;out MCUCR, r23 ; envoyer autorisation ecriture
;ldi r23, (1<<BODS)|(0<<BODSE) ; Ecrire valeur a envoyer dans R23
;out MCUCR, r23 ; Envoyer R23 dans MCUCR
;init WDT for interrupt mode
ldi r23, (1<<WDCE)|(1<<WDE)
out WDTCR, r23
ldi r23, (1<<WDIE)|(0<<WDE)|(0<<WDP0)|(1<<WDP1)|(0<<WDP2)|(0<<WDP3) ; sec time out WDT interrupt; no system reset
out WDTCR, r23
sei ; global interrupt enable bit is active
L1_INTERIEUR: ;init sleep modes
ldi r23, (1<<SM1) ;Power-down mode
out MCUCR, r23
in r23, MCUCR
ldi r23, (1<<SE) ;sleep mode enabled
out MCUCR, r23 ;put MCU into sleep
L1A_INTERIEUR:
in R15,SREG ;save Sreg
wdr
sleep
L2_INTERIEUR: ;wakeup label; flash LED
;==============================================================================================
; Count down Watch Dog - 3 times + light each count down
;==============================================================================================
ldi R27,0x06 ; Set value count down
Loop_watchdog_INTERIEUR: ; count down 6 = 0.64ms * 6 loops
dec R27 ; Decrememnte 1 a R(egistre)27 a chaque passage
;loop count down (used as timer)
sbi PORTB,PB4 ; light ON PB4
ldi R20,0x20
Tempo_001:
ldi R19,0xff
Tempo_002:
dec R19 ; Dec value R -1
brne Tempo_002 ; Compare Valu and loop till = 0
dec R20 ; Dec value R -1
brne Tempo_001 ; Compare Valu and loop till = 0
cbi PORTB,PB4 ; light OFF PB4
brne L1A_INTERIEUR ; Compare Valeur R(egristre)27 et boucle tant que pas egal a 0
ldi R27,0x0b ; Valeur du nombre de relative JUMP dans R27 (longeur watchdog)
;==============================================================================================
; Wake up Watch dog - 3 times
;==============================================================================================
;loop count down (used as timer)
sbi PORTB,PB4 ; light ON PB4
ldi R20,0x20
Tempo_out_001:
ldi R19,0xff
Tempo_out_002:
dec R19 ; Dec value R -1
brne Tempo_out_002 ; Compare Valu and loop till = 0
dec R20 ; Dec value R -1
brne Tempo_out_001 ; Compare Valu and loop till = 0
cbi PORTB,PB4 ; light OFF PB4
;loop count down (used as timer)
ldi R20,0xff
Tempo_out_0011:
ldi R19,0xff
Tempo_out_00211:
dec R19 ; Dec value R -1
brne Tempo_out_00211 ; Compare Valu and loop till = 0
dec R20 ; Dec value R -1
brne Tempo_out_0011 ; Compare Valu and loop till = 0
sbi PORTB,PB4 ; light OFF PB4
;loop count down (used as timer)
ldi R20,0x20
Tempo_out_0013:
ldi R19,0xff
Tempo_out_00212:
dec R19 ; Dec value R -1
brne Tempo_out_00212 ; Compare Valu and loop till = 0
dec R20 ; Dec value R -1
brne Tempo_out_0013 ; Compare Valu and loop till = 0
cbi PORTB,PB4 ; light OFF PB4
;loop count down (used as timer)
ldi R20,0xff
Tempo_out_00213:
ldi R19,0xff
Tempo_out_00214:
dec R19 ; Dec value R -1
brne Tempo_out_00214 ; Compare Valu and loop till = 0
dec R20 ; Dec value R -1
brne Tempo_out_00213 ; Compare Valu and loop till = 0
sbi PORTB,PB4 ; light OFF PB4
;loop count down (used as timer)
ldi R20,0x20
Tempo_out_00314:
ldi R19,0xff
Tempo_out_00315:
dec R19 ; Dec value R -1
brne Tempo_out_00315 ; Compare Valu and loop till = 0
dec R20 ; Dec value R -1
brne Tempo_out_00314 ; Compare Valu and loop till = 0
cbi PORTB,PB4 ; light OFF PB4
rjmp L1A_INTERIEUR ; jumpG
As you can see the BODS instruction are set as comment that i could test the program
;init brown out detection desealble for sleep mode
;ldi r23, (1<<BODSE) ; En 2 fois 1- pour autoriser ecriture (1<<BODSE)|(1<<BODS)
;out MCUCR, r23 ; envoyer autorisation ecriture
;ldi r23, (1<<BODS)|(0<<BODSE) ; Ecrire valeur a envoyer dans R23
;out MCUCR, r23 ; Envoyer R23 dans MCUCR
to answer your question : the target of setting the DOBS is to save maximum energy during watchdog.
I need the BOD to be sure that the Attiny is starting properly in case of low battery (during recharge phase)
One function i would like to ass is a blinking led when the power is reaching 3.6V ( but i guess this is another story !