File indexing completed on 2024-04-06 12:19:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <iostream>
0012 #include <iomanip>
0013 #include <fstream>
0014 #include <sstream>
0015 #include <cstring>
0016 #include <math.h>
0017 #include <stdio.h>
0018
0019 using namespace std;
0020
0021
0022 void IEEE32toDSP(float f, short int & DSPmantissa, short int & DSPexp);
0023
0024
0025 int main()
0026 {
0027
0028 float ST = 30.;
0029 float pitch = 4.2;
0030 float h = 1.3;
0031 float DD = 18.;
0032
0033 for(int i=-511;i<512;i++) {
0034 float fpsi = atan( ((float)(i) * pitch) /(DD * h * ST ) );
0035 unsigned short int ipsi = int(fpsi*512);
0036 unsigned short int ipsi_9bits = ipsi & 0x1FF;
0037
0038
0039 }
0040
0041
0042 short int DSPmantissa = 0;
0043 short int DSPexp = 0;
0044 float d = 34.;
0045 short int btic = 31;
0046 cout << "CHECK BTIC " << btic << endl;
0047 short int Low_byte = (btic & 0x00FF);
0048 short int High_byte =( btic>>8 & 0x00FF);
0049
0050 cout << setw(2) << setfill('0') << hex << High_byte << setw(2) << setfill('0')
0051 << Low_byte << endl;
0052
0053
0054 IEEE32toDSP(d, DSPmantissa, DSPexp);
0055
0056 Low_byte = (DSPmantissa & 0x00FF);
0057 High_byte =( DSPmantissa>>8 & 0x00FF);
0058 cout << setw(2) << setfill('0') << hex << High_byte << setw(2) << setfill('0') << Low_byte << endl;
0059 Low_byte = (DSPexp & 0x00FF);
0060 High_byte =( DSPexp>>8 & 0x00FF);
0061 cout << setw(2) << setfill('0') << High_byte << setw(2) << setfill('0') << Low_byte << endl;
0062
0063 return 0;
0064 }
0065
0066
0067
0068
0069 void IEEE32toDSP(float f, short int & DSPmantissa, short int & DSPexp)
0070 {
0071 long int pl = 0;
0072 long int lm;
0073
0074 bool sign=false;
0075
0076 DSPmantissa = 0;
0077 DSPexp = 0;
0078
0079 if( f!=0.0 )
0080 {
0081 memcpy (&pl,&f,sizeof(float));
0082 if((pl & 0x80000000)!=0)
0083 sign=true;
0084 lm = ( 0x800000 | (pl & 0x7FFFFF));
0085 lm >>= 9;
0086 lm &= 0x7FFF;
0087 DSPexp = ((pl>>23)&0xFF)-126;
0088 DSPmantissa = (short)lm;
0089 if(sign)
0090 DSPmantissa = - DSPmantissa;
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112 }
0113 return;
0114 }
0115