View Full Version : i2c with a dac
fabritio
- 11th February 2005, 10:27
Hello,
I am quite new in picbasic programming.
I am trying to figure out if it's possible to send bits to a dac (tc1321) form a pic16f876.
I want to send a 10bit serial word to the device.
I wrote this program:
SDA var byte
SCL var byte
ADDR var byte
VAL var word
i var word
TRISB.4 = 1 ' Pin B4ingresso
TRISC = 0 ' Porta C uscita
SDA = 12 ' Imposto l'uscita SDA sul pin C4
SCL = 11 ' Imposto l'uscita SCL sul pin C3
ADDR = %10010000 ' Indirizzo del TC1321
main:
if PORTB.4 then
goto inizia
else
goto main
endif
inizia:
val = %0000000000
for i=0 to 14
i2cwrite sda,scl,addr,[val]
val = val + %1000000
next
val = %1111111111
i2cwrite sda,scl,addr,[val]
while PORTB.4 = 0
i2cwrite sda,scl,addr,[val]
wend
goto inizia
end
Do you think it's right or I've done GREAT errors?
Thank you very much!!
Fabrizio
fabritio
- 11th February 2005, 12:24
Originally posted by Acetronics
Hi,
I suppose it might have been this
for i=0 to 14
i2cwrite sda,scl,addr,[val]
val = val + %0000001
instead of that
for i=0 to 14
i2cwrite sda,scl,addr,[val]
val = val + %1000000
.....
or there's no need for a DAC.
Alain
I only meant to do a conversion from 0 to 1024 in 16 steps, so I add 64 for every step (%1000000).
Thank you for the answer however...
Acetronics2
- 11th February 2005, 13:55
Hi
I undertand ...
But, you're sending a 16 bits word for 10 needed bits ...
is that a problem with the DAC ???
Alain
fabritio
- 11th February 2005, 14:25
So, how can I define that I am sending only 10 bits?
fabritio
- 11th February 2005, 15:35
Is there a configuration of the SSP registers that I have to do first?
mister_e
- 11th February 2005, 17:33
Originally posted by fabritio
So, how can I define that I am sending only 10 bits?
i2cwrite sda,scl,addr,[val\10]
fabritio
- 14th February 2005, 12:12
Thank you,
i am still wondering about the ssp registers configurations....
Acetronics2
- 14th February 2005, 14:35
Did you had a look at table 4-4 page 10 from the TC Datasheet ???
Seems that the 6 lower data bits must be 0, and 16 bits to be sent.
so your example gives the 2 to 16 lower values ( less than 4% of full output ... )
that at a very high speed , as there is no PAUSE between each FOR-NEXT ... and then jumps and stops to the max value.
output seems not to be clearly visible ... even on a good scope !
Alain
Bongo
- 5th April 2005, 12:58
Please send me working Basic code for TC1321 ...
Melanie
- 5th April 2005, 13:30
Gesh... try this thread...
http://www.picbasic.co.uk/forum/showthread.php?t=1498
NavMicroSystems
- 5th April 2005, 14:31
Bongo,
great start on this forum!
here is your welcome gift (http://www.getdigital.de/images/produkte/rtfm.jpg)
scholar
- 29th March 2006, 17:13
@ device hs_osc
define osc 4
Ctrl con %10010000
CPIN var portb.1
DPIN var portb.0
trisa=0
porta=255
pause 1000
porta=0
pause 1000' Pause 50ms for MC23016 to start-up
main:
i2cwrite DPIN, CPIN, Ctrl,%00000000,%10000000,%00000000 '512*Vref/1024
pause 2000
i2cwrite DPIN, CPIN, Ctrl,%00000000,%00000000,%00000000
pause 2000
goto main
with this code i able to generate analog voltage at the output. But funny thing is i only able to generate the first value (512*Vref/1024) but no respond after 2s. It suppose to change to 0V after 2s.
Powered by vBulletin® Version 4.1.7 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.