LEDs are not fading, ATtiny13A, assembly

The vid I followed and the scheme

i have 2 questions. Why in the first case when the INC COUNT is on the commented 180 line, it will light only the first 3 LEDs.
And the second question is why my code is not fading like it does in the vid? Case 2 when INC COUNT is executed once every 125mS(And this is the only working case for me, when it atleast will roll the LEDs). Also for this I only use the GAP string, ignore the other ones

;
; Timer ISR Test 
;
; Created: 
; Author : 
;

.org 0

rjmp main                     ; Reset - Address 0
reti                          ; INT0 (address 01)
reti                          ; Pin Change Interrupt Request 0        
reti                          ; Timer/Counter Overflow
reti                          ; EEPROM Ready
reti						  ; Analog Comparator
rjmp TCC0_cmpA_handler        ; Timer/Counter Compare Match A
rjmp TCC0_cmpB_handler        ; Timer/Counter Compare Match B
reti                          ; Watchdog Time-out
reti                          ; ADC Conversion Complete

ROTATE_1:  .DB 0x09, 0X0A, 0X0C, 0X11, 0X12, 0X14, 0x00, 0x00  ; 0x00 is the end-of-string marker
GAP: .DB 0x0F, 0x13, 0x0F, 0x15, 0x0F, 0x16, 0x17, 0x0B, 0x17, 0x0D, 0x17, 0x0E, 0x0, 0x0 
ROTATE_2:  .DB 0x01, 0x02, 0x04, 0x00
ROTATE_OPP: .DB 0x0B, 0x13, 0x0E, 0x16, 0x00, 0x00
OPPOSITES: .DB 0x0F, 0x17, 0x00, 0x00
ALL: .DB 0x07, 0xFF, 0x00, 0x00

;LED  PORT--> PB4   PB3   PB2   PB1   PB0  PORTB
; |            |     |     |     |     |   value    
; V            V     V     V     V     V     V  
;                                              
; 1        --> 0     1     0     0     1   0x09
; 2        --> 0     1     0     1     0   0x0A  (0A= 0000 1010)
; 3        --> 0     1     1     0     0   0x0C
; 4        --> 1     0     0     0     1   0x11
; 5        --> 1     0     0     1     0   0x12
; 6        --> 1     0     1     0     0   0x14
; 1,3,4,6  --> 0     0     1     0     1   0x05
; 1,2,3    --> 1     0     1     1     1   0x17
; 4,5,6    --> 0     1     1     1     1   0x0F
; 1,2,3,4,5,6> 0     0     1     1     1   0x07
; none     --> 1     1     1     1     1   0x1F

; REGISTER USAGE
;                | sbr/cbr            | sbrs/sbrc       | Comment
; FLAG[7] (0x80) |                    |                 |
; FLAG[6] (0x40) |                    |                 |
; FLAG[5] (0x20) |                    |                 |
; FLAG[4] (0x10) | Q_H_SEC            | _q_c_sec        | End of quarter-half-second(125mS)
; FLAG[3] (0x08) | OCR0B_CMP          | _ocr0b_cmp      | Interrupt on OCR0B compare
; R18[2] (0x04)  | HALF_SEC           | _half_sec       | End of half-second
; R18[1] (0x02)  | QUARTER_SEC        | _quarter_sec    | End of quarter-second
; R18[0] (0x01)  | MILLISEC           | _millisec       | End of mS - 1 indicates end of mS

.def FLAG = R18
.def LOOP_COUNT = R19
.def LED_A = R20
.def LED_B = R21
.def BOTTOM = R22
.def TOP = R23
.def COUNT = R24

.equ Q_H_SEC = 0x10
.equ _q_h_sec = 4
.equ OCR0B_CMP = 0x08
.equ _ocr0b_cmp = 3
.equ HALF_SEC = 0x04
.equ _half_sec = 2
.equ QUARTER_SEC = 0x02
.equ _quarter_sec = 1
.equ MILLISEC = 0x01
.equ _millisec = 0

TCC0_cmpA_handler:
in R15,SREG
st Y,R16    ; Save R16
sbr FLAG,0x01   ; indicates end of mS to program --------------------->

ldd R16,Y+1   ; quarter-half-second(125mS) counter
dec R16
std Y+1,R16
brne continue
sbr FLAG,Q_H_SEC  ; indicate end of quarter-half-second(125mS) --------------------->
ldi R16, 125
std Y+1,R16    ; start a new  quarter-half-second(125mS)

continue:
ldd R16,Y+2    ; Quarter-second counter
dec R16     
std Y+2,R16    ; does not alter SREG
brne end_TCC0_cmpA_handler
sbr FLAG,QUARTER_SEC  ; indicate end of quarter-second --------------------->
ldi R16,250
std Y+2,R16    ; start a new quarter second

ldd R16,Y+3    ; Half-second counter
dec R16
std Y+3,R16    ; does not alter SREG
brne end_TCC0_cmpA_handler
sbr FLAG,HALF_SEC   ; Indicate end of half-second -------------------->
ldi R16,0x02
std Y+3,R16    ; start a new half-second

end_TCC0_cmpA_handler:
ld R16,Y       ; Restore R16
out SREG,R15
reti

TCC0_cmpB_handler:
in R15, SREG
sbr FLAG, OCR0B_CMP
out SREG, R15
reti

main:
; Load stack register

LDI R16, LOW(RAMEND) ; Lower byte
OUT SPL,R16 ; to stack pointer

; Define directions for port pins
ldi r16,(1<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB3)|(1<<PB4) ; all ports set to output   0001 1111
out DDRB,R16   ; Set OUTput ports.

ldi R16,(1<<CS01)  ; clock counter with Clk/8. 125kHz.
out TCCR0B,R16

ldi R16,(1<<WGM01)  ; WGM[2:0] = 0x2 sets CTC mode. COM0cn =0 : do not control pins with compare match.
out TCCR0A,R16           

ldi R16,(1<<OCIE0A)|(1<<OCIE0B)  ; OC0 int ena
out TIMSK0,R16

ldi R17, 124
out OCR0A,R17
ldi R17, 72
out OCR0B,R17

ldi YL,0x90
clr YH

ldi R16,125  ; 125 mS timer
std Y+1,R16
ldi R16,250  ; quarter-second timer
std Y+2,R16  
ldi R16,2    ; half-second timer
std Y+3,R16
ldi BOTTOM,2
clr COUNT
ldi TOP,124
clr R0     ; constant 0
sei

loop:
ldi ZL,low(2*GAP)   ; Set up Z-reg
ldi ZH,high(2*GAP)

rcall display
rjmp loop

display:
lab_1:
r1_a:
lpm LED_A,Z+   ; load the LEDs to light
lpm LED_B,Z+
tst LED_B      ; check for end of string
breq r1_b
lp:
out PORTB,LED_A

wt_1:                  ;\
sbrs FLAG,_ocr0b_cmp   ; \_ Wait for OCR0B
rjmp wt_1              ; /
cbr FLAG,OCR0B_CMP     ;/ 
out PORTB,LED_B
wt_2:                  ;\
sbrs FLAG,_millisec    ; \_ Wait millisecond
rjmp wt_2              ; /
cbr FLAG,MILLISEC      ;/ 
;inc COUNT


sbrs FLAG, _q_h_sec
rjmp wt_3
cbr FLAG,Q_H_SEC
inc COUNT
rcall between

wt_3:
out OCR0B,COUNT
sbrs FLAG,_half_sec   ; continue to loop for half second
rjmp lp
cbr FLAG,HALF_SEC
rjmp r1_a
r1_b:
ret
;================================
; BOTTOM, TOP and COUNT are defined registers
; test whether COUNT is between bounds set in BOTTOM and TOP
;   BOTTOM <= COUNT <= TOP  inside
;   COUNT < BOTTOM   - out of bounds
;   COUNT > TOP      - out of bounds
; after the subroutine return, test it with brcs (branch on Carry set)

between:
cp COUNT,BOTTOM   ; BOTTOM
brlo outside
cp TOP,COUNT
brlo outside
ret
outside:
MOV COUNT,BOTTOM
ret

Hi, @feaklif
Welcome to the forum.

Did you cut and paste the code or copy it by hand?

Which code its it 5a or b or c or whatever?

Thanks.. Tom.... :smiley: :+1: :coffee: :australia:

Three possible answers to your questions:

  1. You wired the project incorrectly.
  2. You wrote the code incorrectly.
  3. Your IDE does not support the syntax of the code (AtmelStudio versus Arduino IDE)

Follow the video explanation of the author.

i copied 5e by hand and adapted to ATtiny13A cause originaly it is for ATtiny85, and the explanation of fading is in the Fading LEDs chapter, but the implementation was kinda a homework.

Did you use the information in the tiny85 code to help write tiny13A code to fade one LED? I did not see, in your video, any LEDs changing brightness.

Pls, post the tiny85 codes.

You have ATtiny13A MCU (Fig-1). What kind of output do you want the MCU should deliver, and at which pin? Do you want to connect a LED at Pin-5 and seeing it fades from full brightness to zero brightness over 5 sec period? Do you want to use Assembly Language or Arduino Language to write program for the ATTiny13A MCU?


Figure-1:

yes, in the vid on yt you could see how it should have faded, I had to have similar effect, in my second video the LEDs are swritching but not fading. And yes, none have changed the brightness(faded). The fade should be on account of OCR0B changing the portion of time each set will be lit. I think you should atleast see the last chapter of the yt vid to understand what I am talking about. Also I am a beginner in programming. Wanted to understand better how a cpu works. Now I don't think I could explain better.

I am really grateful for the support you all try to give me

Start with using wokwi.com to make one LED fade and one LED toggle, translate (port) it to tiny13A, then increase gradually to six LEDs.

I saw the author's videos.