Products Download Events Support Videos All Product Families ARM7, ARM9, and Cortex-M3 Products C16x, XC16x, and ST10 Products C251 and 80C251 Products Cx51 and 8051 Products Modified Anytime In the Last 7 Days In the Last 14 Days In the Last 30 Days In the Last 90 Days In the Last 6 Months

# µVISION DEBUGGER: SINE WAVE SIGNAL FUNCTION

• 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?

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.

Last Reviewed: Monday, June 28, 2004

Yes
No
Not Sure ##### Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.