ARM Technical Support Knowledge Articles

# USING THE AINX VTREGS

Applies to: uVision Debugger

• C166 Version 4
• C251 Version 3
• C51 Version 6
• uVision Version 2

### QUESTION

What are the AINx VTReg and how do I use it?

When simulating a target microcontroller, the Keil uVision Debugger provides Virtual Target Registers (VTRegs) to allow you to provide input to the pins of the simulated device.

The AINx VTRegs represent the inputs to the analog input pins of the MCU for analog input 0, 1, 2, and so on.

So, if you have configured the analog inputs, the following commands (typed in the debugger's Command Window) input the voltages specified.

```AIN0 = 0.000  /* Analog Input 0 = 0.000 volts */
```

You may create signal functions that inject waveforms into the analog inputs. For example:

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

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

while (1)  {          /* forever */

/* SIN swings from -1 to 1 so... adjust it to scale 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) {
sine = i * (1.570796329
- i * i * (0.6459640960
- i * i * (0.07969262599
- i * i * (0.004681754102
- i * i * (0.0001604411842)))));
/*      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) {
sine = i * (1.570796329
- i * i * (0.6459640960
- i * i * (0.07969262599
- i * i * (0.004681754102
- i * i * (0.0001604411842)))));
/*      printf ("SIN(%4f) = %6f
", i * 90.0, sine); */
ain0 = ((sine + 1.0) / 2.0) * limit;
twatch (2000000);
}
}
}
```