Example: DAC (Digital to Analog IC)

Learn how to use a H-bridge motor driver to help us spin a small DC motor.

Hardware Required

  • TI LaunchPad

  • Breadboard

  • TLC5615CP

Relevant Groundwork

In this example we will use a Digital to Analog converter.

Code

/* DAC Example */
#define CS 8 // chip select
#define CLOCK 9
#define DATA  10

#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));
}

Troubleshooting

Code not uploading?

  • Check for errors in Energia debug window. The compiler will tell you what is happening. Errors are in red text.

  • Sometimes your LaunchPad gets stuck or hung up on the previous code. Unplug your LaunchPad and plug it back in to perform a full reset. This is called a power on reset. Sometimes using the RESET button can work but taking away the power and letting the microcontroller fully reset is often best.

  • If you have a failure to upload it could be your drivers are not properly installed. Energia will sometimes give the error "No unused FET Found" which means it can’t find a LaunchPad connected to your computer. Make sure you download the drivers for your operating system found on the Getting Started Guide.

  • If you had no problem with the previous Blink example, your Energia should be correctly set up. Restart your LaunchPad and restart Energia IDE if you encounter any problems. Make sure to select the right serial port and board type under the Tools menu.

No Values? * Make sure you properly connected the pins for clock, data, and chip select.

For additional support, try searching the Energia forums on 43oh.com. We believe in you to figure out any problems, now believe in yourself and find the solution!

Guide Home