Go Down

Topic: a nice 16 bit DAC project (Read 3248 times) previous topic - next topic

kaaasap

First post on first project, but not too new to Arduino and thought I would share. 

I created a nice 16bit DAC project using:
   5 volt Pro Mini
   Analog Devices 16 bit 2 channel SPI DAC AD5663ARMZ
   four - Micrel Inc.s MIC94050YM4 P-channel MOSFets
   four - 0.1uf capacitors.

I used ExpressPCB for a quick board layout and quick turn around. 

Attached is the PCB layout (2 layer - red top, green bottom)

and here is a the code:

#include <SPI.h>

#define SS 10;  //chip select pin
#define MOSI 11;  //master out slave in pin
#define MISO 12;  //master in slave out pin
#define CLK 13;  //clock pin

unsigned int data;
byte DACA = B00011000;  //send to set channel A on DAC
byte DACB = B00011001;  //send to set channel B on DAC
byte bothDAC = B00011111;  //send to set both channels on DAC

word bothPower = 39000;  //will have to adjust to change output

word fullOff = 0xffff;   //turns selected channel(s) of DAC off
word fullOn = 0x0000;  //turns selected channel(s) of DAC to full power
word halfPower = 0x2ee0;  //turns selected channel(s) of DAC to half power


const int slaveSelectPin = 10; 

void setup()
{
  //Serial.begin(115200);  // Serial0 @ 115200 (115200) Baud
  pinMode(slaveSelectPin,OUTPUT);   //must include for spi
  SPI.begin();  //initialize spi communications
  SPI.setDataMode(SPI_MODE1);  //set spi communications to mode 1 standards
  SPI.setClockDivider(SPI_CLOCK_DIV2);  //set spi clock to 4MHz (16MHz system clock, 2 clocks per cycle, divided by 2)
  SPI.setBitOrder(MSBFIRST);  //set to most sig bit first
  digitalWrite(10, HIGH);  //set chip select pin high as SS on chip is active low
 
  delay(200);  //wait 200ms
  digitalWrite(10,LOW);  //set SS low to begin communications
  SPI.transfer(DACA);  //writes to DAC to set both channels
  data= highByte(bothPower);  //gets the first 8 bits of 16 bit value
  SPI.transfer(data);  //writes first 8 bits of 16 bit value from above
  data= lowByte(bothPower);  //gets the second 8 bits of 16 bit value
  SPI.transfer(data);  //writes the second 8 bits of 16 bit value from above
  digitalWrite(10, HIGH);  //set SS high to end communications

  digitalWrite(10,LOW);  //set SS low to begin communications
  SPI.transfer(DACB);  //writes to DAC to set both channels
  data= highByte(bothPower);  //gets the first 8 bits of 16 bit value
  SPI.transfer(data);  //writes first 8 bits of 16 bit value from above
  data= lowByte(halfPower);  //gets the second 8 bits of 16 bit value
  SPI.transfer(data);  //writes the second 8 bits of 16 bit value from above
  digitalWrite(10, HIGH);  //set SS high to end communications
}

void loop()
{
  //nothing in loop
}

The nice thing is the MOSFet can handle 1.2-1.8 Amps.  I know the circuit design is not complete and the code is quite simple, but it can easily be expanded on.


kaaasap

forgot to add I am using these male headers to raise the Pro Mini off of the PCB.

http://www.digikey.com/product-search/en?keywords=S1012EC-06-ND

Go Up