View previous topic :: View next topic |
Author |
Message |
rt_joerg
Joined: 26 Jun 2006 Posts: 9
|
Controlling a MAX510 with a 16F690 |
Posted: Tue Jul 04, 2006 9:44 am |
|
|
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
|
|
Posted: Tue Jul 04, 2006 1:18 pm |
|
|
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
|
|
Posted: Wed Jul 05, 2006 3:28 am |
|
|
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
|
|
Posted: Wed Jul 05, 2006 3:29 am |
|
|
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. |
|
|
|