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 support@ccsinfo.com

10Bit DAC TC1321

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



Joined: 19 Jul 2004
Posts: 33

View user's profile Send private message

10Bit DAC TC1321
PostPosted: Tue Dec 14, 2004 6:20 pm     Reply with quote

Hi..

we are using 16F877 and DAC TC1321.

I have written following simple program to generate saw tooth waveform.
4.7K pullups are connected to both SDA and SCL line.
Reference volgate at pin Vref is 3.0V ( using 2.2k and 3.2k).

The pulses produced at SCL and SDA line are fine.
I have change three DAC TC1321 to make sure it is working.

What can be problem?

Onething to make sure is for sending 8bit data would it be fine to write
i2c_write(data);
line only once or need to write it twice?

Quote:

#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

#ifndef DAC_SDA

#define DAC_SDA PIN_C4
#define DAC_SCL PIN_C3

#endif

#use i2c(MASTER, SDA=DAC_SDA, SCL=DAC_SCL,FAST)

void write_DAC(int data)
{
i2c_start();
i2c_write(0x90); // 7 bit SMBus address for TC1321 and 8th bit is Read/Write(bar i.e negative)
i2c_write(0);
i2c_write(data);
i2c_stop();
}

void main()
{
int i;

delay_ms(100);

while (TRUE) {

write_DAC(i);
i=i+1;
if(i==255)
i=0;

}//while (TRUE)
}



Thanx in advanced...

Regards
Prashant
Charlie U



Joined: 09 Sep 2003
Posts: 183
Location: Somewhere under water in the Great Lakes

View user's profile Send private message

PostPosted: Tue Dec 14, 2004 10:36 pm     Reply with quote

Check the data sheet for the DAC closely. The maximum clock rate is 100kHz, which in I2C land is SLOW, not FAST. Try changing the parameter in your #use i2c() to SLOW.

Let us know if this helps.
Prashant Patel



Joined: 19 Jul 2004
Posts: 33

View user's profile Send private message

PostPosted: Wed Dec 15, 2004 1:43 pm     Reply with quote

Hi..

Thanks for reply.

I checked the datasheet for DAC TC1321. Max clock frequency
is 100KHz.
I have tried the following way to make clock input to DAC slow
but it does not work?
Please tell me if it is not proper or you know some other way.
The interesting thing is clock input and SDA output are fine.
Then shouldn't it produce the sawtooth waveform?
Quote:

#use i2c(MASTER, SDA=DAC_SDA, SCL=DAC_SCL,SLOW)


I have also tried to remove SLOW keyword but no effect.
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Wed Dec 15, 2004 3:47 pm     Reply with quote

Have you confirmed that Vdd of the DAC is connected?

Have you confirmed that Vref of the DAC is connected?

Have you confirmed that SDA and SCL are connected at the DAC and not accidentally swapped?

Are you monitoring pin 5 (VOUT) or pin 7 (DAC-OUT)? I suggest you monitor pin 5 as DAC-OUT is unbuffered and can't drive much load.

I add this function:
Code:
void
init_ext_i2c (void)
{
  output_float (SCL_PIN);
  output_float (SDA_PIN);
}


before I start using the I2C bus. I typically use #use fast_io() and setup the pin directions myself rather than allow the extra instructions inserted by #use standard_io() (the default if you don't specify "fast" or "fixed").

Your function "void write_DAC(int data)" seems reasonable.

Finally, although this shouldn't be stopping your DAC from working, your code:
Code:

while(TRUE) {
   write_DAC(i);
   i=i+1;
   if (i==255)
      i=0;
}

is a bit too much for sending 0 to 255 over and over. All you need is
Code:

while(TRUE) {
   write_DAC(i++);
}

assuming "i" is an 8 bit. "i" will just roll over from 0xFF back to 0 all by itself! Isn't that clever! Very Happy

I generally use "int8" instead of "int" when I mean something to be 8-bit signed but not intended as a character. Eventhough "char" is the same thing, I think it improves the readability of the code because you know a bit more about what the variable is intended to do. Anyway, just personal preference.

Another thing I like to add is #CASE near the beginning to force case sensitivity. Again, personal preference.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
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