| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

DC726B_B.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC726B-B (or DC726A-B) Demonstration Board.
3 LTC6904: 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 DC726B-B demo board (or the DC726A-B), 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/LTC6904
28
29 http://www.linear.com/product/LTC6904#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 LTC6904
68 */
69
70 #include <Arduino.h>
71 #include <stdint.h>
72 #include "Linduino.h"
73 #include "UserInterface.h"
74 #include "LT_I2C.h"
75 #include "QuikEval_EEPROM.h"
76 #include "LTC6904.h"
77 #include <Wire.h>
78
79 // Function Declaration
80 void print_title();
81 void print_prompt();
82 void settings();
83 uint8_t set_frequency();
84 uint8_t manually_set_reg();
85
86
87 // Global variables
88 static uint8_t output_config = LTC6904_CLK_ON_CLK_INV_ON; //!< Keeps track of output configuration.
89
90 //! Initialize Linduino
91 void setup()
92 {
93 quikeval_I2C_init(); // Configure the EEPROM I2C port for 100kHz
94 quikeval_I2C_connect(); // Connect I2C to main data port
95 Serial.begin(115200); // Initialize the serial port to the PC
96 print_title();
97 print_prompt();
98 }
99
100 //! Repeats Linduino loop
101 void loop()
102 {
103 int16_t user_command;
104 uint8_t ack = 0;
105
106 user_command = read_int();
107
108 Serial.println(user_command);
109
110 switch (user_command)
111 {
112 case 1:
113 ack = set_frequency();
114 break;
115 case 2:
116 ack = manually_set_reg();
117 break;
118 case 3:
119 settings();
120 break;
121 default:
122 Serial.println(F("Invalid command"));
123 break;
124 }
125
126 // A buffer is used for SDA to the LTC6904.
127 // This does not allow the Linduino to observe an
128 // I2C ACK. Thus, the following code is not used
129 // to ignore the NACK.
130 /*
131 if(ack == 1)
132 {
133 Serial.println();
134 Serial.println(F("I2C ACK Error"));
135 }
136 */
137
138 print_prompt();
139 }
140
141 //! Prints the title block when program first starts.
142 void print_title()
143 {
144 Serial.println();
145 Serial.println(F("*****************************************************************"));
146 Serial.println(F("* DC726A Demonstration Program *"));
147 Serial.println(F("* *"));
148 Serial.println(F("* This program demonstrates how to send data to the *"));
149 Serial.println(F("* programmable oscillator *"));
150 Serial.println(F("* *"));
151 Serial.println(F("* Set the baud rate to 115200 and select the newline terminator.*"));
152 Serial.println(F("* *"));
153 Serial.println(F("*****************************************************************"));
154 }
155
156 //! Prints main menu.
157 void print_prompt()
158 {
159 Serial.println();
160 Serial.println(F("1-Set frequency out"));
161 Serial.println(F("2-Manually set OCT and DAC code"));
162 Serial.println(F("3-Settings"));
163 Serial.println();
164 Serial.print(F("Enter a command:"));
165 }
166
167 //! Sets the output frequency.
168 //! @return the ACK if 0, NACK if 1
169 uint8_t set_frequency()
170 {
171 float freq;
172 uint16_t clock_code;
173 uint8_t ack;
174
175 Serial.print(F("Enter the desired clock freq (KHz):"));
176
177 freq = read_float();
178
179 Serial.println(freq, 4);
180
181 // Calculates the code necessary to create the clock frequency
182 clock_code = LTC6904_frequency_to_code(freq/1000, output_config);
183
184 ack = LTC6904_write(LTC6904_ADDRESS, (uint16_t)clock_code);
185 return(ack);
186 }
187
188 //! Manually Sets OCT and DAC Code
189 //! @return ack
190 uint8_t manually_set_reg()
191 {
192 uint8_t oct;
193 uint8_t ack;
194 uint16_t dac_code;
195
196 Serial.print(F("Enter the OCT:"));
197
198 oct = read_int();
199 if (oct > 15)
200 oct = 15;
201 Serial.println(oct);
202
203 Serial.println();
204 Serial.print(F("Enter the DAC code:"));
205
206 dac_code = read_int();
207
208 Serial.println(dac_code);
209 Serial.println();
210
211 // Manually set registers
212 ack = LTC6904_write(LTC6904_ADDRESS, (uint16_t)((oct<<12)|(dac_code<<2)|output_config));
213 return(ack);
214 }
215
216 //! Configures the output
217 void settings()
218 {
219 int16_t user_command;
220
221 Serial.println();
222 Serial.println(F("Output Configuration"));
223 Serial.println(F("1-CLK On and CLK INV ON"));
224 Serial.println(F("2-CLK Off and CLK INV ON"));
225 Serial.println(F("3-CLK On and CLK INV Off"));
226 Serial.println(F("4-Power Down"));
227 Serial.println();
228 Serial.print(F("Enter a command:"));
229
230 user_command = read_int();
231
232 Serial.println(user_command);
233
234 switch (user_command)
235 {
236 case 1:
237 output_config = LTC6904_CLK_ON_CLK_INV_ON;
238 break;
239 case 2:
240 output_config = LTC6904_CLK_OFF_CLK_INV_ON;
241 break;
242 case 3:
243 output_config = LTC6904_CLK_ON_CLK_INV_OFF;
244 break;
245 case 4:
246 output_config = LTC6904_POWER_DOWN;
247 break;
248 default:
249 Serial.println(F("Invalid command"));
250 }
251 }
LTC6904_CLK_ON_CLK_INV_OFF
#define LTC6904_CLK_ON_CLK_INV_OFF
Clock on, inverted clock off.
Definition: LTC6904.h:111
LTC6904_CLK_ON_CLK_INV_ON
#define LTC6904_CLK_ON_CLK_INV_ON
Clock on, inverted clock on.
Definition: LTC6904.h:109
LTC6904.h
LTC6904: 1kHz to 68MHz Serial Port Programmable Oscillator.
user_command
unsigned char user_command
Definition: Serial_EEPROM_Test.ino:75
set_frequency
static uint8_t set_frequency()
Sets the output frequency.
Definition: DC726B_B.ino:169
print_prompt
static void print_prompt()
Prints main menu.
Definition: DC726B_B.ino:157
Linduino.h
Header File for Linduino Libraries and Demo Code.
LTC6904_frequency_to_code
uint16_t LTC6904_frequency_to_code(float frequency, uint8_t clk)
Calculates the code necessary to create the clock frequency.
Definition: LTC6904.cpp:82
print_title
static void print_title()
Prints the title block when program first starts.
Definition: DC726B_B.ino:142
setup
static void setup()
Initialize Linduino.
Definition: DC726B_B.ino:91
output_config
static uint8_t output_config
Keeps track of output configuration.
Definition: DC726B_B.ino:88
settings
static void settings()
Configures the output.
Definition: DC726B_B.ino:217
QuikEval_EEPROM.h
QuikEval EEPROM Library.
manually_set_reg
static uint8_t manually_set_reg()
Manually Sets OCT and DAC Code.
Definition: DC726B_B.ino:190
LTC6904_ADDRESS
#define LTC6904_ADDRESS
ADR 0.
Definition: LTC6904.h:64
LTC6904_POWER_DOWN
#define LTC6904_POWER_DOWN
Powers down clocks.
Definition: LTC6904.h:112
LTC6904_write
uint8_t LTC6904_write(uint8_t address, uint16_t code)
Writes 2 bytes.
Definition: LTC6904.cpp:73
LT_I2C.h
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
UserInterface.h
read_int
int32_t read_int()
Definition: UserInterface.cpp:93
read_float
float read_float()
Definition: UserInterface.cpp:78
quikeval_I2C_init
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
quikeval_I2C_connect
void quikeval_I2C_connect(void)
Switch MUX to connect I2C pins to QuikEval connector.
Definition: LT_I2C.cpp:401
LTC6904_CLK_OFF_CLK_INV_ON
#define LTC6904_CLK_OFF_CLK_INV_ON
Clock off, inverted clock on.
Definition: LTC6904.h:110
loop
static void loop()
Repeats Linduino loop.
Definition: DC726B_B.ino:101