Clock determined by FOSC in configuration bits
This code generates a sawtooth signal at the output pin. You may refer to getting started with MPLAB XC8 Compiler tutorial. We used MPLAB XC8 Compiler to write a program for this tutorial. PIC Microcontroller DAC Module Programming
Therefore, the ramp-up voltage goes from 0 to 5 volts. The operating voltage of the PIC18F46K22 microcontroller is 5 volts. After reaching a maximum value, it suddenly falls to zero voltage. Sawtooth is a ramp-up voltage that increases from a minimum value to the maximum value linearly. This circuit diagram shows the connection of RA2 with an oscilloscope. RA2 pin which is PORTA pin2 provides DAC OUT signal. We can use a simple oscilloscope to see the waveform. In this section, we will see a code to generate a triangular waveform using the DAC module of PIC18F46K22 microcontroller.
We will see later on how to select levels. We can select levels using control registers. This 5-bit module can provide 32 levels of the output voltage. Few pic microcontrollers also have both 5-bit and 8-bit DACs inside a single MCU. Therefore, a 5-bit converter generates 32 levels.
A number of bits defines the number of steps or Resolution. Like ADC, we also define its resolution with the help of a number of bits. Some PIC chips also have 8-bit DAC modules. In this tutorial, we will use the PIC18F46K22 microcontroller. But in this tutorial, we will see how to use internal DAC modules of Microchip devices. However, if built-in DAC does not support the specific requirement for your embedded design, we can look for off the chip external DAC ICs such as DAC0832. We will see examples in the latter part of this tutorial. By using registers, a module can be easily configured. We can easily configure internal digital to analog converter module for generating analog signals. Therefore, we don’t need to use any external electronics circuits with a pic microcontroller.