PDA

View Full Version : Dac1220



bsherman
- 11th January 2004, 07:33
Anyone have a code example for use with a DAC1220 20 bit DAC? Having problems getting mine to work. This device uses a SPI interface to clock in 3 bytes to the command registors.

gcoulondres
- 29th August 2005, 11:03
Good morning, i am trying to use dac1220. But it does'nt work with my code. If you have some one, can you send to me please. It is to verify if it work. Thank you.
Gautier ([email protected])

MikeTamu
- 29th August 2005, 18:07
Hi, I don't have code for a DAC1220, but I do have code for a Max1270 which is a 12 bit A/D convertor with SPI interface. You can easily convert my code to match your application by comparing data sheets. Here is my code:

'************************************************* ***************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2005 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 8/14/2005 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
DEFINE OSC 10 'resonator frequency at 10 Mhz

DEFINE LCD_DREG PORTB 'assign portb as data ports (DB4-DB7)
DEFINE LCD_DBIT 0 'assign starting DB4 on portb.0
DEFINE LCD_RSREG PORTB 'assign RS pin on portb
DEFINE LCD_RSBIT 4 'assign RS pin on portb.4
DEFINE LCD_EREG PORTB 'assign E pin on portb
DEFINE LCD_EBIT 5 'assign E pin on portb.5
DEFINE LCD_BITS 4 'set up 4 bit transfer lcd mode
DEFINE LCD_LINES 2 'number of lcd screen display lines

Pause 1000 ' Wait for LCD to startup


'Variables
rng var bit
bip var bit
channel var byte
tval1 var word

result var word
newresult var word
x var byte
pd var byte
xsee var byte

pd0 var bit 'power mode variable
pd1 var bit 'power mode variable

c0 var channel.0
c1 var channel.1
c2 var channel.2

clk var PORTC.6
datin var PORTD.4
csl var PORTC.7
datout var PORTD.5

Quanta5 CON 3125 'the sample conversion constant, (5/4095*256)*10000 for 0-5V
Quanta10 CON 6251 'the sample conversion constant, (10/4095*256)*10000 for 0-5V
Quantab5 CON 6251 'the sample conv. constant, (5/(4095/2)*256)*10000 for -5-5V
Quantab10 CON 12503 'the samp. conv. const., (10/(4095/2)*256)*1000 for -10-10V
Quanta var word

negflag var bit

'set up Max2710 pins
TRISC.6=0 'output clk
TRISD.4=0 'output datin
TRISC.7=0 'output csl
TRISD.5=1 'input datout

pd0=1 'this sets normal power operation mode with external clock
pd1=0





'Inputs
rng=1 'data conversion modes, see data sheet for max1270
bip=1 'data conversion modes, see data sheet for max1270
channel=0 'channel for conversion to read



'Trial run
loop:
negflag=0 'reset the negative flag for lcd
csl=1 'keep max2710 off till called
clk=0 'keep clock low till ready

gosub max1270

if bip = 0 or result.11=0 then skiptwoscompliment 'skip if not in bipolar mode
'if we come here then we are in bipolar mode not caught by above statements
'or if the number is positive we skip this conversion as well

negflag=1 'negative flag for use on lcd

result=result-1 'subtract 1 to get to 1's compliment from 2's compliment

'now we take the 1's compliment of result
if result.0=0 then newresult.0=1
if result.0=1 then newresult.0=0

if result.1=0 then newresult.1=1
if result.1=1 then newresult.1=0

if result.2=0 then newresult.2=1
if result.2=1 then newresult.2=0

if result.3=0 then newresult.3=1
if result.3=1 then newresult.3=0

if result.4=0 then newresult.4=1
if result.4=1 then newresult.4=0

if result.5=0 then newresult.5=1
if result.5=1 then newresult.5=0

if result.6=0 then newresult.6=1
if result.6=1 then newresult.6=0

if result.7=0 then newresult.7=1
if result.7=1 then newresult.7=0

if result.8=0 then newresult.8=1
if result.8=1 then newresult.8=0

if result.9=0 then newresult.9=1
if result.9=1 then newresult.9=0

if result.10=0 then newresult.10=1
if result.10=1 then newresult.10=0

result=newresult

'now we have the 2's compliment of a 2's compliment which is the real value


skiptwoscompliment:

'here we test for which constant to use in the conversion
if bip=0 and rng=0 then Quanta=Quanta5
if bip=0 and rng=1 then Quanta=Quanta10
if bip=1 and rng=0 then Quanta=Quantab5
if bip=1 and rng=1 then Quanta=Quantab10

Lcdout $fe, 1 ' Clear LCD screen
Lcdout DEC result


result=result*/QUANTA
result=result/100 'truncate 2 decimal places

if negflag=1 then Lcdout $fe, $c0,"-"
if negflag=0 then Lcdout $fe, $c0," "

Lcdout $fe, $c0+1 'go to second row of lcd, 2nd position
Lcdout DEC result DIG 2,".",DEC2 result
LCDOUT " Volts"




Lcdout $fe, $80+10
Lcdout DEC result

pause 330
goto loop




max1270:
'start process
csl=0 'cs going low starts the conversion process

'start bit
datin=1
pulsout clk,1

'channel select
datin=c2
pulsout clk,1
datin=c1
pulsout clk,1
datin=c0
pulsout clk,1

'set rng
datin=rng
pulsout clk,1

'set bip
datin=bip
pulsout clk,1

'set pd1,pd0
datin=pd1
pulsout clk,1
datin=pd0
pulsout clk,1

'5 clk pulse wait
datin=0
for x=0 to 4
pulsout clk,1
next

'bring the data in
result=0
shiftin datout,clk,0,[result\12]
pulsout clk,1

return

end


Here is the data sheet for the Max1270: http://pdfserv.maxim-ic.com/en/ds/MAX1270-MAX1271.pdf

gcoulondres
- 30th August 2005, 11:44
Thank you for the code. I look at it.
But I have to work for a job on this dac1220 because I must have a 20 bit digital to analog converter.
Thanks

MikeTamu
- 30th August 2005, 15:59
All you have to do is modify what bits to send in order to access your DAC1220. Take a look at the signal bit trains in the DAC1220 data sheet. The SPI setup for the MAX1270 is similar.