'----------------------------------------------------------------------------------------- ' Name: REAL_TO_BAM_CONVERSION.TIG ' Type: TIGER-BASIC(tm) Source Code ' ' Purpose: Converts a Tiger 64-bit REAL value into a 16-bit BAM 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 Tiger 64-bit REAL value into a 16-bit BAM (Binary ' Angle Measurement) system value. Valid values for the BAM system are between 0 and 360. ' ' The program uses one global array holding the numerical values for each of the 16 BAM ' system bit, which is initialized calling the subroutine BAM_INIT. ' ' For the conversion itself, there is a subroutine REAL2BAM, which is called with ' 2 parameters: ' Input: RealValue = REAL variable containing the value to be converted ' (can be any variable name, RealValue is just example) ' ' Output: BAMValue = WORD variable containing the converted value in BAM format ' (can be any variable name, RealValue is just example) ' '......................................................................................... ' ' In this example program the 16-bit BAM value is additionally outputted on ' 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|L84|L83|L82|L81|L80 ' '----------------------------------------------------------------------------------------- USER_VAR_STRICT USER_EPORT 1,0 ' disable EPort system (only for port 6 output) ARRAY BAM_BITVALUE(16) OF REAL ' global array for BAM bit values TASK MAIN ' begin task MAIN REAL RealValue ' REAL value to be converted WORD BAMValue ' 16-bit BAM value BYTE HiByte, LoByte ' Bytes for port output DIR_PORT 6, 0 ' Port 6 is output (Low BYTE of BAM WORD) DIR_PORT 8, 0 ' Port 8 is output (Hi BYTE of BAM WORD) CALL BAM_INIT ' initialize BAM bit value array RealValue = 137.10 ' example value to be converted ' RealValue = 180.0 ' example value to be converted ' RealValue = 360.0 ' example value to be converted CALL Real2BAM (RealValue, BAMValue) ' call conversion REAL --> BAM HiByte = BAMValue SHR 8 ' extract high byte from BAM value LoByte = BAMValue BITAND 255 ' extract low byte from BAM value OUT 8, 255, HiByte ' output high byte on Tiger port 8 OUT 6, 255, LoByte ' output low byte ob Tiger port 6 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 real value to a BAM 16-bit WORD '----------------------------------------------------------------------------------------- SUB Real2BAM (REAL InValue; VAR WORD OutValue) ' begin subroutine for conversion REAL LocalReal ' holp variable, can be altered BYTE B ' counter for bit position OutValue = 0 ' initialize output value LocalReal = InValue ' copy input value to help var IF LocalReal = 360.0 THEN ' Special case for BAM: all bits to 0 when LocalReal = 0.0 ' angle value is either 0 or 360 ENDIF ' FOR B = 15 TO 0 STEP -1 ' loop over all 16 bits IF LocalReal >= BAM_BITVALUE(B) THEN ' if input value >= BAM bit value LocalReal = LocalReal - BAM_BITVALUE(B) ' subtract bit value from input value OutValue = OutValue + EXP(2, B) ' set bit in output value by adding 2^bit ENDIF ' NEXT ' next bit END ' end subroutine for conversion