Вы находитесь на странице: 1из 4

IMPLEMENTATION OF A HARMONIC OSCILLATOR ON 

VC33

Aim :
To implement a harmonic oscillator in the VC33 processor using the harmonic 
oscillator system equations.

Theory:
The system equations for a harmonic oscillator can be given as follows

Consider a sine wave:
x = sin (wt)
Thus 
dx/dt = w cos (wt)
let y = cos(wt)

dx/dt = wy and  dy/dt = ­wx

This forms the system equations
x[n+1] = x[n] + wT*y[n] ;x[0]=0
y[n+1] = y[n] ­ wT*x[n+1] ;y[0]=1
note: its x[n+1] and not x[n] to make the system stable 
y[n+1] = y[n] ­ wT*x[n] leads to an unstable system, but the simple modification of using 
x[n+1] instead of x[n] pulls the system into a stable zone

In the succeeding part we would be using sin instead of x[n] and cos instead of y[n]

The code snippet for the harmonic oscillator is as follows
ldf @sin,r0
mpyf @wdt,r0
negf r0,r0
addf @cos,r0
stf r0,@cos
mpyf @wdt,r0
addf @sin,r0
stf r0,@sin
T is the time step with which these discrete time equations are solved.
w, the desired angular frequency, is the input to the oscillator
Procedure:
Initialize the variables sin, cos and wT (wdt) and the buffer of length 400 in 
which the values would be stored and a count variable which would keep a track of how 
many values have been updated.
Initialize the Auxiliary register to point to the buffer location.
Use the above code snippet to calculate the values of the sine/cosine wave at each 
iteration.
Update the values to the buffer using the auxiliary register and pre/post increment 
operations.
Check if 400 counts have expired.
If no, again calculate the coefficients using the above snippet code
If yes, spin in a background loop 

Results:
At the end of the correct execution 400 values would be stored in the buffer and 
can be saved to a file using the fsave command.
fsave s:buffer 190 sinewave
0x190 = 400 in decimal representation
Save the values to a file and plot the same using either excel or and plotting tool

Note: 
The makefile and .cmd files would be provided use these files and develop upon 
the same for good performance, faster operation and better understanding.

Instructions & Procedure:
1.            On the command prompt goto the directory to be worked upon. Use 
cd Desktop/Workshop [enter] or similar path to go to the required working 
directory
 
2.            Invoke the makefile
           prompt>  make
            The make file contains the code to sequentially invoke the assembler, followed 
by  the linker and then the terminal interface to connect the VC33 board. The make file 
invokes the command ubsl after an attempt to compile the input .asm file. After the 
makefile execution is completed, the user would be on the VC33 prompt
                                    VC33>       (output)
 
3.            Load the program to the memory of VC33
                                    VC33> load wxyz.out [enter]
 
4.            Execute the program
                                    VC33> x [enter]       here ‘x’ stands for execute
 
5.            Halt the program
                                    VC33> h [enter]      here ‘h’ stands for halt
 
6.            Check the result of the program
                                    VC33> r s:buffer 190 [enter]
The console would then display the value stored at the memory locations pointed by 
variable ‘buffer’ starting a memory location pointed by ‘buffer’ and 190 (hex) = 400 
(dec) location from the address of s:buffer. Here “s:buffer” indicates that the memory 
location to be read is represented in the symbol table as a variable buffer. s:buffer symbol 
table entry matching with buffer
 
7.            Store the result to a file named ‘A’
VC33> fsave s:buffer 190 A
            Save the contents of the memory location pointed by ‘buffer’ 190 locations ( 400 
in decimal representation) from the buffer start location to a a file named A
 
8.            Exit the VC33 console after execution and storing of results to a file
 
9.            The makefile takes over again and executes the gnuplot command
 
   gnuplot
   gnuplot> plot "FileName" using 1:2
10.        At the end of this program, the sine wave generated by the harmonic oscillator  
would be visible.
 

Вам также может понравиться