You are here

Creator Components Aren’t Just For Hardware | Cypress Semiconductor

Creator Components Aren’t Just For Hardware

Often I write programs that can have multiple modes based on a constant or I just want to vary a parameter and rerun the program.  Since the schematic is the main view of the project, it is often beneficial to see the current constants or parameters right on the schematic.  This is done for components such as the DelSig ADC where the resolution of the first configuration is displayed.  This same concept can be used for software only constants as well.

The Constants component is a very simple way to display constants used by the firmware on the schematic.  Also this allows you to change firmware parameters without changing actual source code.  I have created an example component that allows the user to assigns names and values to up to four constants.  The component consists of just a symbol and a header file. Below is what the component would look like on the schematic.  The four constants have already been assigned names, DEBUG, LOOP, DELAY, and COUNT, as well as values.

Figure 1 Example Project Constants Component

 

The configuration is very simple.  The user simply assigns a name and value.  The header file is automatically generated.  The constants defined below will have the instance name pre-pended on the name.  For example, the LOOP constant name will be MyConstants_LOOP .

Figure 2 Configuration dialog of Project Constants Component

 

The generated header file would look like this using the configuration in Figure 2.

 #defineMyConstants_DEBUG   0

#defineMyConstants_LOOP   100

#defineMyConstants_DELAY   95

#defineMyConstants_COUNT   5

 

 

The constants can then be used throughout the firmware, just by including the MyConstants.h header file.  Below is an example of a code snippet that makes use of the constants provided in MyConstants.h.

 

 for(i = 0; i < MyConstants_LOOP; i++)

{

      LCD_Position(1,5);  
   
      LCD_PrintHexUint8(i);

      CyDelay(MyConstants_DELAY);

}

  

The same concept could be used for user created components for a specific application. For example a project phase component that displays on the schematic whether the project is in the release or debug phase.  The header file would contain the #define statements for the different mode.

 

 

Figure 3 Project Phase Component

 

Other similar components can easily be generated by the user, with just some simple basic knowledge of how to create components. For example if you wanted a waveform generator to change the waveform without changing code.

 

Figure 4 Application Mode Example

 

The header file would contain the following:

 

 #defineAppMode_Mode     2

#defineAppMode_SINE     0

#defineAppMode_SQUARE   1

#defineAppMode_TRIANGLE 2

 

 

The firmware would look at the AppMode_Mode constant to determine which waveform to generate, requiring no code changes.

This is just one simple trick to make a project more flexible and easier to change its operation without editing code.  It is also a good way to demo an application to a customer.  The user can then try different operations without editing code.  The MyConst component is generic and can be used with any project.  The ProjectPhase and AppMode components can easily be created by the user in a matter of minutes.

 

By Mark Hastings

ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.