TLC5615 D/A converter-problems with code....

Fellas,

This is my first time posting here. I am excited to become part of this unique online community. I am attempting to use a recently purchased TLC5615 breakout board with an arduino UNO. I am getting an error message when uploading saying ‘data’ was not declared in this scope. Here is the code I am attempting to upload:

#define CS 2 //chip enable
#define CLOCK 3
#define DATA 4

#define HALF_CLOCK_PERIOD 2 //2 uS of clock period
float j=0;
void setup()
{
pinMode(DATA, OUTPUT);
pinMode(CLOCK,OUTPUT);
pinMode(CS,OUTPUT);
digitalWrite(CS,HIGH);
digitalWrite(DATA,LOW);
digitalWrite(CLOCK,LOW);
}

void writeValue(uint16_t value)
{
digitalWrite(CS,LOW);//start of 12 bit data sequence
digitalWrite(CLOCK,LOW);
data = data << 2; //Add 2 0 at the end of the data. A 10-bit data word should add 2 0 at the LSB bit (sub-LSB) since the DAC input latch is 12 bits wide.(SEE TLC5615C DATASHEET)
for(int i=11; i>=0; i–)//send the 12 bit sample data
{
digitalWrite(DATA, (value & (1 << i) ) >> i );//DATA ready
delayMicroseconds(HALF_CLOCK_PERIOD);
digitalWrite(CLOCK,HIGH);//DAC get DATA at positive edge
delayMicroseconds(HALF_CLOCK_PERIOD);
digitalWrite(CLOCK,LOW);
}
digitalWrite(CS,HIGH);//end 12 bit data sequence
}

void loop()
{
j=567; //in here, 567 is a example. DAC OUT=j*Vref/1024
writeValue(floor(j));
}

Programming isn’t exactly my strong point, and I have no idea what might be causing the issue. Any assistance would be appreciated by this newbie :slight_smile:

It's telling you that you have not declared anything called 'data'. Guessing, I suspect you meant value instead.

I re-named the data to value and it didn't seem to help. I also capitalized data and it didn't help either. hmmm...

No where do you define data or value - is this all your code?

KeithRB:
No where do you define data or value - is this all your code?

Yes, unfortunately that was all the code that was found when I did my google search. looks like I will need to look into how exactly to define those parameters in the code.

A simple

int data;
int value;

might be a good start.

josh8loop:
I re-named the data to value and it didn’t seem to help. I also capitalized data and it didn’t help either. hmmm…

value is passed to writeValue. This change made it compile at least:

 value = value << 2; //Add 2 0 at the end of the data. A 10-bit data word should add 2 0 at the LSB bit (sub-LSB) since the DAC input latch is 12 bits wide.(SEE TLC5615C DATASHEET)

KeithRB:
A simple

int data;

int value;




might be a good start.

Right, I was just looking through the arduino.cc information on declaring values and saw that the int might be the way to declare it. I will try your recommendation.

Here is what I ended up with:

#define CS 2 //chip enable
#define CLOCK 3
#define DATA 4

#define HALF_CLOCK_PERIOD 2 //2 uS of clock period
float j=0;
int data;
int value;
void setup()
{
pinMode(DATA, OUTPUT);
pinMode(CLOCK,OUTPUT);
pinMode(CS,OUTPUT);
digitalWrite(CS,HIGH);
digitalWrite(DATA,LOW);
digitalWrite(CLOCK,LOW);
}

void writeValue(uint16_t value)
{
digitalWrite(CS,LOW);//start of 12 bit data sequence
digitalWrite(CLOCK,LOW);
data = data << 2; //Add 2 0 at the end of the data. A 10-bit data word should add 2 0 at the LSB bit (sub-LSB) since the DAC input latch is 12 bits wide.(SEE TLC5615C DATASHEET)
for(int i=11; i>=0; i–)//send the 12 bit sample data
{
digitalWrite(DATA, (value & (1 << i) ) >> i );//DATA ready
delayMicroseconds(HALF_CLOCK_PERIOD);
digitalWrite(CLOCK,HIGH);//DAC get DATA at positive edge
delayMicroseconds(HALF_CLOCK_PERIOD);
digitalWrite(CLOCK,LOW);
}
digitalWrite(CS,HIGH);//end 12 bit data sequence
}

void loop()
{
j=567; //in here, 567 is a example. DAC OUT=j*Vref/1024
writeValue(floor(j));
}

I uploaded it to a Leonardo board with no problems. Also appeared to upload onto the UNO just fine as well. Only issue now is where to hook up the CS pin on the breakout board. From the sketch it isn’t obvious.

Well, you know you need to connect D2:

#define CS 2 //chip enable

You have not provided any data on the breakout board tho. Obvious answer for us to provide is: Find the Chip Select or Slave Select input and connect to that.

CrossRoads:
Well, you know you need to connect D2:

#define CS 2 //chip enable

You have not provided any data on the breakout board tho. Obvious answer for us to provide is: Find the Chip Select or Slave Select input and connect to that.

Ah hah,

So CS 2 is digital pin #2. Got it, thanks. Here is the breakout board:

http://www.ebay.com/itm/TLC5615-10-bit-Serial-Interface-DAC-Module-Digital-to-Analog-Module-/310699879944?pt=LH_DefaultDomain_0&hash=item485727ee08

Looks like CLOCK 3 is digital pin #3, and DATA 4 is digital pin #4

Just wanted to update this thread. I used the above sketch with the suggested modifications and was able to output analog output voltages through the D/A converter. Changing the j= value at the bottom of the sketch to anywhere between 0-400 and then uploading it to the arduino gives an output voltage of approx 0-5 vdc output. Pretty neat! Now I want to modify it so that I can use serial communication to allow me to change the j= value. Looks like I may have some work to do.....Thanks to all who have helped on this so far. If anyone knows a good effective way for me to use serial communication from the computer to change the j= value on the fly feel free to recommend changes to the sketch :slight_smile:

This should get you going:

KeithRB:
This should get you going:
http://arduino.cc/en/Tutorial/ReadASCIIString

On my way....