/* lab1.c -- Simple C program to run on dSPACE boxes. Rich Kozick, 1997 */ #include "brtenv.h" /* basic real-time environment */ #define TS 1.25e-3 /* Sample spacing */ #define TMR0 0 /* Use timer0 for exec-time trace */ float f, y; /* input/output variables */ 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() { 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 */ f = ds1102_ad(1); /* read input from ADC channel 1 */ y = f; /* output = input */ ds1102_da(1, y); /* 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() { 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 */ while (*error == NO_ERROR); /* background process */ ds1102_da(1, 0.0); /* on error clear DAC channel 1 */ }