![]() |
RTXI 1.3
|
00001 /* 00002 * Antialiasing Analog Output Demo 00003 * Part of Comedilib 00004 * 00005 * Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org> 00006 * 00007 * This file may be freely modified, distributed, and combined with 00008 * other software, as long as proper attribution is given in the 00009 * source code. 00010 */ 00011 00012 /* Not functional */ 00013 00014 /* 00015 * Requirements: an analog output subdevice that is capable 00016 * of ansynchronous output. 00017 * 00018 * Normally, the resolution of analog output channels is limited by 00019 * the resolution of the D/A converter. However, if you limit the 00020 * bandwith of the D/A converter by using a low-pass filter, you 00021 * can trade some of the bandwidth for additional resolution. This 00022 * is done by changing the output rapidly between two adjacent 00023 * values: a signal of an alternating 0,1,0,1,0,1 sequence will 00024 * look like 0.5 after an appropriate low-pass filter. 00025 * 00026 * The disadvantage, of course, is that you lose bandwidth. Worse, 00027 * the simple technique demonstrated here will cause predictable 00028 * noise in the stop band. More complicated techniques will allow 00029 * you to tune the spectrum of the noise in the stop band. 00030 */ 00031 00032 #include <stdio.h> 00033 #include <comedilib.h> 00034 #include <fcntl.h> 00035 #include <unistd.h> 00036 #include <stdlib.h> 00037 #include <errno.h> 00038 #include <getopt.h> 00039 #include <ctype.h> 00040 #include "examples.h" 00041 00042 void ao_antialias(unsigned int data); 00043 00044 comedi_t *device; 00045 00046 int main(int argc, char *argv[]) 00047 { 00048 lsampl_t data; 00049 int ret; 00050 struct parsed_options options; 00051 00052 init_parsed_options(&options); 00053 parse_options(&options, argc, argv); 00054 00055 device = comedi_open(options.filename); 00056 if(!device){ 00057 comedi_perror(options.filename); 00058 exit(0); 00059 } 00060 00061 data = options.value; 00062 if(options.verbose){ 00063 printf("writing %d to device=%s subdevice=%d channel=%d range=%d analog reference=%d\n", 00064 data, options.filename, options.subdevice, options.channel, options.range, options.aref); 00065 } 00066 00067 ret = comedi_data_write(device, options.subdevice, options.channel, options.range, options.aref, data); 00068 if(ret<0){ 00069 comedi_perror(options.filename); 00070 exit(0); 00071 } 00072 00073 printf("%d\n", data); 00074 00075 ao_antialias((1000<<16)+1000); 00076 00077 return 0; 00078 } 00079 00080 00081 void ao_antialias(unsigned int data) 00082 { 00083 unsigned int hibits=data>>16; 00084 unsigned int lobits=data&0xffff; 00085 int i; 00086 unsigned int acc; 00087 00088 acc=0; 00089 for(i=0;i<100;i++){ 00090 acc+=lobits; 00091 printf("%d\n",hibits+(acc>>16)); 00092 acc&=0xffff; 00093 } 00094 } 00095