'---------------------------------------------------------------------------------------- ' 1 6 B i t A / D Device Driver for Analog Devices "AD 7663" / Parallel interface '---------------------------------------------------------------------------------------- ' Name: ANALOG4_DEMO.TIG ' Type: Tiger-BASIC(tm) Source Code ' Purpose: Show & explain the functionality of new device driver: "ANALOG4.TDD" ' ' (C) - Copyright Wilke Technology, P.O.Box 1727, D-52018 Aachen, Germany '---------------------------------------------------------------------------------------- ' ' Thank you for using BASIC Tigers in your products. If you have questions, ideas ' or special needs, please contact your next distributor or the Tiger support team ' and visit our web site: ' ' Wilke Technology GmbH ' The Tiger Support Team ' P.O.Box 1727, D-52018 Aachen, Germany ' Krefelder Str. 147, D-52070 Aachen, Germany ' ' email: support@wilke-technology.com (english) ' email: support@wilke.de (german) ' Phone: +49 (241) 918 900 Mo to Fr, 7:00 to 16:00 (GMT) ' Fax: +49 (241) 918 9068 ' ' New information, new drivers and free downloads see: ' ' www.wilke-technology.com (english) ' www.wilke.de (german) ' ' Sincerely, ' ' Your Tiger Support Team ' '---------------------------------------------------------------------------------------- ' ' This short example program was compiled with TIGER-BASIC 5.01 to run with a AXI-4/4 ' BASIC Tiger Module on the Plug & Play Lab. ' ' 16 Bit AD Converter for BASIC Tiger Applications: Analog Devices "AD 7663" ' using 8-Bit parallel interface ' ' ' ' G e n e r a l ' ' ' ANALOG4.TDD is an easy to apply driver for precision measuring tasks in BASIC Tiger ' systems. ' ' ANALOG4 makes use of the TIMER-A driver to start a automatic sampling process ' at a specified sampling speed. ' ' ANALOG4 supports single and multichannel configurations: ' 1 ADC + analog switch ' or multiple ADCs ' ' ANAOLG4 offers a number of settings through USER function codes to specify measuring ' parameters. ' ' ANALOG4 interfaces AD 7663 and compatible products through an 8-bit parallel ' interface and makes use of the Tiger I/O bus. ' '---------------------------------------------------------------------------------------- ' ' This driver supports single- and multichannel data aquisition systems to be built ' with a BASIC-Tiger and 1 or more AD converters. ' ' Two configurations for multichannel configurations are supported: ' ' ' a) 1 ADC + analog channel switch b) Multiple ADCs ' ======================================= ======================================= ' ' - cost effective, only 1 ADC required - more expensive: 1 ADC per cahnnel ' - sequencial channel sampling - true synchronous sampling on all channels ' - additional signal error coupling - shortest signal path from source to ADC ' - minimum signal distortion ' ' ' !------------! !! ' !--------! Ch-0 ---! AD 7663 !<---->!! ' Ch-0 ---! ! ! 16-bit ADC ! !! ' ! ! !------------! !! ' Ch-1 ---! Analog ! !--------! !! ' ! ! ! AD7663 ! !------------! !! ' Ch-2 ---! Switch ! ! ! Ch-1 ---! AD 7663 !<---->!! ' ! ! ! ! ! 16-bit ADC ! !! ' Ch-3 ---! ! ! 16-bit ! !------------! !! ' ! !-----! ADC !<---> BASIC !! ' Ch-4 ---! ! ! ! Tiger !------------! !! ' ! ! ! ! Ch-2 ---! AD 7663 !<---->!! ' Ch-5 ---! ! ! ! ! 16-bit ADC ! !! ' . ! ! ! ! !------------! !! ' . ! ! !--------! !! ' . ! ! !------------! !! ' . ! ! Ch-3 ---! AD 7663 !<---->!! ' Ch-n ---! ! ! 16-bit ADC ! !! ' ! ! . !------------! !! ' !--------! . !!<---> BASIC-Tiger ' . !! ' . !! ' !------------! !! ' Ch-N ---! AD 7663 !<---->!! ' ! 16-bit ADC ! !! ' !------------! !! ' ' ' ' The driver directly supports up to 4 address lines, allowing up to 16 channels. ' For more channels an easy banking scheme controlled though any I/O pins or extended I/Os ' may be used for a virtual unlimited number of channels. ' '---------------------------------------------------------------------------------------- ' ' ---> D e f a u l t pins for device driver "ANALOG4.TDD" ' ' Data D0...D7 / D8...D15: P60...P67 ' BYTE: P87 ' -RD: P86 ' -CE: P85 ' ' A0: P80 (if ADDR) <-- 0...4 ADDR bits: 1...16 AD converters ' A1: P81 (if ADDR) (or channel switch) ' A2: P82 (if ADDR) ' A3: P83 (if ADDR) ' ' CNVST: P70 Conversion start signal ' ' PD: --> Powerdown may be used through any available I/O pin from ' the BASIC program to minimize power consumption of the ' AD chips during periods of no activity. ' This reduces also chip warming, keeping tolerances in a ' smaller range. ' '---------------------------------------------------------------------------------------- ' ' Setting parameters during INSTALL to individual values: ' ' ' INSTALL_DEVICE #1, "ANALOG4.TDD", p1, p2, p3, p4, ... parameters ' ' ' x <--- BYTE value if no change is wanted: 0 = 00H, EE = 0EEH ' Param-1: 0 Bus port (6 or 8) ' Param-2: 0 CTRL port for signals: -RD, -CE, BYTE (4, 6, 7, 8, 9) ' Param-3: 0EEH Bit position for signal: "-CE" (0...7) ' Param-4: 0EEH Bit position for signal: "-RD" (0...7) ' Param-5: 0EEH Bit position for signal: "BYTE" (0...7) ' ' Param-6: 0 CTRL port for signals: CNVST (4, 6, 7, 8, 9) ' Param-7: 0EEH Bit position for signal: "CNVST" (0...7) ' Param-8: - .. reserved - don't care value ' ' Param-9: 0EEH Speed scaling: 1=no delay, 2...32 short delay for ADC ' ' Param-10: 0EEH No of ADDR lines: 0 => No ADDR line (no more parameters following !) ' 1...4 => 2...16 x AD_7663 = 2...16 AD channels ' 1 => 1 addr line --> 2 x AD_7663 = 2 AD channels ' 2 => 2 addr lines --> 4 x AD_7663 = 4 AD channels ' 3 => 3 addr lines --> 8 x AD_7663 = 8 AD channels ' 4 => 4 addr lines --> 16 x AD_7663 = 16 AD channels ' Param-11: 0EEH Flag: 1 => only 1 "Conversion Start" pulse (multiple ADCs for multiple channels) ' 0 => many conversion start pulses (1 pulse for each channel, ' 1 ADC + analog switch) ' Param-12: 0EEH Port for ADDR signals: A0...A3 ' Param-13: 0EEH Bit position for first of 1...4 ADDR lines. Value range: 0...7 ' Defines the bit no on a port (Parameter-12) where A0 gets positioned ' '---------------------------------------------------------------------------------------- USER_VAR_STRICT ' Check for proper variable declaration #INCLUDE DEFINE_A.INC ' Use general definitions '#INCLUDE UFUNC3.INC ' User Function Codes USER_EPORT ACT, NOACTIVE ' No ePorts here '---------------------------------------------------------------------------------------- ' Definitions for device driver "ANALOG4.TDD" ' ' PUT #DEV_NO, #0, #UFCO_DEV_OPT, p0 ' ' GET #DEV_NO, #0, #UFCI_DEV_OPT, 0, N ' '---------------------------------------------------------------------------------------- #DEFINE UFCO_AD4_CHAN 80H ' Set single channel mode + channel no #DEFINE UFCO_AD4_CNT 84H ' Set no of samples (per channel): ' 0 = endless (only FIFO), n = fixed number (1...32760) #DEFINE UFCO_AD4_PSCAL 85H ' Set prescaler, divides Timer-A frequency ' 0...1 = no prescaler, 2...FFFF (65535) #DEFINE UFCO_AD4_STOP 86H ' Stop AD sampling #DEFINE UFCO_AD4_SCAN 88H ' Set scan mode (multichannel) ' 1,2,3,4 ... channels simultaneously (as channels in system) #DEFINE UFCO_AD4_PSCIMM 8FH ' Set prescaler during running measurement, divides Timer-A freq ' 0...1 = no prescaler, 2...FFFF (65535) '--------------------------------------------------------- #DEFINE UFCI_AD4_STAT_RUN 91H ' Tell us if data aquisition is active: 0 = YES, XX = No #DEFINE UFCI_AD4_STAT_REL 92H ' Tell us the no of not started reload settings (0, 1) #DEFINE UFCI_AD4_STAT_REST 93H ' Tell us the remaining no of samples to be taken '--------------------------------------------------------- '---------------------------------------------------------------------------------------- ' TASK main '---------------------------------------------------------------------------------------- TASK main STRING SAMPLE$ (24K), SAMPLE2$ (24K) LONG N, TIME LONG FLG, REST INSTALL_DEVICE #1, "LCD1.TDD" ' INSTALL_DEVICE #2, "TIMERA.TDD", 3,156 ' 3,156 = 1 kHz INSTALL_DEVICE #2, "TIMERA.TDD", 2, 57 ' 2, 57 = 11 kHz INSTALL_DEVICE #3, "ANALOG4.TDD" ' Use default pinning ' Fill sample strings with dummy data ... just for testing purposes SAMPLE$ = FILL$ ("the quick brown fox jumps over tha lazy dog ", 24K) SAMPLE2$ = FILL$ ("-------", 24K) SAMPLE2$ = "" SET_LEN$ (SAMPLE$, 22) PRINT #1, "<1><27>c<0><240>"; ' Clear screen + cursor off '---------------------------------------------------------------------------------------- ' Set a prescaler value to divide TIMER-A sample frequency: ' ' 0, 1 = no prescaler used ' 2...FFFF = Timer-A frequency is devided by prescaler value before sampling ' ' This setting gets valid with next start of a sampling '---------------------------------------------------------------------------------------- PUT #3, #0, #UFCO_AD4_PSCAL, 15 ' Set prescaler ' PUT #3, #0, #UFCO_AD4_CNT, 777 ' Set default number of measurements PUT #3, #0, #UFCO_AD4_SCAN, 1 ' Set single- / multichannel mode: 1...n-channel '---------------------------------------------------------------------------------------- ' Start sampling ' -------------- ' To start the sampling process, the PUT instruction is used to pass a ' destination BUFFER (String) for ANALOG data beeing aquired. ' ' As the sampling is done in a SYSTEM task in the background, it is necessary to ' use a fully STATIC buffer (String) - which always exists - as the destination. ' In contrast, a local string in a subroutine would not be accepted as the live ' time of such strings ends with exiting the subroutine. ' ' STATIC buffers: GLOBAL STRINGs ' TASK LOCAL STRINGs ' ' More parameters may be specified in the PUT instruction: ' ' PUT #17, XYZ$, , ' Start analog sampling into XYZ$ ' -stat- -any- -any- ' ' ' -stat- = must be s t a t i c variable ! ' -any- = any kind of integer value: variable, constant or expression ' ' = optional: Destination offset in string ' Specifies the location of the first sample to be ' written into the destination string. ' Default offset = 0 ' ' = optional: Specify no of samples to be taken (1 sample = 1 WORD = 16 bit) ' ' Value = 0 ---> Sample as many times as possible ' until string is full or has only left ' 1 byte of free space. ' '---------------------------------------------------------------------------------------- ' DESTIN$, , ' -static- -any- -any- <--- Var / const type: STATIC or ANYTHING ' PUT #3, SAMPLE$, 0 ' PUT #3, SAMPLE$, 0, 0 PUT #3, SAMPLE$, 49, 3000 ' PUT #3, SAMPLE$ '---------------------------------------------------------------------------------------- ' For continuous + endless sampling process a second buffer + settings may be specified ' ' PUT #17, #1, R1$, , ' Set R1$ as reload buffer ' -stat- -any- -any- ' ' ' Note: The reload setting is written into secondary address = 1 ' ' If a reload buffer is specified through a PUT instruction as shown above, the driver ' automatically will continue to write into the RELOAD buffer, as soon as the initial ' sampling process as started has been completed (Count is fulfilled, or string is FULL). ' ' As soon as the sampling process has started to use the RELOAD buffer, specified in the ' reload setting (see above), another reload setting may be specified to build ' an endless chain of RELOADs for endless (or very long) sampling. ' ' Note: Before a subsequent RELOAD setting can be specified, check the driver status ' to make sure that no previous RELOAD setting is waiting to be used. ' ' Typical scheme for endless sampling: ' ' START sampling to BUF1$ ' Set reload buffer to BUF2$ ' ' Wait for reload buffer BUF2$ beeing used ' Use DATA in BUF1$ as needed ' Set reload buffer to BUF1$ ' ' Wait for reload buffer BUF1$ beeing used ' Use DATA in BUF2$ as needed ' Set reload buffer to BUF2$ ' ' '---------------------------------------------------------------------------------------- ' RUN_TASK SET_PRESC ' <----- Task could be started for testing LOOP 999999999 ' <------------ many loops ---------------> '---------------------------------------------------------------------------------------- ' Ask if a data aquisition is running now '---------------------------------------------------------------------------------------- GET #3, #0, #UFCI_AD4_STAT_RUN, 1, FLG ' Aquisition running? 0 = YES, FF = no '---------------------------------------------------------------------------------------- ' Check the no of not started RELOAD settings (0, 1) '---------------------------------------------------------------------------------------- GET #3, #0, #UFCI_AD4_STAT_REL, 1, N ' <-- No. of RELOAD settings IF N = 0 THEN ' DESTIN$, , ' -static- -any- -any- <--- Var / const type: STATIC or ANYTHING PUT #3, #1, SAMPLE2$, 17, 1000 ENDIF '---------------------------------------------------------------------------------------- ' Get the no of remaining samples '---------------------------------------------------------------------------------------- GET #3, #0, #UFCI_AD4_STAT_REST, 0, REST ' <-- Remaining samples: 0...nnnn PRINT #1,"<1BH>A<0><0><0F0H> Flag =";FLG ;" " PRINT #1,"<1BH>A<0><1><0F0H>Reloads =";N ;" " PRINT #1,"<1BH>A<0><2><0F0H> Remain =";REST;" " WAIT_DURATION 100 ENDLOOP END '---------------------------------------------------------------------------------------- ' Task for setting the prescaler while measurement is running '---------------------------------------------------------------------------------------- TASK SET_PRESC LOOP 999999999 ' <----------- many loops -----------> PUT #3, #0, #UFCO_AD4_PSCIMM, 10 ' <- Prescaler i m m e d i a t e l y PRINT #1, "<1BH>A<0><3><0F0h> 10 "; WAIT_DURATION 2000 PUT #3, #0, #UFCO_AD4_PSCIMM, 50 ' <- Prescaler i m m e d i a t e l y PRINT #1, "<1BH>A<0><3><0F0h> 50 "; WAIT_DURATION 5000 PUT #3, #0, #UFCO_AD4_PSCIMM, 300 ' <- Prescaler i m m e d i a t e l y PRINT #1, "<1BH>A<0><3><0F0h> 300"; WAIT_DURATION 10000 ENDLOOP ' ---> many loops END