i2c with a dac


Closed Thread
Results 1 to 12 of 12

Thread: i2c with a dac

  1. #1
    fabritio's Avatar
    fabritio Guest

    Default i2c with a dac

    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

  2. #2
    fabritio's Avatar
    fabritio Guest


    Did you find this post helpful? Yes | No

    Default

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

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Question

    Hi

    I undertand ...

    But, you're sending a 16 bits word for 10 needed bits ...

    is that a problem with the DAC ???

    Alain

  4. #4
    fabritio's Avatar
    fabritio Guest


    Did you find this post helpful? Yes | No

    Default

    So, how can I define that I am sending only 10 bits?

  5. #5
    fabritio's Avatar
    fabritio Guest


    Did you find this post helpful? Yes | No

    Default

    Is there a configuration of the SSP registers that I have to do first?

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Originally posted by fabritio
    So, how can I define that I am sending only 10 bits?
    i2cwrite sda,scl,addr,[val\10]
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    fabritio's Avatar
    fabritio Guest


    Did you find this post helpful? Yes | No

    Default

    Thank you,
    i am still wondering about the ssp registers configurations....

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Question

    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
    Last edited by Acetronics2; - 14th February 2005 at 14:38.

  9. #9
    Bongo's Avatar
    Bongo Guest


    Did you find this post helpful? Yes | No

    Default Tc1321 Sample Code Please!

    Please send me working Basic code for TC1321 ...

  10. #10
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

  11. #11
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Bongo,

    great start on this forum!

    here is your welcome gift
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  12. #12
    scholar's Avatar
    scholar Guest


    Did you find this post helpful? Yes | No

    Default

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

Similar Threads

  1. I2C Master/Slave 16F88/16F767 working code
    By DanPBP in forum Code Examples
    Replies: 2
    Last Post: - 23rd October 2012, 22:31
  2. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  3. Another I2C Slave Routine Problem
    By DanPBP in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th February 2009, 05:50
  4. I2C Master Slave issues.
    By cpayne in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th March 2008, 19:33
  5. Please help with i2cslave i2c slave
    By cycle_girl in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st December 2005, 13:55

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts