/* Data acquisition program for two microphones and a speaker. Rich Kozick, Spring 1997 */ #include "brtenv.h" /* basic real-time environment */ #include "math.h" #define TS 1e-4 /* Sample spacing */ #define TMR0 0 /* Use timer0 for exec-time trace */ #define PER 1e4 /* Pulse period (samples) */ #define DUR 1e2 /* Pulse duration (samples) */ #define PFREQ 500 /* Sinusoid frequency, in hertz */ float mic1, mic2, out, freq; long per_cnt=0, pulse_flag=0, dur_cnt=0; float exec_time; /* execution time */ unsigned long count0; /* timer0 time count */ /* error flag for CHKERR31 at last dual-port memory location */ int *error = (int *) (DP_MEM_BASE + DP_MEM_SIZE - 1); /* timer0 interrupt service routine */ isr_t0() { register int i; /* Counter */ begin_isr_t0(*error); /* delete if overload check not needed */ service_trace(); /* call TRACE service routine */ count0 = count_timer(TMR0); /* get current time count of timer0 */ ds1102_ad_start(); /* start DS1102 ADCs */ mic1 = ds1102_ad(1); /* read input from ADC channel 1 */ mic2 = ds1102_ad(2); /* read input from ADC channel 2 */ if (++per_cnt == PER) { pulse_flag = 1; dur_cnt = 0; per_cnt = 0; } if (pulse_flag) { if (++dur_cnt <= DUR) out = 0.1*sin(freq*dur_cnt); else { pulse_flag = 0; out = 0; } } else out = 0; ds1102_da(1, out); /* write output to DAC channel 1 */ exec_time = time_elapsed(TMR0, count0); /* get execution-time */ end_isr_t0(); /* delete if overload check not needed */ } main() { register int i; init(); /* init DAC mode, calibrate ADCs */ *error = NO_ERROR; /* initialize overload error flag */ dp_mem[0].f = 0.0; /* init 1st dp-mem loc for type float */ start_isr_t0(TS); /* initialize sampling clock timer */ freq = 2*3.14159*PFREQ*TS; while (*error == NO_ERROR); /* background process */ ds1102_da(1, 0.0); /* on error clear DAC channel 1 */ }