Programmed Adjustable Power PART 2: Using Arduino to control DAC (TLC5615)

0

Comments

We use TI's TLC5615, 10-BIT DIGITAL-TO-ANALOG CONVERTERS as our DAC.
This chip has 3-Wire Serial Interface, so we can use Arduino to control it.
Arduino is an open-source physical computing platform based on the AVR MCU.
Now give the Arduino program.

//Arduino project http://arduino.cc
//by Mini Dragon at http://minidr.com/archives/687
//This program is licensed under a Creative Commons Attribution-ShareAlike 3.0 License.
#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));
}

Each DAC output voltage maps a main Vout.
To be continued.

[Update 2014/Tue/22] Code Opt

来了你就吐槽我吧!






Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).