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

How to interface PIC18F2520 with External 16 bit DAC

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



Joined: 03 Oct 2012
Posts: 242
Location: chennai

View user's profile Send private message

How to interface PIC18F2520 with External 16 bit DAC
PostPosted: Wed Mar 20, 2024 3:24 am     Reply with quote

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: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Mar 20, 2024 4:54 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Mar 21, 2024 6:51 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Mar 21, 2024 11:49 am     Reply with quote

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: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Mar 21, 2024 2:18 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Mar 21, 2024 3:41 pm     Reply with quote

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: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Mar 21, 2024 4:55 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Mar 22, 2024 2:24 am     Reply with quote

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