{___________________________________________________________________________ TALKTHRU.ASM ADSP-21020 EZLAB test program Reads the AD1849 audio input left and right samples, then writes the same values back out to the AD1849 and writes the left sample out the AD7769 output channel A. The setup for the AD1849s line or mike input, input gain, anb sample rate can be changed by holding the flag0 button during reset. See the setup_1849 routine for this procedure. The use of the flag input LEDs, flag input push button and the interrupt 2 push button is also demonstrated in the following way: flag 1 LED blinks periodicaly flag 2 LED toggles when the flag 0 button is pressed flag 3 LED toggles when the interrupt 2 button is pressed To assemble this demo from scratch use the following commands: asm21k talkthru ld21k -a ezlab21k talkthru spl21k -a ezlab21k -ram -dm -pm -f B talkthru Author: 14-Feb-92, Steven Cox, Analog Devices Inc. DSP Division ____________________________________________________________________________} { ADSP-21020 System Register bit definitions } #include "def21020.h" {___________________________________________________________________________} .SEGMENT/DM hip_regs; .PORT in_audio_l; { ADSP-2111 HDR0 = left input from AD1849 } .PORT in_audio_r; { ADSP-2111 HDR1 = right input from AD1849 } .PORT out_audio_l; { ADSP-2111 HDR2 = left output to AD1849 } .PORT out_audio_r; { ADSP-2111 HDR3 = right output to AD1849 } .PORT control_0; { ADSP-2111 HDR4 = AD1849 input and gain } .PORT control_1; { ADSP-2111 HDR5 = ad1849 sample rate select } .ENDSEG; .SEGMENT/DM dac_a; .PORT dac_a; .ENDSEG; .SEGMENT/DM dac_b; .PORT dac_b; .ENDSEG; .SEGMENT/DM adc_b; .PORT adc_b; .ENDSEG; .SEGMENT/DM dm_sram; .VAR predicted, previous, error, first_sample, sample; .ENDSEG; {___________________________________________________________________________} .SEGMENT/PM rst_svc; call init_21k; call setup_1849; jump main; .ENDSEG; {___________________________________________________________________________} .SEGMENT/PM irq2_svc; bit tst ustat1 2; { test if AD1849 setup mode is enabled } if not tf jump skip_setup; { for AD1849 setup } bit set ustat1 1; { for AD1849 setup } rti; { for AD1849 setup } skip_setup: { label for AD1849 setup } jump irq2_asserted; .ENDSEG; {___________________________________________________________________________} .SEGMENT/PM irq3_svc; jump irq3_asserted; .ENDSEG; {___________________________________________________________________________} .SEGMENT/PM tmzh_svc; jump timer_hi_prior; .ENDSEG; {___________________________________________________________________________} .SEGMENT/PM pm_sram; main: bit set astat FLG1|FLG2|FLG3; { turn on all LEDs} r5=1; dm(first_sample) = r5; bit set mode1 IRPTEN; { enable global int.} bit set mode2 TIMEN; { timer on! } wait: call wait_flag0; bit tgl astat FLG2; { toggle flag 2 led } jump wait; {___________________________initialize the chip___________________________} init_21k: pmwait =0x1c21; { pgsz=32K,pmwtstates=0,sw.wtstates only} dmwait =0x70a421; { pgsz=32K,bank2_dmwtstates=1,sw.wtstates only} tperiod =0x004c4640;{ timer interrupt at 5 Hz } tcount = tperiod; irptl =0; { clear any pending interrupts} bit set mode2 0x10; nop; read cache 0; bit clr mode2 0x10;{clr cache} { irq2,3 enable, timer enable high priority} bit set imask TMZHI|IRQ2I|IRQ3I; { irq2,3 edge sens, flag 1,2,3,outputs} bit set mode2 IRQ2E|IRQ3E|FLG1O|FLG2O|FLG3O; { turn flag LEDs off} bit clr astat FLG1|FLG2|FLG3; rts; nop; nop; {_________________Wait for Flag 3 button press and release__________________} wait_flag0: if not flag0_in jump wait_flag0; { wait for button press} release: if flag0_in jump release; { wait for button release} rts; nop; nop; {__________________________Timer Interrupt__________________________________} timer_hi_prior: pop sts; { get ASTAT from stack, pushed there by IRQ } bit tgl astat FLG1; { toggle the flag 1 LED} push sts; { restore stack so effect happens after rti } rti; nop; nop; {__________________________IRQ2 Interrupt Vector____________________________} irq2_asserted: pop sts; { get ASTAT from stack, pushed there by IRQ } bit tgl astat FLG3; { toggle the flag 3 LED} push sts; { restore stack so effect happens after rti } rti; nop; nop; {__________________________IRQ3 Interrupt Vector____________________________} irq3_asserted: {.....audio talk through.....} r4 = dm(first_sample); r5 = 0; r4 = r4 + r5; if EQ jump not_first; r4=dm(in_audio_l); { get AD1849 left value } dm(out_audio_l)=r5; { output AD1849 left value } dm(previous) = r4; r6 = r4; dm(first_sample)=r5; rti; nop; nop; not_first: r5 = 2; r4 = dm(in_audio_l); r3 = dm(previous); dm(previous) = r4; r4 = r4 - r3; if GT jump greater_than; r4 =r4 + r5; if LT r4 = -r5; jump continue; greater_than: r4 = r4 - r5; if GT r4 = r5; continue: r4 = r4 + r6; r6 = r4; r3 = dm(previous); r3 = r4 - r3; dm(error) = r3; dm(out_audio_l) = r4; dm(out_audio_r) = r3; rti; nop; nop; {___________________________________________________________________________} {_____________________Change Setup for the AD1849____________________________ Allows one to change the AD1849s setup from the default state using the FLAG and interrupt push buttons. Attributes that can be changed are: line or microphone input source, input gain, and the sample rate. Do not press the IRQ2 button too fast when changing the sample rate. The 2111 reboots and sets up the AD1849 each time the button is pressed, and will get confused if the button is pressed when this is happening. Initialization: flag0 must be setup as an input. irq2 must be enabled. ustat1 bits 0 and 1 are reserved to tell the irq2 if in setup mode. Operation: Press and hold button Press and release button Release button to enter the setup routine Push button to toggle between Line and Microphone input Push button to go to the next state Push button to change the input gain, (8 levels) Push button to go to the next state Push button to change the sample rate, (16 frequencies) Push button to exit the setup routine Microphone Input Gain Default: level 4 => 20dB + level*2*1.5dB = 34dB Line Input Gain Default: level 0 => level*2*1.5dB = 0dB Sample Rates: ( 0) 8 ( 8) 5.5125 ( 1) 16 (default) ( 9) 11.025 ( 2) 27.42857 (10) 18.9 ( 3) 32 (11) 22.05 ( 4) N/A (12) 37.8 ( 5) N/A (13) 44.1 ( 6) 48 (14) 33.075 ( 7) 9.6 (15) 6.615 ___________________________________________________________________________} setup_1849: bit clr ustat1 2; { clear the setup flag state } if not flag0_in jump exit_setup; yes_setup: if flag0_in jump yes_setup; { wait for flag button release } bit set ustat1 2; { set the setup flag } bit clr ustat1 1; { clear the irq2 pressed flag } bit set mode1 IRPTEN; { enable global int.} {....Set the AD1849 input source....} input_wait: bit tst ustat1 1; if tf jump set_input; if flag0_in jump level_state; jump input_wait; set_input: r0=dm(control_0); { read from 2111 hip } r0=btgl r0 by 30; { toggle between line and mic } r1=0xc0ffffff; { mask line gain default } r2=0x24000000; { mask mic gain default } btst r0 by 30; if sz r0 = r0 and r1; { its line so gain is 0 } if not sz r0 = r0 or r2; { its mic so gain is 4 } dm(control_0)=r0; { write to 2111 hip } bit clr ustat1 1; { reset the irq2 pressed flag } jump input_wait; {....Set the AD1849 input level....} level_state: if flag0_in jump level_state; { wait for release of flag button } bit clr ustat1 1; level_wait: bit tst ustat1 1; if tf jump set_level; if flag0_in jump sample_state; jump level_wait; set_level: r0=dm(control_0); { read from 2111 hip } {....bump up lg....} r1=lshift r0 by -24; r1=r1+1; { increment lg } r2=0x00000007; { modulo 8 for lg } r1=r1 and r2; r2=0xf8ffffff; { clear lg field } r0=r0 and r2; r0=r0 or lshift r1 by 24; {....bump up rg....} r1=lshift r0 by -27; r1=r1+1; { increment rg } r2=0x00000007; { modulo 8 for rg } r1=r1 and r2; r2=0xc7ffffff; { clear rg field } r0=r0 and r2; r0=r0 or lshift r1 by 27; {....output to 2111 hip....} dm(control_0)=r0; bit clr ustat1 1; { reset the irq2 pressed flag } jump level_wait; {....Set the AD1849 sample rate....} sample_state:if flag0_in jump sample_state; { wait for release of flag button } bit clr ustat1 1; sample_wait: bit tst ustat1 1; if tf jump set_sample; if flag0_in jump exit_setup; jump sample_wait; set_sample: r0=dm(control_1); { read from 2111 hip } r0=lshift r0 by -16; r0=r0+1; { increment sample rate } r0=lshift r0 by 16; r1=0x000f0000; { modulo 16 } r0=r0 and r1; dm(control_1)=r0; { output sample rate to 2111 hip } bit clr ustat1 1; { reset the irq2 pressed flag } jump sample_wait; exit_setup: if flag0_in jump exit_setup; { wait for release of flag button } bit clr ustat1 2; { clear the setup flag } rts; nop; nop; {___________________________________________________________________________} .ENDSEG;