Keil Logo

µVISION DEBUGGER: SINE WAVE SIGNAL FUNCTION


Information in this article applies to:

  • C51 Version 6.10a
  • µVision Version 2.10

QUESTION

Is it possible to create a sine wave input on the analog inputs using the signal functions in the µVision 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.\n", 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\n", 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\n", 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

Last Reviewed: Monday, June 28, 2004


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  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.