Table 1 Data types supported by C28x C/C++
Ø 64-bit integer processing
From the table above, we can see that the C28x compiler supports 64-bit integer types, which makes it particularly convenient to process the feedback data of some high-precision smart encoders. Because when programming on older devices that do not support 64-bit integer types, we need to define the 64-bit type ourselves and define the operation rules ourselves when performing operations. A long long type integer needs to use the ll or LL prefix to be correctly processed by I/O. For example, we can use the following code to correctly display them on the screen:
printf("%lld", 0x0011223344556677);
printf("%llx", 0x0011223344556677);
It should be noted that although the compiler supports 64-bit integers, the actual CPU accumulator and related CPU registers are still 32 bits. When the program is running, the 64-bit integer type is "softly supported" by the CPU. We can add related real-time runtime libraries to improve efficiency, including llabs(), strtoll() and strtoull() functions.
Ø Floating point processing
From Table 1, we can see that the C28x compiler supports 32-bit single-precision floating point, 64-bit single-precision and double-precision floating point operations. When defining a double-precision 64-bit variable, remember to use the l or L prefix, otherwise it will be regarded as a double-precision 32-bit variable, resulting in a loss of precision. For example:
long double a = 12.34L; /* Initialize to double-precision 64-bit floating point */
long double b = 56.78; /* Convert single-precision floating point to double-precision floating point*/
When processing I/O, it should also be marked with relevant prefixes, for example:
printf("%Lg", 1.23L);
printf("%Le", 3.45L);
It should be noted that although the compiler supports double-precision floating point, the FPU only supports hardware 32-bit single-precision floating point. When the program is running, the double-precision floating point type is "softly supported" by the CPU. In particular, the operation of long double requires the cooperation of multiple CPU registers to complete (the code size and execution time will increase); in the case of multiple long double operands, the addresses of the first two operands will be passed to the CPU auxiliary registers XAR4 and XAR5, and the other addresses will be placed in the stack. For example, in the following code:
long double foo(long double a, long double b, long double c)
{
long double d = a + b + c;
return d;
}
long double a = 1.2L;
long double b = 2.2L;
long double c = 3.2L;
long double d;
void bar()
{
d = foo(a, b, c);
}
When foo is called in function bar(), the values of the CPU registers are:
The value of the CPU register register:
In the floating-point operation of C28x, taking addition as an example, the assembly code is different:
LCR FS$$ADD ; single-precision addition
LCR FD$$ADD ; double precision addition
Generally speaking, double-precision floating-point can be completely unnecessary without special needs. For example, in motor control systems, the accuracy of the entire system cannot be achieved with such high precision due to the accuracy limitations of A/D sampling.
Ø There are many data types, so be careful when using them
Single precision and double precision, signed and unsigned, a number greater than 65535 assigned to a 16-bit wide type... These conversions are full of hidden dangers, so be careful when using them! For example:
If you use Excel to analyze and compare data
Remember that the floating point type in Excel can only use double-precision floating point numbers. So if you take the single-precision floating point data from DSP and put it into Excel, you will not be surprised if you find that the data has changed. For example, if you put the single-precision floating point 0.2 into Excel, it will become 0.200000002980232.
Previous article:Design of Suspension Motion Control System Based on DSP and L298N
Next article:DSP Programming Tips - Five Issues You Must Consider When Using Code Optimization
- Popular Resources
- Popular amplifiers
- "Cross-chip" quantum entanglement helps build more powerful quantum computing capabilities
- Why is the vehicle operating system (Vehicle OS) becoming more and more important?
- Car Sensors - A detailed explanation of LiDAR
- Simple differences between automotive (ultrasonic, millimeter wave, laser) radars
- Comprehensive knowledge about automobile circuits
- Introduction of domestic automotive-grade bipolar latch Hall chip CHA44X
- Infineon Technologies and Magneti Marelli to Drive Regional Control Unit Innovation with AURIX™ TC4x MCU Family
- Power of E-band millimeter-wave radar
- Hardware design of power supply system for automobile controller
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- GigaDevice's full range of automotive-grade SPI NOR Flash GD25/55 wins ISO 26262 ASIL D functional safety certification
- GigaDevice's full range of automotive-grade SPI NOR Flash GD25/55 wins ISO 26262 ASIL D functional safety certification
- New IsoVu™ Isolated Current Probes: Bringing a New Dimension to Current Measurements
- New IsoVu™ Isolated Current Probes: Bringing a New Dimension to Current Measurements
- Infineon Technologies Launches ModusToolbox™ Motor Kit to Simplify Motor Control Development
- Infineon Technologies Launches ModusToolbox™ Motor Kit to Simplify Motor Control Development
- STMicroelectronics IO-Link Actuator Board Brings Turnkey Reference Design to Industrial Monitoring and Equipment Manufacturers
- Melexis uses coreless technology to reduce the size of current sensing devices
- Melexis uses coreless technology to reduce the size of current sensing devices
- Vicor high-performance power modules enable the development of low-altitude avionics and EVTOL
- Shenzhen: Support individual consumers to purchase new energy vehicles with a subsidy of up to RMB 10,000 per vehicle
- Getting Ready for DOCSIS 4.0
- FM radio based on Si4702MM32
-
My view on Wap portals - what is the most important thing
- Decomposition and practical application of instrument loops and control system loops
- ANT 3D spherical pattern results
- ADS Simulation of Microstrip Filter
- Intel has set up a special website to promote that its own chips are superior to Apple M1. Who do you stand with?
- Digital display electronic point-and-shoot, reaction test, multi-function experiment device
- Programmable Motor Controllers