Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Document Type: Tutorial
NI Supported: Yes
Publish Date: Sep 6, 2006


Feedback


Yes No

Related Links - Developer Zone

Related Links - Products and Services

Automatic C Code Generation in Hypersignal RIDE

5 ratings | 3.00 out of 5
Print

Description

Before source code can be automatically generated with the C Source Code Generator there must first be a Block Diagram design simulation of the algorithm. This is accomplished by creating a worksheet project with individual block components and arranging them to construct a specific algorithm or design. The data flow for the algorithm is represented by lines that have been established via mouse-click connection logic. An example design simulation is presented in the first part of the next section, and is used as the basis for source code generation for this application note.

Once a worksheet simulation has been completed within the Block Diagram environment then the C Source Code Generator is used to create the C source code for the design. The second part of the next section discusses this process and also presents some generated C source code for the design example.

Figure 1: Hypersignal Block Diagram Design Simulation

Design Simulation

The first step for this example involves creating a simulation within the Hypersignal Block Diagram graphical design environment. Block Diagram contains a large block component library from which the building blocks of the algorithm can be chosen.

By arranging and connecting block component icons, signal processing and algorithm implementation can be programmed, adjusted, and easily tested. The visually designed block diagram algorithm can then be used for simulation, proof-of-concept designs, and final software solutions.

In this example we are implementing an AM Modulation/Demodulation (Square Demodulation) algorithm. As can be seen in Figure 1, above, a Block Diagram worksheet design has been graphically constructed from block component icons. The example worksheet is comprised of several block component functions that have been arranged and connected to establish the proper data flow for the algorithm. The individual design parameters for each block component, such as sample rate, amplitude settings, and data precision, have been selected and the entire design simulated in Block Diagram.

Automatic C Source Code Generation


After all design parameters have been set accordingly in Block Diagram to produce the desired results, and the design worksheet has been saved, the next step is to generate source code for the design.

The Block Diagram design simulation is converted to source code form through use of the ANSI C Source Code Generator application. This tool allows you to very quickly produce source code, which would have otherwise taken a much longer time. Figure 2, below, shows a typical C Source Code Generator Project Workspace, and provides a list of files produced.

The C source code that is created is organized into several files. This includes the main body of the program, as well as an initialization section and a utility section. The main body of code is responsible for the calling of the appropriate design routines, which will implement the algorithm. The initialization section of code is responsible for setting all algorithm design parameters. The routines that actually perform the data computations are organized in the utility file. All of the files created by the C Source Code Generator can be user-modified. This allows you the option of modifying the design in the event you wish to make some changes.

The ANSI C source code at this point can be compiled directly into an executable program, complete with graphical display outputs. Any standard C compiler can be used to compile the source code. When executed, the program will produce the identical results as were first obtained in the original Block Diagram design worksheet.

Because the source code created by the C Source Code Generator is written in ANSI C, the algorithm can be used on many types of platforms since C is a portable language.

Figure 2: ANSI C Source Code File Generation

Figure 3, below, shows some code sections from the generated C source files. The resulting C source code can be conveniently edited from within the C Source Code Generator application. The source files can be compiled using a standard C compiler.

Expandability


Both the Block Diagram product and the C Source Code Generator allow for the introduction of user-defined block components. The user can easily and simply create new custom block components unique to a particular design project by using an included Block Wizard utility. The C Source Code Generator provides for a “Learn” function that allows these newly created components to be utilized in simulations and subsequent C source code generation. This makes it easy for the user to adapt the product to a particular field of interest and lowers the technical risk for a given design project.





Figure 3: A Section of Generated Source Code

5 ratings | 3.00 out of 5
Print

Reader Comments | Submit a comment »

 

Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).