Test Example-1: CASP Sine Wave Generator

Test Example-1: CASP Sine Wave Generator

This test example generates and plots a sine wave. It is suggested to run this example model immediately after installing CASP. It tests whether CASP and native compiler tool chains are installed correctly on your computer.

Pre-Requisites

  • CASP software is properly installed and functional.
  • Native compiler tool chain is installed.

Quick Start

  1. This example is provided as part of CASP installation. It is also available for download at this link.
  2. Run CASP by selecting (or double clicking) on CASP icon from desktop or operating system start menu.
  3. Within CASP main window, click the start button at the top left corner. Select ‘Tutorials & Examples > Open Examples’ menu item, browse to folder ‘/test_examples/test01_sine_plotter’ and select ‘test01_sine_plotter.prj’ file to load the project.
  4. Click the ‘Run’ button from CASP main window tool bar to build and run the project. The project should successfully build and run.

CASP Model Creation

As this is the first example, CASP model creation is briefly elaborated in this section. Model creation in CASP is basically a three step process.

  1. Create a new project and set basic configuration such as target selection, simulation settings, serial programmer port selection, setting up simulation panel sub-windows etc. with a few button clicks.
  2. Based on your logic, search blocks from block viewer, insert them in the model, configure the block parameters and connect them.
  3. Build and Run the model to either start simulation panel or program the target with the generated binary.

This section elaborates the above steps and shows how to do the following

  • Create a new project and add workspace files
  • Select Target Hardware
  • Create Model
  • Configure simulation panel
  • Setup simulation parameters
  • Run simulation in real time

Model Details

  • A signal generator with user specified wave shape is modelled and its output waveform is plotted.
  • Amplitude of signal generator is configured to be controlled at run time.

Step 1: Create New Project

  • Start CASP program by clicking on relevant desktop icon or from operating system start menu.
  • Open CASP documentation from CASP main menu icon .
  • Create a new project as explained in CASP Documentation > Modelling > Creating New Project.
  • Add a new workspace file as explained in CASP Documentation > Modelling > Adding Workspace File.

Step 2: Select Target Hardware

  • Click Setup Simulation button from CASP main menu. From ‘Target HW > General’ set ‘Target Architecture’ to ‘Native’ and ‘Target Platform/Hardware’ as relevant to the operating system. For example, on Windows platform it is ‘Desktop_MinGW’ as shown below.
  • Leave rest of the parameters to default. Click ‘Save’ and close the window.

Step 3: Creating Model

  • Create a model with a ‘Signal Generator’ and ‘Time Plotter’ and connect them as explained in CASP Documentation > Modelling > Creating Model.
  • Set signal generator parameters such as wave shape, amplitude, frequency and phase as desired.
  • Set block name of ‘Time Plotter’ block as ‘plotter’.
  • Now, let’s try to change output amplitude of signal generator during run time. To achieve this, configure signal generator block parameter Basic->External Control->External Amplitude Control to ‘Yes’. Observe that an additional input port ‘a’ appears at bottom of signal generator block.
  • Add Slider block from block library to the model and connect it to input port ‘a’ of signal generator block. Name the block as ‘amp_ctrl’. Configure the slider block parameters as shown below

Step 4: Configuring Simulation Panel

  • This step is required to display output of the ‘plotter’ block added in above step. Select ‘Configure Simulation Panel’ icon from CASP main menu.
  • Add ‘Group’ and two sub-windows. Set one sub-window type to ‘Plot Display’ and other to ‘Control/Meter’ as explained in CASP Documentation > Project Simulation & Execution > Configuring Simulation Panel.
  • After configuring simulation panel add ‘plotter‘ block to simulation panel Group1->SubWindow1 and ‘amp_ctrl’ block to Group1->SubWindow2.
  • Configure initial value of slider block to 0.5 by right clicking on the slider block and selecting ‘Edit Initial Condition’.

Step 5: Setup Simulation Parameters

  • Click Setup Simulation button again from CASP main menu. Set simulation speed factor to ‘1’ and leave rest to defaults. Click ‘Save’ and close the window.

Step 6: Run Simulation

  • Press Build/Run button from Home->Simulation menu item. CASP builds and compiles the model and opens separate simulation panel window. In the simulation panel window press ‘Run Simulation’ button to run simulation. The output of simulation is shown below.
  • Above simulation will run in real time. User can change the amplitude by varying the slider value.

Related Links