CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How can I use DAC?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pkipyy



Joined: 21 Nov 2013
Posts: 25

View user's profile Send private message

How can I use DAC?
PostPosted: Mon Mar 24, 2014 11:31 am     Reply with quote

How can I use DAC?
I have seen manual. But I don't know well.
Please give me example and explanation.
Thank you.
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 24, 2014 11:48 am     Reply with quote

It'd help if you said which PIC you're using as there are DAC examples in the 'examples' folder that CCS supplies.

It the simplest form, you set the DAC data register a value and the PIC will output a DC voltage in proportion to the Vref of the DAC.

So, for an 8 bit DAC,a Vref of 4 volts and a data value of 64 bits....

64/256 * 4 = 1 volt

...so 1 volt would be seen on the DAC output pin.

Depending on the PIC and the DAC peripheral, there will be many options or setups available to the programmer.

hth
jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 24, 2014 2:25 pm     Reply with quote

Quote:
How can I use DAC?

Tell us what DAC you are using. Are you using an external DAC,
such as MCP4921 ?
http://ww1.microchip.com/downloads/en/DeviceDoc/21897a.pdf

The CCS compiler comes with a driver for that DAC:
Quote:
c:\program files\picc\drivers\mcp4921.c

It's always easier to use a DAC which already has a driver file
which you can use.

Or are you using a PIC that has a built-in DAC module ?
This page has a selection guide for PICs. To make it easy, select only
"8-bit" at the top. Then in the left column, set "Dac Modules" to 1
and leave all other settings unchanged.
http://www.microchip.com/maps/microcontroller.aspx
Wait a few seconds between each change to the settings.
Then look at the "Search Results" box at the top. It shows a large number
of 18F, 16F and 12F PICs that have a built-in DAC module. Examples
are 18F46K22, 16F1847, and 12F1822. There are many more.
pkipyy



Joined: 21 Nov 2013
Posts: 25

View user's profile Send private message

I tell DAC in pic16f1937.
PostPosted: Mon Mar 24, 2014 6:38 pm     Reply with quote

Thank you.
I tell DAC in pic16f1937.
I'm sorry!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 24, 2014 10:31 pm     Reply with quote

What is your CCS compiler version ? There are bugs in the DAC support
in some early versions. Tell us your version.
pkipyy



Joined: 21 Nov 2013
Posts: 25

View user's profile Send private message

My ccs version is 5.008.
PostPosted: Tue Mar 25, 2014 8:31 am     Reply with quote

My ccs version is 5.008.
How about 5.008?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 25, 2014 11:38 am     Reply with quote

Try something like this. I didn't have time to test this in hardware, but
it should work. Look at the DACOUT pin with your oscilloscope.
Code:

#include <16F1937.h>
#fuses INTRC_IO,NOWDT,BROWNOUT,PUT
#use delay(clock=4M)

//==================================
void main(void)
{
int8 i;

// Turn on the DAC and enable output on the DACOUT pin, and use
// the Vdd and Vss as the limits for the DAC output voltage.
setup_dac(DAC_OUTPUT | DAC_VSS_VDD);

// Create a sawtooth waveform by ramping up the DAC
// from 0 to 31, one step at a time, continuously.

while(1)
  {
   for(i=0; i< 32; i++)
       dac_write(i);

   delay_us(10);
  }

}
pkipyy



Joined: 21 Nov 2013
Posts: 25

View user's profile Send private message

Thank you.
PostPosted: Wed Mar 26, 2014 6:14 pm     Reply with quote

Code work properly.
But maximum of dacout pin is 2.1V,
I want make maximum of dac equal 5V.
stinky



Joined: 05 Mar 2012
Posts: 99
Location: Central Illinois

View user's profile Send private message

PostPosted: Wed Mar 26, 2014 7:52 pm     Reply with quote

How are you measuring the output of the DAC?
pkipyy



Joined: 21 Nov 2013
Posts: 25

View user's profile Send private message

I used analog tester.
PostPosted: Wed Mar 26, 2014 9:43 pm     Reply with quote

I used tester and prepared probe and reset cpu and see tester.
So needle indicate (rise) zero to 2.1V.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 27, 2014 12:32 am     Reply with quote

The output is not a solid DC level at Vdd. The output is a sawtooth
waveform, in other words, it's a ramp from 0v to whatever the maximum
output level of the DAC is. I didn't look at it with a scope. I could do this
but I'm lazy tonight. But anyway, the value that you see with your
meter may be the average value of the ramp, or maybe it's the RMS
value. 2.1v is in roughly in the correct range for an expected average
output for a sawtooth waveform.
pkipyy



Joined: 21 Nov 2013
Posts: 25

View user's profile Send private message

Thank you.
PostPosted: Thu Mar 27, 2014 9:03 am     Reply with quote

I don't know why. But now maxmum voltge is 5V!
I guess tester was out of order for a moment.
By the way why 0 to 31?
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Thu Mar 27, 2014 9:26 am     Reply with quote

Read the chip's data sheet.
Section 17.
First line.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group