Programming the PIC Microcontroller with MBasic

Digital-to-analog conversion (DAC) is the process of converting a numeric value to an analog parameter, often a voltage. The voltage may represent an alerting "beep" tone driving a loudspeaker, or it may, through an amplifier, control the speed of a DC motor, or it may be used for wide range of other applications. The voltage may have a 1:1 relationship to the digital value (numerical value 123 generates 123 volts) or it may scaled (numerical value 123 generates 1.23 volts), level shifted (digital value 123 generates 523 volts; digital 124 generates 524 volts) or otherwise linearly or nonlinearly transformed. The output may change with time, as the digital value changes with time. Finally, the digital value may be user controlled or it may be generated by the PIC in response to an external sensor.
We will explore MBasic's digital-to-analog abilities by building a direct digital synthesis sine wave generator. Our first approach, entirely in MBasic, has a maximum output frequency just under 1 KHz. By coding time critical elements in assembler, we'll see usable results at more than 10 kHz. We will also compare the DDS design with other D/A approaches available with MBasic.
Let's examine a simple digital-to-analog voltage converter, the DAC equivalent of the 3-bit ADC we examined in Chapter 11. Figure 16-1 illustrates the relationship between digital input and output for this DAC. Comparing Figure 11-1 with Figure 16-1 shows and it should be no great surprise digital-to-analog conversion is the inverse of the analog-to-digital...