View previous topic :: View next topic |
Author |
Message |
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
How to interface PIC18F2520 with External 16 bit DAC |
Posted: Wed Mar 20, 2024 3:24 am |
|
|
Hello,
I want to interface the PIC18F2520 with external 16 bit DAC (Example: AD5061). Please can you support how to send data to the external DAC. Any code snippets to understand.
Voltage reference: +5V
uC PIN 16 (SDO) is connected to DIN
uC PIN 14 (SCK) is connected to SCLK
uC PIN B0 is connected to SYNC
Thanks in advance. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9232 Location: Greensville,Ontario
|
|
Posted: Wed Mar 20, 2024 4:54 pm |
|
|
Curious, so I downloaded the data sheet for that DAC.
Simple ,basic SPI interface and requires 3 bytes to be sent to it...
1st byte, all zeros
2nd byte, high byte of DAC word
3rd byte, low byte of DAC word
Now SPI has 4 'modes', so you'll have to decide which it is....
It also has a 'speed or clock', again you'll have to read the datasheet for that.
You could try Google to see if others have used that DAC. probably some Ardunio C code, you could look at
I don't have the DAC, so I can't cut and test code for you. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19529
|
|
Posted: Thu Mar 21, 2024 6:51 am |
|
|
The only thing he has to do more complex than the basic SPI, is the SYNC
line.
Leave this low, then pulse it high for just one processor instruction, and drop
it again, then send the data. The sync line should remain low all the time
except for this pulse. This signals that a data packet is about to come.
Resets the shift register.
Mode1 |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Thu Mar 21, 2024 11:49 am |
|
|
According to the datasheet send diagram I have (Rev E page 16), Sync is
treated like an Enable/Chip Select line. Low when sending register data,
back high when finished and stays high between send sequences.
Am I missing something? _________________ Google and Forum Search are some of your best tools!!!! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9232 Location: Greensville,Ontario
|
|
Posted: Thu Mar 21, 2024 2:18 pm |
|
|
hmm, the way I read it is
normally keep sync high
to send data to DAC
set sync low
send 24 bits SPI data....
set sync high
at least that seems to be the 'safe' way to use the chip...
must be an old chip, seems too simple to use, even for me...
Jay |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Thu Mar 21, 2024 3:41 pm |
|
|
Just for grins I requested CoPilot to give me CCS code for the AD5061 and it
gave me a fairly good starting point using the 16F877A and 16 bits output
rather than 24.
Took me about 15 minutes to modify the code to prefix the eight control/mode
bits in front of the 16 data bits...once I did that and changed the processor it
worked (gave me a repeating ramp). Dang AI is getting better all the time.. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9232 Location: Greensville,Ontario
|
|
Posted: Thu Mar 21, 2024 4:55 pm |
|
|
more grins here !!!!
I too said PIC16F877 and AD5061... dang pretty fast and a good 'starting point'.
Now, can the AI TELL me how to get rid of the 4" of 'white' coming here tomorrow ???
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19529
|
|
Posted: Fri Mar 22, 2024 2:24 am |
|
|
Just have to point out Jay, that you have the operation of the sync line
wrong in this. The data sheet says:
"The write sequence begins by bringing the /sync line low".
Basically you have to pulse this high then low, to trigger the start of the
write.
You can keep it high, but the sheet also says the chip draws less current
if this is kept low. So the easiest 'low current' route is to keep sync low
and just pulse is high then low.The pulse only needs to be a few nSec.
So what you post will work, but draws unnecessary power.
temtronic wrote: | hmm, the way I read it is
normally keep sync high
to send data to DAC
set sync low
send 24 bits SPI data....
set sync high
at least that seems to be the 'safe' way to use the chip...
must be an old chip, seems too simple to use, even for me...
Jay |
|
|
|
|