Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
FAE_April_2013.ino
Go to the documentation of this file.
1 //! @todo Move to "User Contributed" and change name from FAE..., document with Doxygen, etc.
2 /*
3 FAE Demonstration of DC934A and RGB Diode
4 
5 Copyright 2018(c) Analog Devices, Inc.
6 
7 All rights reserved.
8 
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
11  - Redistributions of source code must retain the above copyright
12  notice, this list of conditions and the following disclaimer.
13  - Redistributions in binary form must reproduce the above copyright
14  notice, this list of conditions and the following disclaimer in
15  the documentation and/or other materials provided with the
16  distribution.
17  - Neither the name of Analog Devices, Inc. nor the names of its
18  contributors may be used to endorse or promote products derived
19  from this software without specific prior written permission.
20  - The use of this software may or may not infringe the patent rights
21  of one or more patent holders. This license does not release you
22  from the requirement that you obtain separate licenses from these
23  patent holders to use this software.
24  - Use of the software either in source or binary form, must be run
25  on or directly connected to an Analog Devices Inc. component.
26 
27 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
28 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
29 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
31 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
33 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38 
39 /*! @file
40  @ingroup LTC2607
41  DC934A Science Project
42  FAE Meeting April 2013
43 */
44 
45 #include <Arduino.h> // Always include this in Arduino programs.
46 #include <stdint.h> // Standard 'C' library that defines fixed-length datatypes
47 #include "Linduino.h" // Include this in every Linduino program.
48 #include "LT_I2C.h" // Functions to talk to I2C parts through QuikEval connector
49 #include "LT_SPI.h" // Functions to talk to SPI
50 #include "LTC2607.h"
51 #include "LTC2422.h"
52 #include "Wire.h"
53 #include "SPI.h"
54 
55 const uint16_t LTC2422_timeout = 1000; //!< The timeout for the LTC2422
56 
57 //! Initialize Linduino once on power-up or reset.
58 void setup()
59 {
60 
61  Serial.begin(115200); //! Initializes the serial port to the PC.
62 
63  output_high(LTC2422_CS); //! Pull LTC2442 Chip Select High.
64 
65  quikeval_I2C_init(); //! Initializes Linduino I2C port.
67 
68  pinMode(2, OUTPUT); //! Configure Arduino Pins 2, 3, and 4 as outputs.
69  pinMode(3, OUTPUT);
70  pinMode(4, OUTPUT);
71 
72  uint16_t dac_code;
73  //! Find LTC2607 dac_code that corresponds to 4.5V
75  //! Set DAC_A output to 4.5V
77  //! Make DAC_B output high impedance (power down)
79 
80  quikeval_SPI_init(); //! Configures the SPI port for 4Mhz SCK.
81  quikeval_SPI_connect(); //! Connects SPI to QuikEval port.
82 
83  uint8_t adc_channel;
84  uint32_t adc_code;
85 
86  if (LTC2422_EOC_timeout(LTC2422_CS, LTC2422_timeout)) // Check for EOC
87  return;
88  LTC2422_adc_read(LTC2422_CS, &adc_channel, &adc_code); // Align channel by reading again if adc_channel=0
89 
90  if (adc_channel == 0)
91  {
92  if (LTC2422_EOC_timeout(LTC2422_CS, LTC2422_timeout)) // Check for EOC
93  return;
94  LTC2422_adc_read(LTC2422_CS, &adc_channel, &adc_code);
95  }
96 }
97 
98 void loop()
99 {
100  static int32_t previous_adc_code; //stores ADC code from previous time through loop
101  uint32_t adc_code;
102  int32_t delta_adc_code;
103  uint8_t adc_channel;
104 
105  if (LTC2422_EOC_timeout(LTC2422_CS, LTC2422_timeout)) // Check for EOC
106  return;
107  LTC2422_adc_read(LTC2422_CS, &adc_channel, &adc_code); // Read channel 0 and throw it away
108 
109  if (LTC2422_EOC_timeout(LTC2422_CS, LTC2422_timeout)) // Check for EOC
110  return;
111  LTC2422_adc_read(LTC2422_CS, &adc_channel, &adc_code); // Read channel 1 into adc_code
112  delay(300);
113 
114  delta_adc_code = adc_code - previous_adc_code;
115 
116  uint8_t pin2=0, pin3=0, pin4=0;
117  if (delta_adc_code > 30) pin2 = 1;
118  if ((delta_adc_code <= 30) && (delta_adc_code >=-30)) pin3=1;
119  if (delta_adc_code < -30) pin4=1;
120 
121  digitalWrite(2,pin2);
122  digitalWrite(3,pin3);
123  digitalWrite(4,pin4);
124 
125  Serial.println();
126  Serial.print("RED: "); //! Print "RED: " to serial port
127  Serial.println(pin4);
128  Serial.print("GREEN: ");
129  Serial.println(pin3);
130  Serial.print("BLUE: ");
131  Serial.println(pin2);
132 
133  previous_adc_code=adc_code;
134 }
LTC2422: 1-/2-Channel 20-Bit uPower No Latency Delta-Sigma ADC in MSOP-10.
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
const uint16_t LTC2422_timeout
The timeout for the LTC2422.
#define output_high(pin)
Set "pin" high.
Definition: Linduino.h:75
const float LTC2607_TYPICAL_OFFSET
The LTC2607 typical offset voltage.
Definition: LTC2607.h:168
Header File for Linduino Libraries and Demo Code.
const float LTC2607_TYPICAL_lsb
The LTC2607 typical least significant bit value with 5V full-scale.
Definition: LTC2607.h:167
void LTC2422_adc_read(uint8_t cs, uint8_t *adc_channel, int32_t *code)
Read ADC code from the LTC2422.
Definition: LTC2422.cpp:98
#define LTC2607_WRITE_UPDATE_COMMAND
Command to write and update (and power up) the LTC2607.
Definition: LTC2607.h:153
void quikeval_SPI_init(void)
Configure the SPI port for 4Mhz SCK.
Definition: LT_SPI.cpp:151
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
static void loop()
#define LTC2607_POWER_DOWN_COMMAND
Command to power down the LTC2607.
Definition: LTC2607.h:154
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
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
uint8_t LTC2422_EOC_timeout(uint8_t cs, uint16_t miso_timeout)
Checks for EOC with a specified timeout.
Definition: LTC2422.cpp:76
static void setup()
Initialize Linduino once on power-up or reset.
static uint32_t adc_code
Definition: DC2071AA.ino:113