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

DAC converter Program

 
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

DAC converter Program
PostPosted: Thu Nov 18, 2004 9:19 pm     Reply with quote

Hi..we are using 16F877 and DAC TC1320 .
We are using CCS C compiler 3.202 . I have
tried to test the following program of Sawtooth
generator to test DAC functionality. But it doesn't
give anything to output. I am not sure the way, I am
writting the data is correct or not..?
Can anybody give any idea that following program has
correct or not?
Quote:

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

#define DAC_SDA PIN_C4
#define DAC_SCL PIN_C3

#use i2c(SLAVE, SDA=DAC_SDA, SCL=DAC_SCL, address=0x9B)
//address is SMBus Slave address which is given in TC1320 datasheet

void init_DAC()
{
output_float(DAC_SCL);
output_float(DAC_SDA);
}

BOOLEAN DAC_ready()
{
int1 ack;
i2c_start();
ack=i2c_write(0x48);
i2c_stop();
return !ack;
}

void write_DAC(BYTE data)
{
while(!DAC_ready());

i2c_start();
i2c_write(0x48); // 7 bit SMBus address for TC1320 and 8th bit is Read/Write(bar i.e negative)
i2c_write(data);
i2c_stop();

}

void main()
{
int8 i;

init_DAC();

while (TRUE) {

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



Any idea appreciated.....

Regards
Prashant
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Thu Nov 18, 2004 11:29 pm     Reply with quote

Quote:
#use i2c(SLAVE, SDA=DAC_SDA, SCL=DAC_SCL, address=0x9B)


The address you specified here is if you want the pic to act as a slave. You do not! The PIC is the master and the DAC is the slave. Take out the address and configure as a master.

You are also a bit confused on the DAC's address. The 8th bit as the datasheet calls it is actually bit0. So the DAC's address is 0x90 in write mode and 0x91 to read. This is probably where the 0x9B came from. The datasheet shows 1001 000b and you mixed hex notation with binary notation. It would have been more clearer to show it as 1001 000x.

Also note that you must write 0x00 after the address and then your data byte. If you want to access the Config register, then write a 0x01 and then the data for the config reg. Refer to Figure 3-1 for more info on this.
Prashant Patel



Joined: 19 Jul 2004
Posts: 33

View user's profile Send private message

DAC converter Program
PostPosted: Sun Nov 21, 2004 2:40 pm     Reply with quote

Thanx Mark,

You have tought me good points. But I am new to
DAC or slave mode or I2C. Still it is not giving
any output. Following is the program that I have
modified. I can't figure out what can be the problem?
Please help to find out.
Quote:

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

#define DAC_SDA PIN_C4
#define DAC_SCL PIN_C3

#use i2c(MASTER, SDA=DAC_SDA, SCL=DAC_SCL)
//address is SMBus Slave address which is given in TC1320 datasheet

void init_DAC()
{
output_float(DAC_SCL);
output_float(DAC_SDA);
}

void write_DAC(BYTE data)
{
i2c_start();
while(!i2c_write(0x90)); // 7 bit SMBus address for TC1320 and 8th bit is Read/Write(bar i.e negative)
while(!i2c_write(0x00)); // I have tried without while as well.
while(!i2c_write(data));
i2c_stop();

}

void main()
{
int8 i;

init_DAC();

while (TRUE) {

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


Here is the protocol for sending the data.
Quote:

Start->Address-> R/W ->ACK-> Command-> ACK-> Data-> ACK->Stop


Help appreciated.....

Regards
Prashant
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Sun Nov 21, 2004 5:03 pm     Reply with quote

You only need the while(!i2c_write(0x90)). The others are not needed.

You do not need to do the output floats.

Do you have pullups on the data and clock lines?
Prashant Patel



Joined: 19 Jul 2004
Posts: 33

View user's profile Send private message

DAC converter Program
PostPosted: Sun Nov 21, 2004 5:58 pm     Reply with quote

Hi..

I have removed the floating lines. And also used
pullups of 4.7K on data and clock line. But still
not getting anything on the output.

Let me ask you one question, if we use the following line.
#use i2c(MASTER, SDA=PIN_C4, SCL=PIN_C3, FAST)

Should the PIN_C3 produce the clock pulses or not?
What should I do to test it?
Should it required to make PIN_C3 or PIN_C4 output or
input?

I can't understand what can be problem?
Do you want to check the simple circuit of TC1320 with 16F877?

Help appreciated.....

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