Generating a sine wave

Sinusoidal signals are commonly used in signal processing applications and generating these waveforms provides an interesting project that is the focus of this recipe. A common approach is a direct method that stores the sinusoidal waveform samples in a look-up-table (LUT). This recipe is called dacSinusoid_c5v0.

Getting ready

First, we need to calculate the (12-bit) DAC values that will be stored in the LUT. We'll attempt to generate a 50 Hz sinusoidal signal and use a spreadsheet (for example, Microsoft Excel) to calculate the following values:

Smpl. No

Theta Rads

floor((sin(theta)+1)*4095/2)

0

0

2047

1

0.31415927

2680

2

0.62831853

3250

3

0.9424778

3703

4

1.25663706

3994

5

1.57079633

4095

6

1.88495559 ...

Get ARM® Cortex® M4 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.