View previous topic :: View next topic |
Author |
Message |
Lyreco
Joined: 07 Jul 2011 Posts: 4
|
CCS routine for writing to a DAC? |
Posted: Thu Jul 07, 2011 1:38 am |
|
|
Hi Guys/Gals
I am new to PIC programming and use CCS PCW for compiling.
I am trying to program an external DAC from a 18F series mpu via SPI.
Has anyone any pointers or insight into this.?
Would I have a LUT or array store DAC codes (VID) or just call them from a routine?
I would like to have some fixed values for both Voltage and Current to send out of the DAC.
cheers. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9170 Location: Greensville,Ontario
|
|
Posted: Thu Jul 07, 2011 4:47 am |
|
|
First step is to program your PIC with the 'Hello World' program and get familiar with it.
Second it to show us your DAC code along with PIC type, compiler version AND the DAC chip number. There are hundreds of 'external DACs' on the market and we can't help you without more information.
One hint though, be sure to use the defines for the SPI modes. It'll make programming a LOT easier. |
|
![](templates/subSilver/images/spacer.gif) |
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Thu Jul 07, 2011 11:04 am |
|
|
Hi,
I used the MAX517, an i2c connected DAC, in a recent project. It's easy to use, but may not have the required resolution (8 bit) for your project?
Here is the subroutine I use to send data to the MAX517.
Code: |
// This routine receives a byte from Main, and sends it out to the MAX517
// D-to-A converter. The range of the input is 0 to 255, which
// corresponds to an output voltage of 0 to 5V.
void write_dac(int data_out)
{
i2c_start();
i2c_write(0x58); // Device address when AD0 and AD1 are tied to ground
i2c_write(0);
i2c_write(data_out); // Send the data to the device
i2c_stop();
}
|
As was already mentioned, there are lots of choices!
John |
|
![](templates/subSilver/images/spacer.gif) |
Lyreco
Joined: 07 Jul 2011 Posts: 4
|
|
Posted: Fri Jul 08, 2011 1:06 am |
|
|
Yes, thanks John.
You are missing the SPI set up part, ie: SPI L-H for the mode 0 i need here.
That code is pretty exactly what i wrote with avr studio for an Atmel.
The ccs has its own lingo it seems. |
|
![](templates/subSilver/images/spacer.gif) |
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Fri Jul 08, 2011 10:15 am |
|
|
Hi,
Sorry, I missed the fact that you were looking for help with an SPI connected external D/A.
The MAX517 is an I2C part. If the resolution is adequate, it sure is easy to use, so you might still give it a look!
John |
|
![](templates/subSilver/images/spacer.gif) |
|