Simon... the lookup tables offered by Rick are great, but you asked for some simple Math. Hopefully you will understand this. A sine wave is calculated from the values for the sine of an angle from 0 to 360 degrees. So you can do this (I'm a lazy sod, so I got Excel to do it for me). Now you have a 5-bit DAC, so you have 32 possible states (in binary from 00000 to 11111). So you list the 32 steps (in this case from 0 to 31), divide 360 degrees by 32 (you have 32 steps), take the sine of each angle, then multiply the sine value by 31 (because the maximum value you can generate is 11111 = 31), convert it to Binary and you'll generate your own value for the DAC. I've done this below. The DAC(1) column is just the basic value multiplied by 31, All well and good till we get to the negative values, Excel gives us the two's complement value (to 8 bits). Here you can use the 6th bit to indicate the sign (1= negative) and discard bits 7 and 8. If your DAC can't do negative numbers (most can't) you just add 1 to the sine value (so instead of going from 1 to -1 it goes from 0 to 2) and do the same process (shown in the DAC(2) column. Here are the results:
Step |
Degrees |
Sine |
DAC (1) |
DAC (2) |
0 |
0 |
0.00 |
0 |
1111 |
1 |
11.25 |
0.20 |
110 |
10010 |
2 |
22.5 |
0.38 |
1011 |
10101 |
3 |
33.75 |
0.56 |
10001 |
11000 |
4 |
45 |
0.71 |
10101 |
11010 |
5 |
56.25 |
0.83 |
11001 |
11100 |
6 |
67.5 |
0.92 |
11100 |
11101 |
7 |
78.75 |
0.98 |
11110 |
11110 |
8 |
90 |
1.00 |
11111 |
11111 |
9 |
101.25 |
0.98 |
11110 |
11110 |
10 |
112.5 |
0.92 |
11100 |
11101 |
11 |
123.75 |
0.83 |
11001 |
11100 |
12 |
135 |
0.71 |
10101 |
11010 |
13 |
146.25 |
0.56 |
10001 |
11000 |
14 |
157.5 |
0.38 |
1011 |
10101 |
15 |
168.75 |
0.20 |
110 |
10010 |
16 |
180 |
0.00 |
0 |
1111 |
17 |
191.25 |
-0.20 |
1111111010 |
1100 |
18 |
202.5 |
-0.38 |
1111110101 |
1001 |
19 |
213.75 |
-0.56 |
1111101111 |
110 |
20 |
225 |
-0.71 |
1111101011 |
100 |
21 |
236.25 |
-0.83 |
1111100111 |
10 |
22 |
247.5 |
-0.92 |
1111100100 |
1 |
23 |
258.75 |
-0.98 |
1111100010 |
0 |
24 |
270 |
-1.00 |
1111100001 |
0 |
25 |
281.25 |
-0.98 |
1111100010 |
0 |
26 |
292.5 |
-0.92 |
1111100100 |
1 |
27 |
303.75 |
-0.83 |
1111100111 |
10 |
28 |
315 |
-0.71 |
1111101011 |
100 |
29 |
326.25 |
-0.56 |
1111101111 |
110 |
30 |
337.5 |
-0.38 |
1111110101 |
1001 |
31 |
348.75 |
-0.20 |
1111111010 |
1100 |
You'll notice some inconsistencies here - steps 7/8/9 have differences of 1 and steps 23/24/25 don't in the DAC(2) column. This is due to excel (I hope) rounding off. It will lead to some slight distortion in your waveform but with only 5 bits you'll get that anyway.
Years ago I came across another way of generating sine waves using a shift register (Look Ma, no microcomputers!). If I can find this I'll post it below.