Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
DC726B_A.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC726B-A (or DC726A-A) Demonstration Board.
3 LTC6903: 1kHz to 68MHz Serial Port Programmable Oscillator
4 
5 @verbatim
6 
7 NOTES
8  Setup:
9  Set the terminal baud rate to 115200 and select the newline terminator. Equipment
10  required is a precision voltage source and a precision voltmeter (to monitor
11  voltage source). No external power supply is required. Ensure JP1 is installed in
12  the default position from the factory.
13 
14  Demo Board Configuration:
15  To properly use this program with the DC72B-A (or the DC726A-A) demo board, JMP 2
16  needs to be set to QuikEval.
17 
18 USER INPUT DATA FORMAT:
19  decimal : 1024
20  hex : 0x400
21  octal : 02000 (leading 0 "zero")
22  binary : B10000000000
23  float : 1024.0
24 
25 @endverbatim
26 
27 http://www.linear.com/product/LTC6903
28 
29 http://www.linear.com/product/LTC6903#demoboards
30 
31 
32 Copyright 2018(c) Analog Devices, Inc.
33 
34 All rights reserved.
35 
36 Redistribution and use in source and binary forms, with or without
37 modification, are permitted provided that the following conditions are met:
38  - Redistributions of source code must retain the above copyright
39  notice, this list of conditions and the following disclaimer.
40  - Redistributions in binary form must reproduce the above copyright
41  notice, this list of conditions and the following disclaimer in
42  the documentation and/or other materials provided with the
43  distribution.
44  - Neither the name of Analog Devices, Inc. nor the names of its
45  contributors may be used to endorse or promote products derived
46  from this software without specific prior written permission.
47  - The use of this software may or may not infringe the patent rights
48  of one or more patent holders. This license does not release you
49  from the requirement that you obtain separate licenses from these
50  patent holders to use this software.
51  - Use of the software either in source or binary form, must be run
52  on or directly connected to an Analog Devices Inc. component.
53 
54 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
55 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
56 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
57 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
58 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
59 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
60 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
61 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
62 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
63 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 */
65 
66 /*! @file
67  @ingroup LTC6903
68 */
69 
70 #include <Arduino.h>
71 #include <stdint.h>
72 #include "Linduino.h"
73 #include "LT_SPI.h"
74 #include "LT_I2C.h"
75 #include "UserInterface.h"
76 #include "QuikEval_EEPROM.h"
77 #include "LTC6903.h"
78 #include <SPI.h>
79 
80 
81 // Function Declaration
82 void print_title();
83 void print_prompt();
84 void settings();
85 void set_frequency();
86 void manually_set_reg();
87 
88 
89 // Global variables
90 static uint8_t output_config = LTC6903_CLK_ON_CLK_INV_ON; //!< Keeps track of output configuration.
91 
92 //! Initialize Linduino
93 void setup()
94 {
95  quikeval_SPI_init(); // Configure the EEPROM I2C port for 100kHz
96  quikeval_SPI_connect(); // Connect SPI to main data port
97  Serial.begin(115200); // Initialize the serial port to the PC
98  print_title();
99  print_prompt();
100 }
101 
102 //! Repeats Linduino loop
103 void loop()
104 {
105  int16_t user_command;
106 
107  user_command = read_int();
108 
109  Serial.println(user_command);
110 
111  switch (user_command)
112  {
113  case 1:
114  set_frequency();
115  break;
116  case 2:
118  break;
119  case 3:
120  settings();
121  break;
122  default:
123  Serial.println(F("Invalid command"));
124  break;
125  }
126  print_prompt();
127 }
128 
129 //! Prints the title block when program first starts.
131 {
132  Serial.println();
133  Serial.println(F("*****************************************************************"));
134  Serial.println(F("* DC726B Demonstration Program *"));
135  Serial.println(F("* *"));
136  Serial.println(F("* This program demonstrates how to send data to the *"));
137  Serial.println(F("* programmable oscillator *"));
138  Serial.println(F("* *"));
139  Serial.println(F("* Set the baud rate to 115200 and select the newline terminator.*"));
140  Serial.println(F("* *"));
141  Serial.println(F("*****************************************************************"));
142 }
143 
144 //! Prints main menu.
146 {
147  Serial.println();
148  Serial.println(F("1-Set frequency out"));
149  Serial.println(F("2-Manually set OCT and DAC code"));
150  Serial.println(F("3-Settings"));
151  Serial.println();
152  Serial.print(F("Enter a command:"));
153 }
154 
155 //! Sets the output frequency.
157 {
158  float freq;
159  uint16_t clock_code;
160  uint8_t ack;
161 
162  Serial.print(F("Enter the desired clock freq (KHz):"));
163 
164  freq = read_float();
165 
166  Serial.println(freq, 4);
167 
168  // Calculates the code necessary to create the clock frequency
169  clock_code = LTC6903_frequency_to_code(freq/1000, output_config);
170 
171 
172  LTC6903_write(LTC6903_CS, (uint16_t)clock_code);
173 }
174 
175 //! Manually Sets OCT and DAC Code
177 {
178  uint8_t oct;
179  uint8_t ack;
180  uint16_t dac_code;
181 
182  Serial.print(F("Enter the OCT:"));
183 
184  oct = read_int();
185  if (oct > 15)
186  oct = 15;
187  Serial.println(oct);
188 
189  Serial.println();
190  Serial.print(F("Enter the DAC code:"));
191 
192  dac_code = read_int();
193 
194  Serial.println(dac_code);
195  Serial.println();
196 
197  // Manually set registers
198  LTC6903_write(LTC6903_CS, (uint16_t)((oct<<12)|(dac_code<<2)|output_config));
199 }
200 
201 //! Configures the output
202 void settings()
203 {
204  int16_t user_command;
205 
206  Serial.println();
207  Serial.println(F("Output Configuration"));
208  Serial.println(F("1-CLK On and CLK INV ON"));
209  Serial.println(F("2-CLK Off and CLK INV ON"));
210  Serial.println(F("3-CLK On and CLK INV Off"));
211  Serial.println(F("4-Power Down"));
212  Serial.println();
213  Serial.print(F("Enter a command:"));
214 
215  user_command = read_int();
216 
217  Serial.println(user_command);
218 
219  switch (user_command)
220  {
221  case 1:
223  break;
224  case 2:
226  break;
227  case 3:
229  break;
230  case 4:
232  break;
233  default:
234  Serial.println(F("Invalid command"));
235  }
236 }
static void print_prompt()
Prints main menu.
Definition: DC726B_A.ino:145
unsigned char user_command
#define LTC6903_CS
Define the SPI CS pin.
Definition: LTC6903.h:66
static void set_frequency()
Sets the output frequency.
Definition: DC726B_A.ino:156
Header File for Linduino Libraries and Demo Code.
void LTC6903_write(uint8_t cs, uint16_t code)
Writes 2 bytes.
Definition: LTC6903.cpp:73
#define LTC6903_CLK_OFF_CLK_INV_ON
Clock off, inverted clock on.
Definition: LTC6903.h:112
static void print_title()
Prints the title block when program first starts.
Definition: DC726B_A.ino:130
static void setup()
Initialize Linduino.
Definition: DC726B_A.ino:93
static uint8_t output_config
Keeps track of output configuration.
Definition: DC726B_A.ino:90
#define LTC6903_CLK_ON_CLK_INV_OFF
Clock on, inverted clock off.
Definition: LTC6903.h:113
uint16_t LTC6903_frequency_to_code(float frequency, uint8_t clk)
Calculates the code necessary to create the clock frequency.
Definition: LTC6903.cpp:81
static void settings()
Configures the output.
Definition: DC726B_A.ino:202
QuikEval EEPROM Library.
#define LTC6903_POWER_DOWN
Powers down clocks.
Definition: LTC6903.h:114
void quikeval_SPI_init(void)
Configure the SPI port for 4Mhz SCK.
Definition: LT_SPI.cpp:151
#define LTC6903_CLK_ON_CLK_INV_ON
Clock on, inverted clock on.
Definition: LTC6903.h:111
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
static void manually_set_reg()
Manually Sets OCT and DAC Code.
Definition: DC726B_A.ino:176
void quikeval_SPI_connect()
Connect SPI pins to QuikEval connector through the Linduino MUX. This will disconnect I2C...
Definition: LT_SPI.cpp:138
int32_t read_int()
float read_float()
static void loop()
Repeats Linduino loop.
Definition: DC726B_A.ino:103
LTC6903: 1kHz to 68MHz Serial Port Programmable Oscillator.