Advertisement
Advertisement

EDN Access — 09.02.96 68HC11 synthesizes accurate sine wav

-September 02, 1996

EDN logo


Design Ideas:September 2, 1996

68HC11 synthesizes accurate sine wave

Mika Maaspuro,
Espoo, Finland


You can use a 68HC11 and a 12-bit serial DAC (Figure 1) to generate accurate sine waves without using floating-point arithmetic. Figure 2 shows a block diagram for this sine-wave generator. You can easily analyze the generator's behavior by writing state equations in the z domain. You can also write equations in the s domain. The location of the two poles on the right-hand side reveals the generator's oscillatory nature. The inverse Laplace transformation is simple and results in a sine-wave statement.

This algorithm calculates the sine wave step by step. The step size is the number of degrees or radians moved by one step. The algorithm derives new values of sine and cosine using their previous values. Reducing step size improves accuracy, but it also affects the number of samples in one cycle. However, using decimation, you can independently adjust both the frequency and the number of samples in one cycle.

This algorithm uses steps in the form of n/m, where n is an integer multiplier that is not a power of 2 and m is an integer that is a number with a power of 2. Making n and m relatively independent allows you to accurately set the number of samples in one cycle. When n is larger than 255, multiplying by n using 8-bit is time consuming. This algorithm allows n to be as high as 215 and the results to be as high as 231. Division by m is easy and fast because you simply left shift the register value. The overall operating principle is to keep these values as integers to avoid using floating-point arithmetic. The resultant assembler routine is simple and fast.

The algorithm is an approximation for sine and cosine and uses only the first three terms of the serial representation for ejvt. The resultant error is sinusoidal and has the same period as the generated waveform. Thus, there is no cumulative error over one period.

The following example shows a case where n=778 and m=16,384. The algorithm calculates with 16-bit accuracy (15 bits plus sign), converts the results with 12-bit accuracy, and sends them to the MAX537. With these parameters, the signal peak is at bin 31 in the FFT of 4096 samples, which satisfies the requirement that signal and sampling frequencies be independent of each other. This independence is vitally important when calculating parameters from the spectrum. Results of this analysis indicate that the generated sine wave has a S/N ratio of 68.1 dB, which is equivalent to 11.01 effective bits.

The test circuit includes one A1 version of the MC68HC11, which runs at 2 MHz internally. Minimum hardware requirements are a MC68HC11, MAX537, and 32 kbytes of external SRAM. You can store 1 kbyte of program code in the µP's internal EEPROM. The assembler program stores 4096 samples of sine and 4096 samples of cosine into SRAM. Then, the program starts to download the samples to the serial DACs with a maximum speed of the µP (reading memory table and downloading memory data to the serial bus) of approximately 21.3k samples/sec.

The most time-consuming process is multiplication by n. With the given parameters, counting 4096 samples of sine and cosine takes approximately 165 seconds. If this is too much time for your application, you can speed things up using an arithmetic circuit such as the AM9511A (8231A). Using this circuit, the time for this example reduces to below 2 seconds.

The assembler program allows you to specify n, m, and initial values for sine and cosine. One practical hint for choosing initial values: although the initial value of sine is set to 0, you should set the initial value of cosine to one step less than the maximum value. These values ensure that the algorithm proceeds after points where the cosine value changes its polarity. The proper setting of initial values is the only thing you have to be aware of in this program.

Click here to download DI- SIG #1912.


| EDN Access | feedback | subscribe to EDN! |
| design features | out in front | design ideas | departments | products | columnist |


Copyright c 1996 EDN Magazine. EDN is a registered trademark of Reed Properties Inc, used under license.

Loading comments...

Write a Comment

To comment please Log In

FEATURED RESOURCES