This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320VC5401 - audio project

Other Parts Discussed in Thread: TMS320VC5401

Hello

I'm working on an audio related project. I have to send a sample to the DAC of my board every 48kHz. The sending is OK as I have written a small code to write to it (two channels). Now I have to setup a 48kHz timer0. I have tried several things and alternatives but I found no source code example.

Could someone please, point me to some examples (in Assembly)?

Also, could someone, please, review this code and see what is wrong with it or at least, give some directions on what to inspect? It shows nothing on the LED pin when it should be toogling at 48kHz

;==============================================================================================================================
; linker directives
;==============================================================================================================================
.SECT "CodeLivesHere" ; main code section in the DSP memory
.GLOBAL CodeStart ; this makes CodeStart global so I can add it as entry point for the code in
; the linker command file

;=============================================================================================================================
; registers address definition (these are for TMS320VC5401)
; please re-check them if the chip changes
;=============================================================================================================================
IMR .SET 0x0000 ; Interrupt Mask Register
IFR .SET 0x0001 ; Interrupt Flag Register

SWWSR .SET 0x0028 ; Software wait state register

TIM .SET 0x0024 ; Timer Register
PRD .SET 0x0025 ; Timer Period Register
TCR .SET 0x0026 ; Timer Control Register

AlawTableAddr .SET 0xFC00 ; A-law table address
MlawTableAddr .SET 0xFD00 ; µ-law table address
SineTableAddr .SET 0xFE00 ; Sine table address
SineTableSize .SET 0x0100 ; size of the sine table

;=============================================================================================================================
; program entry point (defined in the linker script)
;=============================================================================================================================
CodeStart:

;=============================================================================================================================
; constants definition
; these are specific to the board we are using, CPLD takes care of this
;=============================================================================================================================
LeftChannelAddr .SET 0x0001 ; DAC Left Channel address (EXTERNAL MEMORY)
RightChannelAddr .SET 0x0002 ; DAC Right Channel address (EXTERNAL MEMORY)

;=============================================================================================================================
; main routine
;=============================================================================================================================
main:
; Mask off all interrupts, except Timer0
STM #0008h, IFR

; Set stack pointer
STM #2FFEh, SP

; Set internal registers
STM #7FFFh, SWWSR ; Wait state things (default value)

; initializes accumulators
LD #0000h, A
LD #0000h, B

; initializes general purpose registers
STM #0000h, AR0
STM #0000h, AR1
STM #0000h, AR2
STM #0000h, AR3
STM #0000h, AR4
STM #0000h, AR5
STM #0000h, AR6
STM #0000h, AR7

; loads up 0x0000 in the AR0 register
STM #0000h, AR0

; loads up 0x0000 in the AR1 register
STM #0FFFFh, AR1

; init timer
CALL init48kHzTimer0

; loop for the main routine
mainLoop:

; branches to mainLoop
B mainLoop

;=============================================================================================================================
; setup 48kHz timer
;=============================================================================================================================
init48kHzTimer0:

; loads A with 0x0000
LD #0000h, A

; loads the value of TCR in A
LDM TCR, A

;enables TSS bit (stops the timer)
OR #0010h, A

; loads TCR with the value of A
STLM A, TCR

; loads A with 0x7F (127 decimal)
LD #007Fh, A

; loads PRD with the value of A
STLM A, PRD

; loads A with 0x0000
LD #0000h, A

; loads the value of IMR in A
LDM IMR, A

; writes 1 to the 4th bit (Timer0 int) in IMR (without messing other bits)
OR 0x0008, A

; loads IMR with the value of A
STLM A, IMR

; loads A with 0x0000
LD #0000h, A

; loads the value of TCR in A
LDM TCR, A

; loads TDDR with 0x0007 and TRB with 1
OR 0x0027, A

; loads TCR with the value of A (starts the timer)
STLM A, TCR

; returns to main routine
RET

;=============================================================================================================================
; interrupt vectors
;=============================================================================================================================
.SECT "IntVectors"
IntVectors:
.WORD CodeStart, NonMskInt, SoftInt17, SoftInt18, SoftInt19, SoftInt20, SoftInt21, SoftInt22
.WORD SoftInt23, SoftInt24, SoftInt25, SoftInt26, SoftInt27, SoftInt28, SoftInt29, SoftInt30
.WORD ExUsrInt0, ExUsrInt1, ExUsrInt2, Timer0Int, McBSP0RXi, McBSP0TXi, DMA0__int, Timer1Int
.WORD ExUsrInt3, HPI___int, DMA2__int, DMA3__int, DMA4__int, DMA5__int, Interrupt, Interrupt

;=============================================================================================================================
; Interrupt handlers live here
;=============================================================================================================================
ExUsrInt0: ; DAC
ExUsrInt1:
ExUsrInt2: ; DSP Write
ExUsrInt3:
RETE

;=============================================================================================================================
; state machine definitions (use accumulator B)
; probably it is better to use a register for this
;=============================================================================================================================
ledStateON .SET 0x0000
ledStateOFF .SET 0x0001

Timer0Int: ; Timer stuff

; loads A with 0x0000
LD #0000h, A
; loads the value of IFR in A
LDM IFR, A
; loads A with 4th bit high
OR 0x0008, A
; loads TCR with the value of A (clears pending int)
STLM A, IFR

; compare B with ledStateON (ledStateON = 0) and
; executes next 2-word instruction (call) if B == 0
; otherwise runs a NOP
XC 2, BEQ
; calls led_on
call __led_on
; returns to main routine
RETE

; compare B with ledStateOFF (ledStateOFF = 1) and
; executes next 2-word instruction (call) if B != 0
; otherwise, runs a NOP
XC 2, BNEQ
; calls led off
call __led_off
; returns to main routine
RETE

__led_on:
; turns LED on
SSBX XF
; goto next state
LD ledStateOFF, B
; return
RET

__led_off:
; turns LED off
RSBX XF
; goto next state
LD ledStateON, B
; return
RET


Timer1Int:
RETE

SoftInt17: ; Software ints
SoftInt18:
SoftInt19:
SoftInt20:
SoftInt21:
SoftInt22:
SoftInt23:
SoftInt24:
SoftInt25:
SoftInt26:
SoftInt27:
SoftInt28:
SoftInt29:
SoftInt30:
Interrupt: ; Stuff that should never happen
NonMskInt: ; NMI, unused
RETE

McBSP0RXi: ; Serial comms stuff
McBSP0TXi:
RETE

HPI___int: ; More comms stuff
RETE

DMA0__int: ; Whole bunch of DMA
DMA2__int:
DMA3__int:
DMA4__int:
DMA5__int:
RETE


;============================================================================================================================
; program end
;=============================================================================================================================
.END
;=============================================================================================================================