#include /********************************************************** * Example program SPI-OSC interface with Arduino. * * SETUP: SPI-OSC => Arduino * SCK=D13 SDI=D12 SEN=D6 FREQ_INT=D5 OE=ADC3 * FreqCounter library needed for displaying the frequency set into the ltc6903 * Frequency is read by the Instance of the FreqCounter Class Library * Document: LTC6903 datasheet * Updated: 20101230 * E-mail: wmoritz@aaahawk.com * Web Page: www.eastco-inc.com * Bill Moirtz * (C) Copyright 2010 All Rights Reserved **********************************************************/ const int SEN = 6; //Serial Enable for ltc6903 const int SCK = 13; //Serial Clock for clocking in data const int SDI = 12; //Serial Data Input, D15 first const int OE = A3; //Enable Output using a AD pin word Word=0; //shifting word sent to ltc6903 long int frq; //read the frequency from D5 input pin word Oct=12; //From Linear Technology Spec Sheet page 7 word DAC=707; //Or you can calculate these values yourself /* Get everyone set up to an initial state */ void setup() { Serial.begin(9600); //set normal serial communications pinMode(SEN, OUTPUT); //define SEN enable pinMode(SCK, OUTPUT); //define SCK clock pinMode(SDI, OUTPUT); //define SDI data digitalWrite(SEN,HIGH); //set safely high digitalWrite(SCK,HIGH); //set safely high digitalWrite(SDI,HIGH); //set safely high pinMode(OE, OUTPUT); //set OE of the ltc6903 ltc6903(Oct,DAC); //Set Freq from Linear Technology Spec Sheet page 7 delay(1); //wait one... digitalWrite(OE, HIGH); //Turn on the output frequency } /* Display the Frquency in the Serial Monitor by INT1 input tied to ltc6903's output pin */ void loop() { FreqCounter::f_comp= 8; // Set compensation to 12 FreqCounter::start(100); // Start counting with gatetime of 10ms while (FreqCounter::f_ready == 0) // wait until counter ready frq=FreqCounter::f_freq; // read result frq*=10; //Forget the units make the value full freq. Serial.println(frq); // print result to the monitor } /* Get OCT and DAC into shift word */ void ltc6903(word oct,word dac) { Word=oct; // do OCT first Word<<=12; // move it to D15 dac<<=2; //align the DAC value Word|=dac; //OR it in, leave CN1 and CN0 at zero Transfer(Word); //Send word as sdi to ltc6903 } /* Clock the Data Word into the ltc6903 as fast as you can. The D15 bit is first and then shift all bits the the left in thru D15 location. */ void Transfer(word sdi) { int value=0; //set D15 test value to zero; digitalWrite(SEN,LOW); //set Serial Enable True at ltc6903 for(int i=0;i!=16;i++) //Got 16 bits to clock in { value=sdi&32768; //Strip for testing if D15 if (value!=0) // 1? { digitalWrite(SDI,HIGH); //Set SDI to TRUE } else { digitalWrite(SDI,LOW); //Else set to LOW } digitalWrite(SCK,LOW); //Drop the clock line digitalWrite(SCK,HIGH); //Trigger in the SDI low sdi<<=1; //Shift next bit into D15 position } digitalWrite(SEN,HIGH); //deselect serial transfer digitalWrite(SDI,HIGH); //put data high as initial state }