danielt3
Newbie level 2
- Joined
- Apr 26, 2011
- Messages
- 2
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,355
Hello
I have designed a board around the TMS320VC5401 TI DSP.
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
I have designed a board around the TMS320VC5401 TI DSP.
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
Code ASM - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 ;======================================================================================================= ; 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 ;======================