; DDS, with frequency jitter [12,96 and 768-cycle loop]
DDS_asm:
; ACCU_L= lower register of ACCU
CLR ACCU_L
; sineAddr= start address of sine table in SRAM
= 0x??00 [table size 256 bytes]
; init XL at start address of sine table in SRAM [0x00]
LDI XL, low(sineAddr)
; XH == high address of SRAM sine table [0x??, constant]
LDI XH, high(sineAddr)
DDSloop:
; step_H\L [16-bit]
; average F_sine= F_sample/(ACCU/step_H\L)
; no jitter if step_H\L is 2^integer
; or
; step_H\L= int(F_sine*T_sample*ACCU+0.5)
; ACCU= ACCU_H:ACCU_L = XL:ACCU_L
ADD ACCU_L, step_L ; 1abc
ADC ACCU_H, step_H ; 1abc
; Test band_idx (a high register, 0=band_3, 1=band_2, 2=band_1)
TST band_Idx ; 1abc
BREQ DOband3 ; 2a/1bc , [5a,4bc]
CPI band_Idx, 1 ; 1bc
BREQ DOband2 ; 2b/1c , [+3b,+2c]
DOband3:
LDI delayCntr, 224 ; 1c
band3Lp:
; 1+(224-1)*3+1 = 671
DEC delayCntr ; 1c
BRNE band3Lp ; 2c/1c , [+671c]
DOband2:
NOP ; 1bc
LDI delayCntr, 28 ; 1bc
band2Lp:
; 2+(28-1)*3+1 = 85
DEC delayCntr ; 1bc
BRNE band2Lp ; 2bc/1bc , [+84bc]
DOband3:
NOP ; 1abc
NOP ; 1abc
; read sample from SRAM table [at XH:XL, XH fixed]]
LD sineSmpl, X ; 2abc
OUT PORTB, sineSmpl ; 1abc
RJMP DDSloop ; 2abc , [+7abc]
; loop cycles: 12a,96b,768c