Mostafa
I tryed your code below and I can compile now .;
in r23, MCUCR
ori r23, 0x80
out MCUCR, r23 ; BODS-bit = bit-7 of MCUCR = HIGH; all other bits are unaffected)
I have no way to check the consumtion of the attiny, I still have a concern if it does work really as we do not have respected the following from the datsheet.
"In order to disable BOD during sleep the BODS bit must be written to logic one. This is controlled by a timed sequence and the enable bit, BODSE in MCUCR.
1 - both BODS and BODSE must be set to one.
2 - within four clock cycles, BODS must be set to one and BODSE must be set to zero
3 - The BODS bit is active three clock cycles after it is set. A sleep instruction must be executed while BODS is active in order to turn off the BOD for the actual sleep mode. The BODS bit is automatically cleared after three clock cycles"
We have not done the 1 .
We have made the 2 .
I will change the prog to have the SLEEP instruction in the 3 clock cycles .. to respect the 3.
But this is also make me thin that it is recommended to set the SM1 just before the SLEEP instruction.
so what would you think about the lower code ?
;
; 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 | | |
.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 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
;init brown out detection desealble for sleep mode
in r23, MCUCR
ori r23, 0x80
out MCUCR, r23 ; BODS-bit = bit-7 of MCUCR = HIGH; all other bits are unaffected)
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