Keil Logo

Signal Combination

Signal functions or signal inputs can be combined easily. The following signal function shows how to invoke several signals so that they are processed at the same time.

Redirect the previous functions to the VTREG AIN0.

 Combine signals. Output is sent to AD Channel 0
SIGNAL void Combine_Signals (void)  {
  swatch (0.1);      // wait 0.1 seconds
  AIN0_Square ();
  swatch (0.006);    // wait 0.06 seconds
  AIN1_Saw ();
  swatch (0.003);    // wait 0.03 seconds
  AIN2_Sine ();
  swatch (0.0001);

DEFINE BUTTON "AutoComb", "Combine_Signals()"

Start debugging in simulation mode and drag the port into the Logic Analyzer. Open the Toolbox and click the button AutoComb to view the signal output:

Combined Signal Displayed on Logic Analyzer Window

It is even possible to mix two sine wave signals:

  Generate a Sine Wave Input
SIGNAL void Mix_Sine (float freq1, float freq2)  {
  float sig1;
  float sig2;
  int z;

  z = 0;

  while (z < 10000)  {            // generate 100 mSec sine wave pulse

    // Generate 1. Sine Wave input signal
    sig1 = __sin (((states * freq1) / CLOCK) * 3.1415926 * 2);

    // Generate 2. Sine Wave input signal
    sig2 = __sin (((states * freq2) / CLOCK) * 3.1415926 * 2);

    // Input: 1. Sine Wave with 0.5V, 2. Sine Wave with 0.2V, offset 2.5V
    AIN0 =  (sig1 * 0.5) + (sig2 * 0.2) + 2.5;
    swatch (0.00001);

DEFINE BUTTON "Mix Sine", "Mix_Sine(300,2000)"

The signal function combines two signals and adds an offset of 2.5V. The first signal has a frequency of 300Hz and an amplitude of 0.5V; the second signal has a frequency of 2000Hz and an amplitude of 0.2V.

Mixed Sine Wave Signals Displayed on Logic Analyzer Window

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.