Keil™, An ARM® Company

µVision® User's Guide

Square Wave Signal

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

//
// Generates an Square Wave Signal on AD Channel 0
//
signal void ADC0_Square (void)  {
  float volts;        // peak-to-peak volatage
  float frequency;    // output frequency in Hz
  float offset;       // volatge offset
  float duration;     // duration in Seconds

  volts     = 0.5;
  offset    = 1.6;
  frequency = 2400;
  duration  = 0.5;

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

  while (duration > 0.0)  {
    ADC0 = volts + offset;
    swatch (0.5 / frequency);
    ADC0 = offset;
    swatch (0.5 / frequency);
    duration -= 1.0 / frequency;
  }
}

The above setting generates the following output.

Square Wave Output Displayed on Logic Analyzer Window