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

CCS routine for writing to a DAC?

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



Joined: 07 Jul 2011
Posts: 4

View user's profile Send private message

CCS routine for writing to a DAC?
PostPosted: Thu Jul 07, 2011 1:38 am     Reply with quote

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



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

View user's profile Send private message

PostPosted: Thu Jul 07, 2011 4:47 am     Reply with quote

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



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu Jul 07, 2011 11:04 am     Reply with quote

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
Lyreco



Joined: 07 Jul 2011
Posts: 4

View user's profile Send private message

PostPosted: Fri Jul 08, 2011 1:06 am     Reply with quote

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



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Fri Jul 08, 2011 10:15 am     Reply with quote

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