Become a subscriber (Free)

Join 29,000 other subscribers to receive subscriber sale discounts and other free resources.
Don't worry -- your e-mail address is totally secure. I promise to use it only to send you MicroZine.

Configuring the PIC pin for DAC output

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.

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)

pin 1 of 16F88 RA2

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.

  • ANSEL for pin RA2 to 1
  • TRISA for pin RA2 to 1
  • CVROE to 1
  • CVREN to 1

Controlling ANSEL

The 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 values

Vsupply = 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 information

Low volt range

(i) for CVRR=1
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

Measured (i) 0.01V to  3.05V
For (i) Range is 0V to  4.93*0.625 = 3.08V
Measured (ii) 1.22V to  3.53V
For (ii) Range is 0.25*4.93 = 1.23V to  4.93*0.72 = 3.55V

This shows the practical measurements match the datasheet predictions very well.


Running 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.

Setting up and controlling the DAC in C



New! Comments

Have your say about what you just read! Leave me a comment in the box below.

Claim Your: Useful

"Arduino Software Guide"

   Right Now...

Privacy Policy | Contact | About Me

Site Map | Terms of Use

Visit our Facebook Page:

   Click Here

Recent Articles

  1. Hitachi HD44780: A very Useful Guide to using 1602 LCD displays.

    Use an Hitachi HD44780 as a simple display for any project.

    Read more

  2. Easily make an IR Pulse Rate Sensor with one opamp, an Arduino, and a matched Infrared phototransistor and LED pair.

    How to make a Pulse Rate Sensor using a simple single opamp circuit with an Arduino and a few other components.

    Read more

  3. 74HC595

    74HC595 : How to add nearly unlimited outputs to any microcontoller.

    Read more

Sign up for MicroZine
''The'' Microcontroller Newsletter

Enter your first Name and primary email address in the form below:

And receive absolutely FREE a full project for:

"Measuring Analogue Voltages
Without An ADC"

(Using only one pin).

Instant Download:
You Can
Get It Right Now

Warning: This project could be  Removed 
at any time.  

It will  NOT be 
available indefinitely SO
To avoid 
disappointment  get it:


Don't worry -- your e-mail address is totally secure. I promise to use it only to send you MicroZine
Remember this is a project with full description and fully debugged C Source code - and it's not available from the main website.

You can only get it through this newsletter.

To get exclusive access Enter your first name Name and primary email address Now in the form above.:

But wait !

There's more...

You'll receive more
free and exclusive reports as well as site information and site product updates

Scroll up to the form above and sign up NOW. Don't forget it's FREE and if you don't like it, you can unsubscribe at any time.

Click Here Now to use the form above to get your Valuable information absolutely free.

Readers Comments

"I wanted to thank
you so so so much
for all the information
you have provided in
your site it's


- Ranish Pottath

"This site really is
the best and my favorite.
I find here many useful
projects and tips."

- Milan


"Awesome site,
very, very easy and nice
to navigate!"

- Matt

Learn Microcontrollers

"Interested in

Sign up for The
Free 7 day guide:


"I am a newbie to PIC
and I wanted to say
 how great your
site has been for me."

- Dave


"Your site is a great
and perfect work.

- Suresh


"I couldn't find the correct
words to define
yourweb site.

Very useful, uncovered,
honest and clear.

Thanks so much for
your time and works.

- Anon