DSP Programming Skills 16-Data Types in DSP, Do You Know Them?

Publisher:science56Latest update time:2014-09-30 Source: 互联网Keywords:DSP Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
  How many data types are there in DSP C/C++ programming? What are the differences between float, double and long double, long and long long? What are the consequences of using data types incorrectly? If you feel it is not clear, let's take a look at what these are:

  Table 1  Data types supported by C28x C/C++

      DSP Programming Skills 16-Data Types in DSP, Do You Know Them?
       Ø 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:

  DSP Programming Skills 16-Data Types in DSP, Do You Know Them?
       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.

Keywords:DSP Reference address:DSP Programming Skills 16-Data Types in DSP, Do You Know Them?

Previous article:DSP Programming Tips - Five Issues You Must Consider When Using Code Optimization
Next article:DSP Programming Skills 14-Unveiling the Mystery of the Compiler: Advanced Linker Options

Recommended ReadingLatest update time:2024-11-22 13:20

Design and research of active noise reduction system based on DSP
Today, with the rapid development of science and technology, while people enjoy the convenience brought by modern science and technology, they are also facing increasingly serious pollution problems. Among these pollutions, noise is one of the pollution sources that directly endangers people's physical and mental he
[Embedded]
Advantages and Disadvantages of Using DSP Filtering on Oscilloscopes
All current high-speed real-time digital oscilloscopes use various forms of digital signal processing technology ( DSP ). Some engineers worry that using software to filter the acquired data waveform may be different from the actual signal. However, the original waveform captured by the oscilloscope does
[Test Measurement]
Advantages and Disadvantages of Using DSP Filtering on Oscilloscopes
What is dsp technology
Digital Signal Processing (DSP) is an emerging discipline that involves many disciplines and is widely used in many fields. Since the 1960s, with the rapid development of computer and information technology, digital signal processing technology has emerged and developed rapidly. In the past two decades, digital sign
[Analog Electronics]
Implementation of Multi-Waveform Radar Echo Intermediate Frequency Simulator Based on DSP and FPGA
This paper discusses the design and implementation method of the intermediate frequency part of an autonomous radar echo simulator. The simulator can generate radar echo signals of various waveforms such as pulse single frequency, pulse linear frequency modulation, step frequency, step frequency + linear frequency mod
[Embedded]
Implementation of Multi-Waveform Radar Echo Intermediate Frequency Simulator Based on DSP and FPGA
Modular educational robot hardware system solution based on DSP
As a complex of high-tech, intelligent robots directly reflect the development level of a country's information technology and have been highly valued by all sectors of society. Intelligent robots involve almost all the contents of information technology, allowing students to access and see the full view of informatio
[Embedded]
Modular educational robot hardware system solution based on DSP
Design and implementation of remote monitoring system based on FPGA+DSP
  Research purposes   In order to remotely manage equipment and monitor the environment on site, simplify on-site monitoring equipment, and effectively improve the stability and security of the entire system, a remote controller is planned to be developed, referred to as RCM remote controller. The remote controller
[Embedded]
Design and implementation of remote monitoring system based on FPGA+DSP
Design of frequency converter based on TMS320LF2407
1 Chip Introduction TMS320LF2407 A is a single-chip DSP controller designed by TI for motor control. It has a high-performance C2XLP core, adopts an improved Harvard structure, and has a four-stage pipeline operation. It not only has a powerful and high-speed computing capability, but also integrates a wealth of m
[Embedded]
Design of frequency converter based on TMS320LF2407
Design of communication system between single chip microcomputer and digital signal processor based on CAN bus
0 Introduction As we all know, although 8-bit single-chip microcomputers are gradually being replaced by 16-bit or 32-bit microprocessors with high speed and strong performance, 8-bit single-chip microcomputers still occupy the mainstream position in the low-end application market with their low price, rich
[Microcontroller]
Design of communication system between single chip microcomputer and digital signal processor based on CAN bus
Latest Embedded Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号