'----------------------------------------------------------------------------------------- ' Name: BAM_TO_REAL_CONVERSION.TIG ' Type: TIGER-BASIC(tm) Source Code ' ' Purpose: Converts a 16-bit BAM value into a Tiger 64-bit REAL value ' ' (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 ' ' '----------------------------------------------------------------------------------------- ' ' Example program for converting a 16-bit BAM (Binary Angle Measurement) system value ' into a Tiger 64-bit REAL value. ' ' The program uses one global array holding the numerical values for each of the 16 BAM ' system bits, which is initialized calling the subroutine BAM_INIT. ' ' For the conversion itself, there is a subroutine BAM2REAL, which is called with ' 3 parameters: ' ' Input: HiBytePort = Tiger Port holding bits 8..15 of the BAM value ' (high byte, possible ports: 6, 7, 8, 9, 10) ' ' LoBytePort = Tiger Port holding bits 0..7 of the BAM value ' (low byte, possible ports: 6, 7, 8, 9, 10) ' ' Output: RealValue = REAL variable containing the converted BAM value ' (can be any variable name, RealValue is just example) ' ' * Ports 7, 9 and 10 are only possible when using TINY-Tiger 2. ' '......................................................................................... ' ' In this example program the 16-bit BAM value is read from the Tiger ports 6 and 8 ' in the following order: ' ' Bit-No.: 15| 14| 13| 12| 11| 10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0 ' Tiger-Pin: L87|L86|L85|L84|L83|L82|L81|L80|L67|L66|L65|L64|L63|L62|L61|L60 ' '----------------------------------------------------------------------------------------- USER_VAR_STRICT USER_EPORT 1,0 ' disable EPort system (only for port 6 input) ARRAY BAM_BITVALUE(16) OF REAL ' global array for BAM bit values TASK MAIN ' begin task MAIN REAL RealValue ' REAL value to be converted DIR_PORT 6, 255 ' Port 6 is input (Low BYTE of BAM WORD) DIR_PORT 8, 255 ' Port 8 is input (Hi BYTE of BAM WORD) CALL BAM_INIT ' initialize BAM bit value array CALL BAM2Real (8, 6, RealValue) ' call conversion BAM --> REAL ' ' proceed working with real value ' END ' end task MAIN '----------------------------------------------------------------------------------------- ' Subroutine initializing the array with the BAM format bit values '----------------------------------------------------------------------------------------- SUB BAM_INIT ' begin subroutine for initialization BAM_BITVALUE(15) = 180.0 ' Value for MSB (Bit 15) BAM_BITVALUE(14) = 90.0 BAM_BITVALUE(13) = 45.0 BAM_BITVALUE(12) = 22.5 BAM_BITVALUE(11) = 11.25 BAM_BITVALUE(10) = 5.625 BAM_BITVALUE( 9) = 2.8125 BAM_BITVALUE( 8) = 1.406 BAM_BITVALUE( 7) = 0.703 BAM_BITVALUE( 6) = 0.3515 BAM_BITVALUE( 5) = 0.1757 BAM_BITVALUE( 4) = 0.088 BAM_BITVALUE( 3) = 0.0439 BAM_BITVALUE( 2) = 0.0219 BAM_BITVALUE( 1) = 0.0109 BAM_BITVALUE( 0) = 0.0055 ' Value for LSB (Bit 0) END ' end subroutine for initialization '----------------------------------------------------------------------------------------- ' Subroutine converting a BAM 16-bit WORD to a real value '----------------------------------------------------------------------------------------- SUB BAM2Real (BYTE HiBytePort, LoBytePort; VAR REAL OutValue) ' begin subroutine for conversion REAL LocalReal ' help variable, can be altered WORD BAMVal ' variable holding BAM value BYTE HiByteVal, LoByteVal ' help variables holding BAM high and low bytes BYTE B ' counter for bit position IN LoBytePort, LoByteVal ' Real Port holding BAM Low Byte (Bits 0..7) IN HiBytePort, HiByteVal ' Real Port holding BAM High Byte (Bits 8..15) BAMVal = HiByteVal * 256 + LoByteVal ' calculate 16-bit BAM value LocalReal = 0.0 ' initialize real value FOR B = 15 TO 0 STEP -1 ' loop over all 16 bits IF BIT(BAMVal, B) = 1 THEN ' if bit is set LocalReal = LocalReal + BAM_BITVALUE(B) ' add bit value for this position to real value ENDIF ' NEXT ' next bit OutValue = LocalReal ' write result to parameter var END ' end subroutine for conversion