View previous topic :: View next topic |
Author |
Message |
pkipyy
Joined: 21 Nov 2013 Posts: 25
|
How can I use DAC? |
Posted: Mon Mar 24, 2014 11:31 am |
|
|
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: 9245 Location: Greensville,Ontario
|
|
Posted: Mon Mar 24, 2014 11:48 am |
|
|
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
|
|
Posted: Mon Mar 24, 2014 2:25 pm |
|
|
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
|
I tell DAC in pic16f1937. |
Posted: Mon Mar 24, 2014 6:38 pm |
|
|
Thank you.
I tell DAC in pic16f1937.
I'm sorry! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 24, 2014 10:31 pm |
|
|
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
|
My ccs version is 5.008. |
Posted: Tue Mar 25, 2014 8:31 am |
|
|
My ccs version is 5.008.
How about 5.008? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 25, 2014 11:38 am |
|
|
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
|
Thank you. |
Posted: Wed Mar 26, 2014 6:14 pm |
|
|
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
|
|
Posted: Wed Mar 26, 2014 7:52 pm |
|
|
How are you measuring the output of the DAC? |
|
|
pkipyy
Joined: 21 Nov 2013 Posts: 25
|
I used analog tester. |
Posted: Wed Mar 26, 2014 9:43 pm |
|
|
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
|
|
Posted: Thu Mar 27, 2014 12:32 am |
|
|
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
|
Thank you. |
Posted: Thu Mar 27, 2014 9:03 am |
|
|
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: 19549
|
|
Posted: Thu Mar 27, 2014 9:26 am |
|
|
Read the chip's data sheet.
Section 17.
First line. |
|
|
|