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 support@ccsinfo.com

Controlling a MAX510 with a 16F690

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



Joined: 26 Jun 2006
Posts: 9

View user's profile Send private message

Controlling a MAX510 with a 16F690
PostPosted: Tue Jul 04, 2006 9:44 am     Reply with quote

Hi everyone,

for a small application I used the 16F690 and the MAX510 (DAC).
The PIC needs to control the output of the MAX by using SPI. Using SPI_WRITE() works well and I can see both the data and the CLK on the oscilloscope.

But I can not control the MAX as I want to.
The MAX expects to receive a 12bit-word. Since the PIC can only send 8 bit I send it twice and the MAX ignores the first four digits.

But the SDO-port (C7) stays at the last level sent. E.g. if the last message was 0x01 the pin stays ‘H’ and if the last message was 0x00 the pin stays ‘L’.

Since the MAX does not react on the messages as explained in the datasheet, I wonder if it causes a problem when the level at the SDO-port is not predictable to the beginning of a new message.

The code I use:
SETUP_SPI(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_64);
set_tris_c(0x21);
SPI_WRITE(0x0B); SPI_WRITE(0xFF); SPI_WRITE(0x02); SPI_WRITE(0x00);


Does anyone have experiences in this matter? Or even in programming a MAX510 with a PIC.

Best regards and thanks in advance.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 04, 2006 1:18 pm     Reply with quote

The initial state of the PIC's SDO pin doesn't matter.

But I noticed in your code that you don't handle the CS signal for the
MAX510. You need to do that. Assign a pin on the PIC for CS.
Set it low before you send each pair of command/data bytes.
Then set it high after that. Examples:

Code:
output_low(MAX510_CS);
spi_write(0x0B);         // Load DAC C
spi_write(0xFF);         // Set it to max value
output_high(MAX510_CS);

delay_us(1);   // This delay might be necessary

output_low(MAX510_CS);
spi_write(0x02);           // Update all DACs
spi_write(0x00);           // Dummy data for this command
output_high(MAX510_CS);

The data sheet doesn't say anything about an idle time being required
between CS pulses, but it might be necessary, so I showed where you
would insert a delay if needed.


Also, I don't think you're using the correct SPI mode. On page 9 of
the MAX510 data sheet, it shows that incoming data (to the MAX510)
is sampled on the rising edge of SCLK, and it should change on the
falling edge. Look at a diagram of SPI modes here:
http://www.totalphase.com/support/articles/article03/#modes
The MAX510 uses mode 0.

If you want to use the CCS constants to set the SPI mode, ckielstra
has prepared a chart which shows how to do it:
http://www.ccsinfo.com/forum/viewtopic.php?t=21650&start=8
So this is what you should be using:
Code:
SETUP_SPI(SPI_MASTER | SPI_L_TO_H | SPI_XMIT_L_TO_H | SPI_CLK_DIV_64);


Also, CharlieU has posted a convenient way to set the modes:
http://www.ccsinfo.com/forum/viewtopic.php?t=26662&start=4
Guest








PostPosted: Wed Jul 05, 2006 3:28 am     Reply with quote

Great, that solved the problem!
I set the CS of the MAX to low at the beginning to the program but did not set it high later on.
With the settings you showed me I can control the MAX almost perfect.

The last problem is that the MAX gave me an output between 0,4V (0x00) and 2,8V (0xFF) instead of 0..5V. But that seems to be a problem with the MAX.

Thanks a lot for your quick and helpful advice.
rt_joerg



Joined: 26 Jun 2006
Posts: 9

View user's profile Send private message

PostPosted: Wed Jul 05, 2006 3:29 am     Reply with quote

Great, that solved the problem!
I set the CS of the MAX to low at the beginning to the program but did not set it high later on.
With the settings you showed me I can control the MAX almost perfect.

The last problem is that the MAX gave me an output between 0,4V (0x00) and 2,8V (0xFF) instead of 0..5V. But that seems to be a problem with the MAX.

Thanks a lot for your quick and helpful advice.
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