ARM Technical Support Knowledge Articles

SINE WAVE SIGNAL FUNCTION

Applies to: uVision Debugger

Answer


Information in this article applies to:


QUESTION

Is it possible to create a sine wave input on the analog inputs using the signal functions in the uVision Debugger?

ANSWER

Yes. The following signal function does just that.

signal void analog0_sine (float limit)  {
  float i;
  float i2;
  float sine;

  printf ("Analog0_sine (%f) entered.
", limit);

  while (1)  {          /* forever */

    /* SIN swings from -1 to 1 so... adjust it to swing from 0 to 1 */
    /* This is a Taylor series that calculates SIN */
    /* i is the angle where -1.0 = -pi/2 and 1.0 = +pi/2 */

    for (i = -1.0; i < 1.0; i += 0.01) {
      i2 = i * i;
      sine = i * (1.5707963 - i2*(0.6459640 - i2*(0.0796926 - i2*(0.0046817 - i2*(0.0001604)))));
/*      printf ("SIN(%4f) = %6f
", i * 90.0, sine); */
      ain0 = ((sine + 1.0) / 2.0) * limit;
      twatch (2000000);
    }

    for (i = 1.0; i > -1.0; i -= 0.01) {
      i2 = i * i;
      sine = i * (1.5707963 - i2*(0.6459640 - i2*(0.0796926 - i2*(0.0046817 - i2*(0.0001604)))));
/*      printf ("SIN(%4f) = %6f
", i * 90.0, sine); */
      ain0 = ((sine + 1.0) / 2.0) * limit;
      twatch (2000000);
    }
  }
}

This signal function uses a Taylor series to calculate the sin for -pi/2 to pi/2. The sin (which normally ranges from -1.0 to 1.0) is normalized to a range of 0.0 to 1.0 and this is used to calculate the input voltage (by multiplying by a maximum limit).

To start this signal function, you must invoke it from the command line in the debugger. For example:

analog0_sine (2.500)

starts the sine wave function which will generate a sine wave on analog input 0 ranging from 0.0 volts to 2.5 volts.

You will need to change the increment and decrement in the for i loops to change the number of steps. You must change the number of clock cycles to delay for each step in the twatch calls.

SEE ALSO

Article last edited on: 2004-06-28 10:21:27

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential