Keil Logo

Sine Wave

The following signal function template may be used to generate a sine wave signal. The input signal is provided to the VTREG ADC0. The variables volts, frequency, offset, and duration allow to adjust the sine wave signal.

//
// Generate Sine Wave Signal on AD Channel 0
//
signal void ADC0_Sine (void)  {
  float volts;        // peak-to-peak voltage
  float frequency;    // output frequency in Hz
  float offset;       // voltage offset
  float duration;     // duration in Seconds
  float val;
  long  i, end;

  volts     = 1.4;
  offset    = 1.6;
  frequency = 1800;
  duration  = 0.1;

  printf ("Sine Wave Signal on AD Channel 0.\n");

  end = (duration * 100000);
  for (i = 0 ; i < end; i++)  {
    val = __sin (frequency * (((float) STATES) / CLOCK) * 2 * 3.1415926);
    ADC0 = (val * volts) + offset;
    swatch (0.00001);                // in 10 uSec steps
  }
}

The above setting generates the following output.

Sine Wave Output 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.