![]() |
|||||||||||||||||||||||||
![]() |
|
Useful For You. Readers
comments
|
|||||||||||||||||||||||
"Configuring the PIC pin for DAC output"DAC output pin RA2/AN2/CVREF/VREF(Pin Block Diagram). The block diagram below shows pin 1 of the 16F88 - it's useful to see how the hardware is connected so you can set up the pin correctly for voltage reference output. RA2/AN2/CVREF/VREF pin (pin1
16F88)
![]() It shows that the voltage reference is directly connected to the pin so all you need to do to output a voltage is to set the TRISA bit (to 1) - to make the P & N fets go into high impedance i.e. drawing no current - and set CVROE (1) obviously CVREN has to be 1 to enable the voltage reference. As well as this set ANSEL (1) (see below). Note: The TRIS control circuit not shown on this diagram.
Controlling ANSELThe RA2 pin is the only pin that is analogue I/O (because of the voltage reference output) all other analogue pins are analogue input only.This register (ANSEL) defaults to all ones so they are all analogue I/(O) at power up but it's best to control the values so you know what they should be. Making it go.Measured valuesVsupply = 4.93V(i) CVRR = 1 (Low range) Outputs 16 voltage steps from 0.01V to 3.05V (ii) CVRR = 0 (high range) Outputs 16 voltage steps from 1.22V to 3.53V Data sheet informationLow volt range(i) for CVRR=1
and 0.00 CVRSRC to 0.625 CVRSRC with CVRSRC/24 step size CVREF = (VR<3:0>/24) • (CVRSRC) High volt range (ii) for CVRR=0
0.25 CVRSRC to 0.72 CVRSRC with CVRSRC/32 step size CVREF = 1/4 • (CVRSRC) + (VR3:VR0/32) • (CVRSRC) So for the second range (higher voltage output range) you can have finer step sizes and a slightly higher maximum voltage output (but the minimum is not zero). CVRSRC = 4.93V
This shows the practical measurements match the datasheet predictions very well. SpeedRunning at 8MHz with the following code produces a pulse width for an output step of 11us (90kHz) - obviously this will change depending on the code used but you could probably create a simple signal generator.Note: You can increase the output speed by using a 20MHz crystal - for the current project it is using the internal oscillator at 8MHz so there's room for improvement. Jump from DAC page to Home page: Best-Microcontroller-Projects.com |
|||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||
|
|||||||||||||||||||||||||