'---------------------------------------------------------------------------------------- ' Name: PLSOUT_Demo_1_00j.TIG ' Type: Tiger-BASIC(tm) Source Code ' Purpose: Demo for device driver "PLSOUT1.TDD", driver version 1.00j ' ' (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 ' '---------------------------------------------------------------------------------------- ' ' Programmable pulse generator for BASIC-Tiger(R) ' ' This demo program is written to be used directly on the Tiger Plug & Play Lab. ' An oscilloscope and the LCD are used to watch results. ' ' ' G e n e r a l : ' ' PLSOUT1.TDD is a 1-channel pulse genarator with settable DUTY / CYCLE values ' and optional count setting. ' ' Output pin = L86 ' ' The pulse output cycle always starts with the "DUTY" period (low signal level). ' The rest of the cycle is in high signal state. - See below: ' ' ' :<------------CYCLE--------------->. ' : . ' : !-----------------------! !------- ... ' :<--DUTY-->! ! ! ' : ! ! ! Output signal ' ---------:----------! !----------! ' : . . ' : . . ' ' ' If a number of pulses is specified (count), signal level is low after all pulses ' beeing issued. ' '---------------------------------------------------------------------------------------- ' ' Installing the driver: ' ' ' INSTALL_DEVICE #22, "PLSOUT1.TDD", p1, p2 ' ' ' ' !<--- Parameter no. ' ! ' ! !<---- Value to skip parameter ' ! ! 0 = 00h, EE= 0EEH, - = skipping not possible ' ! ! ' p1 - ' Timebase range: 0 = not installed ' ' 1, 2, 3 = Timebase as specified below ' ' ' p2 EE ' Mode of operation: ' ' 0: endless=full speed, COUNT=LONG up to 25 kHz ("A"-type modules) ' ' 1: endless=full speed, COUNT=WORD up to 50 kHz " ' ' 2: - unused - ' ' 3: NON endless, CNT=WORD, DUTY+CYCLE, 256 byte buffer, up to 25 kHz ' ' 4: - unused - ' ' 5: NON endless, CNT=WORD, DUTY+CYCLE+RANGE, 256 byte buffer, up to 25 kHz ' ' ' ' Timebase ranges (Standard "A"-type Tiger modules) ' ' Range: ' <----Units---> <--slowest--> ' Steps abs-MAX max speed max speed <--Pulses---> ' Mode-1 Mode-0+2+3 CYCLE=FFFF ' (us)| (Hz) | (Hz) | (Hz+CYCLE) |(Hz+CYCLE) |(Hz+CYCLE) | (Hz ms) ' --+----+----------+----------+------------+-----------+-----------+-------------- ' 1 |0.4 |2,500,000 |1,250,000 |119,047 21 |50,000 50 |25,000 100 |38.46 = 26 ms ' 2 |1.6 | 625,000 | 312,500 |104,167 6 |52,083 12 |25,000 25 | 9.61 = 104 ms ' 3 |6.4 | 156,255 | 78,127 | 78,127 2 |52,085 3 |26,043 6 | 2.39 = 418 ms ' '---------------------------------------------------------------------------------------- ' ' T h e m o d e s: ' ' ' Mode 0: 1. Number of pulses ' 2. DUTY time according to current timebase range ' 3. CYCLE time according to current timebase range ' '........................................................................................ ' ' Mode 1: 1. Number of pulses ' 2. DUTY time according to current timebase range ' 3. CYCLE time according to current timebase range ' ' Special values: ' ' Number = 0 --> endless ! ' Number = 1...nnnnn --> put out nnnn pulses ! ' Number = -1 --> stop currently running pulse output ' ' Note: CYCLE > DUTY must always be fulfilled, otherwise no pulse output takes place. ' '........................................................................................ ' ' Mode 3: Operation from a buffer of up to 32 pulse groups to be stored. ' ' Pulse groups get issued in the same sequence as written into the buffer: ' ' Data structure: ' ' <1st WORD> <2nd WORD> <3rd WORD> <4th WORD> ' ' Count: 1...FFFF DUTY CYCLE - unused - ' 0=10000H 1...FFFE 2...FFFF ' ' Note: DUTY < CYCLE ! ' ' 1.) Shortest DUTY is limited (e.g. to 50usec duration at 25 kHz repeat frequency) ' 2.) 1st pulse of new group immediately comes correctly, immediately correct DUTY ! ' '........................................................................................ ' ' Mode 5: - CNT=WORD, DUTY+CYCLE+RANGE, buffer, up to 20 kHz ' ' Structure of data set: ' ' <1st WORD> <2nd WORD> <3rd WORD> <4th WORD> ' ' Count: 1...FFFF DUTY CYCLE 1st byte=RANGE: 0,1,2,3 ' 0=10000H 1...nnnn 2...nnnn 2nd byte= - unused - ' ' Note: DUTY < CYCLE ! ' ' Here used ring buffer is always 256 bytes ' '---------------------------------------------------------------------------------------- ' ' --> USER s t a t u s r e q u e s t s (CTRL-IN): ' ' GET #n, #0, #FC, N ' ' #0 --> Secondary address = 0 ' ' <-----FC----> ' UFCI_OBU_FILL 21H -> Output buffer: Filling --> No. of data sets in buffer ' UFCI_OBU_FREE 22H -> Output buffer: Free --> Space for "No. of data sets" ' UFCI_OBU_VOL 23H -> Output buffer: Total size --> No. of data sets ' ' UFCI_DEV_VERS 63H -> Device driver version: e.g. 1016 = 1.01g ' ' UFC_DEV_OSTAT0 B0H -> Output state: get current T O T A L countdown remaining pulses ' 0 -> last period is processed ' 1 -> 1 pulse left after currently running period ' n -> ... etc. ' -1 -> pulse output already finished ! ' ' UFC_DEV_OSTAT1 B1H -> Output state: get current remain countdown of T H I S group ' Remain count of current pulse group (Modes 0,1,3,5) ' 0 -> last period is processed ' 1 -> 1 pulse left after currently running period ' n -> ... etc. ' -1 -> pulse output already finished ! ' ' ' Mode 3, 5 and 6: ' ================ ' Only the number of remaining pulses in T H I S ' pulse group is reported. Needed for e.g. ' extending (see: --> BLKOUT: ' ' PUT #9, #0, #UFCO_DEV_OOPT1, number ' UFCO_DEV_OOPT1 ( w) Change akt. pulse-count: soft-stop / instant-stop ' 1...nnnn = stop after X pulses (soft-stop) ' -1 = stop the current pulse right now ' ' To see A L L pulses in modes 3, 5 and 6 still to ' be sended you use: ' ' GET #9, #0, #UFC_DEV_OSTAT0, 0, VARIABLE ' ' UFC_DEV_OSTAT2 B2H -> Pulse generator state: 0=running, -1=STOPPED ' ' all modes: ' ' PUT #9, #0, #UFC_DEV_OSTAT2, 0, STAT ' ' Values: STAT = 0 --> still running ' STAT = -1 --> is stopped (not running) '---------------------------------------------------------------------------------------- USER_VAR_STRICT ' variables have to be declared #INCLUDE UFUNC3.INC ' get symbols for device driver user functions TASK MAIN ' begin task MAIN LONG FREESPACE, NOW, N ' some variables INSTALL_DEVICE #1, "LCD1.TDD" ' install LCD driver ' INSTALL_DEVICE #9, "PLSOUT1.TDD", 1, 0 ' time base range (1,2,3), Mode: 0,1,3,5 INSTALL_DEVICE #9, "PLSOUT1.TDD", 1, 3 ' time base range (1,2,3), Mode: 0,1,3,5 PUT #9, "07 00 00 00 22 00 33 00"% WAIT_DURATION 99 LOOP 99999999 PRINT #1, "<1>Test #1 now" WAIT_NEXT 10 ' show pulse groups every 10 ms LOOP 100*5 ' loop to make pulse groups visible on analog scope for 10 seconds ' ' Pulse group 1 Pulse group 2 Pulse group 3 ' <---------------------> <---------------------> <---------------------> ' COUNT DUTY CYCLE FREE COUNT DUTY CYCLE FREE COUNT DUTY CYCLE FREE ' <---> <---> <---> <---> <---> <---> <---> <---> <---> <---> <---> <---> PUT #9, "01 00 70 00 77 01 01 00 02 00 7F 00 80 00 01 00 01 00 90 01 20 02 01 00"% ' pulse output on L86 WAIT_NEXT ENDLOOP '---------------------------------------------------------------------------------------- ' Approx. 5 seconds of pulses issued. ' Use oscilloscope setting: 0.5 ms per div + trigger on falling edge '---------------------------------------------------------------------------------------- PRINT #1, "Test #2 now" NOW = TICKS () WHILE DIFF_TICKS (NOW) < 5000 ' let's see for 10 seconds groups of pulses with 2 kHz GET #9, #0, #UFCI_OBU_FREE, 0, FREESPACE ' get free space of buffer IF FREESPACE > 3 THEN ' check: enough space for 3 more pulse groups? PUT #9, "& ' pulse output on L86 01 00 60 01 E2 04 FF FF& ' <- pulse group 1 02 00 7F 03 E2 04 FF FF& ' <- pulse group 2 01 00 90 02 E2 04 01 00"% ' <- pulse group 3 ' <---> <---> <---> <---> ' ' COUNT DUTY CYCLE FREE ' ELSE ' WAIT_DURATION 10 ' just wait here and give CPU time to other tasks (if existing) ENDIF ' ENDWHILE ' '---------------------------------------------------------------------------------------- ' Approx. 10 seconds of pulses issued. ' Use a storage scope and see the effect of the ERASE (buffer) function. ' ' "UFCO_OBU_ERASE" erases the buffer '---------------------------------------------------------------------------------------- WAIT_NEXT 100 ' show every 100 ms PRINT #1, "Test #3 now" ' NOW = TICKS () ' N = 0 ' WHILE DIFF_TICKS (NOW) < 10000 ' let's see for 10 seconds groups of pulses with 2 kHz N = N + 1 ' LOOP 3 ' write 3 x 9 pulse groups into device driver buffer PUT #9, "& ' pulse output on L86 02 00 60 01 E2 04 FF FF& ' <- pulse group 1 02 00 60 01 E2 04 FF FF& ' <- pulse group 2 02 00 60 01 E2 04 FF FF& ' <- pulse group 3 02 00 60 01 E2 04 FF FF& ' <- pulse group 4 02 00 60 01 E2 04 FF FF& ' <- pulse group 5 02 00 60 01 E2 04 FF FF& ' <- pulse group 6 02 00 60 01 E2 04 FF FF& ' <- pulse group 7 02 00 60 01 E2 04 FF FF& ' <- pulse group 8 02 00 60 01 E2 04 FF FF"% ' <- pulse group 9 ' <---> <---> <---> <---> ' ' COUNT DUTY CYCLE FREE ' ENDLOOP ' LOOP N ' just a moment of delay ... ENDLOOP ' PUT #9, #0, #UFCO_OBU_ERASE, 0 ' erase output buffer now WAIT_NEXT ' and wait a moment ENDWHILE ' '---------------------------------------------------------------------------------------- ' Test 4: Issues many slow pulses and displays the no. of remaining pulses on the LCD. ' After 4 seconds the buffer will be erased, reducing the no. of remaining ' pulses spontaniously. ' After 4 more seconds the pulse generator will be stopped setting the ' no. of remaining pulses to 0. '---------------------------------------------------------------------------------------- PUT #9, #0, #UFCO_OBU_ERASE, 0 ' erase output buffer first PRINT #1, "<1>Test #4 now" ' PUT #9, "& ' pulse output on L86 88 03 60 01 77 77 00 00& ' <- pulse group 1 61 FF 60 01 77 77 00 00& ' <- pulse group 2 61 FF 60 01 77 77 00 00& ' <- pulse group 3 61 FF 60 01 77 77 00 00& ' <- pulse group 4 61 FF 60 01 77 77 00 00"% ' <- pulse group 5 ' <---> <---> <---> <---> ' ' COUNT DUTY CYCLE FREE ' WAIT_NEXT 100 ' show results on LCD every 100 ms NOW = TICKS () ' WHILE DIFF_TICKS (NOW) < 4000 ' phase 1: 4 seconds CALL SHOW_PULSES () ' WAIT_NEXT ' ENDWHILE ' PUT #9, #0, #UFCO_OBU_ERASE, 0 ' erase output buffer now PRINT #1,"<1BH>A<13><2><0F0H>erased"; NOW = TICKS () ' WHILE DIFF_TICKS (NOW) < 4000 ' phase 2: 4 seconds CALL SHOW_PULSES () ' WAIT_NEXT ' ENDWHILE ' PUT #9, #0, #UFCO_DEV_OOPT1, 1 ' STOP pulse output now (set pulse count to 1) PRINT #1,"<1BH>A<13><1><0F0H>STOPPED"; NOW = TICKS () ' WHILE DIFF_TICKS (NOW) < 4000 ' phase 3: 4 seconds CALL SHOW_PULSES () ' WAIT_NEXT ' ENDWHILE ' '---------------------------------------------------------------------------------------- ' Test 5: Generate pulse groups in mode 5 with different time range settings '---------------------------------------------------------------------------------------- PUT #9, #0, #UFCO_OBU_ERASE, 0 ' erase output buffer first PRINT #1, "<1>Test #5 now" ' WAIT_NEXT 10 ' issue pulses every 100 ms LOOP 1000 ' PUT #9, "& ' pulse output on L86 02 00 60 00 80 00 01 00& ' <- pulse group 1: range 1 02 00 60 00 80 00 02 00& ' <- pulse group 2: range 2 02 00 60 00 80 00 03 00"% ' <- pulse group 3: range 3 ' <---> <---> <---> <---> ' ' COUNT DUTY CYCLE FREE ' WAIT_NEXT ' PUT #9, #0, #UFCO_OBU_ERASE, 0 ' erase output buffer now ENDLOOP ' '---------------------------------------------------------------------------------------- ' Test 6: (in mode 5) -> Write 3 pulse groups, ' -> Soft stop of pulse output ' -> Soft restart with existing data (a) ' ' -> Soft restart with additional data (b) '---------------------------------------------------------------------------------------- PRINT #1, "<1>Test #6 now" ' LOOP 10 + 999999999 ' LOOP 100 + 999999999 ' PRINT #1, "."; PUT #9, #0, #0, "& ' pulse output on L86 08 00 70 00 80 00 03 00& ' <- pulse group 1: range 3 04 00 50 00 80 00 03 00& ' <- pulse group 2: range 3 02 00 30 00 80 00 03 00"% ' <- pulse group 3: range 3 ' <---> <---> <---> <---> ' ' COUNT DUTY CYCLE FREE ' WAIT_DURATION 2 ' wait a moment PUT #9, #0, #UFCO_DEV_OOPT1, 0 ' soft stop '' PUT #9, #0, #UFCO_DEV_OOPT1, 30 ' re-trigger ' WAIT_DURATION 20 ' wait a moment ' PUT #9, "" ' restart with existing data WAIT_DURATION 200 ' ENDLOOP ' LOOP 100 PUT #9, "& ' pulse output on L86 05 00 60 00 80 00 02 00& ' <- pulse group 1: range 2 02 00 60 00 80 00 01 00"% ' <- pulse group 2: range 1 ' <---> <---> <---> <---> ' ' COUNT DUTY CYCLE FREE ' ENDLOOP ' ENDLOOP ' '---------------------------------------------------------------------------------------- ' Test 7: Generate pulse groups in mode 6 with DIR pin output '---------------------------------------------------------------------------------------- PRINT #1, "<1>Test #7 now" ' WAIT_NEXT 10 ' issue pulses every 100 ms LOOP 1000 ' PUT #9, "& ' pulse output on L86 02 00 60 00 80 00 01 00& ' <- pulse group 1: range 1 02 00 60 00 80 00 02 01& ' <- pulse group 2: range 2 02 00 60 00 80 00 03 00"% ' <- pulse group 3: range 3 ' <---> <---> <---> <---> ' ' COUNT DUTY CYCLE FREE ' PRINT #1, "."; ' WAIT_NEXT ' PUT #9, #0, #UFCO_OBU_ERASE, 0 ' erase output buffer now ENDLOOP ' ENDLOOP ' END ' '---------------------------------------------------------------------------------------- ' Show some information on LCD '---------------------------------------------------------------------------------------- SUB SHOW_PULSES () ' LONG NO_OF_PULSES, BUF_LEN ' GET #9, #0, #UFCI_DEV_OSTAT0, 0, NO_OF_PULSES ' read no. of pulses remaining GET #9, #0, #UFCI_OBU_FILL, 0, BUF_LEN ' read buffer length PRINT #1, "<1BH>A<0><1><0F0H>Pls:"; NO_OF_PULSES; " " PRINT #1, "Buf:"; BUF_LEN; " " END '