Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
vmClock.ino
Go to the documentation of this file.
1 /*
2 makes a DC934 output 1 millivolt per minute plus 100 millivolts per hour
3 
4 @verbatim
5 
6 NOTES
7  Setup:
8  Set the terminal baud rate to 115200 and select the newline terminator.
9  No external power supply is required.
10 
11 @endverbatim
12 
13 http://www.linear.com/product/LTC2607
14 
15 http://www.linear.com/product/LTC2607#demoboards
16 
17 Copyright 2018(c) Analog Devices, Inc.
18 
19 All rights reserved.
20 
21 Redistribution and use in source and binary forms, with or without
22 modification, are permitted provided that the following conditions are met:
23  - Redistributions of source code must retain the above copyright
24  notice, this list of conditions and the following disclaimer.
25  - Redistributions in binary form must reproduce the above copyright
26  notice, this list of conditions and the following disclaimer in
27  the documentation and/or other materials provided with the
28  distribution.
29  - Neither the name of Analog Devices, Inc. nor the names of its
30  contributors may be used to endorse or promote products derived
31  from this software without specific prior written permission.
32  - The use of this software may or may not infringe the patent rights
33  of one or more patent holders. This license does not release you
34  from the requirement that you obtain separate licenses from these
35  patent holders to use this software.
36  - Use of the software either in source or binary form, must be run
37  on or directly connected to an Analog Devices Inc. component.
38 
39 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
40 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
41 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
42 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
43 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
45 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
46 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
48 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49 */
50 
51 #include <Arduino.h>
52 #include <stdint.h>
53 #include "Linduino.h"
54 #include "UserInterface.h"
55 #include "LT_I2C.h"
56 #include "LT_SPI.h"
57 #include "LTC2607.h"
58 #include "LTC2422.h"
59 #include "QuikEval_EEPROM.h"
60 
61 // Globals
62 
63 //! Demo Board Name stored in QuikEval EEPROM
64 char demo_name[] = "DC934";
65 //! Look-up table for DAC_A, DAC_B, or both command byte option
67 //! Set to 1 if the board is connected
69 
70 uint32_t startMinutes = 10*60 + 24;
71 
72 float MY_LSB = 7.65841584E-5;
73 float MY_OFF = 0.0012425743;
74 
75 //! Initialize Linduino
76 void setup()
77 // Setup the Program
78 {
79  output_high(LTC2422_CS); //! Pulls LTC2442 Chip Select High
80  quikeval_I2C_init(); //! Initializes Linduino I2C port.
81  quikeval_SPI_init(); //! Configures the SPI port for 4MHz SCK
82  quikeval_SPI_connect(); //! Connects SPI to QuikEval port
83 
84  Serial.begin(115200); //! Initializes the serial port to the PC
85 
86  demo_board_connected = discover_demo_board(demo_name); //! Checks if correct demo board is connected.
87 }
88 
89 // calculate current time and convert to millivolts for display in voltmeter
90 void loop()
91 {
92  quikeval_I2C_connect(); //! Connects I2C port to the QuikEval connector
93 
94  uint32_t elapsedTime = millis();
95  Serial.print("elapsedTime: ");
96  Serial.println(elapsedTime);
97 
98  // convert milliseconds to minutes
99  uint32_t elapsedMinutes = elapsedTime / (1000L*60L);
100  // current TOTAL minutes (minutes in the hour plus 60 per hour)
101  uint32_t minutes = startMinutes + elapsedMinutes;
102  // get the current hour from the minutes, make it go from 1-12 (not 0-11)
103  uint32_t hours = 1 + (((minutes / 60) - 1) % 12);
104  // now minutes is just minutes in the current hour
105  minutes %= 60;
106 
107  Serial.print("minutes: ");
108  Serial.println(minutes);
109  Serial.print("hours: ");
110  Serial.println(hours);
111 
112  // make the hours in the 1000's and 100's column, minutes in 10's and 1's on a millivolt display
113  uint32_t mV = hours * 100L + minutes;
114 
115  Serial.print("Outputting ");
116  Serial.print(mV, 4);
117  Serial.println(" mV on DAC 0");
118 
119  //! Write a code to the LTC2607 internal register and update the output voltage. (convert millivolts to volts)
121  LTC2607_voltage_to_code((float)mV/1000.0F, MY_LSB, MY_OFF));
122 }
static void loop()
Definition: vmClock.ino:90
LTC2422: 1-/2-Channel 20-Bit uPower No Latency Delta-Sigma ADC in MSOP-10.
char demo_name[]
Demo Board Name stored in QuikEval EEPROM.
Definition: vmClock.ino:64
uint16_t LTC2607_voltage_to_code(float dac_voltage, float LTC2607_lsb, int32_t LTC2607_offset)
Calculates an LTC2607 DAC code for the desired output voltage.
Definition: LTC2607.cpp:110
#define output_high(pin)
Set "pin" high.
Definition: Linduino.h:75
Header File for Linduino Libraries and Demo Code.
static float MY_LSB
Definition: vmClock.ino:72
#define LTC2607_ALL_DACS
Command (and DAC code) will modify both DAC A and DAC B.
Definition: LTC2607.h:163
static float MY_OFF
Definition: vmClock.ino:73
#define LTC2607_WRITE_UPDATE_COMMAND
Command to write and update (and power up) the LTC2607.
Definition: LTC2607.h:153
QuikEval EEPROM Library.
void quikeval_SPI_init(void)
Configure the SPI port for 4Mhz SCK.
Definition: LT_SPI.cpp:151
static uint32_t startMinutes
Definition: vmClock.ino:70
int8_t discover_demo_board(char *demo_name)
Read the ID string from the EEPROM and determine if the correct board is connected.
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
#define LTC2607_DAC_B
Command (and DAC code) will modify DAC B.
Definition: LTC2607.h:162
const uint8_t address_map[3]
Look-up table for DAC_A, DAC_B, or both command byte option.
Definition: vmClock.ino:66
static void setup()
Initialize Linduino.
Definition: vmClock.ino:76
static int8_t demo_board_connected
Set to 1 if the board is connected.
Definition: vmClock.ino:68
void quikeval_SPI_connect()
Connect SPI pins to QuikEval connector through the Linduino MUX. This will disconnect I2C...
Definition: LT_SPI.cpp:138
#define LTC2607_I2C_GLOBAL_ADDRESS
LTC2607 Global I2C Address.
Definition: LTC2607.h:145
#define LTC2422_CS
Define the SPI CS pin.
Definition: LTC2422.h:104
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
void quikeval_I2C_connect(void)
Switch MUX to connect I2C pins to QuikEval connector.
Definition: LT_I2C.cpp:401
LTC2607: 16-Bit, Dual Rail-to-Rail DACs with I2C Interface.
int8_t LTC2607_write(uint8_t i2c_address, uint8_t dac_command, uint8_t dac_address, uint16_t dac_code)
Writes command, DAC address, and DAC code to the LTC2607.
Definition: LTC2607.cpp:100
#define LTC2607_DAC_A
Command (and DAC code) will modify DAC A.
Definition: LTC2607.h:161