Texas Instruments MSC1210 User Manual

Page 257

Advertising
background image

Summation/Shifter

17-29

Keil Simulator

In addition to the previous sample code, a sample driving code for the debugging
is included below. This is a special feature of the

µ

Vision2 Simulator system that

allows you to send input voltage values to the editable analog text fields in the
ADC peripheral module. In the case of this example, the AIN0 input channel is
selected. These input values are automatically written to the text window within
a preprogrammed time interval, which is determined by the argument of the pre-
defined function twatch (ulong states, where states is the unsigned long value of
the number of CPU clock states that must elapse before the next statement in
the program is executed). While this function is being executed, the debug sys-
tem is placed in an idle state, and the target program continues executing. Upon
expiration of this timer period (number of CPU clock states), the debugging pro-
cess continues at the next statement. For all intents and purposes, the target pro-
cess is oblivious to the execution or the state of the debugging program.

The debugging program is declared as one with a return value of type SIGNAL.
The debugging variable AIN0 is assigned an initial value of 0.5V. This will be
subsequently incremented by an incremental value of 0.01V. After the AIN0
value has been initialized, a delay of 196 000 CPU clock samples is imposed,
while the main program, which started at the same time as this debug program,
is performing its parameter initialization and book keeping until it is ready for
the next data to be sampled. Within the For Loop, another 900 CPU clock delay
is imposed, then the value of AIN0 is incremented by 0.01. It then processes
another 130 100 CPU clock delay. This is repeated until the For Loop count
expires. In the meantime, the AIN0 text window in the ADC peripheral is incre-
mentally updated, and its value is periodically sampled, converted, averaged
and displayed from within the main program.

Please refer to the

µ

Vision2 Debug Functions chapter in the Keil’s Getting

Started and Creative Programming document for more information on writing,
compiling and running script files.

SIGNAL void a_to_d_sim (void)

{

int i;

/*Data written into the variable ain0 is automatically entered into the

editable text window labeled AIN0 in the A/D Converter peripheral dialog.*/

ain0 = 0.5;

//specify start value for ain0

//debug program idles for 196000 clock cycles, while simulation continues

running in parallel*/

twatch (196000);

/*the following loop sends out 64 consecutive samples of ain0,

each incremented by 0.01. Each transmittal is spaced 131000 clock cycles

from the previous one.*/

for (i = 0; i < 0x40; i++)

{

twatch (900);

ain0 += 0.01;

twatch (130100);

}

}

Advertising