Keil Logo Arm Logo

Saw Tooth Signal

The following Signal Function template may be used to generate a saw tooth signal. The input signal is provided to the VTREG ADC0. The variables volts, frequency, offset, and duration allow to adjust the saw tooth signal.

//
// Generate Saw Tooth Signal on AD Channel 0
//
signal void ADC0_Saw (void)  {
  float volts;        // peak-to-peak volatage
  float frequency;    // output frequency in Hz
  float offset;       // volatge offset
  float duration;     // duration in Seconds
  float val;
  long  i, end, steps;

  volts     = 2.0;
  offset    = 0.2;
  frequency = 1400;
  duration  = 0.2;

  printf ("Saw Tooth Signal on AD Channel 0.\n");

  steps = (100000 * (1/frequency));
  end = (duration * 100000);
  for (i = 0 ; i < end; i++)  {
    val = (i % steps) / ((float) steps);
    ADC0 = (val * volts) + offset;
    swatch (0.00001);                // in 10 uSec increments
  }
}

The above setting generates the following output.

Sawtooth Signal Output Displayed on Logic Analyzer Window

 

Keil logo

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