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)

and

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.

Speed

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

 

Continue>>>>





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



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:

Now



:
:
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

SUPERB and FANTASTIC."

- Ranish Pottath

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

- Milan

bursach<at>gmail.com<

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


- Matt
matt_tr<at>
wolf359.cjb.net


Learn Microcontrollers

"Interested in
Microcontrollers?"

Sign up for The
Free 7 day guide:

FREE GUIDE : CLICK HERE


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


- Dave

de_scott<at>bellsouth.net

"Your site is a great
and perfect work.
congratulations."


- Suresh

integratredinfosys<at>
yahoo.com

"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.
Regards."


- Anon

Recent Articles

  1. How to use the DHT22 (or DHT11) with an Arduino; full code and description. Also including a comparison of the DHT11 vs DHT22.

    The Essential Guide to the DHT22/11 humidity sensor including a library code guide for the Arduino. Learn how to determine Humidity, Dew point and Heat Index.

    Read more

  2. How to Use the MAX7219 to drive an 8x8 LED display Matrix on the Arduino.

    The Essential Guide to the MAX7219; What it is and how you can easily use one in any of your projects.

    Read more

  3. How to use a DS18B20 (single or multiple on one wire) for temperature measurement using the Arduino Uno.

    How to Easily Use the DS18B20 Maxim One-Wire thermometer with Arduino example code showing external or parasitic power modes.

    Read more