MAX11410 high speed 24-bit Delta-Sigma ADC
Dependents: MAX11410BOB_24bit_ADC MAX11410BOB_Serial_Tester
MAX11410.cpp@10:7adee48a7f82, 2020-02-11 (annotated)
- Committer:
- whismanoid
- Date:
- Tue Feb 11 01:32:24 2020 +0000
- Revision:
- 10:7adee48a7f82
- Parent:
- 9:06ca88952f1c
- Child:
- 11:abde565b8497
commandByte distinct from regAddress
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
whismanoid | 0:68e64068330f | 1 | // /******************************************************************************* |
whismanoid | 4:c169ba85d673 | 2 | // * Copyright (C) 2020 Maxim Integrated Products, Inc., All Rights Reserved. |
whismanoid | 0:68e64068330f | 3 | // * |
whismanoid | 0:68e64068330f | 4 | // * Permission is hereby granted, free of charge, to any person obtaining a |
whismanoid | 0:68e64068330f | 5 | // * copy of this software and associated documentation files (the "Software"), |
whismanoid | 0:68e64068330f | 6 | // * to deal in the Software without restriction, including without limitation |
whismanoid | 0:68e64068330f | 7 | // * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
whismanoid | 0:68e64068330f | 8 | // * and/or sell copies of the Software, and to permit persons to whom the |
whismanoid | 0:68e64068330f | 9 | // * Software is furnished to do so, subject to the following conditions: |
whismanoid | 0:68e64068330f | 10 | // * |
whismanoid | 0:68e64068330f | 11 | // * The above copyright notice and this permission notice shall be included |
whismanoid | 0:68e64068330f | 12 | // * in all copies or substantial portions of the Software. |
whismanoid | 0:68e64068330f | 13 | // * |
whismanoid | 0:68e64068330f | 14 | // * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
whismanoid | 0:68e64068330f | 15 | // * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
whismanoid | 0:68e64068330f | 16 | // * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
whismanoid | 0:68e64068330f | 17 | // * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
whismanoid | 0:68e64068330f | 18 | // * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
whismanoid | 0:68e64068330f | 19 | // * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
whismanoid | 0:68e64068330f | 20 | // * OTHER DEALINGS IN THE SOFTWARE. |
whismanoid | 0:68e64068330f | 21 | // * |
whismanoid | 0:68e64068330f | 22 | // * Except as contained in this notice, the name of Maxim Integrated |
whismanoid | 0:68e64068330f | 23 | // * Products, Inc. shall not be used except as stated in the Maxim Integrated |
whismanoid | 0:68e64068330f | 24 | // * Products, Inc. Branding Policy. |
whismanoid | 0:68e64068330f | 25 | // * |
whismanoid | 0:68e64068330f | 26 | // * The mere transfer of this software does not imply any licenses |
whismanoid | 0:68e64068330f | 27 | // * of trade secrets, proprietary technology, copyrights, patents, |
whismanoid | 0:68e64068330f | 28 | // * trademarks, maskwork rights, or any other form of intellectual |
whismanoid | 0:68e64068330f | 29 | // * property whatsoever. Maxim Integrated Products, Inc. retains all |
whismanoid | 0:68e64068330f | 30 | // * ownership rights. |
whismanoid | 0:68e64068330f | 31 | // ******************************************************************************* |
whismanoid | 0:68e64068330f | 32 | // */ |
whismanoid | 0:68e64068330f | 33 | // ********************************************************************* |
whismanoid | 0:68e64068330f | 34 | // @file MAX11410.cpp |
whismanoid | 0:68e64068330f | 35 | // ********************************************************************* |
whismanoid | 0:68e64068330f | 36 | // Device Driver file |
whismanoid | 0:68e64068330f | 37 | // DO NOT EDIT; except areas designated "CUSTOMIZE". Automatically generated file. |
whismanoid | 0:68e64068330f | 38 | // generated by XMLSystemOfDevicesToMBED.py |
whismanoid | 0:68e64068330f | 39 | // System Name = ExampleSystem |
whismanoid | 0:68e64068330f | 40 | // System Description = Device driver example |
whismanoid | 0:68e64068330f | 41 | |
whismanoid | 0:68e64068330f | 42 | #include "MAX11410.h" |
whismanoid | 0:68e64068330f | 43 | |
whismanoid | 0:68e64068330f | 44 | // Device Name = MAX11410 |
whismanoid | 0:68e64068330f | 45 | // Device Description = 1.9ksps, Low-Power, Serial SPI 24-Bit, 10-Channel, Differential/Single-Ended Input, SAR ADC |
whismanoid | 0:68e64068330f | 46 | // Device DeviceBriefDescription = 24-bit 1.9ksps Delta-Sigma ADC |
whismanoid | 0:68e64068330f | 47 | // Device Manufacturer = Maxim Integrated |
whismanoid | 0:68e64068330f | 48 | // Device PartNumber = MAX11410ATI+ |
whismanoid | 0:68e64068330f | 49 | // Device RegValue_Width = DataWidth16bit_HL |
whismanoid | 0:68e64068330f | 50 | // |
whismanoid | 0:68e64068330f | 51 | // ADC MaxOutputDataRate = 1.9ksps |
whismanoid | 0:68e64068330f | 52 | // ADC NumChannels = 10 |
whismanoid | 0:68e64068330f | 53 | // ADC ResolutionBits = 24 |
whismanoid | 0:68e64068330f | 54 | // |
whismanoid | 0:68e64068330f | 55 | // SPI CS = ActiveLow |
whismanoid | 0:68e64068330f | 56 | // SPI FrameStart = CS |
whismanoid | 0:68e64068330f | 57 | // SPI CPOL = 0 |
whismanoid | 0:68e64068330f | 58 | // SPI CPHA = 0 |
whismanoid | 0:68e64068330f | 59 | // SPI MOSI and MISO Data are both stable on Rising edge of SCLK |
whismanoid | 0:68e64068330f | 60 | // SPI SCLK Idle Low |
whismanoid | 0:68e64068330f | 61 | // SPI SCLKMaxMHz = 8 |
whismanoid | 0:68e64068330f | 62 | // SPI SCLKMinMHz = 0 |
whismanoid | 0:68e64068330f | 63 | // |
whismanoid | 0:68e64068330f | 64 | |
whismanoid | 0:68e64068330f | 65 | // CODE GENERATOR: class constructor definition |
whismanoid | 0:68e64068330f | 66 | MAX11410::MAX11410(SPI &spi, DigitalOut &cs_pin, // SPI interface |
whismanoid | 0:68e64068330f | 67 | // CODE GENERATOR: class constructor definition gpio InputPin pins |
whismanoid | 0:68e64068330f | 68 | // CODE GENERATOR: class constructor definition gpio OutputPin pins |
whismanoid | 0:68e64068330f | 69 | // CODE GENERATOR: class constructor definition ic_variant |
whismanoid | 0:68e64068330f | 70 | MAX11410_ic_t ic_variant) |
whismanoid | 0:68e64068330f | 71 | // CODE GENERATOR: class constructor initializer list |
whismanoid | 0:68e64068330f | 72 | : m_spi(spi), m_cs_pin(cs_pin), // SPI interface |
whismanoid | 0:68e64068330f | 73 | // CODE GENERATOR: class constructor initializer list gpio InputPin pins |
whismanoid | 0:68e64068330f | 74 | // CODE GENERATOR: class constructor initializer list gpio OutputPin pins |
whismanoid | 0:68e64068330f | 75 | // CODE GENERATOR: class constructor initializer list ic_variant |
whismanoid | 0:68e64068330f | 76 | m_ic_variant(ic_variant) |
whismanoid | 0:68e64068330f | 77 | { |
whismanoid | 0:68e64068330f | 78 | // CODE GENERATOR: class constructor definition SPI interface initialization |
whismanoid | 0:68e64068330f | 79 | // |
whismanoid | 0:68e64068330f | 80 | // SPI CS = ActiveLow |
whismanoid | 0:68e64068330f | 81 | // SPI FrameStart = CS |
whismanoid | 0:68e64068330f | 82 | m_SPI_cs_state = 1; |
whismanoid | 0:68e64068330f | 83 | m_cs_pin = m_SPI_cs_state; |
whismanoid | 0:68e64068330f | 84 | |
whismanoid | 0:68e64068330f | 85 | // SPI CPOL = 0 |
whismanoid | 0:68e64068330f | 86 | // SPI CPHA = 0 |
whismanoid | 0:68e64068330f | 87 | // SPI MOSI and MISO Data are both stable on Rising edge of SCLK |
whismanoid | 0:68e64068330f | 88 | // SPI SCLK Idle Low |
whismanoid | 0:68e64068330f | 89 | m_SPI_dataMode = 0; //SPI_MODE0; // CPOL=0,CPHA=0: Rising Edge stable; SCLK idle Low |
whismanoid | 0:68e64068330f | 90 | m_spi.format(8,m_SPI_dataMode); // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=0 |
whismanoid | 0:68e64068330f | 91 | |
whismanoid | 0:68e64068330f | 92 | // SPI SCLKMaxMHz = 8 |
whismanoid | 0:68e64068330f | 93 | // SPI SCLKMinMHz = 0 |
whismanoid | 0:68e64068330f | 94 | //#define SPI_SCLK_Hz 48000000 // 48MHz |
whismanoid | 0:68e64068330f | 95 | //#define SPI_SCLK_Hz 24000000 // 24MHz |
whismanoid | 0:68e64068330f | 96 | //#define SPI_SCLK_Hz 12000000 // 12MHz |
whismanoid | 0:68e64068330f | 97 | //#define SPI_SCLK_Hz 6000000 // 6MHz |
whismanoid | 0:68e64068330f | 98 | //#define SPI_SCLK_Hz 4000000 // 4MHz |
whismanoid | 0:68e64068330f | 99 | //#define SPI_SCLK_Hz 2000000 // 2MHz |
whismanoid | 0:68e64068330f | 100 | //#define SPI_SCLK_Hz 1000000 // 1MHz |
whismanoid | 0:68e64068330f | 101 | m_SPI_SCLK_Hz = 8000000; // 8MHz; MAX11410 limit is 8MHz |
whismanoid | 0:68e64068330f | 102 | m_spi.frequency(m_SPI_SCLK_Hz); |
whismanoid | 0:68e64068330f | 103 | |
whismanoid | 0:68e64068330f | 104 | } |
whismanoid | 0:68e64068330f | 105 | |
whismanoid | 0:68e64068330f | 106 | // CODE GENERATOR: class destructor definition |
whismanoid | 0:68e64068330f | 107 | MAX11410::~MAX11410() |
whismanoid | 0:68e64068330f | 108 | { |
whismanoid | 0:68e64068330f | 109 | // do nothing |
whismanoid | 0:68e64068330f | 110 | } |
whismanoid | 0:68e64068330f | 111 | |
whismanoid | 0:68e64068330f | 112 | // CODE GENERATOR: spi_frequency setter definition |
whismanoid | 0:68e64068330f | 113 | /// set SPI SCLK frequency |
whismanoid | 0:68e64068330f | 114 | void MAX11410::spi_frequency(int spi_sclk_Hz) |
whismanoid | 0:68e64068330f | 115 | { |
whismanoid | 0:68e64068330f | 116 | m_SPI_SCLK_Hz = spi_sclk_Hz; |
whismanoid | 0:68e64068330f | 117 | m_spi.frequency(m_SPI_SCLK_Hz); |
whismanoid | 0:68e64068330f | 118 | } |
whismanoid | 0:68e64068330f | 119 | |
whismanoid | 0:68e64068330f | 120 | // CODE GENERATOR: omit global g_MAX11410_device |
whismanoid | 0:68e64068330f | 121 | // CODE GENERATOR: extern function declarations |
whismanoid | 0:68e64068330f | 122 | // CODE GENERATOR: extern function requirement MAX11410::SPIoutputCS |
whismanoid | 0:68e64068330f | 123 | // Assert SPI Chip Select |
whismanoid | 0:68e64068330f | 124 | // SPI chip-select for MAX11410 |
whismanoid | 0:68e64068330f | 125 | // |
whismanoid | 0:68e64068330f | 126 | void MAX11410::SPIoutputCS(int isLogicHigh) |
whismanoid | 0:68e64068330f | 127 | { |
whismanoid | 0:68e64068330f | 128 | // CODE GENERATOR: extern function definition for function SPIoutputCS |
whismanoid | 0:68e64068330f | 129 | // CODE GENERATOR: extern function definition for standard SPI interface function SPIoutputCS(int isLogicHigh) |
whismanoid | 0:68e64068330f | 130 | m_SPI_cs_state = isLogicHigh; |
whismanoid | 0:68e64068330f | 131 | m_cs_pin = m_SPI_cs_state; |
whismanoid | 0:68e64068330f | 132 | } |
whismanoid | 0:68e64068330f | 133 | |
whismanoid | 0:68e64068330f | 134 | // CODE GENERATOR: extern function requirement MAX11410::SPIwrite16bits |
whismanoid | 0:68e64068330f | 135 | // SPI write 16 bits |
whismanoid | 0:68e64068330f | 136 | // SPI interface to MAX11410 shift 16 bits mosiData into MAX11410 DIN |
whismanoid | 0:68e64068330f | 137 | // |
whismanoid | 0:68e64068330f | 138 | void MAX11410::SPIwrite16bits(int16_t mosiData16) |
whismanoid | 0:68e64068330f | 139 | { |
whismanoid | 0:68e64068330f | 140 | // CODE GENERATOR: extern function definition for function SPIwrite16bits |
whismanoid | 0:68e64068330f | 141 | // TODO1: CODE GENERATOR: extern function definition for standard SPI interface function SPIwrite16bits(int16_t mosiData16) |
whismanoid | 0:68e64068330f | 142 | size_t byteCount = 2; |
whismanoid | 0:68e64068330f | 143 | static char mosiData[2]; |
whismanoid | 0:68e64068330f | 144 | static char misoData[2]; |
whismanoid | 0:68e64068330f | 145 | mosiData[0] = (char)((mosiData16 >> 8) & 0xFF); // MSByte |
whismanoid | 0:68e64068330f | 146 | mosiData[1] = (char)((mosiData16 >> 0) & 0xFF); // LSByte |
whismanoid | 0:68e64068330f | 147 | // |
whismanoid | 0:68e64068330f | 148 | // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() |
whismanoid | 0:68e64068330f | 149 | //~ noInterrupts(); |
whismanoid | 0:68e64068330f | 150 | // |
whismanoid | 0:68e64068330f | 151 | //~ digitalWrite(Scope_Trigger_Pin, LOW); // diagnostic Scope_Trigger_Pin |
whismanoid | 0:68e64068330f | 152 | // |
whismanoid | 0:68e64068330f | 153 | unsigned int numBytesTransferred = m_spi.write(mosiData, byteCount, misoData, byteCount); |
whismanoid | 0:68e64068330f | 154 | //~ m_spi.transfer(mosiData8_FF0000); |
whismanoid | 0:68e64068330f | 155 | //~ m_spi.transfer(mosiData16_00FF00); |
whismanoid | 0:68e64068330f | 156 | //~ m_spi.transfer(mosiData16_0000FF); |
whismanoid | 0:68e64068330f | 157 | // |
whismanoid | 0:68e64068330f | 158 | //~ digitalWrite(Scope_Trigger_Pin, HIGH); // diagnostic Scope_Trigger_Pin |
whismanoid | 0:68e64068330f | 159 | // |
whismanoid | 0:68e64068330f | 160 | // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() |
whismanoid | 0:68e64068330f | 161 | //~ interrupts(); |
whismanoid | 0:68e64068330f | 162 | // Optional Diagnostic function to print SPI transactions |
whismanoid | 0:68e64068330f | 163 | if (onSPIprint) |
whismanoid | 0:68e64068330f | 164 | { |
whismanoid | 0:68e64068330f | 165 | onSPIprint(byteCount, (uint8_t*)mosiData, (uint8_t*)misoData); |
whismanoid | 0:68e64068330f | 166 | } |
whismanoid | 0:68e64068330f | 167 | // |
whismanoid | 0:68e64068330f | 168 | // VERIFY: SPIwrite24bits print diagnostic information |
whismanoid | 0:68e64068330f | 169 | //cmdLine.serial().printf(" MOSI->")); |
whismanoid | 0:68e64068330f | 170 | //cmdLine.serial().printf(" 0x")); |
whismanoid | 0:68e64068330f | 171 | //Serial.print( (mosiData8_FF0000 & 0xFF), HEX); |
whismanoid | 0:68e64068330f | 172 | //cmdLine.serial().printf(" 0x")); |
whismanoid | 0:68e64068330f | 173 | //Serial.print( (mosiData16_00FF00 & 0xFF), HEX); |
whismanoid | 0:68e64068330f | 174 | //cmdLine.serial().printf(" 0x")); |
whismanoid | 0:68e64068330f | 175 | //Serial.print( (mosiData16_0000FF & 0xFF), HEX); |
whismanoid | 0:68e64068330f | 176 | // hex dump mosiData[0..byteCount-1] |
whismanoid | 0:68e64068330f | 177 | #if 0 // HAS_MICROUSBSERIAL |
whismanoid | 0:68e64068330f | 178 | cmdLine_microUSBserial.serial().printf("\r\nSPI"); |
whismanoid | 0:68e64068330f | 179 | if (byteCount > 7) { |
whismanoid | 0:68e64068330f | 180 | cmdLine_microUSBserial.serial().printf(" byteCount:%d", byteCount); |
whismanoid | 0:68e64068330f | 181 | } |
whismanoid | 0:68e64068330f | 182 | cmdLine_microUSBserial.serial().printf(" MOSI->"); |
whismanoid | 0:68e64068330f | 183 | for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) |
whismanoid | 0:68e64068330f | 184 | { |
whismanoid | 0:68e64068330f | 185 | cmdLine_microUSBserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); |
whismanoid | 0:68e64068330f | 186 | } |
whismanoid | 0:68e64068330f | 187 | // hex dump misoData[0..byteCount-1] |
whismanoid | 0:68e64068330f | 188 | cmdLine_microUSBserial.serial().printf(" MISO<-"); |
whismanoid | 0:68e64068330f | 189 | for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) |
whismanoid | 0:68e64068330f | 190 | { |
whismanoid | 0:68e64068330f | 191 | cmdLine_microUSBserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); |
whismanoid | 0:68e64068330f | 192 | } |
whismanoid | 0:68e64068330f | 193 | cmdLine_microUSBserial.serial().printf(" "); |
whismanoid | 0:68e64068330f | 194 | #endif |
whismanoid | 0:68e64068330f | 195 | #if 0 // HAS_DAPLINK_SERIAL |
whismanoid | 0:68e64068330f | 196 | cmdLine_DAPLINKserial.serial().printf("\r\nSPI"); |
whismanoid | 0:68e64068330f | 197 | if (byteCount > 7) { |
whismanoid | 0:68e64068330f | 198 | cmdLine_DAPLINKserial.serial().printf(" byteCount:%d", byteCount); |
whismanoid | 0:68e64068330f | 199 | } |
whismanoid | 0:68e64068330f | 200 | cmdLine_DAPLINKserial.serial().printf(" MOSI->"); |
whismanoid | 0:68e64068330f | 201 | for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) |
whismanoid | 0:68e64068330f | 202 | { |
whismanoid | 0:68e64068330f | 203 | cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); |
whismanoid | 0:68e64068330f | 204 | } |
whismanoid | 0:68e64068330f | 205 | // hex dump misoData[0..byteCount-1] |
whismanoid | 0:68e64068330f | 206 | cmdLine_DAPLINKserial.serial().printf(" MISO<-"); |
whismanoid | 0:68e64068330f | 207 | for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) |
whismanoid | 0:68e64068330f | 208 | { |
whismanoid | 0:68e64068330f | 209 | cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); |
whismanoid | 0:68e64068330f | 210 | } |
whismanoid | 0:68e64068330f | 211 | cmdLine_DAPLINKserial.serial().printf(" "); |
whismanoid | 0:68e64068330f | 212 | #endif |
whismanoid | 0:68e64068330f | 213 | // VERIFY: DIAGNOSTIC: print MAX5715 device register write |
whismanoid | 0:68e64068330f | 214 | // TODO: MAX5715_print_register_verbose(mosiData8_FF0000, mosiData16_00FFFF); |
whismanoid | 0:68e64068330f | 215 | // TODO: print_verbose_SPI_diagnostic(mosiData16_FF00, mosiData16_00FF, misoData16_FF00, misoData16_00FF); |
whismanoid | 0:68e64068330f | 216 | // |
whismanoid | 0:68e64068330f | 217 | // int misoData16 = (misoData16_FF00 << 8) | misoData16_00FF; |
whismanoid | 0:68e64068330f | 218 | // return misoData16; |
whismanoid | 0:68e64068330f | 219 | } |
whismanoid | 0:68e64068330f | 220 | |
whismanoid | 0:68e64068330f | 221 | // CODE GENERATOR: extern function requirement MAX11410::SPIreadWrite16bits |
whismanoid | 0:68e64068330f | 222 | // SPI read and write 16 bits |
whismanoid | 0:68e64068330f | 223 | // SPI interface to MAX11410 shift 16 bits mosiData16 into MAX11410 DIN |
whismanoid | 0:68e64068330f | 224 | // while simultaneously capturing 16 bits miso data from MAX11410 DOUT |
whismanoid | 0:68e64068330f | 225 | // |
whismanoid | 0:68e64068330f | 226 | int16_t MAX11410::SPIreadWrite16bits(int16_t mosiData16) |
whismanoid | 0:68e64068330f | 227 | { |
whismanoid | 0:68e64068330f | 228 | // CODE GENERATOR: extern function definition for function SPIreadWrite16bits |
whismanoid | 0:68e64068330f | 229 | // TODO1: CODE GENERATOR: extern function definition for standard SPI interface function SPIreadWrite16bits(int16_t mosiData16) |
whismanoid | 0:68e64068330f | 230 | size_t byteCount = 2; |
whismanoid | 0:68e64068330f | 231 | static char mosiData[2]; |
whismanoid | 0:68e64068330f | 232 | static char misoData[2]; |
whismanoid | 0:68e64068330f | 233 | mosiData[0] = (char)((mosiData16 >> 8) & 0xFF); // MSByte |
whismanoid | 0:68e64068330f | 234 | mosiData[1] = (char)((mosiData16 >> 0) & 0xFF); // LSByte |
whismanoid | 0:68e64068330f | 235 | // |
whismanoid | 0:68e64068330f | 236 | // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() |
whismanoid | 0:68e64068330f | 237 | //~ noInterrupts(); |
whismanoid | 0:68e64068330f | 238 | // |
whismanoid | 0:68e64068330f | 239 | //~ digitalWrite(Scope_Trigger_Pin, LOW); // diagnostic Scope_Trigger_Pin |
whismanoid | 0:68e64068330f | 240 | // |
whismanoid | 0:68e64068330f | 241 | unsigned int numBytesTransferred = m_spi.write(mosiData, byteCount, misoData, byteCount); |
whismanoid | 0:68e64068330f | 242 | //~ m_spi.transfer(mosiData8_FF0000); |
whismanoid | 0:68e64068330f | 243 | //~ m_spi.transfer(mosiData16_00FF00); |
whismanoid | 0:68e64068330f | 244 | //~ m_spi.transfer(mosiData16_0000FF); |
whismanoid | 0:68e64068330f | 245 | // |
whismanoid | 0:68e64068330f | 246 | //~ digitalWrite(Scope_Trigger_Pin, HIGH); // diagnostic Scope_Trigger_Pin |
whismanoid | 0:68e64068330f | 247 | // |
whismanoid | 0:68e64068330f | 248 | // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() |
whismanoid | 0:68e64068330f | 249 | //~ interrupts(); |
whismanoid | 0:68e64068330f | 250 | // Optional Diagnostic function to print SPI transactions |
whismanoid | 0:68e64068330f | 251 | if (onSPIprint) |
whismanoid | 0:68e64068330f | 252 | { |
whismanoid | 0:68e64068330f | 253 | onSPIprint(byteCount, (uint8_t*)mosiData, (uint8_t*)misoData); |
whismanoid | 0:68e64068330f | 254 | } |
whismanoid | 0:68e64068330f | 255 | // |
whismanoid | 0:68e64068330f | 256 | // VERIFY: SPIwrite24bits print diagnostic information |
whismanoid | 0:68e64068330f | 257 | //cmdLine.serial().printf(" MOSI->")); |
whismanoid | 0:68e64068330f | 258 | //cmdLine.serial().printf(" 0x")); |
whismanoid | 0:68e64068330f | 259 | //Serial.print( (mosiData8_FF0000 & 0xFF), HEX); |
whismanoid | 0:68e64068330f | 260 | //cmdLine.serial().printf(" 0x")); |
whismanoid | 0:68e64068330f | 261 | //Serial.print( (mosiData16_00FF00 & 0xFF), HEX); |
whismanoid | 0:68e64068330f | 262 | //cmdLine.serial().printf(" 0x")); |
whismanoid | 0:68e64068330f | 263 | //Serial.print( (mosiData16_0000FF & 0xFF), HEX); |
whismanoid | 0:68e64068330f | 264 | // hex dump mosiData[0..byteCount-1] |
whismanoid | 0:68e64068330f | 265 | #if 0 // HAS_MICROUSBSERIAL |
whismanoid | 0:68e64068330f | 266 | cmdLine_microUSBserial.serial().printf("\r\nSPI"); |
whismanoid | 0:68e64068330f | 267 | if (byteCount > 7) { |
whismanoid | 0:68e64068330f | 268 | cmdLine_microUSBserial.serial().printf(" byteCount:%d", byteCount); |
whismanoid | 0:68e64068330f | 269 | } |
whismanoid | 0:68e64068330f | 270 | cmdLine_microUSBserial.serial().printf(" MOSI->"); |
whismanoid | 0:68e64068330f | 271 | for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) |
whismanoid | 0:68e64068330f | 272 | { |
whismanoid | 0:68e64068330f | 273 | cmdLine_microUSBserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); |
whismanoid | 0:68e64068330f | 274 | } |
whismanoid | 0:68e64068330f | 275 | // hex dump misoData[0..byteCount-1] |
whismanoid | 0:68e64068330f | 276 | cmdLine_microUSBserial.serial().printf(" MISO<-"); |
whismanoid | 0:68e64068330f | 277 | for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) |
whismanoid | 0:68e64068330f | 278 | { |
whismanoid | 0:68e64068330f | 279 | cmdLine_microUSBserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); |
whismanoid | 0:68e64068330f | 280 | } |
whismanoid | 0:68e64068330f | 281 | cmdLine_microUSBserial.serial().printf(" "); |
whismanoid | 0:68e64068330f | 282 | #endif |
whismanoid | 0:68e64068330f | 283 | #if 0 // HAS_DAPLINK_SERIAL |
whismanoid | 0:68e64068330f | 284 | cmdLine_DAPLINKserial.serial().printf("\r\nSPI"); |
whismanoid | 0:68e64068330f | 285 | if (byteCount > 7) { |
whismanoid | 0:68e64068330f | 286 | cmdLine_DAPLINKserial.serial().printf(" byteCount:%d", byteCount); |
whismanoid | 0:68e64068330f | 287 | } |
whismanoid | 0:68e64068330f | 288 | cmdLine_DAPLINKserial.serial().printf(" MOSI->"); |
whismanoid | 0:68e64068330f | 289 | for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) |
whismanoid | 0:68e64068330f | 290 | { |
whismanoid | 0:68e64068330f | 291 | cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); |
whismanoid | 0:68e64068330f | 292 | } |
whismanoid | 0:68e64068330f | 293 | // hex dump misoData[0..byteCount-1] |
whismanoid | 0:68e64068330f | 294 | cmdLine_DAPLINKserial.serial().printf(" MISO<-"); |
whismanoid | 0:68e64068330f | 295 | for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) |
whismanoid | 0:68e64068330f | 296 | { |
whismanoid | 0:68e64068330f | 297 | cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); |
whismanoid | 0:68e64068330f | 298 | } |
whismanoid | 0:68e64068330f | 299 | cmdLine_DAPLINKserial.serial().printf(" "); |
whismanoid | 0:68e64068330f | 300 | #endif |
whismanoid | 0:68e64068330f | 301 | // VERIFY: DIAGNOSTIC: print MAX5715 device register write |
whismanoid | 0:68e64068330f | 302 | // TODO: MAX5715_print_register_verbose(mosiData8_FF0000, mosiData16_00FFFF); |
whismanoid | 0:68e64068330f | 303 | // TODO: print_verbose_SPI_diagnostic(mosiData16_FF00, mosiData16_00FF, misoData16_FF00, misoData16_00FF); |
whismanoid | 0:68e64068330f | 304 | // |
whismanoid | 0:68e64068330f | 305 | //int misoData16 = (misoData16_FF00 << 8) | misoData16_00FF; |
whismanoid | 0:68e64068330f | 306 | int misoData16 = (misoData[0] << 8) | misoData[1]; |
whismanoid | 0:68e64068330f | 307 | return misoData16; |
whismanoid | 0:68e64068330f | 308 | } |
whismanoid | 0:68e64068330f | 309 | |
whismanoid | 0:68e64068330f | 310 | // CODE GENERATOR: extern function requirement MAX11410::SPIreadWrite32bits |
whismanoid | 0:68e64068330f | 311 | // SPI read and write 32 bits |
whismanoid | 0:68e64068330f | 312 | // SPI interface to MAX11410 shift 32 bits mosiData into MAX11410 DIN |
whismanoid | 0:68e64068330f | 313 | // while simultaneously capturing 32 bits miso data from MAX11410 DOUT |
whismanoid | 0:68e64068330f | 314 | // |
whismanoid | 0:68e64068330f | 315 | int32_t MAX11410::SPIreadWrite32bits(int32_t mosiData32) |
whismanoid | 0:68e64068330f | 316 | { |
whismanoid | 0:68e64068330f | 317 | // CODE GENERATOR: extern function definition for function SPIreadWrite32bits |
whismanoid | 0:68e64068330f | 318 | // TODO1: CODE GENERATOR: extern function definition for standard SPI interface function SPIreadWrite32bits(int32_t mosiData32) |
whismanoid | 0:68e64068330f | 319 | size_t byteCount = 4; |
whismanoid | 0:68e64068330f | 320 | static char mosiData[4]; |
whismanoid | 0:68e64068330f | 321 | static char misoData[4]; |
whismanoid | 0:68e64068330f | 322 | mosiData[0] = (char)((mosiData32 >> 24) & 0xFF); // MSByte |
whismanoid | 0:68e64068330f | 323 | mosiData[1] = (char)((mosiData32 >> 16) & 0xFF); |
whismanoid | 0:68e64068330f | 324 | mosiData[2] = (char)((mosiData32 >> 8) & 0xFF); |
whismanoid | 0:68e64068330f | 325 | mosiData[3] = (char)((mosiData32 >> 0) & 0xFF); // LSByte |
whismanoid | 0:68e64068330f | 326 | // |
whismanoid | 0:68e64068330f | 327 | // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() |
whismanoid | 0:68e64068330f | 328 | //~ noInterrupts(); |
whismanoid | 0:68e64068330f | 329 | // |
whismanoid | 0:68e64068330f | 330 | //~ digitalWrite(Scope_Trigger_Pin, LOW); // diagnostic Scope_Trigger_Pin |
whismanoid | 0:68e64068330f | 331 | // |
whismanoid | 0:68e64068330f | 332 | unsigned int numBytesTransferred = m_spi.write(mosiData, byteCount, misoData, byteCount); |
whismanoid | 0:68e64068330f | 333 | //~ m_spi.transfer(mosiData8_FF0000); |
whismanoid | 0:68e64068330f | 334 | //~ m_spi.transfer(mosiData16_00FF00); |
whismanoid | 0:68e64068330f | 335 | //~ m_spi.transfer(mosiData16_0000FF); |
whismanoid | 0:68e64068330f | 336 | // |
whismanoid | 0:68e64068330f | 337 | //~ digitalWrite(Scope_Trigger_Pin, HIGH); // diagnostic Scope_Trigger_Pin |
whismanoid | 0:68e64068330f | 338 | // |
whismanoid | 0:68e64068330f | 339 | // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() |
whismanoid | 0:68e64068330f | 340 | //~ interrupts(); |
whismanoid | 0:68e64068330f | 341 | // Optional Diagnostic function to print SPI transactions |
whismanoid | 0:68e64068330f | 342 | if (onSPIprint) |
whismanoid | 0:68e64068330f | 343 | { |
whismanoid | 0:68e64068330f | 344 | onSPIprint(byteCount, (uint8_t*)mosiData, (uint8_t*)misoData); |
whismanoid | 0:68e64068330f | 345 | } |
whismanoid | 0:68e64068330f | 346 | // |
whismanoid | 0:68e64068330f | 347 | // VERIFY: SPIwrite24bits print diagnostic information |
whismanoid | 0:68e64068330f | 348 | //cmdLine.serial().printf(" MOSI->")); |
whismanoid | 0:68e64068330f | 349 | //cmdLine.serial().printf(" 0x")); |
whismanoid | 0:68e64068330f | 350 | //Serial.print( (mosiData8_FF0000 & 0xFF), HEX); |
whismanoid | 0:68e64068330f | 351 | //cmdLine.serial().printf(" 0x")); |
whismanoid | 0:68e64068330f | 352 | //Serial.print( (mosiData16_00FF00 & 0xFF), HEX); |
whismanoid | 0:68e64068330f | 353 | //cmdLine.serial().printf(" 0x")); |
whismanoid | 0:68e64068330f | 354 | //Serial.print( (mosiData16_0000FF & 0xFF), HEX); |
whismanoid | 0:68e64068330f | 355 | // hex dump mosiData[0..byteCount-1] |
whismanoid | 0:68e64068330f | 356 | #if 0 // HAS_MICROUSBSERIAL |
whismanoid | 0:68e64068330f | 357 | cmdLine_microUSBserial.serial().printf("\r\nSPI"); |
whismanoid | 0:68e64068330f | 358 | if (byteCount > 7) { |
whismanoid | 0:68e64068330f | 359 | cmdLine_microUSBserial.serial().printf(" byteCount:%d", byteCount); |
whismanoid | 0:68e64068330f | 360 | } |
whismanoid | 0:68e64068330f | 361 | cmdLine_microUSBserial.serial().printf(" MOSI->"); |
whismanoid | 0:68e64068330f | 362 | for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) |
whismanoid | 0:68e64068330f | 363 | { |
whismanoid | 0:68e64068330f | 364 | cmdLine_microUSBserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); |
whismanoid | 0:68e64068330f | 365 | } |
whismanoid | 0:68e64068330f | 366 | // hex dump misoData[0..byteCount-1] |
whismanoid | 0:68e64068330f | 367 | cmdLine_microUSBserial.serial().printf(" MISO<-"); |
whismanoid | 0:68e64068330f | 368 | for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) |
whismanoid | 0:68e64068330f | 369 | { |
whismanoid | 0:68e64068330f | 370 | cmdLine_microUSBserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); |
whismanoid | 0:68e64068330f | 371 | } |
whismanoid | 0:68e64068330f | 372 | cmdLine_microUSBserial.serial().printf(" "); |
whismanoid | 0:68e64068330f | 373 | #endif |
whismanoid | 0:68e64068330f | 374 | #if 0 // HAS_DAPLINK_SERIAL |
whismanoid | 0:68e64068330f | 375 | cmdLine_DAPLINKserial.serial().printf("\r\nSPI"); |
whismanoid | 0:68e64068330f | 376 | if (byteCount > 7) { |
whismanoid | 0:68e64068330f | 377 | cmdLine_DAPLINKserial.serial().printf(" byteCount:%d", byteCount); |
whismanoid | 0:68e64068330f | 378 | } |
whismanoid | 0:68e64068330f | 379 | cmdLine_DAPLINKserial.serial().printf(" MOSI->"); |
whismanoid | 0:68e64068330f | 380 | for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) |
whismanoid | 0:68e64068330f | 381 | { |
whismanoid | 0:68e64068330f | 382 | cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); |
whismanoid | 0:68e64068330f | 383 | } |
whismanoid | 0:68e64068330f | 384 | // hex dump misoData[0..byteCount-1] |
whismanoid | 0:68e64068330f | 385 | cmdLine_DAPLINKserial.serial().printf(" MISO<-"); |
whismanoid | 0:68e64068330f | 386 | for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) |
whismanoid | 0:68e64068330f | 387 | { |
whismanoid | 0:68e64068330f | 388 | cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); |
whismanoid | 0:68e64068330f | 389 | } |
whismanoid | 0:68e64068330f | 390 | cmdLine_DAPLINKserial.serial().printf(" "); |
whismanoid | 0:68e64068330f | 391 | #endif |
whismanoid | 0:68e64068330f | 392 | // VERIFY: DIAGNOSTIC: print MAX5715 device register write |
whismanoid | 0:68e64068330f | 393 | // TODO: MAX5715_print_register_verbose(mosiData8_FF0000, mosiData16_00FFFF); |
whismanoid | 0:68e64068330f | 394 | // TODO: print_verbose_SPI_diagnostic(mosiData16_FF00, mosiData16_00FF, misoData16_FF00, misoData16_00FF); |
whismanoid | 0:68e64068330f | 395 | // |
whismanoid | 0:68e64068330f | 396 | //int misoData32 = (misoData32_FF000000 << 24) | (misoData32_FF0000 << 16) | (misoData32_0000FF00 << 8) | misoData32_000000FF; |
whismanoid | 0:68e64068330f | 397 | int misoData32 = (misoData[0] << 24) | (misoData[1] << 16) | (misoData[2] << 8) | misoData[3]; |
whismanoid | 0:68e64068330f | 398 | return misoData32; |
whismanoid | 0:68e64068330f | 399 | } |
whismanoid | 0:68e64068330f | 400 | |
whismanoid | 0:68e64068330f | 401 | // CODE GENERATOR: class member function definitions |
whismanoid | 0:68e64068330f | 402 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 403 | // Menu item '!' |
whismanoid | 0:68e64068330f | 404 | // Initialize device |
whismanoid | 0:68e64068330f | 405 | // @return 1 on success; 0 on failure |
whismanoid | 0:68e64068330f | 406 | uint8_t MAX11410::Init(void) |
whismanoid | 0:68e64068330f | 407 | { |
whismanoid | 0:68e64068330f | 408 | |
whismanoid | 0:68e64068330f | 409 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 410 | // AIN0-AIN1 reference voltage, in Volts |
whismanoid | 1:d57c1a2cb83c | 411 | VRef_REF0 = 2.500; |
whismanoid | 1:d57c1a2cb83c | 412 | |
whismanoid | 1:d57c1a2cb83c | 413 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 414 | // REF1P-REF1N reference resistance, in Ohms |
whismanoid | 1:d57c1a2cb83c | 415 | VRef_REF1 = 4999; |
whismanoid | 1:d57c1a2cb83c | 416 | |
whismanoid | 1:d57c1a2cb83c | 417 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 418 | // REF2P-REF2N reference voltage, in Volts |
whismanoid | 1:d57c1a2cb83c | 419 | VRef_REF2 = 2.500; |
whismanoid | 1:d57c1a2cb83c | 420 | |
whismanoid | 1:d57c1a2cb83c | 421 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 422 | // AVDD-AGND supply voltage, in Volts |
whismanoid | 1:d57c1a2cb83c | 423 | VRef_AVDD = 3.300; |
whismanoid | 1:d57c1a2cb83c | 424 | |
whismanoid | 1:d57c1a2cb83c | 425 | //---------------------------------------- |
whismanoid | 5:a2e74357cfc0 | 426 | // RTD Resistance measurement; Thermocouple Cold Junction, in Ohms |
whismanoid | 5:a2e74357cfc0 | 427 | rtd_resistance = 1000.0; |
whismanoid | 5:a2e74357cfc0 | 428 | |
whismanoid | 5:a2e74357cfc0 | 429 | //---------------------------------------- |
whismanoid | 3:658a93dfb2d8 | 430 | // Temperature calculated from RTD Resistance; Thermocouple Cold Junction, in degrees C |
whismanoid | 3:658a93dfb2d8 | 431 | RTD_Temperature = 25.0; |
whismanoid | 3:658a93dfb2d8 | 432 | |
whismanoid | 3:658a93dfb2d8 | 433 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 434 | // shadow of register ctrl CMD_r000_1001_dddd_dddd_CTRL |
whismanoid | 1:d57c1a2cb83c | 435 | ctrl = 0x01; |
whismanoid | 1:d57c1a2cb83c | 436 | |
whismanoid | 1:d57c1a2cb83c | 437 | //---------------------------------------- |
whismanoid | 9:06ca88952f1c | 438 | // set by Configure_PGA gain index register pga CMD_r000_1110_xxdd_xddd_PGA |
whismanoid | 9:06ca88952f1c | 439 | pgaGain = 1; |
whismanoid | 9:06ca88952f1c | 440 | |
whismanoid | 9:06ca88952f1c | 441 | //---------------------------------------- |
whismanoid | 9:06ca88952f1c | 442 | // Device ID Validation |
whismanoid | 9:06ca88952f1c | 443 | #warning "Not Implemented Yet: MAX11410::Init Device ID Validation..." |
whismanoid | 9:06ca88952f1c | 444 | const uint32_t part_id_expect = 0x000F02; |
whismanoid | 9:06ca88952f1c | 445 | uint32_t part_id_readback; |
whismanoid | 9:06ca88952f1c | 446 | RegRead(CMD_r001_0001_xxxx_xxxx_xxxx_xxxx_xxxx_xddd_PART_ID, &part_id_readback); |
whismanoid | 9:06ca88952f1c | 447 | if (part_id_readback != part_id_expect) return 0; |
whismanoid | 9:06ca88952f1c | 448 | |
whismanoid | 9:06ca88952f1c | 449 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 450 | // write8 0x00 PD = 0x03 (Reset Registers; enter Standby mode) |
whismanoid | 1:d57c1a2cb83c | 451 | RegWrite(CMD_r000_0000_xxxx_xxdd_PD, PD_11_Reset); |
whismanoid | 1:d57c1a2cb83c | 452 | |
whismanoid | 1:d57c1a2cb83c | 453 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 454 | // write8 0x00 PD = 0x00 (NOP) |
whismanoid | 1:d57c1a2cb83c | 455 | RegWrite(CMD_r000_0000_xxxx_xxdd_PD, PD_00_Normal); |
whismanoid | 0:68e64068330f | 456 | |
whismanoid | 0:68e64068330f | 457 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 458 | // success |
whismanoid | 0:68e64068330f | 459 | return 1; |
whismanoid | 0:68e64068330f | 460 | } |
whismanoid | 0:68e64068330f | 461 | |
whismanoid | 0:68e64068330f | 462 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 463 | // Return the physical voltage corresponding to conversion result, |
whismanoid | 1:d57c1a2cb83c | 464 | // for unipolar mode. |
whismanoid | 0:68e64068330f | 465 | // Does not perform any offset or gain correction. |
whismanoid | 0:68e64068330f | 466 | // |
whismanoid | 1:d57c1a2cb83c | 467 | // @pre CTRL::U_BN = 1 -- Unipolar mode |
whismanoid | 1:d57c1a2cb83c | 468 | // @pre CTRL::FORMAT = x |
whismanoid | 0:68e64068330f | 469 | // @pre VRef = Voltage of REF input, in Volts |
whismanoid | 0:68e64068330f | 470 | // @param[in] value_u24: raw 24-bit MAX11410 code (right justified). |
whismanoid | 0:68e64068330f | 471 | // @return physical voltage corresponding to MAX11410 code. |
whismanoid | 4:c169ba85d673 | 472 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0xFFFFFF) expect 2.500 within 0.030 Full Scale |
whismanoid | 4:c169ba85d673 | 473 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0xFFFFFE) expect 2.500 Full Scale |
whismanoid | 4:c169ba85d673 | 474 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0xCCCCCC) expect 2.000 Two Volts |
whismanoid | 4:c169ba85d673 | 475 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0xC00000) expect 1.875 75% Scale |
whismanoid | 4:c169ba85d673 | 476 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0x800000) expect 1.250 Mid Scale |
whismanoid | 4:c169ba85d673 | 477 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0x666666) expect 1.000 One Volt |
whismanoid | 4:c169ba85d673 | 478 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0x400000) expect 0.625 25% Scale |
whismanoid | 4:c169ba85d673 | 479 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0x0A3D70) expect 0.100 100mV |
whismanoid | 4:c169ba85d673 | 480 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0x000064) expect 0.000014901162 100 LSB |
whismanoid | 4:c169ba85d673 | 481 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0x00000A) expect 0.0000014901162 Ten LSB |
whismanoid | 4:c169ba85d673 | 482 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0x000003) expect 0.00000044703483 Three LSB |
whismanoid | 4:c169ba85d673 | 483 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0x000002) expect 0.00000029802326 Two LSB |
whismanoid | 4:c169ba85d673 | 484 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0x000001) expect 0.00000014901162 One LSB |
whismanoid | 4:c169ba85d673 | 485 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0x000000) expect 0.0 Zero Scale |
whismanoid | 1:d57c1a2cb83c | 486 | // |
whismanoid | 1:d57c1a2cb83c | 487 | double MAX11410::VoltageOfCode_Unipolar(uint32_t value_u24) |
whismanoid | 0:68e64068330f | 488 | { |
whismanoid | 0:68e64068330f | 489 | |
whismanoid | 0:68e64068330f | 490 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 491 | // Linear map min and max endpoints |
whismanoid | 1:d57c1a2cb83c | 492 | double VRef = VRef_REF2; |
whismanoid | 1:d57c1a2cb83c | 493 | uint8_t ref_sel = (ctrl & 0x03); // MAX11410_REF_SEL_enum_t |
whismanoid | 1:d57c1a2cb83c | 494 | switch(ref_sel) |
whismanoid | 1:d57c1a2cb83c | 495 | { |
whismanoid | 1:d57c1a2cb83c | 496 | case REF_SEL_000_AIN0_AIN1: VRef = VRef_REF0; break; |
whismanoid | 1:d57c1a2cb83c | 497 | case REF_SEL_001_REF1P_REF1N: VRef = VRef_REF1; break; |
whismanoid | 1:d57c1a2cb83c | 498 | case REF_SEL_010_REF2P_REF2N: VRef = VRef_REF2; break; |
whismanoid | 1:d57c1a2cb83c | 499 | case REF_SEL_011_AVDD_AGND: VRef = VRef_AVDD; break; |
whismanoid | 1:d57c1a2cb83c | 500 | case REF_SEL_100_AIN0_AGND: VRef = VRef_REF0; break; |
whismanoid | 1:d57c1a2cb83c | 501 | case REF_SEL_101_REF1P_AGND: VRef = VRef_REF1; break; |
whismanoid | 1:d57c1a2cb83c | 502 | case REF_SEL_110_REF2P_AGND: VRef = VRef_REF2; break; |
whismanoid | 1:d57c1a2cb83c | 503 | case REF_SEL_111_AVDD_AGND: VRef = VRef_AVDD; break; |
whismanoid | 1:d57c1a2cb83c | 504 | } |
whismanoid | 0:68e64068330f | 505 | double MaxScaleVoltage = VRef; // voltage of maximum code 0xffffff |
whismanoid | 0:68e64068330f | 506 | double MinScaleVoltage = 0.0; // voltage of minimum code 0x000 |
whismanoid | 0:68e64068330f | 507 | const uint32_t FULL_SCALE_CODE_24BIT = 0xffffff; |
whismanoid | 0:68e64068330f | 508 | const uint32_t MaxCode = FULL_SCALE_CODE_24BIT; |
whismanoid | 0:68e64068330f | 509 | const uint32_t MinCode = 0x000; |
whismanoid | 0:68e64068330f | 510 | double codeFraction = ((double)value_u24 - MinCode) / (MaxCode - MinCode + 1); |
whismanoid | 1:d57c1a2cb83c | 511 | return (MinScaleVoltage + ((MaxScaleVoltage - MinScaleVoltage) * codeFraction)) / pgaGain; |
whismanoid | 1:d57c1a2cb83c | 512 | } |
whismanoid | 1:d57c1a2cb83c | 513 | |
whismanoid | 1:d57c1a2cb83c | 514 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 515 | // Return the physical voltage corresponding to conversion result, |
whismanoid | 1:d57c1a2cb83c | 516 | // when conversion format is Bipolar mode, offset binary. |
whismanoid | 1:d57c1a2cb83c | 517 | // Does not perform any offset or gain correction. |
whismanoid | 1:d57c1a2cb83c | 518 | // |
whismanoid | 1:d57c1a2cb83c | 519 | // @pre CTRL::U_BN = 0 -- Bipolar mode |
whismanoid | 1:d57c1a2cb83c | 520 | // @pre CTRL::FORMAT = 1 -- offset binary |
whismanoid | 1:d57c1a2cb83c | 521 | // @pre VRef = Voltage of REF input, in Volts |
whismanoid | 1:d57c1a2cb83c | 522 | // @param[in] value_u24: raw 24-bit MAX11410 code (right justified). |
whismanoid | 1:d57c1a2cb83c | 523 | // @return physical voltage corresponding to MAX11410 code. |
whismanoid | 4:c169ba85d673 | 524 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0xFFFFFF) expect 2.5 within 0.030 Full Scale |
whismanoid | 4:c169ba85d673 | 525 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0xFFFFFE) expect 2.5 Full Scale |
whismanoid | 4:c169ba85d673 | 526 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0xC00000) expect 1.25 Mid Scale |
whismanoid | 4:c169ba85d673 | 527 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x800003) expect 0.00000894069671 Three LSB |
whismanoid | 4:c169ba85d673 | 528 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x800002) expect 0.00000596046447 Two LSB |
whismanoid | 4:c169ba85d673 | 529 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x800001) expect 0.0000029802326 One LSB |
whismanoid | 4:c169ba85d673 | 530 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x800000) expect 0.0 Zero Scale |
whismanoid | 4:c169ba85d673 | 531 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x7FFFFF) expect -0.0000029802326 Negative One LSB |
whismanoid | 4:c169ba85d673 | 532 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x7FFFFE) expect -0.0000059604644 Negative Two LSB |
whismanoid | 4:c169ba85d673 | 533 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x7FFFFD) expect -0.0000089406967 Negative Three LSB |
whismanoid | 4:c169ba85d673 | 534 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x400000) expect -1.25 Negative Mid Scale |
whismanoid | 4:c169ba85d673 | 535 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x000001) expect -2.5 Negative Full Scale |
whismanoid | 4:c169ba85d673 | 536 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x000000) expect -2.5 Negative Full Scale |
whismanoid | 1:d57c1a2cb83c | 537 | // |
whismanoid | 1:d57c1a2cb83c | 538 | double MAX11410::VoltageOfCode_Bipolar_OffsetBinary(uint32_t value_u24) |
whismanoid | 1:d57c1a2cb83c | 539 | { |
whismanoid | 1:d57c1a2cb83c | 540 | |
whismanoid | 1:d57c1a2cb83c | 541 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 542 | // Linear map min and max endpoints |
whismanoid | 1:d57c1a2cb83c | 543 | double VRef = VRef_REF2; |
whismanoid | 1:d57c1a2cb83c | 544 | uint8_t ref_sel = (ctrl & 0x03); // MAX11410_REF_SEL_enum_t |
whismanoid | 1:d57c1a2cb83c | 545 | switch(ref_sel) |
whismanoid | 1:d57c1a2cb83c | 546 | { |
whismanoid | 1:d57c1a2cb83c | 547 | case REF_SEL_000_AIN0_AIN1: VRef = VRef_REF0; break; |
whismanoid | 1:d57c1a2cb83c | 548 | case REF_SEL_001_REF1P_REF1N: VRef = VRef_REF1; break; |
whismanoid | 1:d57c1a2cb83c | 549 | case REF_SEL_010_REF2P_REF2N: VRef = VRef_REF2; break; |
whismanoid | 1:d57c1a2cb83c | 550 | case REF_SEL_011_AVDD_AGND: VRef = VRef_AVDD; break; |
whismanoid | 1:d57c1a2cb83c | 551 | case REF_SEL_100_AIN0_AGND: VRef = VRef_REF0; break; |
whismanoid | 1:d57c1a2cb83c | 552 | case REF_SEL_101_REF1P_AGND: VRef = VRef_REF1; break; |
whismanoid | 1:d57c1a2cb83c | 553 | case REF_SEL_110_REF2P_AGND: VRef = VRef_REF2; break; |
whismanoid | 1:d57c1a2cb83c | 554 | case REF_SEL_111_AVDD_AGND: VRef = VRef_AVDD; break; |
whismanoid | 1:d57c1a2cb83c | 555 | } |
whismanoid | 1:d57c1a2cb83c | 556 | double MaxScaleVoltage = 2*VRef; // voltage of maximum code 0x7fffff |
whismanoid | 1:d57c1a2cb83c | 557 | double MinScaleVoltage = 0; // voltage of minimum code 0x800000; |
whismanoid | 1:d57c1a2cb83c | 558 | const uint32_t FULL_SCALE_CODE_24BIT = 0x7fffff; |
whismanoid | 1:d57c1a2cb83c | 559 | const uint32_t MaxCode = FULL_SCALE_CODE_24BIT; |
whismanoid | 1:d57c1a2cb83c | 560 | const int32_t CodeSpan = 0x1000000; |
whismanoid | 1:d57c1a2cb83c | 561 | const uint32_t MinCode = 0x800000; |
whismanoid | 1:d57c1a2cb83c | 562 | double codeFraction = ((double)value_u24 - MinCode) / CodeSpan; |
whismanoid | 1:d57c1a2cb83c | 563 | return (MinScaleVoltage + ((MaxScaleVoltage - MinScaleVoltage) * codeFraction)) / pgaGain; |
whismanoid | 1:d57c1a2cb83c | 564 | } |
whismanoid | 1:d57c1a2cb83c | 565 | |
whismanoid | 1:d57c1a2cb83c | 566 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 567 | // Return the physical voltage corresponding to conversion result, |
whismanoid | 1:d57c1a2cb83c | 568 | // when conversion format is Bipolar mode, 2's complement. |
whismanoid | 1:d57c1a2cb83c | 569 | // Does not perform any offset or gain correction. |
whismanoid | 1:d57c1a2cb83c | 570 | // |
whismanoid | 1:d57c1a2cb83c | 571 | // @pre CTRL::U_BN = 0 -- Bipolar mode |
whismanoid | 1:d57c1a2cb83c | 572 | // @pre CTRL::FORMAT = 0 -- 2's complement |
whismanoid | 1:d57c1a2cb83c | 573 | // @pre VRef = Voltage of REF input, in Volts |
whismanoid | 1:d57c1a2cb83c | 574 | // @param[in] value_u24: raw 24-bit MAX11410 code (right justified). |
whismanoid | 1:d57c1a2cb83c | 575 | // @return physical voltage corresponding to MAX11410 code. |
whismanoid | 4:c169ba85d673 | 576 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x7FFFFF) expect 2.500 within 0.030 Full Scale |
whismanoid | 4:c169ba85d673 | 577 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x7FFFFE) expect 2.500 Full Scale |
whismanoid | 4:c169ba85d673 | 578 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x666666) expect 2.000 Two Volts |
whismanoid | 4:c169ba85d673 | 579 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x600000) expect 1.875 75% Scale |
whismanoid | 4:c169ba85d673 | 580 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x400000) expect 1.250 Mid Scale |
whismanoid | 4:c169ba85d673 | 581 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x333333) expect 1.000 One Volt |
whismanoid | 4:c169ba85d673 | 582 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x200000) expect 0.625 25% Scale |
whismanoid | 4:c169ba85d673 | 583 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x051eb8) expect 0.100 100mV |
whismanoid | 4:c169ba85d673 | 584 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x000003) expect 0.00000894069671 Three LSB |
whismanoid | 4:c169ba85d673 | 585 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x000002) expect 0.00000596046447 Two LSB |
whismanoid | 4:c169ba85d673 | 586 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x000001) expect 0.0000029802326 One LSB |
whismanoid | 4:c169ba85d673 | 587 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x000000) expect 0.0 Zero Scale |
whismanoid | 4:c169ba85d673 | 588 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0xFFFFFF) expect -0.0000029802326 Negative One LSB |
whismanoid | 4:c169ba85d673 | 589 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0xFFFFFE) expect -0.0000059604644 Negative Two LSB |
whismanoid | 4:c169ba85d673 | 590 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0xFFFFFD) expect -0.0000089406967 Negative Three LSB |
whismanoid | 4:c169ba85d673 | 591 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0xFAE148) expect -0.100 Negative 100mV |
whismanoid | 4:c169ba85d673 | 592 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0xE00000) expect -0.625 Negative 25% Scale |
whismanoid | 4:c169ba85d673 | 593 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0xCCCCCD) expect -1.000 Negative One Volt |
whismanoid | 4:c169ba85d673 | 594 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0xC00000) expect -1.250 Negative Mid Scale |
whismanoid | 4:c169ba85d673 | 595 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0xA00000) expect -1.875 Negative 75% Scale |
whismanoid | 4:c169ba85d673 | 596 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x99999A) expect -2.000 Negative Two Volts |
whismanoid | 4:c169ba85d673 | 597 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x800001) expect -2.500 Negative Full Scale |
whismanoid | 4:c169ba85d673 | 598 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x800000) expect -2.500 Negative Full Scale |
whismanoid | 1:d57c1a2cb83c | 599 | // |
whismanoid | 1:d57c1a2cb83c | 600 | double MAX11410::VoltageOfCode_Bipolar_2sComplement(uint32_t value_u24) |
whismanoid | 1:d57c1a2cb83c | 601 | { |
whismanoid | 1:d57c1a2cb83c | 602 | |
whismanoid | 1:d57c1a2cb83c | 603 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 604 | // Linear map min and max endpoints |
whismanoid | 1:d57c1a2cb83c | 605 | double VRef = VRef_REF2; |
whismanoid | 1:d57c1a2cb83c | 606 | uint8_t ref_sel = (ctrl & 0x03); // MAX11410_REF_SEL_enum_t |
whismanoid | 1:d57c1a2cb83c | 607 | switch(ref_sel) |
whismanoid | 1:d57c1a2cb83c | 608 | { |
whismanoid | 1:d57c1a2cb83c | 609 | case REF_SEL_000_AIN0_AIN1: VRef = VRef_REF0; break; |
whismanoid | 1:d57c1a2cb83c | 610 | case REF_SEL_001_REF1P_REF1N: VRef = VRef_REF1; break; |
whismanoid | 1:d57c1a2cb83c | 611 | case REF_SEL_010_REF2P_REF2N: VRef = VRef_REF2; break; |
whismanoid | 1:d57c1a2cb83c | 612 | case REF_SEL_011_AVDD_AGND: VRef = VRef_AVDD; break; |
whismanoid | 1:d57c1a2cb83c | 613 | case REF_SEL_100_AIN0_AGND: VRef = VRef_REF0; break; |
whismanoid | 1:d57c1a2cb83c | 614 | case REF_SEL_101_REF1P_AGND: VRef = VRef_REF1; break; |
whismanoid | 1:d57c1a2cb83c | 615 | case REF_SEL_110_REF2P_AGND: VRef = VRef_REF2; break; |
whismanoid | 1:d57c1a2cb83c | 616 | case REF_SEL_111_AVDD_AGND: VRef = VRef_AVDD; break; |
whismanoid | 1:d57c1a2cb83c | 617 | } |
whismanoid | 1:d57c1a2cb83c | 618 | double MaxScaleVoltage = 2 * VRef; // voltage of maximum code 0x7fffff |
whismanoid | 1:d57c1a2cb83c | 619 | double MinScaleVoltage = 0; // voltage of minimum code 0x800000 |
whismanoid | 1:d57c1a2cb83c | 620 | const int32_t FULL_SCALE_CODE_24BIT_2S_COMPLEMENT = 0x7fffff; |
whismanoid | 1:d57c1a2cb83c | 621 | const int32_t SIGN_BIT_24BIT_2S_COMPLEMENT = 0x800000; |
whismanoid | 1:d57c1a2cb83c | 622 | if (value_u24 >= SIGN_BIT_24BIT_2S_COMPLEMENT) { value_u24 = value_u24 - (2 * SIGN_BIT_24BIT_2S_COMPLEMENT); } |
whismanoid | 1:d57c1a2cb83c | 623 | const int32_t MaxCode = FULL_SCALE_CODE_24BIT_2S_COMPLEMENT; |
whismanoid | 1:d57c1a2cb83c | 624 | const int32_t CodeSpan = 0x1000000; |
whismanoid | 1:d57c1a2cb83c | 625 | const int32_t MinCode = 0; |
whismanoid | 1:d57c1a2cb83c | 626 | double codeFraction = ((double)((int32_t)value_u24) - MinCode) / CodeSpan; |
whismanoid | 1:d57c1a2cb83c | 627 | return (MinScaleVoltage + ((MaxScaleVoltage - MinScaleVoltage) * codeFraction)) / pgaGain; |
whismanoid | 1:d57c1a2cb83c | 628 | } |
whismanoid | 1:d57c1a2cb83c | 629 | |
whismanoid | 1:d57c1a2cb83c | 630 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 631 | // Return the physical voltage corresponding to conversion result, |
whismanoid | 1:d57c1a2cb83c | 632 | // when conversion format is determined by the CTRL register. |
whismanoid | 1:d57c1a2cb83c | 633 | // Does not perform any offset or gain correction. |
whismanoid | 1:d57c1a2cb83c | 634 | // |
whismanoid | 1:d57c1a2cb83c | 635 | // @pre CTRL::U_BN and CTRL::FORMAT = 0 select offset binary, 2's complement, or straight binary |
whismanoid | 1:d57c1a2cb83c | 636 | // @pre VRef = Voltage of REF input, in Volts |
whismanoid | 1:d57c1a2cb83c | 637 | // @param[in] value_u24: raw 24-bit MAX11410 code (right justified). |
whismanoid | 1:d57c1a2cb83c | 638 | // @return physical voltage corresponding to MAX11410 code. |
whismanoid | 1:d57c1a2cb83c | 639 | double MAX11410::VoltageOfCode(uint32_t value_u24) |
whismanoid | 1:d57c1a2cb83c | 640 | { |
whismanoid | 1:d57c1a2cb83c | 641 | |
whismanoid | 1:d57c1a2cb83c | 642 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 643 | // warning -- WIP work in progress |
whismanoid | 1:d57c1a2cb83c | 644 | #warning "Not Tested Yet: MAX11410::VoltageOfCode..." |
whismanoid | 1:d57c1a2cb83c | 645 | |
whismanoid | 1:d57c1a2cb83c | 646 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 647 | // Determine format from CTRL register U_BN and FORMAT |
whismanoid | 1:d57c1a2cb83c | 648 | uint8_t u_bn_bitmask = (1 << 6); |
whismanoid | 1:d57c1a2cb83c | 649 | uint8_t format_bitmask = (1 << 5); |
whismanoid | 1:d57c1a2cb83c | 650 | if ((ctrl & u_bn_bitmask) != 0) |
whismanoid | 1:d57c1a2cb83c | 651 | { |
whismanoid | 1:d57c1a2cb83c | 652 | return VoltageOfCode_Unipolar(value_u24); |
whismanoid | 1:d57c1a2cb83c | 653 | } |
whismanoid | 1:d57c1a2cb83c | 654 | if ((ctrl & format_bitmask) != 0) |
whismanoid | 1:d57c1a2cb83c | 655 | { |
whismanoid | 1:d57c1a2cb83c | 656 | return VoltageOfCode_Bipolar_OffsetBinary(value_u24); |
whismanoid | 1:d57c1a2cb83c | 657 | } |
whismanoid | 1:d57c1a2cb83c | 658 | return VoltageOfCode_Bipolar_2sComplement(value_u24); |
whismanoid | 0:68e64068330f | 659 | } |
whismanoid | 0:68e64068330f | 660 | |
whismanoid | 0:68e64068330f | 661 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 662 | // Write a MAX11410 register. |
whismanoid | 0:68e64068330f | 663 | // |
whismanoid | 0:68e64068330f | 664 | // CMD_1aaa_aaaa_REGISTER_READ bit is cleared 0 indicating a write operation. |
whismanoid | 0:68e64068330f | 665 | // |
whismanoid | 0:68e64068330f | 666 | // MAX11410 register length can be determined by function RegSize. |
whismanoid | 0:68e64068330f | 667 | // |
whismanoid | 0:68e64068330f | 668 | // For 8-bit register size: |
whismanoid | 0:68e64068330f | 669 | // |
whismanoid | 0:68e64068330f | 670 | // SPI 16-bit transfer |
whismanoid | 0:68e64068330f | 671 | // |
whismanoid | 0:68e64068330f | 672 | // SPI MOSI = 0aaa_aaaa_dddd_dddd |
whismanoid | 0:68e64068330f | 673 | // |
whismanoid | 0:68e64068330f | 674 | // SPI MISO = xxxx_xxxx_xxxx_xxxx |
whismanoid | 0:68e64068330f | 675 | // |
whismanoid | 0:68e64068330f | 676 | // For 16-bit register size: |
whismanoid | 0:68e64068330f | 677 | // |
whismanoid | 0:68e64068330f | 678 | // SPI 24-bit or 32-bit transfer |
whismanoid | 0:68e64068330f | 679 | // |
whismanoid | 0:68e64068330f | 680 | // SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd |
whismanoid | 0:68e64068330f | 681 | // |
whismanoid | 0:68e64068330f | 682 | // SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx |
whismanoid | 0:68e64068330f | 683 | // |
whismanoid | 0:68e64068330f | 684 | // For 24-bit register size: |
whismanoid | 0:68e64068330f | 685 | // |
whismanoid | 0:68e64068330f | 686 | // SPI 32-bit transfer |
whismanoid | 0:68e64068330f | 687 | // |
whismanoid | 0:68e64068330f | 688 | // SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd_dddd_dddd |
whismanoid | 0:68e64068330f | 689 | // |
whismanoid | 0:68e64068330f | 690 | // SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx |
whismanoid | 0:68e64068330f | 691 | // |
whismanoid | 0:68e64068330f | 692 | // @return 1 on success; 0 on failure |
whismanoid | 10:7adee48a7f82 | 693 | uint8_t MAX11410::RegWrite(MAX11410_CMD_enum_t commandByte, uint32_t regData) |
whismanoid | 0:68e64068330f | 694 | { |
whismanoid | 0:68e64068330f | 695 | |
whismanoid | 0:68e64068330f | 696 | //---------------------------------------- |
whismanoid | 10:7adee48a7f82 | 697 | // switch based on register address szie RegSize(commandByte) |
whismanoid | 10:7adee48a7f82 | 698 | commandByte = (MAX11410_CMD_enum_t)((commandByte &~ CMD_1aaa_aaaa_REGISTER_READ) & 0xFF); |
whismanoid | 10:7adee48a7f82 | 699 | switch(RegSize(commandByte)) |
whismanoid | 0:68e64068330f | 700 | { |
whismanoid | 0:68e64068330f | 701 | case 8: // 8-bit register size |
whismanoid | 0:68e64068330f | 702 | { |
whismanoid | 0:68e64068330f | 703 | // SPI 16-bit transfer |
whismanoid | 0:68e64068330f | 704 | // SPI MOSI = 0aaa_aaaa_dddd_dddd |
whismanoid | 0:68e64068330f | 705 | // SPI MISO = xxxx_xxxx_xxxx_xxxx |
whismanoid | 10:7adee48a7f82 | 706 | int16_t mosiData16 = ((int16_t)commandByte << 8) | ((int16_t)regData & 0xFF); |
whismanoid | 0:68e64068330f | 707 | SPIoutputCS(0); |
whismanoid | 0:68e64068330f | 708 | SPIwrite16bits(mosiData16); |
whismanoid | 0:68e64068330f | 709 | SPIoutputCS(1); |
whismanoid | 0:68e64068330f | 710 | } |
whismanoid | 0:68e64068330f | 711 | break; |
whismanoid | 0:68e64068330f | 712 | case 16: // 16-bit register size |
whismanoid | 0:68e64068330f | 713 | #warning "Not Verified Yet: MAX11410::RegWrite 16-bit SPIreadWrite32bits" |
whismanoid | 0:68e64068330f | 714 | { |
whismanoid | 0:68e64068330f | 715 | // SPI 24-bit or 32-bit transfer |
whismanoid | 0:68e64068330f | 716 | // SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd |
whismanoid | 0:68e64068330f | 717 | // SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx |
whismanoid | 0:68e64068330f | 718 | // SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd_0000_0000 |
whismanoid | 0:68e64068330f | 719 | // SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx |
whismanoid | 10:7adee48a7f82 | 720 | int32_t mosiData32 = ((int32_t)commandByte << 24) | (((int32_t)regData & 0xFFFF) << 8); |
whismanoid | 0:68e64068330f | 721 | SPIoutputCS(0); |
whismanoid | 0:68e64068330f | 722 | SPIreadWrite32bits(mosiData32); |
whismanoid | 0:68e64068330f | 723 | SPIoutputCS(1); |
whismanoid | 0:68e64068330f | 724 | } |
whismanoid | 0:68e64068330f | 725 | break; |
whismanoid | 0:68e64068330f | 726 | case 24: // 24-bit register size |
whismanoid | 0:68e64068330f | 727 | { |
whismanoid | 0:68e64068330f | 728 | // SPI 32-bit transfer |
whismanoid | 0:68e64068330f | 729 | // SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd_dddd_dddd |
whismanoid | 0:68e64068330f | 730 | // SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx |
whismanoid | 10:7adee48a7f82 | 731 | int32_t mosiData32 = ((int32_t)commandByte << 24) | ((int32_t)regData & 0x00FFFFFF); |
whismanoid | 0:68e64068330f | 732 | SPIoutputCS(0); |
whismanoid | 0:68e64068330f | 733 | SPIreadWrite32bits(mosiData32); |
whismanoid | 0:68e64068330f | 734 | SPIoutputCS(1); |
whismanoid | 0:68e64068330f | 735 | } |
whismanoid | 0:68e64068330f | 736 | break; |
whismanoid | 0:68e64068330f | 737 | } |
whismanoid | 0:68e64068330f | 738 | |
whismanoid | 0:68e64068330f | 739 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 740 | // success |
whismanoid | 0:68e64068330f | 741 | return 1; |
whismanoid | 0:68e64068330f | 742 | } |
whismanoid | 0:68e64068330f | 743 | |
whismanoid | 0:68e64068330f | 744 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 745 | // Read an 8-bit MAX11410 register |
whismanoid | 0:68e64068330f | 746 | // |
whismanoid | 0:68e64068330f | 747 | // CMD_1aaa_aaaa_REGISTER_READ bit is set 1 indicating a read operation. |
whismanoid | 0:68e64068330f | 748 | // |
whismanoid | 0:68e64068330f | 749 | // MAX11410 register length can be determined by function RegSize. |
whismanoid | 0:68e64068330f | 750 | // |
whismanoid | 0:68e64068330f | 751 | // For 8-bit register size: |
whismanoid | 0:68e64068330f | 752 | // |
whismanoid | 0:68e64068330f | 753 | // SPI 16-bit transfer |
whismanoid | 0:68e64068330f | 754 | // |
whismanoid | 0:68e64068330f | 755 | // SPI MOSI = 1aaa_aaaa_0000_0000 |
whismanoid | 0:68e64068330f | 756 | // |
whismanoid | 0:68e64068330f | 757 | // SPI MISO = xxxx_xxxx_dddd_dddd |
whismanoid | 0:68e64068330f | 758 | // |
whismanoid | 0:68e64068330f | 759 | // For 16-bit register size: |
whismanoid | 0:68e64068330f | 760 | // |
whismanoid | 0:68e64068330f | 761 | // SPI 24-bit or 32-bit transfer |
whismanoid | 0:68e64068330f | 762 | // |
whismanoid | 0:68e64068330f | 763 | // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000 |
whismanoid | 0:68e64068330f | 764 | // |
whismanoid | 0:68e64068330f | 765 | // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd |
whismanoid | 0:68e64068330f | 766 | // |
whismanoid | 0:68e64068330f | 767 | // For 24-bit register size: |
whismanoid | 0:68e64068330f | 768 | // |
whismanoid | 0:68e64068330f | 769 | // SPI 32-bit transfer |
whismanoid | 0:68e64068330f | 770 | // |
whismanoid | 0:68e64068330f | 771 | // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000 |
whismanoid | 0:68e64068330f | 772 | // |
whismanoid | 0:68e64068330f | 773 | // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_dddd_dddd |
whismanoid | 0:68e64068330f | 774 | // |
whismanoid | 0:68e64068330f | 775 | // |
whismanoid | 0:68e64068330f | 776 | // @return 1 on success; 0 on failure |
whismanoid | 10:7adee48a7f82 | 777 | uint8_t MAX11410::RegRead(MAX11410_CMD_enum_t commandByte, uint32_t* ptrRegData) |
whismanoid | 0:68e64068330f | 778 | { |
whismanoid | 0:68e64068330f | 779 | |
whismanoid | 0:68e64068330f | 780 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 781 | // switch based on register address szie RegSize(regAddress) |
whismanoid | 10:7adee48a7f82 | 782 | commandByte = (MAX11410_CMD_enum_t)((commandByte &~ CMD_1aaa_aaaa_REGISTER_READ) & 0xFF); |
whismanoid | 10:7adee48a7f82 | 783 | switch(RegSize(commandByte)) |
whismanoid | 0:68e64068330f | 784 | { |
whismanoid | 0:68e64068330f | 785 | case 8: // 8-bit register size |
whismanoid | 0:68e64068330f | 786 | { |
whismanoid | 0:68e64068330f | 787 | // SPI 16-bit transfer |
whismanoid | 0:68e64068330f | 788 | // SPI MOSI = 1aaa_aaaa_0000_0000 |
whismanoid | 0:68e64068330f | 789 | // SPI MISO = xxxx_xxxx_dddd_dddd |
whismanoid | 10:7adee48a7f82 | 790 | int16_t mosiData16 = ((CMD_1aaa_aaaa_REGISTER_READ | (int16_t)commandByte) << 8) | ((int16_t)0); |
whismanoid | 0:68e64068330f | 791 | SPIoutputCS(0); |
whismanoid | 0:68e64068330f | 792 | int16_t misoData16 = SPIreadWrite16bits(mosiData16); |
whismanoid | 0:68e64068330f | 793 | SPIoutputCS(1); |
whismanoid | 0:68e64068330f | 794 | (*ptrRegData) = (misoData16 & 0x00FF); |
whismanoid | 0:68e64068330f | 795 | } |
whismanoid | 0:68e64068330f | 796 | break; |
whismanoid | 0:68e64068330f | 797 | case 16: // 16-bit register size |
whismanoid | 0:68e64068330f | 798 | #warning "Not Verified Yet: MAX11410::RegRead 16-bit SPIreadWrite32bits" |
whismanoid | 0:68e64068330f | 799 | { |
whismanoid | 0:68e64068330f | 800 | // SPI 24-bit or 32-bit transfer |
whismanoid | 0:68e64068330f | 801 | // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000 |
whismanoid | 0:68e64068330f | 802 | // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd |
whismanoid | 0:68e64068330f | 803 | // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000 |
whismanoid | 0:68e64068330f | 804 | // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_xxxx_xxxx |
whismanoid | 10:7adee48a7f82 | 805 | int32_t mosiData32 = ((CMD_1aaa_aaaa_REGISTER_READ | (int32_t)commandByte) << 24); |
whismanoid | 0:68e64068330f | 806 | SPIoutputCS(0); |
whismanoid | 0:68e64068330f | 807 | int32_t misoData32 = SPIreadWrite32bits(mosiData32); |
whismanoid | 0:68e64068330f | 808 | SPIoutputCS(1); |
whismanoid | 0:68e64068330f | 809 | (*ptrRegData) = ((misoData32 >> 8) & 0x00FFFF); |
whismanoid | 0:68e64068330f | 810 | } |
whismanoid | 0:68e64068330f | 811 | break; |
whismanoid | 0:68e64068330f | 812 | case 24: // 24-bit register size |
whismanoid | 0:68e64068330f | 813 | { |
whismanoid | 0:68e64068330f | 814 | // SPI 32-bit transfer |
whismanoid | 0:68e64068330f | 815 | // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000 |
whismanoid | 0:68e64068330f | 816 | // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_dddd_dddd |
whismanoid | 10:7adee48a7f82 | 817 | int32_t mosiData32 = ((CMD_1aaa_aaaa_REGISTER_READ | (int32_t)commandByte) << 24); |
whismanoid | 0:68e64068330f | 818 | SPIoutputCS(0); |
whismanoid | 0:68e64068330f | 819 | int32_t misoData32 = SPIreadWrite32bits(mosiData32); |
whismanoid | 0:68e64068330f | 820 | SPIoutputCS(1); |
whismanoid | 0:68e64068330f | 821 | (*ptrRegData) = (misoData32 & 0x00FFFFFF); |
whismanoid | 0:68e64068330f | 822 | } |
whismanoid | 0:68e64068330f | 823 | break; |
whismanoid | 0:68e64068330f | 824 | } |
whismanoid | 0:68e64068330f | 825 | |
whismanoid | 0:68e64068330f | 826 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 827 | // success |
whismanoid | 0:68e64068330f | 828 | return 1; |
whismanoid | 0:68e64068330f | 829 | } |
whismanoid | 0:68e64068330f | 830 | |
whismanoid | 0:68e64068330f | 831 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 832 | // Return the size of a MAX11410 register |
whismanoid | 0:68e64068330f | 833 | // |
whismanoid | 0:68e64068330f | 834 | // @return 8 for 8-bit, 16 for 16-bit, 24 for 24-bit, else 0 for undefined register size |
whismanoid | 10:7adee48a7f82 | 835 | uint8_t MAX11410::RegSize(MAX11410_CMD_enum_t commandByte) |
whismanoid | 0:68e64068330f | 836 | { |
whismanoid | 0:68e64068330f | 837 | |
whismanoid | 0:68e64068330f | 838 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 839 | // switch based on register address value regAddress |
whismanoid | 10:7adee48a7f82 | 840 | commandByte = (MAX11410_CMD_enum_t)((commandByte &~ CMD_1aaa_aaaa_REGISTER_READ) & 0xFF); |
whismanoid | 10:7adee48a7f82 | 841 | switch(commandByte) |
whismanoid | 0:68e64068330f | 842 | { |
whismanoid | 0:68e64068330f | 843 | default: |
whismanoid | 0:68e64068330f | 844 | return 0; // undefined register size |
whismanoid | 0:68e64068330f | 845 | case CMD_r000_0000_xxxx_xxdd_PD: |
whismanoid | 0:68e64068330f | 846 | case CMD_r000_0001_xddd_xxdd_CONV_START: |
whismanoid | 0:68e64068330f | 847 | case CMD_r000_0010_xddd_dddd_SEQ_START: |
whismanoid | 0:68e64068330f | 848 | case CMD_r000_0011_xxxx_xddd_CAL_START: |
whismanoid | 0:68e64068330f | 849 | case CMD_r000_0100_dddd_xddd_GP0_CTRL: |
whismanoid | 0:68e64068330f | 850 | case CMD_r000_0101_dddd_xddd_GP1_CTRL: |
whismanoid | 0:68e64068330f | 851 | case CMD_r000_0110_xddd_xxdd_GP_CONV: |
whismanoid | 0:68e64068330f | 852 | case CMD_r000_0111_xddd_dddd_GP_SEQ_ADDR: |
whismanoid | 0:68e64068330f | 853 | case CMD_r000_1000_x0dd_dddd_FILTER: |
whismanoid | 0:68e64068330f | 854 | case CMD_r000_1001_dddd_dddd_CTRL: |
whismanoid | 0:68e64068330f | 855 | case CMD_r000_1010_dddd_dddd_SOURCE: |
whismanoid | 0:68e64068330f | 856 | case CMD_r000_1011_dddd_dddd_MUX_CTRL0: |
whismanoid | 0:68e64068330f | 857 | case CMD_r000_1100_dddd_dddd_MUX_CTRL1: |
whismanoid | 0:68e64068330f | 858 | case CMD_r000_1101_dddd_dddd_MUX_CTRL2: |
whismanoid | 0:68e64068330f | 859 | case CMD_r000_1110_xxdd_xddd_PGA: |
whismanoid | 0:68e64068330f | 860 | case CMD_r000_1111_dddd_dddd_WAIT_EXT: |
whismanoid | 0:68e64068330f | 861 | case CMD_r001_0000_xxxx_xxxx_WAIT_START: |
whismanoid | 0:68e64068330f | 862 | return 8; // 8-bit register size |
whismanoid | 0:68e64068330f | 863 | case CMD_r001_0001_xxxx_xxxx_xxxx_xxxx_xxxx_xddd_PART_ID: |
whismanoid | 0:68e64068330f | 864 | case CMD_r001_0010_xxxx_xxxx_dddd_xxdd_dddd_dddd_SYSC_SEL: |
whismanoid | 0:68e64068330f | 865 | case CMD_r001_0011_dddd_dddd_dddd_dddd_dddd_dddd_SYS_OFF_A: |
whismanoid | 0:68e64068330f | 866 | case CMD_r001_0100_dddd_dddd_dddd_dddd_dddd_dddd_SYS_OFF_B: |
whismanoid | 0:68e64068330f | 867 | case CMD_r001_0101_dddd_dddd_dddd_dddd_dddd_dddd_SYS_GAIN_A: |
whismanoid | 0:68e64068330f | 868 | case CMD_r001_0110_dddd_dddd_dddd_dddd_dddd_dddd_SYS_GAIN_B: |
whismanoid | 0:68e64068330f | 869 | case CMD_r001_0111_dddd_dddd_dddd_dddd_dddd_dddd_SELF_OFF: |
whismanoid | 0:68e64068330f | 870 | case CMD_r001_1000_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_1: |
whismanoid | 0:68e64068330f | 871 | case CMD_r001_1001_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_2: |
whismanoid | 0:68e64068330f | 872 | case CMD_r001_1010_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_4: |
whismanoid | 0:68e64068330f | 873 | case CMD_r001_1011_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_8: |
whismanoid | 0:68e64068330f | 874 | case CMD_r001_1100_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_16: |
whismanoid | 0:68e64068330f | 875 | case CMD_r001_1101_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_32: |
whismanoid | 0:68e64068330f | 876 | case CMD_r001_1110_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_64: |
whismanoid | 0:68e64068330f | 877 | case CMD_r001_1111_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_128: |
whismanoid | 0:68e64068330f | 878 | case CMD_r010_0000_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH0: |
whismanoid | 0:68e64068330f | 879 | case CMD_r010_0001_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH1: |
whismanoid | 0:68e64068330f | 880 | case CMD_r010_0010_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH2: |
whismanoid | 0:68e64068330f | 881 | case CMD_r010_0011_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH3: |
whismanoid | 0:68e64068330f | 882 | case CMD_r010_0100_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH4: |
whismanoid | 0:68e64068330f | 883 | case CMD_r010_0101_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH5: |
whismanoid | 0:68e64068330f | 884 | case CMD_r010_0110_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH6: |
whismanoid | 0:68e64068330f | 885 | case CMD_r010_0111_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH7: |
whismanoid | 0:68e64068330f | 886 | case CMD_r010_1000_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH0: |
whismanoid | 0:68e64068330f | 887 | case CMD_r010_1001_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH1: |
whismanoid | 0:68e64068330f | 888 | case CMD_r010_1010_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH2: |
whismanoid | 0:68e64068330f | 889 | case CMD_r010_1011_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH3: |
whismanoid | 0:68e64068330f | 890 | case CMD_r010_1100_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH4: |
whismanoid | 0:68e64068330f | 891 | case CMD_r010_1101_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH5: |
whismanoid | 0:68e64068330f | 892 | case CMD_r010_1110_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH6: |
whismanoid | 0:68e64068330f | 893 | case CMD_r010_1111_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH7: |
whismanoid | 0:68e64068330f | 894 | case CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0: |
whismanoid | 0:68e64068330f | 895 | case CMD_r011_0001_dddd_dddd_dddd_dddd_dddd_dddd_DATA1: |
whismanoid | 0:68e64068330f | 896 | case CMD_r011_0010_dddd_dddd_dddd_dddd_dddd_dddd_DATA2: |
whismanoid | 0:68e64068330f | 897 | case CMD_r011_0011_dddd_dddd_dddd_dddd_dddd_dddd_DATA3: |
whismanoid | 0:68e64068330f | 898 | case CMD_r011_0100_dddd_dddd_dddd_dddd_dddd_dddd_DATA4: |
whismanoid | 0:68e64068330f | 899 | case CMD_r011_0101_dddd_dddd_dddd_dddd_dddd_dddd_DATA5: |
whismanoid | 0:68e64068330f | 900 | case CMD_r011_0110_dddd_dddd_dddd_dddd_dddd_dddd_DATA6: |
whismanoid | 0:68e64068330f | 901 | case CMD_r011_0111_dddd_dddd_dddd_dddd_dddd_dddd_DATA7: |
whismanoid | 0:68e64068330f | 902 | case CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS: |
whismanoid | 0:68e64068330f | 903 | case CMD_r011_1001_dddd_dddd_dddd_dddd_dxxd_dddd_STATUS_IE: |
whismanoid | 0:68e64068330f | 904 | return 24; // 24-bit register size |
whismanoid | 0:68e64068330f | 905 | case CMD_r011_1010_xaaa_aaaa_dddd_dddd_UC_0: |
whismanoid | 0:68e64068330f | 906 | case CMD_r011_1011_xaaa_aaaa_dddd_dddd_UC_1: |
whismanoid | 0:68e64068330f | 907 | case CMD_r011_1100_xaaa_aaaa_dddd_dddd_UC_2: |
whismanoid | 0:68e64068330f | 908 | case CMD_r011_1101_xaaa_aaaa_dddd_dddd_UC_3: |
whismanoid | 0:68e64068330f | 909 | case CMD_r011_1110_xaaa_aaaa_dddd_dddd_UC_4: |
whismanoid | 0:68e64068330f | 910 | case CMD_r011_1111_xaaa_aaaa_dddd_dddd_UC_5: |
whismanoid | 0:68e64068330f | 911 | case CMD_r100_0000_xaaa_aaaa_dddd_dddd_UC_6: |
whismanoid | 0:68e64068330f | 912 | case CMD_r100_0001_xaaa_aaaa_dddd_dddd_UC_7: |
whismanoid | 0:68e64068330f | 913 | case CMD_r100_0010_xaaa_aaaa_dddd_dddd_UC_8: |
whismanoid | 0:68e64068330f | 914 | case CMD_r100_0011_xaaa_aaaa_dddd_dddd_UC_9: |
whismanoid | 0:68e64068330f | 915 | case CMD_r100_0100_xaaa_aaaa_dddd_dddd_UC_10: |
whismanoid | 0:68e64068330f | 916 | case CMD_r100_0101_xaaa_aaaa_dddd_dddd_UC_11: |
whismanoid | 0:68e64068330f | 917 | case CMD_r100_0110_xaaa_aaaa_dddd_dddd_UC_12: |
whismanoid | 0:68e64068330f | 918 | case CMD_r100_0111_xaaa_aaaa_dddd_dddd_UC_13: |
whismanoid | 0:68e64068330f | 919 | case CMD_r100_1000_xaaa_aaaa_dddd_dddd_UC_14: |
whismanoid | 0:68e64068330f | 920 | case CMD_r100_1001_xaaa_aaaa_dddd_dddd_UC_15: |
whismanoid | 0:68e64068330f | 921 | case CMD_r100_1010_xaaa_aaaa_dddd_dddd_UC_16: |
whismanoid | 0:68e64068330f | 922 | case CMD_r100_1011_xaaa_aaaa_dddd_dddd_UC_17: |
whismanoid | 0:68e64068330f | 923 | case CMD_r100_1100_xaaa_aaaa_dddd_dddd_UC_18: |
whismanoid | 0:68e64068330f | 924 | case CMD_r100_1101_xaaa_aaaa_dddd_dddd_UC_19: |
whismanoid | 0:68e64068330f | 925 | case CMD_r100_1110_xaaa_aaaa_dddd_dddd_UC_20: |
whismanoid | 0:68e64068330f | 926 | case CMD_r100_1111_xaaa_aaaa_dddd_dddd_UC_21: |
whismanoid | 0:68e64068330f | 927 | case CMD_r101_0000_xaaa_aaaa_dddd_dddd_UC_22: |
whismanoid | 0:68e64068330f | 928 | case CMD_r101_0001_xaaa_aaaa_dddd_dddd_UC_23: |
whismanoid | 0:68e64068330f | 929 | case CMD_r101_0010_xaaa_aaaa_dddd_dddd_UC_24: |
whismanoid | 0:68e64068330f | 930 | case CMD_r101_0011_xaaa_aaaa_dddd_dddd_UC_25: |
whismanoid | 0:68e64068330f | 931 | case CMD_r101_0100_xaaa_aaaa_dddd_dddd_UC_26: |
whismanoid | 0:68e64068330f | 932 | case CMD_r101_0101_xaaa_aaaa_dddd_dddd_UC_27: |
whismanoid | 0:68e64068330f | 933 | case CMD_r101_0110_xaaa_aaaa_dddd_dddd_UC_28: |
whismanoid | 0:68e64068330f | 934 | case CMD_r101_0111_xaaa_aaaa_dddd_dddd_UC_29: |
whismanoid | 0:68e64068330f | 935 | case CMD_r101_1000_xaaa_aaaa_dddd_dddd_UC_30: |
whismanoid | 0:68e64068330f | 936 | case CMD_r101_1001_xaaa_aaaa_dddd_dddd_UC_31: |
whismanoid | 0:68e64068330f | 937 | case CMD_r101_1010_xaaa_aaaa_dddd_dddd_UC_32: |
whismanoid | 0:68e64068330f | 938 | case CMD_r101_1011_xaaa_aaaa_dddd_dddd_UC_33: |
whismanoid | 0:68e64068330f | 939 | case CMD_r101_1100_xaaa_aaaa_dddd_dddd_UC_34: |
whismanoid | 0:68e64068330f | 940 | case CMD_r101_1101_xaaa_aaaa_dddd_dddd_UC_35: |
whismanoid | 0:68e64068330f | 941 | case CMD_r101_1110_xaaa_aaaa_dddd_dddd_UC_36: |
whismanoid | 0:68e64068330f | 942 | case CMD_r101_1111_xaaa_aaaa_dddd_dddd_UC_37: |
whismanoid | 0:68e64068330f | 943 | case CMD_r110_0000_xaaa_aaaa_dddd_dddd_UC_38: |
whismanoid | 0:68e64068330f | 944 | case CMD_r110_0001_xaaa_aaaa_dddd_dddd_UC_39: |
whismanoid | 0:68e64068330f | 945 | case CMD_r110_0010_xaaa_aaaa_dddd_dddd_UC_40: |
whismanoid | 0:68e64068330f | 946 | case CMD_r110_0011_xaaa_aaaa_dddd_dddd_UC_41: |
whismanoid | 0:68e64068330f | 947 | case CMD_r110_0100_xaaa_aaaa_dddd_dddd_UC_42: |
whismanoid | 0:68e64068330f | 948 | case CMD_r110_0101_xaaa_aaaa_dddd_dddd_UC_43: |
whismanoid | 0:68e64068330f | 949 | case CMD_r110_0110_xaaa_aaaa_dddd_dddd_UC_44: |
whismanoid | 0:68e64068330f | 950 | case CMD_r110_0111_xaaa_aaaa_dddd_dddd_UC_45: |
whismanoid | 0:68e64068330f | 951 | case CMD_r110_1000_xaaa_aaaa_dddd_dddd_UC_46: |
whismanoid | 0:68e64068330f | 952 | case CMD_r110_1001_xaaa_aaaa_dddd_dddd_UC_47: |
whismanoid | 0:68e64068330f | 953 | case CMD_r110_1010_xaaa_aaaa_dddd_dddd_UC_48: |
whismanoid | 0:68e64068330f | 954 | case CMD_r110_1011_xaaa_aaaa_dddd_dddd_UC_49: |
whismanoid | 0:68e64068330f | 955 | case CMD_r110_1100_xaaa_aaaa_dddd_dddd_UC_50: |
whismanoid | 0:68e64068330f | 956 | case CMD_r110_1101_xaaa_aaaa_dddd_dddd_UC_51: |
whismanoid | 0:68e64068330f | 957 | case CMD_r110_1110_xaaa_aaaa_dddd_dddd_UC_52: |
whismanoid | 0:68e64068330f | 958 | case CMD_r110_1111_xxxx_xxxx_xaaa_aaaa_UCADDR: |
whismanoid | 0:68e64068330f | 959 | return 16; // 16-bit register size |
whismanoid | 0:68e64068330f | 960 | } |
whismanoid | 0:68e64068330f | 961 | } |
whismanoid | 0:68e64068330f | 962 | |
whismanoid | 0:68e64068330f | 963 | //---------------------------------------- |
whismanoid | 10:7adee48a7f82 | 964 | // Return the address field of a MAX11410 register |
whismanoid | 10:7adee48a7f82 | 965 | // |
whismanoid | 10:7adee48a7f82 | 966 | // @return register address field as given in datasheet |
whismanoid | 10:7adee48a7f82 | 967 | uint8_t MAX11410::RegAddrOfCommand(MAX11410_CMD_enum_t commandByte) |
whismanoid | 10:7adee48a7f82 | 968 | { |
whismanoid | 10:7adee48a7f82 | 969 | |
whismanoid | 10:7adee48a7f82 | 970 | //---------------------------------------- |
whismanoid | 10:7adee48a7f82 | 971 | // extract register address value from command byte |
whismanoid | 10:7adee48a7f82 | 972 | return (uint8_t)((commandByte &~ CMD_1aaa_aaaa_REGISTER_READ) & 0xFF); |
whismanoid | 10:7adee48a7f82 | 973 | } |
whismanoid | 10:7adee48a7f82 | 974 | |
whismanoid | 10:7adee48a7f82 | 975 | //---------------------------------------- |
whismanoid | 10:7adee48a7f82 | 976 | // Test whether a command byte is a register read command |
whismanoid | 10:7adee48a7f82 | 977 | // |
whismanoid | 10:7adee48a7f82 | 978 | // @return true if command byte is a register read command |
whismanoid | 10:7adee48a7f82 | 979 | uint8_t MAX11410::IsRegReadCommand(MAX11410_CMD_enum_t commandByte) |
whismanoid | 10:7adee48a7f82 | 980 | { |
whismanoid | 10:7adee48a7f82 | 981 | |
whismanoid | 10:7adee48a7f82 | 982 | //---------------------------------------- |
whismanoid | 10:7adee48a7f82 | 983 | // Test whether a command byte is a register read command |
whismanoid | 10:7adee48a7f82 | 984 | return (commandByte & CMD_1aaa_aaaa_REGISTER_READ) ? 1 : 0; |
whismanoid | 10:7adee48a7f82 | 985 | } |
whismanoid | 10:7adee48a7f82 | 986 | |
whismanoid | 10:7adee48a7f82 | 987 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 988 | // Return the name of a MAX11410 register |
whismanoid | 0:68e64068330f | 989 | // |
whismanoid | 0:68e64068330f | 990 | // @return null-terminated constant C string containing register name or empty string |
whismanoid | 10:7adee48a7f82 | 991 | const char* MAX11410::RegName(MAX11410_CMD_enum_t commandByte) |
whismanoid | 0:68e64068330f | 992 | { |
whismanoid | 0:68e64068330f | 993 | |
whismanoid | 0:68e64068330f | 994 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 995 | // switch based on register address value regAddress |
whismanoid | 10:7adee48a7f82 | 996 | commandByte = (MAX11410_CMD_enum_t)((commandByte &~ CMD_1aaa_aaaa_REGISTER_READ) & 0xFF); |
whismanoid | 10:7adee48a7f82 | 997 | switch(commandByte) |
whismanoid | 0:68e64068330f | 998 | { |
whismanoid | 0:68e64068330f | 999 | default: |
whismanoid | 0:68e64068330f | 1000 | return ""; // undefined register |
whismanoid | 0:68e64068330f | 1001 | case CMD_r000_0000_xxxx_xxdd_PD: return "PD"; |
whismanoid | 0:68e64068330f | 1002 | case CMD_r000_0001_xddd_xxdd_CONV_START: return "CONV_START"; |
whismanoid | 0:68e64068330f | 1003 | case CMD_r000_0010_xddd_dddd_SEQ_START: return "SEQ_START"; |
whismanoid | 0:68e64068330f | 1004 | case CMD_r000_0011_xxxx_xddd_CAL_START: return "CAL_START"; |
whismanoid | 0:68e64068330f | 1005 | case CMD_r000_0100_dddd_xddd_GP0_CTRL: return "GP0_CTRL"; |
whismanoid | 0:68e64068330f | 1006 | case CMD_r000_0101_dddd_xddd_GP1_CTRL: return "GP1_CTRL"; |
whismanoid | 0:68e64068330f | 1007 | case CMD_r000_0110_xddd_xxdd_GP_CONV: return "GP_CONV"; |
whismanoid | 0:68e64068330f | 1008 | case CMD_r000_0111_xddd_dddd_GP_SEQ_ADDR: return "GP_SEQ_ADDR"; |
whismanoid | 0:68e64068330f | 1009 | case CMD_r000_1000_x0dd_dddd_FILTER: return "FILTER"; |
whismanoid | 0:68e64068330f | 1010 | case CMD_r000_1001_dddd_dddd_CTRL: return "CTRL"; |
whismanoid | 0:68e64068330f | 1011 | case CMD_r000_1010_dddd_dddd_SOURCE: return "SOURCE"; |
whismanoid | 0:68e64068330f | 1012 | case CMD_r000_1011_dddd_dddd_MUX_CTRL0: return "MUX_CTRL0"; |
whismanoid | 0:68e64068330f | 1013 | case CMD_r000_1100_dddd_dddd_MUX_CTRL1: return "MUX_CTRL1"; |
whismanoid | 0:68e64068330f | 1014 | case CMD_r000_1101_dddd_dddd_MUX_CTRL2: return "MUX_CTRL2"; |
whismanoid | 0:68e64068330f | 1015 | case CMD_r000_1110_xxdd_xddd_PGA: return "PGA"; |
whismanoid | 0:68e64068330f | 1016 | case CMD_r000_1111_dddd_dddd_WAIT_EXT: return "WAIT_EXT"; |
whismanoid | 0:68e64068330f | 1017 | case CMD_r001_0000_xxxx_xxxx_WAIT_START: return "WAIT_START"; |
whismanoid | 0:68e64068330f | 1018 | case CMD_r001_0001_xxxx_xxxx_xxxx_xxxx_xxxx_xddd_PART_ID: return "PART_ID"; |
whismanoid | 0:68e64068330f | 1019 | case CMD_r001_0010_xxxx_xxxx_dddd_xxdd_dddd_dddd_SYSC_SEL: return "SYSC_SEL"; |
whismanoid | 0:68e64068330f | 1020 | case CMD_r001_0011_dddd_dddd_dddd_dddd_dddd_dddd_SYS_OFF_A: return "SYS_OFF_A"; |
whismanoid | 0:68e64068330f | 1021 | case CMD_r001_0100_dddd_dddd_dddd_dddd_dddd_dddd_SYS_OFF_B: return "SYS_OFF_B"; |
whismanoid | 0:68e64068330f | 1022 | case CMD_r001_0101_dddd_dddd_dddd_dddd_dddd_dddd_SYS_GAIN_A: return "SYS_GAIN_A"; |
whismanoid | 0:68e64068330f | 1023 | case CMD_r001_0110_dddd_dddd_dddd_dddd_dddd_dddd_SYS_GAIN_B: return "SYS_GAIN_B"; |
whismanoid | 0:68e64068330f | 1024 | case CMD_r001_0111_dddd_dddd_dddd_dddd_dddd_dddd_SELF_OFF: return "SELF_OFF"; |
whismanoid | 0:68e64068330f | 1025 | case CMD_r001_1000_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_1: return "SELF_GAIN_1"; |
whismanoid | 0:68e64068330f | 1026 | case CMD_r001_1001_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_2: return "SELF_GAIN_2"; |
whismanoid | 0:68e64068330f | 1027 | case CMD_r001_1010_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_4: return "SELF_GAIN_4"; |
whismanoid | 0:68e64068330f | 1028 | case CMD_r001_1011_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_8: return "SELF_GAIN_8"; |
whismanoid | 0:68e64068330f | 1029 | case CMD_r001_1100_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_16: return "SELF_GAIN_16"; |
whismanoid | 0:68e64068330f | 1030 | case CMD_r001_1101_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_32: return "SELF_GAIN_32"; |
whismanoid | 0:68e64068330f | 1031 | case CMD_r001_1110_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_64: return "SELF_GAIN_64"; |
whismanoid | 0:68e64068330f | 1032 | case CMD_r001_1111_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_128: return "SELF_GAIN_128"; |
whismanoid | 0:68e64068330f | 1033 | case CMD_r010_0000_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH0: return "LTHRESH0"; |
whismanoid | 0:68e64068330f | 1034 | case CMD_r010_0001_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH1: return "LTHRESH1"; |
whismanoid | 0:68e64068330f | 1035 | case CMD_r010_0010_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH2: return "LTHRESH2"; |
whismanoid | 0:68e64068330f | 1036 | case CMD_r010_0011_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH3: return "LTHRESH3"; |
whismanoid | 0:68e64068330f | 1037 | case CMD_r010_0100_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH4: return "LTHRESH4"; |
whismanoid | 0:68e64068330f | 1038 | case CMD_r010_0101_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH5: return "LTHRESH5"; |
whismanoid | 0:68e64068330f | 1039 | case CMD_r010_0110_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH6: return "LTHRESH6"; |
whismanoid | 0:68e64068330f | 1040 | case CMD_r010_0111_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH7: return "LTHRESH7"; |
whismanoid | 0:68e64068330f | 1041 | case CMD_r010_1000_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH0: return "UTHRESH0"; |
whismanoid | 0:68e64068330f | 1042 | case CMD_r010_1001_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH1: return "UTHRESH1"; |
whismanoid | 0:68e64068330f | 1043 | case CMD_r010_1010_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH2: return "UTHRESH2"; |
whismanoid | 0:68e64068330f | 1044 | case CMD_r010_1011_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH3: return "UTHRESH3"; |
whismanoid | 0:68e64068330f | 1045 | case CMD_r010_1100_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH4: return "UTHRESH4"; |
whismanoid | 0:68e64068330f | 1046 | case CMD_r010_1101_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH5: return "UTHRESH5"; |
whismanoid | 0:68e64068330f | 1047 | case CMD_r010_1110_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH6: return "UTHRESH6"; |
whismanoid | 0:68e64068330f | 1048 | case CMD_r010_1111_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH7: return "UTHRESH7"; |
whismanoid | 0:68e64068330f | 1049 | case CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0: return "DATA0"; |
whismanoid | 0:68e64068330f | 1050 | case CMD_r011_0001_dddd_dddd_dddd_dddd_dddd_dddd_DATA1: return "DATA1"; |
whismanoid | 0:68e64068330f | 1051 | case CMD_r011_0010_dddd_dddd_dddd_dddd_dddd_dddd_DATA2: return "DATA2"; |
whismanoid | 0:68e64068330f | 1052 | case CMD_r011_0011_dddd_dddd_dddd_dddd_dddd_dddd_DATA3: return "DATA3"; |
whismanoid | 0:68e64068330f | 1053 | case CMD_r011_0100_dddd_dddd_dddd_dddd_dddd_dddd_DATA4: return "DATA4"; |
whismanoid | 0:68e64068330f | 1054 | case CMD_r011_0101_dddd_dddd_dddd_dddd_dddd_dddd_DATA5: return "DATA5"; |
whismanoid | 0:68e64068330f | 1055 | case CMD_r011_0110_dddd_dddd_dddd_dddd_dddd_dddd_DATA6: return "DATA6"; |
whismanoid | 0:68e64068330f | 1056 | case CMD_r011_0111_dddd_dddd_dddd_dddd_dddd_dddd_DATA7: return "DATA7"; |
whismanoid | 0:68e64068330f | 1057 | case CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS: return "STATUS"; |
whismanoid | 0:68e64068330f | 1058 | case CMD_r011_1001_dddd_dddd_dddd_dddd_dxxd_dddd_STATUS_IE: return "STATUS_IE"; |
whismanoid | 0:68e64068330f | 1059 | case CMD_r011_1010_xaaa_aaaa_dddd_dddd_UC_0: return "UC_0"; |
whismanoid | 0:68e64068330f | 1060 | case CMD_r011_1011_xaaa_aaaa_dddd_dddd_UC_1: return "UC_1"; |
whismanoid | 0:68e64068330f | 1061 | case CMD_r011_1100_xaaa_aaaa_dddd_dddd_UC_2: return "UC_2"; |
whismanoid | 0:68e64068330f | 1062 | case CMD_r011_1101_xaaa_aaaa_dddd_dddd_UC_3: return "UC_3"; |
whismanoid | 0:68e64068330f | 1063 | case CMD_r011_1110_xaaa_aaaa_dddd_dddd_UC_4: return "UC_4"; |
whismanoid | 0:68e64068330f | 1064 | case CMD_r011_1111_xaaa_aaaa_dddd_dddd_UC_5: return "UC_5"; |
whismanoid | 0:68e64068330f | 1065 | case CMD_r100_0000_xaaa_aaaa_dddd_dddd_UC_6: return "UC_6"; |
whismanoid | 0:68e64068330f | 1066 | case CMD_r100_0001_xaaa_aaaa_dddd_dddd_UC_7: return "UC_7"; |
whismanoid | 0:68e64068330f | 1067 | case CMD_r100_0010_xaaa_aaaa_dddd_dddd_UC_8: return "UC_8"; |
whismanoid | 0:68e64068330f | 1068 | case CMD_r100_0011_xaaa_aaaa_dddd_dddd_UC_9: return "UC_9"; |
whismanoid | 0:68e64068330f | 1069 | case CMD_r100_0100_xaaa_aaaa_dddd_dddd_UC_10: return "UC_10"; |
whismanoid | 0:68e64068330f | 1070 | case CMD_r100_0101_xaaa_aaaa_dddd_dddd_UC_11: return "UC_11"; |
whismanoid | 0:68e64068330f | 1071 | case CMD_r100_0110_xaaa_aaaa_dddd_dddd_UC_12: return "UC_12"; |
whismanoid | 0:68e64068330f | 1072 | case CMD_r100_0111_xaaa_aaaa_dddd_dddd_UC_13: return "UC_13"; |
whismanoid | 0:68e64068330f | 1073 | case CMD_r100_1000_xaaa_aaaa_dddd_dddd_UC_14: return "UC_14"; |
whismanoid | 0:68e64068330f | 1074 | case CMD_r100_1001_xaaa_aaaa_dddd_dddd_UC_15: return "UC_15"; |
whismanoid | 0:68e64068330f | 1075 | case CMD_r100_1010_xaaa_aaaa_dddd_dddd_UC_16: return "UC_16"; |
whismanoid | 0:68e64068330f | 1076 | case CMD_r100_1011_xaaa_aaaa_dddd_dddd_UC_17: return "UC_17"; |
whismanoid | 0:68e64068330f | 1077 | case CMD_r100_1100_xaaa_aaaa_dddd_dddd_UC_18: return "UC_18"; |
whismanoid | 0:68e64068330f | 1078 | case CMD_r100_1101_xaaa_aaaa_dddd_dddd_UC_19: return "UC_19"; |
whismanoid | 0:68e64068330f | 1079 | case CMD_r100_1110_xaaa_aaaa_dddd_dddd_UC_20: return "UC_20"; |
whismanoid | 0:68e64068330f | 1080 | case CMD_r100_1111_xaaa_aaaa_dddd_dddd_UC_21: return "UC_21"; |
whismanoid | 0:68e64068330f | 1081 | case CMD_r101_0000_xaaa_aaaa_dddd_dddd_UC_22: return "UC_22"; |
whismanoid | 0:68e64068330f | 1082 | case CMD_r101_0001_xaaa_aaaa_dddd_dddd_UC_23: return "UC_23"; |
whismanoid | 0:68e64068330f | 1083 | case CMD_r101_0010_xaaa_aaaa_dddd_dddd_UC_24: return "UC_24"; |
whismanoid | 0:68e64068330f | 1084 | case CMD_r101_0011_xaaa_aaaa_dddd_dddd_UC_25: return "UC_25"; |
whismanoid | 0:68e64068330f | 1085 | case CMD_r101_0100_xaaa_aaaa_dddd_dddd_UC_26: return "UC_26"; |
whismanoid | 0:68e64068330f | 1086 | case CMD_r101_0101_xaaa_aaaa_dddd_dddd_UC_27: return "UC_27"; |
whismanoid | 0:68e64068330f | 1087 | case CMD_r101_0110_xaaa_aaaa_dddd_dddd_UC_28: return "UC_28"; |
whismanoid | 0:68e64068330f | 1088 | case CMD_r101_0111_xaaa_aaaa_dddd_dddd_UC_29: return "UC_29"; |
whismanoid | 0:68e64068330f | 1089 | case CMD_r101_1000_xaaa_aaaa_dddd_dddd_UC_30: return "UC_30"; |
whismanoid | 0:68e64068330f | 1090 | case CMD_r101_1001_xaaa_aaaa_dddd_dddd_UC_31: return "UC_31"; |
whismanoid | 0:68e64068330f | 1091 | case CMD_r101_1010_xaaa_aaaa_dddd_dddd_UC_32: return "UC_32"; |
whismanoid | 0:68e64068330f | 1092 | case CMD_r101_1011_xaaa_aaaa_dddd_dddd_UC_33: return "UC_33"; |
whismanoid | 0:68e64068330f | 1093 | case CMD_r101_1100_xaaa_aaaa_dddd_dddd_UC_34: return "UC_34"; |
whismanoid | 0:68e64068330f | 1094 | case CMD_r101_1101_xaaa_aaaa_dddd_dddd_UC_35: return "UC_35"; |
whismanoid | 0:68e64068330f | 1095 | case CMD_r101_1110_xaaa_aaaa_dddd_dddd_UC_36: return "UC_36"; |
whismanoid | 0:68e64068330f | 1096 | case CMD_r101_1111_xaaa_aaaa_dddd_dddd_UC_37: return "UC_37"; |
whismanoid | 0:68e64068330f | 1097 | case CMD_r110_0000_xaaa_aaaa_dddd_dddd_UC_38: return "UC_38"; |
whismanoid | 0:68e64068330f | 1098 | case CMD_r110_0001_xaaa_aaaa_dddd_dddd_UC_39: return "UC_39"; |
whismanoid | 0:68e64068330f | 1099 | case CMD_r110_0010_xaaa_aaaa_dddd_dddd_UC_40: return "UC_40"; |
whismanoid | 0:68e64068330f | 1100 | case CMD_r110_0011_xaaa_aaaa_dddd_dddd_UC_41: return "UC_41"; |
whismanoid | 0:68e64068330f | 1101 | case CMD_r110_0100_xaaa_aaaa_dddd_dddd_UC_42: return "UC_42"; |
whismanoid | 0:68e64068330f | 1102 | case CMD_r110_0101_xaaa_aaaa_dddd_dddd_UC_43: return "UC_43"; |
whismanoid | 0:68e64068330f | 1103 | case CMD_r110_0110_xaaa_aaaa_dddd_dddd_UC_44: return "UC_44"; |
whismanoid | 0:68e64068330f | 1104 | case CMD_r110_0111_xaaa_aaaa_dddd_dddd_UC_45: return "UC_45"; |
whismanoid | 0:68e64068330f | 1105 | case CMD_r110_1000_xaaa_aaaa_dddd_dddd_UC_46: return "UC_46"; |
whismanoid | 0:68e64068330f | 1106 | case CMD_r110_1001_xaaa_aaaa_dddd_dddd_UC_47: return "UC_47"; |
whismanoid | 0:68e64068330f | 1107 | case CMD_r110_1010_xaaa_aaaa_dddd_dddd_UC_48: return "UC_48"; |
whismanoid | 0:68e64068330f | 1108 | case CMD_r110_1011_xaaa_aaaa_dddd_dddd_UC_49: return "UC_49"; |
whismanoid | 0:68e64068330f | 1109 | case CMD_r110_1100_xaaa_aaaa_dddd_dddd_UC_50: return "UC_50"; |
whismanoid | 0:68e64068330f | 1110 | case CMD_r110_1101_xaaa_aaaa_dddd_dddd_UC_51: return "UC_51"; |
whismanoid | 0:68e64068330f | 1111 | case CMD_r110_1110_xaaa_aaaa_dddd_dddd_UC_52: return "UC_52"; |
whismanoid | 0:68e64068330f | 1112 | case CMD_r110_1111_xxxx_xxxx_xaaa_aaaa_UCADDR: return "UCADDR"; |
whismanoid | 0:68e64068330f | 1113 | } |
whismanoid | 0:68e64068330f | 1114 | } |
whismanoid | 0:68e64068330f | 1115 | |
whismanoid | 0:68e64068330f | 1116 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1117 | // Menu item 'XF' |
whismanoid | 1:d57c1a2cb83c | 1118 | // |
whismanoid | 1:d57c1a2cb83c | 1119 | // FILTER Select Filter and Rate. |
whismanoid | 1:d57c1a2cb83c | 1120 | // Sets conversion rate based on RATE, LINEF, and CONV_TYPE value. See Table 9a through Table 9d for details. |
whismanoid | 1:d57c1a2cb83c | 1121 | // For CONV_TYPE_01_Continuous, linef=LINEF_11_SINC4, rate=RATE_0100 selects output data rate 60SPS. |
whismanoid | 1:d57c1a2cb83c | 1122 | // |
whismanoid | 1:d57c1a2cb83c | 1123 | // @param[in] linef = filter type, default=MAX11410::LINEF_enum_t::LINEF_11_SINC4 |
whismanoid | 1:d57c1a2cb83c | 1124 | // @param[in] rate = output data rate selection, default=MAX11410::RATE_enum_t::RATE_0100 |
whismanoid | 1:d57c1a2cb83c | 1125 | // |
whismanoid | 1:d57c1a2cb83c | 1126 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1127 | uint8_t MAX11410::Configure_FILTER(uint8_t linef, uint8_t rate) |
whismanoid | 1:d57c1a2cb83c | 1128 | { |
whismanoid | 1:d57c1a2cb83c | 1129 | |
whismanoid | 1:d57c1a2cb83c | 1130 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1131 | // write8 0x08 FILTER |
whismanoid | 1:d57c1a2cb83c | 1132 | RegWrite(CMD_r000_1000_x0dd_dddd_FILTER, (uint8_t)(0 |
whismanoid | 1:d57c1a2cb83c | 1133 | | (((uint8_t)linef & 3) << 4) |
whismanoid | 1:d57c1a2cb83c | 1134 | | (((uint8_t)rate & 15) << 0) |
whismanoid | 1:d57c1a2cb83c | 1135 | )); |
whismanoid | 1:d57c1a2cb83c | 1136 | |
whismanoid | 1:d57c1a2cb83c | 1137 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1138 | // success |
whismanoid | 1:d57c1a2cb83c | 1139 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1140 | } |
whismanoid | 1:d57c1a2cb83c | 1141 | |
whismanoid | 1:d57c1a2cb83c | 1142 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1143 | // Menu item 'XP' |
whismanoid | 1:d57c1a2cb83c | 1144 | // |
whismanoid | 1:d57c1a2cb83c | 1145 | // PGA Select Gain and Signal Path. |
whismanoid | 1:d57c1a2cb83c | 1146 | // |
whismanoid | 1:d57c1a2cb83c | 1147 | // @param[in] sigpath = signal path, default=MAX11410::SIG_PATH_enum_t::SIG_PATH_00_BUFFERED |
whismanoid | 1:d57c1a2cb83c | 1148 | // @param[in] gain = gain selection, default=MAX11410::GAIN_enum_t::GAIN_000_1 |
whismanoid | 1:d57c1a2cb83c | 1149 | // |
whismanoid | 1:d57c1a2cb83c | 1150 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1151 | uint8_t MAX11410::Configure_PGA(uint8_t sigpath, uint8_t gain) |
whismanoid | 1:d57c1a2cb83c | 1152 | { |
whismanoid | 1:d57c1a2cb83c | 1153 | |
whismanoid | 1:d57c1a2cb83c | 1154 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1155 | // pga gain 1, 2, 4, 8, 16, 32, 64, or 128 based on gain index in register pga CMD_r000_1110_xxdd_xddd_PGA |
whismanoid | 1:d57c1a2cb83c | 1156 | static uint8_t pgaGainTable[8] = {1, 2, 4, 8, 16, 32, 64, 128}; |
whismanoid | 1:d57c1a2cb83c | 1157 | pgaGain = (sigpath == SIG_PATH_10_PGA) ? pgaGainTable[(uint8_t)gain] : 1; |
whismanoid | 1:d57c1a2cb83c | 1158 | |
whismanoid | 1:d57c1a2cb83c | 1159 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1160 | // write8 0x0E PGA |
whismanoid | 1:d57c1a2cb83c | 1161 | RegWrite(CMD_r000_1110_xxdd_xddd_PGA, (uint8_t)(0 |
whismanoid | 1:d57c1a2cb83c | 1162 | | (((uint8_t)sigpath & 2) << 4) |
whismanoid | 1:d57c1a2cb83c | 1163 | | (((uint8_t)gain & 7) << 0) |
whismanoid | 1:d57c1a2cb83c | 1164 | )); |
whismanoid | 1:d57c1a2cb83c | 1165 | |
whismanoid | 1:d57c1a2cb83c | 1166 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1167 | // success |
whismanoid | 1:d57c1a2cb83c | 1168 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1169 | } |
whismanoid | 1:d57c1a2cb83c | 1170 | |
whismanoid | 1:d57c1a2cb83c | 1171 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1172 | // Menu item 'XC' |
whismanoid | 1:d57c1a2cb83c | 1173 | // |
whismanoid | 1:d57c1a2cb83c | 1174 | // CTRL Select clock, format, and reference. |
whismanoid | 1:d57c1a2cb83c | 1175 | // |
whismanoid | 1:d57c1a2cb83c | 1176 | // @param[in] extclk = external clock enable, default=0 |
whismanoid | 1:d57c1a2cb83c | 1177 | // @param[in] u_bn = unipolar input range enable, default=0 |
whismanoid | 1:d57c1a2cb83c | 1178 | // @param[in] format = offset binary format enable, default=0 |
whismanoid | 1:d57c1a2cb83c | 1179 | // @param[in] refbufp_en = REFP reference buffer enable, default=0 |
whismanoid | 1:d57c1a2cb83c | 1180 | // @param[in] refbufn_en = REFN reference buffer enable, default=0 |
whismanoid | 1:d57c1a2cb83c | 1181 | // @param[in] ref_sel = reference selection, default=MAX11410::REF_SEL_enum_t::REF_SEL_001_REF1P_REF1N |
whismanoid | 1:d57c1a2cb83c | 1182 | // |
whismanoid | 1:d57c1a2cb83c | 1183 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1184 | uint8_t MAX11410::Configure_CTRL(uint8_t extclk, uint8_t u_bn, uint8_t format, uint8_t refbufp_en, uint8_t refbufn_en, uint8_t ref_sel) |
whismanoid | 1:d57c1a2cb83c | 1185 | { |
whismanoid | 1:d57c1a2cb83c | 1186 | |
whismanoid | 1:d57c1a2cb83c | 1187 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1188 | // shadow of register CMD_r000_1001_dddd_dddd_CTRL |
whismanoid | 1:d57c1a2cb83c | 1189 | ctrl = (uint8_t)(0 |
whismanoid | 1:d57c1a2cb83c | 1190 | | (((uint8_t)extclk & 1) << 7) |
whismanoid | 1:d57c1a2cb83c | 1191 | | (((uint8_t)u_bn & 1) << 6) |
whismanoid | 1:d57c1a2cb83c | 1192 | | (((uint8_t)format & 1) << 5) |
whismanoid | 1:d57c1a2cb83c | 1193 | | (((uint8_t)refbufp_en & 1) << 4) |
whismanoid | 1:d57c1a2cb83c | 1194 | | (((uint8_t)refbufn_en & 1) << 3) |
whismanoid | 1:d57c1a2cb83c | 1195 | | (((uint8_t)ref_sel & 7) << 0) |
whismanoid | 1:d57c1a2cb83c | 1196 | ); |
whismanoid | 1:d57c1a2cb83c | 1197 | |
whismanoid | 1:d57c1a2cb83c | 1198 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1199 | // write8 0x09 CTRL |
whismanoid | 1:d57c1a2cb83c | 1200 | RegWrite(CMD_r000_1001_dddd_dddd_CTRL, ctrl); |
whismanoid | 1:d57c1a2cb83c | 1201 | |
whismanoid | 1:d57c1a2cb83c | 1202 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1203 | // success |
whismanoid | 1:d57c1a2cb83c | 1204 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1205 | } |
whismanoid | 1:d57c1a2cb83c | 1206 | |
whismanoid | 1:d57c1a2cb83c | 1207 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1208 | // Menu item 'XS' |
whismanoid | 1:d57c1a2cb83c | 1209 | // |
whismanoid | 1:d57c1a2cb83c | 1210 | // SOURCE Configure voltage bias source, current source, burnout mode |
whismanoid | 1:d57c1a2cb83c | 1211 | // |
whismanoid | 1:d57c1a2cb83c | 1212 | // @param[in] vbias_mode = _______, default=MAX11410::VBIAS_MODE_enum_t::VBIAS_MODE_00_Active |
whismanoid | 1:d57c1a2cb83c | 1213 | // @param[in] brn_mode = _______, default=MAX11410::BRN_MODE_enum_t::BRN_MODE_00_disabled |
whismanoid | 1:d57c1a2cb83c | 1214 | // @param[in] idac_mode = _______, default=MAX11410::IDAC_MODE_enum_t::IDAC_MODE_0000_10uA |
whismanoid | 1:d57c1a2cb83c | 1215 | // |
whismanoid | 1:d57c1a2cb83c | 1216 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1217 | uint8_t MAX11410::Configure_SOURCE(uint8_t vbias_mode, uint8_t brn_mode, uint8_t idac_mode) |
whismanoid | 1:d57c1a2cb83c | 1218 | { |
whismanoid | 1:d57c1a2cb83c | 1219 | |
whismanoid | 1:d57c1a2cb83c | 1220 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1221 | // warning -- WIP work in progress |
whismanoid | 1:d57c1a2cb83c | 1222 | #warning "Not Tested Yet: MAX11410::Configure_SOURCE..." |
whismanoid | 1:d57c1a2cb83c | 1223 | |
whismanoid | 1:d57c1a2cb83c | 1224 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1225 | // write8 0x0A SOURCE |
whismanoid | 1:d57c1a2cb83c | 1226 | RegWrite(CMD_r000_1010_dddd_dddd_SOURCE, (uint8_t)(0 |
whismanoid | 1:d57c1a2cb83c | 1227 | | (((uint8_t)vbias_mode & 3) << 6) |
whismanoid | 1:d57c1a2cb83c | 1228 | | (((uint8_t)brn_mode & 3) << 4) |
whismanoid | 1:d57c1a2cb83c | 1229 | | (((uint8_t)idac_mode & 15) << 0) |
whismanoid | 1:d57c1a2cb83c | 1230 | )); |
whismanoid | 1:d57c1a2cb83c | 1231 | |
whismanoid | 1:d57c1a2cb83c | 1232 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1233 | // success |
whismanoid | 1:d57c1a2cb83c | 1234 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1235 | } |
whismanoid | 1:d57c1a2cb83c | 1236 | |
whismanoid | 1:d57c1a2cb83c | 1237 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1238 | // Menu item 'XM' |
whismanoid | 1:d57c1a2cb83c | 1239 | // |
whismanoid | 1:d57c1a2cb83c | 1240 | // MUX_CTRL0 Select pins for analog input AINP and AINN |
whismanoid | 1:d57c1a2cb83c | 1241 | // |
whismanoid | 1:d57c1a2cb83c | 1242 | // @param[in] ainp = channel high side, default=MAX11410::AINP_SEL_enum_t::AINP_SEL_0000_AIN0 |
whismanoid | 1:d57c1a2cb83c | 1243 | // @param[in] ainn = channel low side, default=MAX11410::AINN_SEL_enum_t::AINN_SEL_1010_GND |
whismanoid | 1:d57c1a2cb83c | 1244 | // |
whismanoid | 1:d57c1a2cb83c | 1245 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1246 | uint8_t MAX11410::Configure_MUX_CTRL0(uint8_t ainp, uint8_t ainn) |
whismanoid | 1:d57c1a2cb83c | 1247 | { |
whismanoid | 1:d57c1a2cb83c | 1248 | |
whismanoid | 1:d57c1a2cb83c | 1249 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1250 | // warning -- WIP work in progress |
whismanoid | 1:d57c1a2cb83c | 1251 | #warning "Not Tested Yet: MAX11410::Configure_MUX_CTRL0..." |
whismanoid | 1:d57c1a2cb83c | 1252 | |
whismanoid | 1:d57c1a2cb83c | 1253 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1254 | // write8 0x0B MUX_CTRL0 |
whismanoid | 1:d57c1a2cb83c | 1255 | RegWrite(CMD_r000_1011_dddd_dddd_MUX_CTRL0, (uint8_t)(0 |
whismanoid | 1:d57c1a2cb83c | 1256 | | (((uint8_t)ainp & 15) << 4) |
whismanoid | 1:d57c1a2cb83c | 1257 | | (((uint8_t)ainn & 15) << 0) |
whismanoid | 1:d57c1a2cb83c | 1258 | )); |
whismanoid | 1:d57c1a2cb83c | 1259 | |
whismanoid | 1:d57c1a2cb83c | 1260 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1261 | // success |
whismanoid | 1:d57c1a2cb83c | 1262 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1263 | } |
whismanoid | 1:d57c1a2cb83c | 1264 | |
whismanoid | 1:d57c1a2cb83c | 1265 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1266 | // Menu item 'XI' |
whismanoid | 1:d57c1a2cb83c | 1267 | // |
whismanoid | 1:d57c1a2cb83c | 1268 | // MUX_CTRL1 Select pins for current source |
whismanoid | 1:d57c1a2cb83c | 1269 | // |
whismanoid | 1:d57c1a2cb83c | 1270 | // @param[in] idac1_sel = channel high side, default=MAX11410::IDAC1_SEL_enum_t::IDAC1_SEL_1111_unconnected |
whismanoid | 1:d57c1a2cb83c | 1271 | // @param[in] idac0_sel = channel low side, default=MAX11410::IDAC0_SEL_enum_t::IDAC0_SEL_1111_unconnected |
whismanoid | 1:d57c1a2cb83c | 1272 | // |
whismanoid | 1:d57c1a2cb83c | 1273 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1274 | uint8_t MAX11410::Configure_MUX_CTRL1(uint8_t idac1_sel, uint8_t idac0_sel) |
whismanoid | 1:d57c1a2cb83c | 1275 | { |
whismanoid | 1:d57c1a2cb83c | 1276 | |
whismanoid | 1:d57c1a2cb83c | 1277 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1278 | // warning -- WIP work in progress |
whismanoid | 1:d57c1a2cb83c | 1279 | #warning "Not Tested Yet: MAX11410::Configure_MUX_CTRL1..." |
whismanoid | 1:d57c1a2cb83c | 1280 | |
whismanoid | 1:d57c1a2cb83c | 1281 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1282 | // write8 0x0C MUX_CTRL1 |
whismanoid | 1:d57c1a2cb83c | 1283 | RegWrite(CMD_r000_1100_dddd_dddd_MUX_CTRL1, (uint8_t)(0 |
whismanoid | 1:d57c1a2cb83c | 1284 | | (((uint8_t)idac1_sel & 15) << 4) |
whismanoid | 1:d57c1a2cb83c | 1285 | | (((uint8_t)idac0_sel & 15) << 0) |
whismanoid | 1:d57c1a2cb83c | 1286 | )); |
whismanoid | 1:d57c1a2cb83c | 1287 | |
whismanoid | 1:d57c1a2cb83c | 1288 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1289 | // success |
whismanoid | 1:d57c1a2cb83c | 1290 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1291 | } |
whismanoid | 1:d57c1a2cb83c | 1292 | |
whismanoid | 1:d57c1a2cb83c | 1293 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1294 | // Menu item 'XV' |
whismanoid | 1:d57c1a2cb83c | 1295 | // |
whismanoid | 1:d57c1a2cb83c | 1296 | // MUX_CTRL2 Select pins for voltage bias source |
whismanoid | 1:d57c1a2cb83c | 1297 | // |
whismanoid | 1:d57c1a2cb83c | 1298 | // @param[in] vbias_ain7_ain0_bitmap = bit map of AIN7..AIN0 enables for voltage bias, default=0 |
whismanoid | 1:d57c1a2cb83c | 1299 | // |
whismanoid | 1:d57c1a2cb83c | 1300 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1301 | uint8_t MAX11410::Configure_MUX_CTRL2(uint8_t vbias_ain7_ain0_bitmap) |
whismanoid | 1:d57c1a2cb83c | 1302 | { |
whismanoid | 1:d57c1a2cb83c | 1303 | |
whismanoid | 1:d57c1a2cb83c | 1304 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1305 | // warning -- WIP work in progress |
whismanoid | 1:d57c1a2cb83c | 1306 | #warning "Not Tested Yet: MAX11410::Configure_MUX_CTRL2..." |
whismanoid | 1:d57c1a2cb83c | 1307 | |
whismanoid | 1:d57c1a2cb83c | 1308 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1309 | // write8 0x0D MUX_CTRL2 |
whismanoid | 1:d57c1a2cb83c | 1310 | RegWrite(CMD_r000_1101_dddd_dddd_MUX_CTRL2, vbias_ain7_ain0_bitmap); |
whismanoid | 1:d57c1a2cb83c | 1311 | |
whismanoid | 1:d57c1a2cb83c | 1312 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1313 | // success |
whismanoid | 1:d57c1a2cb83c | 1314 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1315 | } |
whismanoid | 1:d57c1a2cb83c | 1316 | |
whismanoid | 1:d57c1a2cb83c | 1317 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1318 | // Menu item 'X0' |
whismanoid | 1:d57c1a2cb83c | 1319 | // |
whismanoid | 1:d57c1a2cb83c | 1320 | // CAL_START Calibrate Self Offset and Gain. |
whismanoid | 1:d57c1a2cb83c | 1321 | // |
whismanoid | 1:d57c1a2cb83c | 1322 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1323 | uint8_t MAX11410::Calibrate_Self_Offset_Gain(void) |
whismanoid | 1:d57c1a2cb83c | 1324 | { |
whismanoid | 1:d57c1a2cb83c | 1325 | |
whismanoid | 1:d57c1a2cb83c | 1326 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1327 | // warning -- WIP work in progress |
whismanoid | 1:d57c1a2cb83c | 1328 | #warning "Not Tested Yet: MAX11410::Calibrate_Self_Offset_Gain..." |
whismanoid | 1:d57c1a2cb83c | 1329 | |
whismanoid | 1:d57c1a2cb83c | 1330 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1331 | // write8 0x03 CAL_START |
whismanoid | 1:d57c1a2cb83c | 1332 | RegWrite(CMD_r000_0011_xxxx_xddd_CAL_START, (uint8_t)CAL_TYPE_000_SELF_CAL); |
whismanoid | 1:d57c1a2cb83c | 1333 | |
whismanoid | 1:d57c1a2cb83c | 1334 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1335 | // success |
whismanoid | 1:d57c1a2cb83c | 1336 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1337 | } |
whismanoid | 1:d57c1a2cb83c | 1338 | |
whismanoid | 1:d57c1a2cb83c | 1339 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1340 | // Menu item 'X1' |
whismanoid | 1:d57c1a2cb83c | 1341 | // |
whismanoid | 1:d57c1a2cb83c | 1342 | // CAL_START Calibrate Selected PGA. |
whismanoid | 1:d57c1a2cb83c | 1343 | // |
whismanoid | 1:d57c1a2cb83c | 1344 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1345 | uint8_t MAX11410::Calibrate_PGA_Gain(void) |
whismanoid | 1:d57c1a2cb83c | 1346 | { |
whismanoid | 1:d57c1a2cb83c | 1347 | |
whismanoid | 1:d57c1a2cb83c | 1348 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1349 | // warning -- WIP work in progress |
whismanoid | 1:d57c1a2cb83c | 1350 | #warning "Not Tested Yet: MAX11410::Calibrate_PGA_Gain..." |
whismanoid | 1:d57c1a2cb83c | 1351 | |
whismanoid | 1:d57c1a2cb83c | 1352 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1353 | // write8 0x03 CAL_START |
whismanoid | 1:d57c1a2cb83c | 1354 | RegWrite(CMD_r000_0011_xxxx_xddd_CAL_START, (uint8_t)CAL_TYPE_001_PGA_GAIN); |
whismanoid | 1:d57c1a2cb83c | 1355 | |
whismanoid | 1:d57c1a2cb83c | 1356 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1357 | // success |
whismanoid | 1:d57c1a2cb83c | 1358 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1359 | } |
whismanoid | 1:d57c1a2cb83c | 1360 | |
whismanoid | 1:d57c1a2cb83c | 1361 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1362 | // Menu item 'X4' |
whismanoid | 1:d57c1a2cb83c | 1363 | // |
whismanoid | 1:d57c1a2cb83c | 1364 | // CAL_START Calibrate System Offset A. |
whismanoid | 1:d57c1a2cb83c | 1365 | // |
whismanoid | 1:d57c1a2cb83c | 1366 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1367 | uint8_t MAX11410::Calibrate_System_Offset_A(void) |
whismanoid | 1:d57c1a2cb83c | 1368 | { |
whismanoid | 1:d57c1a2cb83c | 1369 | |
whismanoid | 1:d57c1a2cb83c | 1370 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1371 | // warning -- WIP work in progress |
whismanoid | 1:d57c1a2cb83c | 1372 | #warning "Not Tested Yet: MAX11410::Calibrate_System_Offset_A..." |
whismanoid | 1:d57c1a2cb83c | 1373 | |
whismanoid | 1:d57c1a2cb83c | 1374 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1375 | // write8 0x03 CAL_START |
whismanoid | 1:d57c1a2cb83c | 1376 | RegWrite(CMD_r000_0011_xxxx_xddd_CAL_START, (uint8_t)CAL_TYPE_100_SYS_OFF_A); |
whismanoid | 1:d57c1a2cb83c | 1377 | |
whismanoid | 1:d57c1a2cb83c | 1378 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1379 | // success |
whismanoid | 1:d57c1a2cb83c | 1380 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1381 | } |
whismanoid | 1:d57c1a2cb83c | 1382 | |
whismanoid | 1:d57c1a2cb83c | 1383 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1384 | // Menu item 'X5' |
whismanoid | 1:d57c1a2cb83c | 1385 | // |
whismanoid | 1:d57c1a2cb83c | 1386 | // X6 0x03 CAL_START 0x06 Calibrate System Offset B |
whismanoid | 1:d57c1a2cb83c | 1387 | // X7 0x03 CAL_START 0x07 Calibrate System Gain B |
whismanoid | 1:d57c1a2cb83c | 1388 | // CAL_START Calibrate System Gain A. |
whismanoid | 1:d57c1a2cb83c | 1389 | // |
whismanoid | 1:d57c1a2cb83c | 1390 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1391 | uint8_t MAX11410::Calibrate_System_Gain_A(void) |
whismanoid | 1:d57c1a2cb83c | 1392 | { |
whismanoid | 1:d57c1a2cb83c | 1393 | |
whismanoid | 1:d57c1a2cb83c | 1394 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1395 | // warning -- WIP work in progress |
whismanoid | 1:d57c1a2cb83c | 1396 | #warning "Not Tested Yet: MAX11410::Calibrate_System_Gain_A..." |
whismanoid | 1:d57c1a2cb83c | 1397 | |
whismanoid | 1:d57c1a2cb83c | 1398 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1399 | // write8 0x03 CAL_START |
whismanoid | 1:d57c1a2cb83c | 1400 | RegWrite(CMD_r000_0011_xxxx_xddd_CAL_START, (uint8_t)CAL_TYPE_101_SYS_GAIN_A); |
whismanoid | 1:d57c1a2cb83c | 1401 | |
whismanoid | 1:d57c1a2cb83c | 1402 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1403 | // success |
whismanoid | 1:d57c1a2cb83c | 1404 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1405 | } |
whismanoid | 1:d57c1a2cb83c | 1406 | |
whismanoid | 1:d57c1a2cb83c | 1407 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1408 | // Menu item 'X6' |
whismanoid | 1:d57c1a2cb83c | 1409 | // |
whismanoid | 1:d57c1a2cb83c | 1410 | // CAL_START Calibrate System Offset B. |
whismanoid | 1:d57c1a2cb83c | 1411 | // |
whismanoid | 1:d57c1a2cb83c | 1412 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1413 | uint8_t MAX11410::Calibrate_System_Offset_B(void) |
whismanoid | 1:d57c1a2cb83c | 1414 | { |
whismanoid | 1:d57c1a2cb83c | 1415 | |
whismanoid | 1:d57c1a2cb83c | 1416 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1417 | // warning -- WIP work in progress |
whismanoid | 1:d57c1a2cb83c | 1418 | #warning "Not Tested Yet: MAX11410::Calibrate_System_Offset_B..." |
whismanoid | 1:d57c1a2cb83c | 1419 | |
whismanoid | 1:d57c1a2cb83c | 1420 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1421 | // write8 0x03 CAL_START |
whismanoid | 1:d57c1a2cb83c | 1422 | RegWrite(CMD_r000_0011_xxxx_xddd_CAL_START, (uint8_t)CAL_TYPE_110_SYS_OFF_B); |
whismanoid | 1:d57c1a2cb83c | 1423 | |
whismanoid | 1:d57c1a2cb83c | 1424 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1425 | // success |
whismanoid | 1:d57c1a2cb83c | 1426 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1427 | } |
whismanoid | 1:d57c1a2cb83c | 1428 | |
whismanoid | 1:d57c1a2cb83c | 1429 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1430 | // Menu item 'X7' |
whismanoid | 1:d57c1a2cb83c | 1431 | // |
whismanoid | 1:d57c1a2cb83c | 1432 | // CAL_START Calibrate System Gain B. |
whismanoid | 1:d57c1a2cb83c | 1433 | // |
whismanoid | 1:d57c1a2cb83c | 1434 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1435 | uint8_t MAX11410::Calibrate_System_Gain_B(void) |
whismanoid | 1:d57c1a2cb83c | 1436 | { |
whismanoid | 1:d57c1a2cb83c | 1437 | |
whismanoid | 1:d57c1a2cb83c | 1438 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1439 | // warning -- WIP work in progress |
whismanoid | 1:d57c1a2cb83c | 1440 | #warning "Not Tested Yet: MAX11410::Calibrate_System_Gain_B..." |
whismanoid | 1:d57c1a2cb83c | 1441 | |
whismanoid | 1:d57c1a2cb83c | 1442 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1443 | // write8 0x03 CAL_START |
whismanoid | 1:d57c1a2cb83c | 1444 | RegWrite(CMD_r000_0011_xxxx_xddd_CAL_START, (uint8_t)CAL_TYPE_111_SYS_GAIN_B); |
whismanoid | 1:d57c1a2cb83c | 1445 | |
whismanoid | 1:d57c1a2cb83c | 1446 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1447 | // success |
whismanoid | 1:d57c1a2cb83c | 1448 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1449 | } |
whismanoid | 1:d57c1a2cb83c | 1450 | |
whismanoid | 1:d57c1a2cb83c | 1451 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1452 | // Configure Measurement for voltage input. |
whismanoid | 0:68e64068330f | 1453 | // |
whismanoid | 0:68e64068330f | 1454 | // Example code for typical voltage measurement. |
whismanoid | 0:68e64068330f | 1455 | // |
whismanoid | 0:68e64068330f | 1456 | // SPI register write sequence test AIN0-AGND voltage input using REF2=2.5V |
whismanoid | 0:68e64068330f | 1457 | // write8 0x00 PD = 0x03 (Reset Registers; enter Standby mode) |
whismanoid | 0:68e64068330f | 1458 | // write8 0x00 PD = 0x00 (NOP) |
whismanoid | 0:68e64068330f | 1459 | // write8 0x08 FILTER = 0x34 to select RATE_0100, LINEF_11_SINC4 60SPS (given CONV_TYPE_01_Continuous ) |
whismanoid | 0:68e64068330f | 1460 | // write8 0x0B MUX_CTRL0 = 0x0A to select AINP=AIN0 and AINN=GND |
whismanoid | 0:68e64068330f | 1461 | // write8 0x09 CTRL = 0x02 to select reference REF2P/REF2N; or CTRL = 0x1A to select reference REF2P/REF2N with reference input buffers enabled; Data Format = Bipolar 2's Complement |
whismanoid | 0:68e64068330f | 1462 | // write8 0x0E PGA = 0x00 to select input path = Buffers, digital gain = 1V/V |
whismanoid | 0:68e64068330f | 1463 | // write8 0x01 CONV_START = 0x01 to set Conversion Mode = Continuous |
whismanoid | 0:68e64068330f | 1464 | // read24 0x80|0x38 STATUS (%SW 0xB8 0 0 0) |
whismanoid | 0:68e64068330f | 1465 | // read24 0x80|0x30 DATA0 (%SW 0xB0 0 0 0) |
whismanoid | 0:68e64068330f | 1466 | // |
whismanoid | 1:d57c1a2cb83c | 1467 | // @param[in] ainp = channel high side, default=AINP_SEL_enum_t::AINP_SEL_0000_AIN0 |
whismanoid | 1:d57c1a2cb83c | 1468 | // @param[in] ainn = channel low side, default=AINN_SEL_enum_t::AINN_SEL_1010_GND |
whismanoid | 0:68e64068330f | 1469 | // |
whismanoid | 0:68e64068330f | 1470 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1471 | uint8_t MAX11410::Configure_Voltage(MAX11410_AINP_SEL_enum_t ainp, MAX11410_AINN_SEL_enum_t ainn) |
whismanoid | 0:68e64068330f | 1472 | { |
whismanoid | 0:68e64068330f | 1473 | |
whismanoid | 0:68e64068330f | 1474 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1475 | // warning -- WIP work in progress |
whismanoid | 0:68e64068330f | 1476 | #warning "Not Tested Yet: MAX11410::Configure_Voltage..." |
whismanoid | 0:68e64068330f | 1477 | |
whismanoid | 0:68e64068330f | 1478 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1479 | // write8 0x00 PD = 0x03 (Reset Registers; enter Standby mode) |
whismanoid | 0:68e64068330f | 1480 | RegWrite(CMD_r000_0000_xxxx_xxdd_PD, PD_11_Reset); |
whismanoid | 0:68e64068330f | 1481 | |
whismanoid | 0:68e64068330f | 1482 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1483 | // write8 0x00 PD = 0x00 (NOP) |
whismanoid | 0:68e64068330f | 1484 | RegWrite(CMD_r000_0000_xxxx_xxdd_PD, PD_00_Normal); |
whismanoid | 0:68e64068330f | 1485 | |
whismanoid | 0:68e64068330f | 1486 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1487 | // write8 0x08 FILTER = 0x34 to select RATE_0100, LINEF_11_SINC4 60SPS (given CONV_TYPE_01_Continuous) |
whismanoid | 2:eac67184cc0c | 1488 | Configure_FILTER((uint8_t) /* MAX11410::MAX11410_LINEF_enum_t:: */ LINEF_11_SINC4, |
whismanoid | 2:eac67184cc0c | 1489 | (uint8_t) /* MAX11410::MAX11410_RATE_enum_t:: */ RATE_0100); |
whismanoid | 0:68e64068330f | 1490 | |
whismanoid | 0:68e64068330f | 1491 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1492 | // write8 0x0B MUX_CTRL0 = 0x0A to select AINP=AIN0 and AINN=GND |
whismanoid | 1:d57c1a2cb83c | 1493 | Configure_MUX_CTRL0((uint8_t)AINP_SEL_0000_AIN0, (uint8_t)AINN_SEL_1010_GND); |
whismanoid | 0:68e64068330f | 1494 | |
whismanoid | 0:68e64068330f | 1495 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1496 | // write8 0x09 CTRL to select reference REF2P/REF2N; Data Format = Bipolar 2's Complement |
whismanoid | 1:d57c1a2cb83c | 1497 | Configure_CTRL(/*extclk*/ 0, /*u_bn*/ 0, /*format*/ 0, |
whismanoid | 1:d57c1a2cb83c | 1498 | /*refbufp_en*/ 0, /*refbufn_en*/ 0, |
whismanoid | 1:d57c1a2cb83c | 1499 | /*ref_sel*/ (uint8_t)REF_SEL_010_REF2P_REF2N); |
whismanoid | 0:68e64068330f | 1500 | |
whismanoid | 0:68e64068330f | 1501 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1502 | // write8 0x0E PGA |
whismanoid | 2:eac67184cc0c | 1503 | Configure_PGA((uint8_t) /* MAX11410_SIG_PATH_enum_t:: */ SIG_PATH_00_BUFFERED, |
whismanoid | 2:eac67184cc0c | 1504 | (uint8_t) /* MAX11410_GAIN_enum_t:: */ GAIN_000_1); |
whismanoid | 0:68e64068330f | 1505 | |
whismanoid | 0:68e64068330f | 1506 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1507 | // write8 0x01 CONV_START = 0x01 to set Conversion Mode = Continuous |
whismanoid | 0:68e64068330f | 1508 | RegWrite(CMD_r000_0001_xddd_xxdd_CONV_START, 0x01); |
whismanoid | 0:68e64068330f | 1509 | |
whismanoid | 0:68e64068330f | 1510 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1511 | // read24 0x80|0x38 STATUS (%SW 0xB8 0 0 0) |
whismanoid | 0:68e64068330f | 1512 | RegRead(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); |
whismanoid | 0:68e64068330f | 1513 | |
whismanoid | 0:68e64068330f | 1514 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1515 | // read24 0x80|0x30 DATA0 (%SW 0xB0 0 0 0) |
whismanoid | 0:68e64068330f | 1516 | RegRead(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &data0); |
whismanoid | 0:68e64068330f | 1517 | |
whismanoid | 0:68e64068330f | 1518 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1519 | // success |
whismanoid | 0:68e64068330f | 1520 | return 1; |
whismanoid | 0:68e64068330f | 1521 | } |
whismanoid | 0:68e64068330f | 1522 | |
whismanoid | 0:68e64068330f | 1523 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1524 | // Menu item '$' |
whismanoid | 1:d57c1a2cb83c | 1525 | // Measure all ADC channels in sequence. |
whismanoid | 8:3a9dfa2e8234 | 1526 | // @post AINcode[0..10]: measurement result LSB code |
whismanoid | 0:68e64068330f | 1527 | // |
whismanoid | 0:68e64068330f | 1528 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1529 | uint8_t MAX11410::Read_All_Voltages(void) |
whismanoid | 0:68e64068330f | 1530 | { |
whismanoid | 0:68e64068330f | 1531 | |
whismanoid | 0:68e64068330f | 1532 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1533 | // scan AIN0..AIN9 |
whismanoid | 1:d57c1a2cb83c | 1534 | const MAX11410_AINN_SEL_enum_t ainn = AINN_SEL_1010_GND; |
whismanoid | 2:eac67184cc0c | 1535 | for(uint8_t ainp = /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_0000_AIN0; ainp <= /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD; ainp++) |
whismanoid | 1:d57c1a2cb83c | 1536 | { |
whismanoid | 1:d57c1a2cb83c | 1537 | Measure_Voltage((MAX11410_AINP_SEL_enum_t)ainp, ainn); |
whismanoid | 1:d57c1a2cb83c | 1538 | } |
whismanoid | 0:68e64068330f | 1539 | |
whismanoid | 0:68e64068330f | 1540 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1541 | // success |
whismanoid | 0:68e64068330f | 1542 | return 1; |
whismanoid | 0:68e64068330f | 1543 | } |
whismanoid | 0:68e64068330f | 1544 | |
whismanoid | 0:68e64068330f | 1545 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1546 | // Menu item 'V' |
whismanoid | 0:68e64068330f | 1547 | // Trigger Measurement for voltage input. |
whismanoid | 0:68e64068330f | 1548 | // |
whismanoid | 0:68e64068330f | 1549 | // Example code for typical voltage measurement. |
whismanoid | 0:68e64068330f | 1550 | // |
whismanoid | 1:d57c1a2cb83c | 1551 | // @pre external connection REF2P-REF2N is a reference voltage |
whismanoid | 1:d57c1a2cb83c | 1552 | // @pre VRef = Voltage of REF input, in Volts |
whismanoid | 1:d57c1a2cb83c | 1553 | // @param[in] ainp = channel high side, default=AINP_SEL_0000_AIN0 |
whismanoid | 1:d57c1a2cb83c | 1554 | // @param[in] ainn = channel low side, default=AINN_SEL_1010_GND |
whismanoid | 1:d57c1a2cb83c | 1555 | // @post AINcode[ainp]: measurement result LSB code |
whismanoid | 0:68e64068330f | 1556 | // |
whismanoid | 1:d57c1a2cb83c | 1557 | // @return ideal voltage calculated from raw LSB code and reference voltage |
whismanoid | 1:d57c1a2cb83c | 1558 | double MAX11410::Measure_Voltage(MAX11410_AINP_SEL_enum_t ainp, MAX11410_AINN_SEL_enum_t ainn) |
whismanoid | 0:68e64068330f | 1559 | { |
whismanoid | 0:68e64068330f | 1560 | |
whismanoid | 0:68e64068330f | 1561 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 1562 | // restrict channel selection to valid index range |
whismanoid | 8:3a9dfa2e8234 | 1563 | if ((uint8_t)ainp > /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD) |
whismanoid | 8:3a9dfa2e8234 | 1564 | { |
whismanoid | 8:3a9dfa2e8234 | 1565 | ainp = /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD; |
whismanoid | 8:3a9dfa2e8234 | 1566 | } |
whismanoid | 8:3a9dfa2e8234 | 1567 | |
whismanoid | 8:3a9dfa2e8234 | 1568 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 1569 | // restrict channel selection to valid index range |
whismanoid | 8:3a9dfa2e8234 | 1570 | if ((uint8_t)ainn > /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND) |
whismanoid | 8:3a9dfa2e8234 | 1571 | { |
whismanoid | 8:3a9dfa2e8234 | 1572 | ainn = /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND; |
whismanoid | 8:3a9dfa2e8234 | 1573 | } |
whismanoid | 8:3a9dfa2e8234 | 1574 | |
whismanoid | 8:3a9dfa2e8234 | 1575 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1576 | // write8 0x0B MUX_CTRL0 = 0x0A to select AINP=AIN0 and AINN=GND |
whismanoid | 1:d57c1a2cb83c | 1577 | Configure_MUX_CTRL0((uint8_t)ainp, (uint8_t)ainn); |
whismanoid | 1:d57c1a2cb83c | 1578 | |
whismanoid | 1:d57c1a2cb83c | 1579 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1580 | // write8 0x09 CTRL to select reference REF2P/REF2N; Data Format = Bipolar 2's Complement |
whismanoid | 1:d57c1a2cb83c | 1581 | Configure_CTRL(/*extclk*/ 0, /*u_bn*/ 0, /*format*/ 0, |
whismanoid | 1:d57c1a2cb83c | 1582 | /*refbufp_en*/ 0, /*refbufn_en*/ 0, |
whismanoid | 1:d57c1a2cb83c | 1583 | /*ref_sel*/ (uint8_t)REF_SEL_010_REF2P_REF2N); |
whismanoid | 1:d57c1a2cb83c | 1584 | |
whismanoid | 1:d57c1a2cb83c | 1585 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1586 | // write8 0x0E PGA |
whismanoid | 2:eac67184cc0c | 1587 | Configure_PGA((uint8_t) /* MAX11410_SIG_PATH_enum_t:: */ SIG_PATH_00_BUFFERED, |
whismanoid | 2:eac67184cc0c | 1588 | (uint8_t) /* MAX11410_GAIN_enum_t:: */ GAIN_000_1); |
whismanoid | 1:d57c1a2cb83c | 1589 | |
whismanoid | 1:d57c1a2cb83c | 1590 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1591 | // write8 0x08 FILTER = 0x34 to select RATE_0100, LINEF_11_SINC4 60SPS (given CONV_TYPE_01_Continuous) |
whismanoid | 2:eac67184cc0c | 1592 | Configure_FILTER((uint8_t) /* MAX11410::MAX11410_LINEF_enum_t:: */ LINEF_11_SINC4, |
whismanoid | 2:eac67184cc0c | 1593 | (uint8_t) /* MAX11410::MAX11410_RATE_enum_t:: */ RATE_0100); |
whismanoid | 1:d57c1a2cb83c | 1594 | |
whismanoid | 1:d57c1a2cb83c | 1595 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1596 | // write8 0x01 CONV_START = 0x01 to set Conversion Mode = Continuous |
whismanoid | 1:d57c1a2cb83c | 1597 | RegWrite(CMD_r000_0001_xddd_xxdd_CONV_START, 0x01); |
whismanoid | 0:68e64068330f | 1598 | |
whismanoid | 0:68e64068330f | 1599 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1600 | // read24 0x80|0x38 STATUS (%SW 0xB8 0 0 0) |
whismanoid | 0:68e64068330f | 1601 | RegRead(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); |
whismanoid | 0:68e64068330f | 1602 | |
whismanoid | 0:68e64068330f | 1603 | //---------------------------------------- |
whismanoid | 9:06ca88952f1c | 1604 | // TODO1: wait until STATUS_enum_t::STATUS_000010_DATA_RDY indicates data is available |
whismanoid | 9:06ca88952f1c | 1605 | #warning "Not Verified Yet: wait until STATUS indicates data is available" |
whismanoid | 9:06ca88952f1c | 1606 | // // TODO1: possible infinite loop; need a timeout or futility countdown to escape |
whismanoid | 9:06ca88952f1c | 1607 | // // TODO1: bad SPI interface can cause bit slippage, which makes this loop get stuck. Expect *PART_ID? = 0x000F02 |
whismanoid | 9:06ca88952f1c | 1608 | while ((status & /* MAX11410_STATUS_enum_t:: */ STATUS_000010_DATA_RDY) == 0) { |
whismanoid | 9:06ca88952f1c | 1609 | RegRead(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); |
whismanoid | 9:06ca88952f1c | 1610 | } |
whismanoid | 9:06ca88952f1c | 1611 | |
whismanoid | 9:06ca88952f1c | 1612 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1613 | // read24 0x80|0x30 DATA0 (%SW 0xB0 0 0 0): AINcode[ainp] = measurement |
whismanoid | 1:d57c1a2cb83c | 1614 | RegRead(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &AINcode[((int)ainp & 0x0F)]); |
whismanoid | 1:d57c1a2cb83c | 1615 | data0 = AINcode[((int)ainp & 0x0F)]; |
whismanoid | 0:68e64068330f | 1616 | |
whismanoid | 0:68e64068330f | 1617 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1618 | // ideal voltage calculated from raw LSB code and reference voltage |
whismanoid | 1:d57c1a2cb83c | 1619 | return VoltageOfCode(AINcode[((int)ainp & 0x0F)]); |
whismanoid | 0:68e64068330f | 1620 | } |
whismanoid | 0:68e64068330f | 1621 | |
whismanoid | 0:68e64068330f | 1622 | //---------------------------------------- |
whismanoid | 5:a2e74357cfc0 | 1623 | // Menu item 'R' -> rtd_resistance, RTD_Temperature |
whismanoid | 0:68e64068330f | 1624 | // Trigger Measurement for Resistive Temperature Device (RTD). |
whismanoid | 0:68e64068330f | 1625 | // |
whismanoid | 0:68e64068330f | 1626 | // Example code for typical RTD measurement. |
whismanoid | 0:68e64068330f | 1627 | // |
whismanoid | 1:d57c1a2cb83c | 1628 | // @pre external connection REF1P-REF1N is a reference resistor |
whismanoid | 1:d57c1a2cb83c | 1629 | // @pre VRef_REF1 = reference resistance in ohms, default=4999 |
whismanoid | 1:d57c1a2cb83c | 1630 | // @param[in] rtd_iout = channel RTD high side force, default=AINP_SEL_0111_AIN7 |
whismanoid | 1:d57c1a2cb83c | 1631 | // @param[in] rtd_ainp = channel RTD high side sense, default=AINP_SEL_1000_AIN8 |
whismanoid | 1:d57c1a2cb83c | 1632 | // @param[in] rtd_ainn = channel RTD low side, default=AINN_SEL_1001_AIN9 |
whismanoid | 1:d57c1a2cb83c | 1633 | // @post AINcode[rtd_ainp]: measurement result LSB code |
whismanoid | 5:a2e74357cfc0 | 1634 | // @post rtd_resistance: measurement result resistance in Ohms |
whismanoid | 5:a2e74357cfc0 | 1635 | // @post RTD_Temperature: Temperature calculated from RTD Resistance; Thermocouple Cold Junction, in degrees C |
whismanoid | 0:68e64068330f | 1636 | // |
whismanoid | 3:658a93dfb2d8 | 1637 | // @return resistance calculated from raw LSB code and reference resistance |
whismanoid | 1:d57c1a2cb83c | 1638 | double MAX11410::Measure_RTD(MAX11410_AINP_SEL_enum_t rtd_iout, MAX11410_AINP_SEL_enum_t rtd_ainp, MAX11410_AINN_SEL_enum_t rtd_ainn) |
whismanoid | 0:68e64068330f | 1639 | { |
whismanoid | 0:68e64068330f | 1640 | |
whismanoid | 0:68e64068330f | 1641 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 1642 | // restrict channel selection to valid index range |
whismanoid | 8:3a9dfa2e8234 | 1643 | if ((uint8_t)rtd_iout > /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD) |
whismanoid | 8:3a9dfa2e8234 | 1644 | { |
whismanoid | 8:3a9dfa2e8234 | 1645 | rtd_iout = /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD; |
whismanoid | 8:3a9dfa2e8234 | 1646 | } |
whismanoid | 8:3a9dfa2e8234 | 1647 | |
whismanoid | 8:3a9dfa2e8234 | 1648 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 1649 | // restrict channel selection to valid index range |
whismanoid | 8:3a9dfa2e8234 | 1650 | if ((uint8_t)rtd_ainp > /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD) |
whismanoid | 8:3a9dfa2e8234 | 1651 | { |
whismanoid | 8:3a9dfa2e8234 | 1652 | rtd_ainp = /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD; |
whismanoid | 8:3a9dfa2e8234 | 1653 | } |
whismanoid | 8:3a9dfa2e8234 | 1654 | |
whismanoid | 8:3a9dfa2e8234 | 1655 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 1656 | // restrict channel selection to valid index range |
whismanoid | 8:3a9dfa2e8234 | 1657 | if ((uint8_t)rtd_ainn > /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND) |
whismanoid | 8:3a9dfa2e8234 | 1658 | { |
whismanoid | 8:3a9dfa2e8234 | 1659 | rtd_ainn = /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND; |
whismanoid | 8:3a9dfa2e8234 | 1660 | } |
whismanoid | 8:3a9dfa2e8234 | 1661 | |
whismanoid | 8:3a9dfa2e8234 | 1662 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1663 | // write8 0x08 FILTER = 0x34 to select RATE_0100, LINEF_11_SINC4 60SPS (given CONV_TYPE_01_Continuous) |
whismanoid | 2:eac67184cc0c | 1664 | Configure_FILTER((uint8_t) /* MAX11410::MAX11410_LINEF_enum_t:: */ LINEF_11_SINC4, |
whismanoid | 2:eac67184cc0c | 1665 | (uint8_t) /* MAX11410::MAX11410_RATE_enum_t:: */ RATE_0100); |
whismanoid | 1:d57c1a2cb83c | 1666 | |
whismanoid | 1:d57c1a2cb83c | 1667 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1668 | // write8 0x09 CTRL to select reference resistor REF1P/REF1N; Data Format = Unipolar |
whismanoid | 1:d57c1a2cb83c | 1669 | Configure_CTRL(/*extclk*/ 0, /*u_bn*/ 1, /*format*/ 0, |
whismanoid | 1:d57c1a2cb83c | 1670 | /*refbufp_en*/ 0, /*refbufn_en*/ 0, |
whismanoid | 1:d57c1a2cb83c | 1671 | /*ref_sel*/ (uint8_t)REF_SEL_001_REF1P_REF1N); |
whismanoid | 1:d57c1a2cb83c | 1672 | |
whismanoid | 1:d57c1a2cb83c | 1673 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1674 | // write8 0x0A SOURCE = 0x0B to select IDAC_MODE 400uA; AIN9=2.000V, AIN8(PT100)=2.040V, AIN8(PT1000)=2.400V |
whismanoid | 1:d57c1a2cb83c | 1675 | Configure_SOURCE(VBIAS_MODE_00_Active, BRN_MODE_00_disabled, IDAC_MODE_1011_400uA); |
whismanoid | 1:d57c1a2cb83c | 1676 | |
whismanoid | 1:d57c1a2cb83c | 1677 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1678 | // write8 0x0B MUX_CTRL0 = 0x89 to select AINP=AIN8 and AINN=AIN9 |
whismanoid | 1:d57c1a2cb83c | 1679 | Configure_MUX_CTRL0((uint8_t)rtd_ainp, (uint8_t)rtd_ainn); |
whismanoid | 1:d57c1a2cb83c | 1680 | |
whismanoid | 1:d57c1a2cb83c | 1681 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1682 | // write8 0x0C MUX_CTRL1 = 0xF7 to select IDAC1_SEL=NC, IDAC0_SEL=AIN7 |
whismanoid | 1:d57c1a2cb83c | 1683 | Configure_MUX_CTRL1((uint8_t)IDAC1_SEL_1111_unconnected, (uint8_t)rtd_iout); |
whismanoid | 1:d57c1a2cb83c | 1684 | |
whismanoid | 1:d57c1a2cb83c | 1685 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1686 | // write8 0x0E PGA |
whismanoid | 2:eac67184cc0c | 1687 | Configure_PGA((uint8_t) /* MAX11410_SIG_PATH_enum_t:: */ SIG_PATH_10_PGA, |
whismanoid | 2:eac67184cc0c | 1688 | (uint8_t) /* MAX11410_GAIN_enum_t:: */ GAIN_001_2); |
whismanoid | 1:d57c1a2cb83c | 1689 | |
whismanoid | 1:d57c1a2cb83c | 1690 | //---------------------------------------- |
whismanoid | 9:06ca88952f1c | 1691 | // TODO1: timing delay after enable RTD bias current |
whismanoid | 9:06ca88952f1c | 1692 | #warning "Not Implemented Yet: timing delay after enable RTD bias current" |
whismanoid | 9:06ca88952f1c | 1693 | |
whismanoid | 9:06ca88952f1c | 1694 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1695 | // write8 0x01 CONV_START = 0x01 to set Conversion Mode = Continuous |
whismanoid | 1:d57c1a2cb83c | 1696 | RegWrite(CMD_r000_0001_xddd_xxdd_CONV_START, 0x01); |
whismanoid | 1:d57c1a2cb83c | 1697 | |
whismanoid | 1:d57c1a2cb83c | 1698 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1699 | // read24 0x80|0x38 STATUS (%SW 0xB8 0 0 0) |
whismanoid | 0:68e64068330f | 1700 | RegRead(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); |
whismanoid | 0:68e64068330f | 1701 | |
whismanoid | 0:68e64068330f | 1702 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1703 | // read24 0x80|0x30 DATA0 (%SW 0xB0 0 0 0): AINcode[ainp] = measurement |
whismanoid | 1:d57c1a2cb83c | 1704 | RegRead(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &AINcode[((int)rtd_ainp & 0x0F)]); |
whismanoid | 1:d57c1a2cb83c | 1705 | data0 = AINcode[((int)rtd_ainp & 0x0F)]; |
whismanoid | 0:68e64068330f | 1706 | |
whismanoid | 0:68e64068330f | 1707 | //---------------------------------------- |
whismanoid | 9:06ca88952f1c | 1708 | // TODO1: turn off RTD bias current to avoid self-heating |
whismanoid | 9:06ca88952f1c | 1709 | #warning "Not Implemented Yet: turn off RTD bias current to avoid self-heating" |
whismanoid | 9:06ca88952f1c | 1710 | |
whismanoid | 9:06ca88952f1c | 1711 | //---------------------------------------- |
whismanoid | 5:a2e74357cfc0 | 1712 | // resistance calculated from raw LSB code and VRef_REF1 reference resistance in ohms |
whismanoid | 5:a2e74357cfc0 | 1713 | rtd_resistance = VoltageOfCode(AINcode[((int)rtd_ainp & 0x0F)]); |
whismanoid | 5:a2e74357cfc0 | 1714 | TemperatureOfRTD_PT1000(rtd_resistance); // calculate RTD_Temperature |
whismanoid | 5:a2e74357cfc0 | 1715 | return rtd_resistance; |
whismanoid | 0:68e64068330f | 1716 | } |
whismanoid | 0:68e64068330f | 1717 | |
whismanoid | 0:68e64068330f | 1718 | //---------------------------------------- |
whismanoid | 3:658a93dfb2d8 | 1719 | // Return the physical temperature corresponding to measured resistance |
whismanoid | 3:658a93dfb2d8 | 1720 | // of a PT1000 type Resistive Temperature Device (RTD). |
whismanoid | 3:658a93dfb2d8 | 1721 | // |
whismanoid | 3:658a93dfb2d8 | 1722 | // @param[in] rtd_resistance = RTD resistance in ohms, default=1000 |
whismanoid | 5:a2e74357cfc0 | 1723 | // @post RTD_Temperature: Temperature calculated from RTD Resistance; Thermocouple Cold Junction, in degrees C |
whismanoid | 3:658a93dfb2d8 | 1724 | // |
whismanoid | 3:658a93dfb2d8 | 1725 | // @return ideal temperature in degrees C, calculated from RTD resistance in ohms |
whismanoid | 5:a2e74357cfc0 | 1726 | // @test group RTD_PT1000 TemperatureOfRTD_PT1000(842.94) expect -40.0 within 0.1 PT-1000 RTD at -40C |
whismanoid | 5:a2e74357cfc0 | 1727 | // @test group RTD_PT1000 TemperatureOfRTD_PT1000(1000.0) expect 0.0 within 0.1 PT-1000 RTD at 0C |
whismanoid | 5:a2e74357cfc0 | 1728 | // @test group RTD_PT1000 TemperatureOfRTD_PT1000(1097.3) expect 25.0 within 0.1 PT-1000 RTD at 25C |
whismanoid | 5:a2e74357cfc0 | 1729 | // @test group RTD_PT1000 TemperatureOfRTD_PT1000(1328.1) expect 85.0 within 0.1 PT-1000 RTD at 85C |
whismanoid | 5:a2e74357cfc0 | 1730 | // @test group RTD_PT1000 TemperatureOfRTD_PT1000(1479.5) expect 125.0 within 0.1 PT-1000 RTD at 125C |
whismanoid | 3:658a93dfb2d8 | 1731 | // |
whismanoid | 3:658a93dfb2d8 | 1732 | double MAX11410::TemperatureOfRTD_PT1000(double rtd_resistance) |
whismanoid | 3:658a93dfb2d8 | 1733 | { |
whismanoid | 3:658a93dfb2d8 | 1734 | |
whismanoid | 3:658a93dfb2d8 | 1735 | //---------------------------------------- |
whismanoid | 3:658a93dfb2d8 | 1736 | // Temperature from RTD Resistance maths |
whismanoid | 4:c169ba85d673 | 1737 | // ITS-90 PT-1000 RTD |
whismanoid | 4:c169ba85d673 | 1738 | double R0 = 1000.0; |
whismanoid | 4:c169ba85d673 | 1739 | double a = 3.9083e-3; |
whismanoid | 4:c169ba85d673 | 1740 | double b = -5.7750e-7; |
whismanoid | 5:a2e74357cfc0 | 1741 | // calculate T from R and R0 |
whismanoid | 4:c169ba85d673 | 1742 | double sqrtTerm = sqrt(R0*R0 * a*a - 4*R0*b*(R0 - rtd_resistance)); |
whismanoid | 4:c169ba85d673 | 1743 | double denominator = 2 * R0 * b; |
whismanoid | 4:c169ba85d673 | 1744 | RTD_Temperature = ((-R0 * a) + (sqrtTerm)) / denominator; |
whismanoid | 3:658a93dfb2d8 | 1745 | return RTD_Temperature; |
whismanoid | 3:658a93dfb2d8 | 1746 | } |
whismanoid | 3:658a93dfb2d8 | 1747 | |
whismanoid | 3:658a93dfb2d8 | 1748 | //---------------------------------------- |
whismanoid | 3:658a93dfb2d8 | 1749 | // Menu item 'TM' |
whismanoid | 0:68e64068330f | 1750 | // Trigger Measurement for Thermocouple |
whismanoid | 0:68e64068330f | 1751 | // |
whismanoid | 0:68e64068330f | 1752 | // Example code for typical Thermocouple measurement. |
whismanoid | 1:d57c1a2cb83c | 1753 | // An RTD measures the "cold junction" where TC connects to the board, |
whismanoid | 1:d57c1a2cb83c | 1754 | // and the TC measures the temperature difference above the cold junction. |
whismanoid | 0:68e64068330f | 1755 | // |
whismanoid | 1:d57c1a2cb83c | 1756 | // @param[in] tc_ainp = channel of Thermocouple high side, default=AINP_SEL_0101_AIN5 |
whismanoid | 1:d57c1a2cb83c | 1757 | // @param[in] tc_ainn = channel of Thermocouple low side, default=AINN_SEL_0110_AIN6 |
whismanoid | 1:d57c1a2cb83c | 1758 | // @param[in] rtd_iout = channel RTD high side force, default=AINP_SEL_0111_AIN7 |
whismanoid | 1:d57c1a2cb83c | 1759 | // @param[in] rtd_ainp = channel RTD high side sense, default=AINP_SEL_1000_AIN8 |
whismanoid | 1:d57c1a2cb83c | 1760 | // @param[in] rtd_ainn = channel RTD low side, default=AINN_SEL_1001_AIN9 |
whismanoid | 1:d57c1a2cb83c | 1761 | // @post AINcode[tc_ainp]: measurement result LSB code |
whismanoid | 0:68e64068330f | 1762 | // |
whismanoid | 0:68e64068330f | 1763 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1764 | double MAX11410::Measure_Thermocouple(MAX11410_AINP_SEL_enum_t tc_ainp, MAX11410_AINN_SEL_enum_t tc_ainn, MAX11410_AINP_SEL_enum_t rtd_iout, MAX11410_AINP_SEL_enum_t rtd_ainp, MAX11410_AINN_SEL_enum_t rtd_ainn) |
whismanoid | 0:68e64068330f | 1765 | { |
whismanoid | 0:68e64068330f | 1766 | |
whismanoid | 0:68e64068330f | 1767 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1768 | // warning -- WIP work in progress |
whismanoid | 0:68e64068330f | 1769 | #warning "Not Implemented Yet: MAX11410::Measure_Thermocouple..." |
whismanoid | 0:68e64068330f | 1770 | |
whismanoid | 0:68e64068330f | 1771 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 1772 | // restrict channel selection to valid index range |
whismanoid | 8:3a9dfa2e8234 | 1773 | if ((uint8_t)tc_ainp > /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD) |
whismanoid | 8:3a9dfa2e8234 | 1774 | { |
whismanoid | 8:3a9dfa2e8234 | 1775 | tc_ainp = /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD; |
whismanoid | 8:3a9dfa2e8234 | 1776 | } |
whismanoid | 8:3a9dfa2e8234 | 1777 | |
whismanoid | 8:3a9dfa2e8234 | 1778 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 1779 | // restrict channel selection to valid index range |
whismanoid | 8:3a9dfa2e8234 | 1780 | if ((uint8_t)tc_ainn > /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND) |
whismanoid | 8:3a9dfa2e8234 | 1781 | { |
whismanoid | 8:3a9dfa2e8234 | 1782 | tc_ainn = /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND; |
whismanoid | 8:3a9dfa2e8234 | 1783 | } |
whismanoid | 8:3a9dfa2e8234 | 1784 | |
whismanoid | 8:3a9dfa2e8234 | 1785 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 1786 | // restrict channel selection to valid index range |
whismanoid | 8:3a9dfa2e8234 | 1787 | if ((uint8_t)rtd_iout > /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD) |
whismanoid | 8:3a9dfa2e8234 | 1788 | { |
whismanoid | 8:3a9dfa2e8234 | 1789 | rtd_iout = /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD; |
whismanoid | 8:3a9dfa2e8234 | 1790 | } |
whismanoid | 8:3a9dfa2e8234 | 1791 | |
whismanoid | 8:3a9dfa2e8234 | 1792 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 1793 | // restrict channel selection to valid index range |
whismanoid | 8:3a9dfa2e8234 | 1794 | if ((uint8_t)rtd_ainp > /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD) |
whismanoid | 8:3a9dfa2e8234 | 1795 | { |
whismanoid | 8:3a9dfa2e8234 | 1796 | rtd_ainp = /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD; |
whismanoid | 8:3a9dfa2e8234 | 1797 | } |
whismanoid | 8:3a9dfa2e8234 | 1798 | |
whismanoid | 8:3a9dfa2e8234 | 1799 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 1800 | // restrict channel selection to valid index range |
whismanoid | 8:3a9dfa2e8234 | 1801 | if ((uint8_t)rtd_ainn > /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND) |
whismanoid | 8:3a9dfa2e8234 | 1802 | { |
whismanoid | 8:3a9dfa2e8234 | 1803 | rtd_ainn = /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND; |
whismanoid | 8:3a9dfa2e8234 | 1804 | } |
whismanoid | 8:3a9dfa2e8234 | 1805 | |
whismanoid | 8:3a9dfa2e8234 | 1806 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 1807 | // write8 0x0B MUX_CTRL0 = 0x0A to select AINP=AIN0 and AINN=GND |
whismanoid | 8:3a9dfa2e8234 | 1808 | Configure_MUX_CTRL0((uint8_t)tc_ainp, (uint8_t)tc_ainn); |
whismanoid | 8:3a9dfa2e8234 | 1809 | |
whismanoid | 8:3a9dfa2e8234 | 1810 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 1811 | // write8 0x09 CTRL to select reference REF2P/REF2N; Data Format = Bipolar 2's Complement |
whismanoid | 8:3a9dfa2e8234 | 1812 | Configure_CTRL(/*extclk*/ 0, /*u_bn*/ 0, /*format*/ 0, |
whismanoid | 8:3a9dfa2e8234 | 1813 | /*refbufp_en*/ 0, /*refbufn_en*/ 0, |
whismanoid | 8:3a9dfa2e8234 | 1814 | /*ref_sel*/ (uint8_t)REF_SEL_010_REF2P_REF2N); |
whismanoid | 8:3a9dfa2e8234 | 1815 | |
whismanoid | 8:3a9dfa2e8234 | 1816 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 1817 | // write8 0x0E PGA |
whismanoid | 8:3a9dfa2e8234 | 1818 | Configure_PGA((uint8_t) /* MAX11410_SIG_PATH_enum_t:: */ SIG_PATH_00_BUFFERED, |
whismanoid | 8:3a9dfa2e8234 | 1819 | (uint8_t) /* MAX11410_GAIN_enum_t:: */ GAIN_000_1); |
whismanoid | 8:3a9dfa2e8234 | 1820 | |
whismanoid | 8:3a9dfa2e8234 | 1821 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 1822 | // write8 0x08 FILTER = 0x34 to select RATE_0100, LINEF_11_SINC4 60SPS (given CONV_TYPE_01_Continuous) |
whismanoid | 8:3a9dfa2e8234 | 1823 | Configure_FILTER((uint8_t) /* MAX11410::MAX11410_LINEF_enum_t:: */ LINEF_11_SINC4, |
whismanoid | 8:3a9dfa2e8234 | 1824 | (uint8_t) /* MAX11410::MAX11410_RATE_enum_t:: */ RATE_0100); |
whismanoid | 8:3a9dfa2e8234 | 1825 | |
whismanoid | 8:3a9dfa2e8234 | 1826 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 1827 | // write8 0x01 CONV_START = 0x01 to set Conversion Mode = Continuous |
whismanoid | 8:3a9dfa2e8234 | 1828 | RegWrite(CMD_r000_0001_xddd_xxdd_CONV_START, 0x01); |
whismanoid | 8:3a9dfa2e8234 | 1829 | |
whismanoid | 8:3a9dfa2e8234 | 1830 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1831 | // read24 0x80|0x38 STATUS (%SW 0xB8 0 0 0) |
whismanoid | 0:68e64068330f | 1832 | RegRead(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); |
whismanoid | 0:68e64068330f | 1833 | |
whismanoid | 0:68e64068330f | 1834 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 1835 | // read24 0x80|0x30 DATA0 (%SW 0xB0 0 0 0): AINcode[tc_ainp] = measurement |
whismanoid | 8:3a9dfa2e8234 | 1836 | RegRead(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &AINcode[((int)tc_ainp & 0x0F)]); |
whismanoid | 8:3a9dfa2e8234 | 1837 | data0 = AINcode[((int)tc_ainp & 0x0F)]; |
whismanoid | 0:68e64068330f | 1838 | |
whismanoid | 0:68e64068330f | 1839 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1840 | // ideal voltage calculated from raw LSB code and reference voltage |
whismanoid | 8:3a9dfa2e8234 | 1841 | return VoltageOfCode(AINcode[((int)tc_ainp & 0x0F)]); |
whismanoid | 0:68e64068330f | 1842 | } |
whismanoid | 0:68e64068330f | 1843 | |
whismanoid | 3:658a93dfb2d8 | 1844 | //---------------------------------------- |
whismanoid | 3:658a93dfb2d8 | 1845 | // Menu item 'TK' |
whismanoid | 3:658a93dfb2d8 | 1846 | // Return the physical temperature corresponding to measured voltage |
whismanoid | 3:658a93dfb2d8 | 1847 | // of a type K Thermocouple (TC). |
whismanoid | 3:658a93dfb2d8 | 1848 | // |
whismanoid | 3:658a93dfb2d8 | 1849 | // @pre {0}.RTD_Temperature = cold junction temperature, in degrees C |
whismanoid | 3:658a93dfb2d8 | 1850 | // @param[in] tc_voltage = Thermocouple voltage in volts, default=0.0254 |
whismanoid | 3:658a93dfb2d8 | 1851 | // |
whismanoid | 3:658a93dfb2d8 | 1852 | // @return ideal temperature in degrees C, calculated from RTD resistance in ohms |
whismanoid | 4:c169ba85d673 | 1853 | // @test group TC_1 TemperatureOfTC_TypeK(0.000e-3) expect 0.0 within 0.1 TC_TypeK at 0C = 0.000mV |
whismanoid | 4:c169ba85d673 | 1854 | // @test group TC_1 TemperatureOfTC_TypeK(0.039e-3) expect 1.0 within 0.1 TC_TypeK at 1C = 0.039mV |
whismanoid | 4:c169ba85d673 | 1855 | // @test group TC_1 TemperatureOfTC_TypeK(0.079e-3) expect 2.0 within 0.1 TC_TypeK at 2C = 0.079mV |
whismanoid | 4:c169ba85d673 | 1856 | // @test group TC_1 TemperatureOfTC_TypeK(0.119e-3) expect 3.0 within 0.1 TC_TypeK at 3C = 0.119mV |
whismanoid | 4:c169ba85d673 | 1857 | // @test group TC_2 TemperatureOfTC_TypeK(0.158e-3) expect 4.0 within 0.1 TC_TypeK at 4C = 0.158mV |
whismanoid | 4:c169ba85d673 | 1858 | // @test group TC_2 TemperatureOfTC_TypeK(0.198e-3) expect 5.0 within 0.1 TC_TypeK at 5C = 0.198mV |
whismanoid | 4:c169ba85d673 | 1859 | // @test group TC_2 TemperatureOfTC_TypeK(0.238e-3) expect 6.0 within 0.1 TC_TypeK at 6C = 0.238mV |
whismanoid | 4:c169ba85d673 | 1860 | // @test group TC_2 TemperatureOfTC_TypeK(0.2775e-3) expect 7.0 within 0.1 TC_TypeK at 7C = 0.2775mV |
whismanoid | 4:c169ba85d673 | 1861 | // @test group TC_2 TemperatureOfTC_TypeK(0.317e-3) expect 8.0 within 0.1 TC_TypeK at 8C = 0.317mV |
whismanoid | 4:c169ba85d673 | 1862 | // @test group TC_2 TemperatureOfTC_TypeK(0.357e-3) expect 9.0 within 0.1 TC_TypeK at 9C = 0.357mV |
whismanoid | 4:c169ba85d673 | 1863 | // @test group TC_1 TemperatureOfTC_TypeK(0.397e-3) expect 10.0 within 0.1 TC_TypeK at 10C = 0.397mV |
whismanoid | 4:c169ba85d673 | 1864 | // @test group TC_1 TemperatureOfTC_TypeK(0.798e-3) expect 20.0 within 0.1 TC_TypeK at 20C = 0.798mV |
whismanoid | 4:c169ba85d673 | 1865 | // @test group TC_1 TemperatureOfTC_TypeK(1.081e-3) expect 27.0 within 0.1 TC_TypeK at 27C = 1.081mV |
whismanoid | 4:c169ba85d673 | 1866 | // @test group TC_1 TemperatureOfTC_TypeK(1.203e-3) expect 30.0 within 0.1 TC_TypeK at 30C = 1.203mV |
whismanoid | 4:c169ba85d673 | 1867 | // @test group TC_1 TemperatureOfTC_TypeK(1.612e-3) expect 40.0 within 0.1 TC_TypeK at 40C = 1.612mV |
whismanoid | 4:c169ba85d673 | 1868 | // @test group TC_1 TemperatureOfTC_TypeK(2.023e-3) expect 50.0 within 0.1 TC_TypeK at 50C = 2.023mV |
whismanoid | 4:c169ba85d673 | 1869 | // @test group TC_1 TemperatureOfTC_TypeK(2.436e-3) expect 60.0 within 0.1 TC_TypeK at 60C = 2.436mV |
whismanoid | 4:c169ba85d673 | 1870 | // @test group TC_1 TemperatureOfTC_TypeK(2.851e-3) expect 70.0 within 0.1 TC_TypeK at 70C = 2.851mV |
whismanoid | 4:c169ba85d673 | 1871 | // @test group TC_1 TemperatureOfTC_TypeK(3.267e-3) expect 80.0 within 0.1 TC_TypeK at 80C = 3.267mV |
whismanoid | 4:c169ba85d673 | 1872 | // @test group TC_1 TemperatureOfTC_TypeK(3.682e-3) expect 90.0 within 0.1 TC_TypeK at 90C = 3.682mV |
whismanoid | 4:c169ba85d673 | 1873 | // @test group TC_1 TemperatureOfTC_TypeK(4.096e-3) expect 100.0 within 0.1 TC_TypeK at 100C = 4.096mV |
whismanoid | 4:c169ba85d673 | 1874 | // @test group TC_2 TemperatureOfTC_TypeK(4.509e-3) expect 110.0 within 0.1 TC_TypeK at 110C = 4.509mV |
whismanoid | 4:c169ba85d673 | 1875 | // @test group TC_2 TemperatureOfTC_TypeK(4.920e-3) expect 120.0 within 0.1 TC_TypeK at 120C = 4.920mV |
whismanoid | 4:c169ba85d673 | 1876 | // @test group TC_2 TemperatureOfTC_TypeK(5.328e-3) expect 130.0 within 0.1 TC_TypeK at 130C = 5.328mV |
whismanoid | 4:c169ba85d673 | 1877 | // @test group TC_2 TemperatureOfTC_TypeK(5.735e-3) expect 140.0 within 0.1 TC_TypeK at 140C = 5.735mV |
whismanoid | 4:c169ba85d673 | 1878 | // @test group TC_2 TemperatureOfTC_TypeK(6.138e-3) expect 150.0 within 0.1 TC_TypeK at 150C = 6.138mV |
whismanoid | 4:c169ba85d673 | 1879 | // @test group TC_2 TemperatureOfTC_TypeK(6.540e-3) expect 160.0 within 0.1 TC_TypeK at 160C = 6.540mV |
whismanoid | 4:c169ba85d673 | 1880 | // @test group TC_2 TemperatureOfTC_TypeK(6.941e-3) expect 170.0 within 0.1 TC_TypeK at 170C = 6.941mV |
whismanoid | 4:c169ba85d673 | 1881 | // @test group TC_2 TemperatureOfTC_TypeK(7.340e-3) expect 180.0 within 0.1 TC_TypeK at 180C = 7.340mV |
whismanoid | 4:c169ba85d673 | 1882 | // @test group TC_1 TemperatureOfTC_TypeK(7.739e-3) expect 190.0 within 0.1 TC_TypeK at 190C = 7.739mV |
whismanoid | 4:c169ba85d673 | 1883 | // @test group TC_1 TemperatureOfTC_TypeK(8.138e-3) expect 200.0 within 0.1 TC_TypeK at 200C = 8.138mV |
whismanoid | 4:c169ba85d673 | 1884 | // @test group TC_1 TemperatureOfTC_TypeK(8.539e-3) expect 210.0 within 0.1 TC_TypeK at 210C = 8.539mV |
whismanoid | 4:c169ba85d673 | 1885 | // @test group TC_1 TemperatureOfTC_TypeK(8.940e-3) expect 220.0 within 0.1 TC_TypeK at 220C = 8.940mV |
whismanoid | 4:c169ba85d673 | 1886 | // @test group TC_2 TemperatureOfTC_TypeK(9.343e-3) expect 230.0 within 0.1 TC_TypeK at 230C = 9.343mV |
whismanoid | 4:c169ba85d673 | 1887 | // @test group TC_2 TemperatureOfTC_TypeK(9.747e-3) expect 240.0 within 0.1 TC_TypeK at 240C = 9.747mV |
whismanoid | 4:c169ba85d673 | 1888 | // @test group TC_2 TemperatureOfTC_TypeK(10.153e-3) expect 250.0 within 0.1 TC_TypeK at 250C = 10.153mV |
whismanoid | 4:c169ba85d673 | 1889 | // @test group TC_2 TemperatureOfTC_TypeK(10.561e-3) expect 260.0 within 0.1 TC_TypeK at 260C = 10.561mV |
whismanoid | 4:c169ba85d673 | 1890 | // @test group TC_2 TemperatureOfTC_TypeK(10.971e-3) expect 270.0 within 0.1 TC_TypeK at 270C = 10.971mV |
whismanoid | 4:c169ba85d673 | 1891 | // @test group TC_2 TemperatureOfTC_TypeK(11.382e-3) expect 280.0 within 0.1 TC_TypeK at 280C = 11.382mV |
whismanoid | 4:c169ba85d673 | 1892 | // @test group TC_2 TemperatureOfTC_TypeK(11.795e-3) expect 290.0 within 0.1 TC_TypeK at 290C = 11.795mV |
whismanoid | 4:c169ba85d673 | 1893 | // @test group TC_1 TemperatureOfTC_TypeK(12.209e-3) expect 300.0 within 0.1 TC_TypeK at 300C = 12.209mV |
whismanoid | 4:c169ba85d673 | 1894 | // @test group TC_2 TemperatureOfTC_TypeK(14.293e-3) expect 350.0 within 0.1 TC_TypeK at 350C = 14.293mV |
whismanoid | 4:c169ba85d673 | 1895 | // @test group TC_1 TemperatureOfTC_TypeK(16.397e-3) expect 400.0 within 0.1 TC_TypeK at 400C = 16.397mV |
whismanoid | 4:c169ba85d673 | 1896 | // @test group TC_1 TemperatureOfTC_TypeK(18.516e-3) expect 450.0 within 0.1 TC_TypeK at 450C = 18.516mV |
whismanoid | 4:c169ba85d673 | 1897 | // @test group TC_1 TemperatureOfTC_TypeK(20.218e-3) expect 490.0 TC_TypeK at 490C = 20.218mV |
whismanoid | 3:658a93dfb2d8 | 1898 | // |
whismanoid | 3:658a93dfb2d8 | 1899 | double MAX11410::TemperatureOfTC_TypeK(double tc_voltage) |
whismanoid | 3:658a93dfb2d8 | 1900 | { |
whismanoid | 3:658a93dfb2d8 | 1901 | |
whismanoid | 3:658a93dfb2d8 | 1902 | //---------------------------------------- |
whismanoid | 3:658a93dfb2d8 | 1903 | // Temperature from TC_TypeK voltage maths |
whismanoid | 5:a2e74357cfc0 | 1904 | // define standard TC_TypeK coefficients |
whismanoid | 4:c169ba85d673 | 1905 | // ITS-90 Thermocouple Inverse Polynomial for a Type K thermocouple |
whismanoid | 5:a2e74357cfc0 | 1906 | // calculate deltaT from tc_voltage |
whismanoid | 4:c169ba85d673 | 1907 | // |
whismanoid | 4:c169ba85d673 | 1908 | // Voltage range -5891uV < tc_voltage < 0uV, |
whismanoid | 4:c169ba85d673 | 1909 | // Temperature Range -200 deg C to 0 deg C |
whismanoid | 4:c169ba85d673 | 1910 | static double coefficients_TCtypeK_V_lt_0[] = { |
whismanoid | 4:c169ba85d673 | 1911 | 0.00000, |
whismanoid | 4:c169ba85d673 | 1912 | 2.5173462e-2, |
whismanoid | 4:c169ba85d673 | 1913 | -1.1662878e-6, |
whismanoid | 4:c169ba85d673 | 1914 | -1.0833638e-9, |
whismanoid | 4:c169ba85d673 | 1915 | -8.9773540e-13, |
whismanoid | 4:c169ba85d673 | 1916 | -3.7342377e-16, |
whismanoid | 4:c169ba85d673 | 1917 | -8.6632643e-20, |
whismanoid | 4:c169ba85d673 | 1918 | -1.0450598e-23, |
whismanoid | 4:c169ba85d673 | 1919 | -5.1920577e-28, |
whismanoid | 4:c169ba85d673 | 1920 | }; |
whismanoid | 4:c169ba85d673 | 1921 | // |
whismanoid | 4:c169ba85d673 | 1922 | // Voltage range 0uV < tc_voltage < 20.644uV, |
whismanoid | 4:c169ba85d673 | 1923 | // Temperature Range 0 deg C to 500 deg C |
whismanoid | 4:c169ba85d673 | 1924 | static double coefficients_TCtypeK_0_lt_V_lt_20u644V[] = { |
whismanoid | 4:c169ba85d673 | 1925 | 0.00000, |
whismanoid | 4:c169ba85d673 | 1926 | 2.508355e-2, |
whismanoid | 4:c169ba85d673 | 1927 | 7.860106e-8, |
whismanoid | 4:c169ba85d673 | 1928 | -2.503131e-10, |
whismanoid | 4:c169ba85d673 | 1929 | 8.315270e-14, |
whismanoid | 4:c169ba85d673 | 1930 | -1.228034e-17, |
whismanoid | 4:c169ba85d673 | 1931 | 9.804036e-22, |
whismanoid | 4:c169ba85d673 | 1932 | -4.413030e-26, |
whismanoid | 4:c169ba85d673 | 1933 | 1.057734e-30, |
whismanoid | 4:c169ba85d673 | 1934 | -1.052755e-35, |
whismanoid | 4:c169ba85d673 | 1935 | }; |
whismanoid | 4:c169ba85d673 | 1936 | // |
whismanoid | 4:c169ba85d673 | 1937 | // Voltage range 20.6440uV < tc_voltage < 54.886uV, |
whismanoid | 4:c169ba85d673 | 1938 | // Temperature Range 500 deg C to 1372 deg C |
whismanoid | 4:c169ba85d673 | 1939 | static double coefficients_TCtypeK_20u644V_lt_V_lt_54u886V[] = { |
whismanoid | 4:c169ba85d673 | 1940 | -1.318058e2, |
whismanoid | 4:c169ba85d673 | 1941 | 4.830222e-2, |
whismanoid | 4:c169ba85d673 | 1942 | -1.646031e-6, |
whismanoid | 4:c169ba85d673 | 1943 | 5.464731e-11, |
whismanoid | 4:c169ba85d673 | 1944 | -9.650715e-16, |
whismanoid | 4:c169ba85d673 | 1945 | 8.802193e-21, |
whismanoid | 4:c169ba85d673 | 1946 | -3.110810e-26, |
whismanoid | 4:c169ba85d673 | 1947 | }; |
whismanoid | 4:c169ba85d673 | 1948 | // |
whismanoid | 3:658a93dfb2d8 | 1949 | double deltaT = 0; |
whismanoid | 4:c169ba85d673 | 1950 | double thermocouple_voltage_uV = tc_voltage * 1e6; |
whismanoid | 4:c169ba85d673 | 1951 | if (thermocouple_voltage_uV < 0) |
whismanoid | 4:c169ba85d673 | 1952 | { |
whismanoid | 4:c169ba85d673 | 1953 | // Voltage range -5891uV < DMMavg < 0uV, Temperature Range -200 deg C to 0 deg C |
whismanoid | 4:c169ba85d673 | 1954 | deltaT = temperatureDegC_polynomial(thermocouple_voltage_uV, 9, coefficients_TCtypeK_V_lt_0); |
whismanoid | 4:c169ba85d673 | 1955 | } |
whismanoid | 4:c169ba85d673 | 1956 | else if (thermocouple_voltage_uV > 20644) |
whismanoid | 4:c169ba85d673 | 1957 | { |
whismanoid | 4:c169ba85d673 | 1958 | // Voltage range 206440uV < DMMavg < 54886uV, Temperature Range 500 deg C to 1372 deg C |
whismanoid | 4:c169ba85d673 | 1959 | deltaT = temperatureDegC_polynomial(thermocouple_voltage_uV, 7, coefficients_TCtypeK_20u644V_lt_V_lt_54u886V); |
whismanoid | 4:c169ba85d673 | 1960 | } |
whismanoid | 4:c169ba85d673 | 1961 | else |
whismanoid | 4:c169ba85d673 | 1962 | { |
whismanoid | 4:c169ba85d673 | 1963 | // Voltage range 0uV < DMMavg < 20.644uV, Temperature Range 0 deg C to 500 deg C |
whismanoid | 4:c169ba85d673 | 1964 | deltaT = temperatureDegC_polynomial(thermocouple_voltage_uV, 10, coefficients_TCtypeK_0_lt_V_lt_20u644V); |
whismanoid | 4:c169ba85d673 | 1965 | } |
whismanoid | 4:c169ba85d673 | 1966 | return deltaT; // + RTD_Temperature; // cold junction |
whismanoid | 4:c169ba85d673 | 1967 | } |
whismanoid | 4:c169ba85d673 | 1968 | |
whismanoid | 4:c169ba85d673 | 1969 | //---------------------------------------- |
whismanoid | 4:c169ba85d673 | 1970 | // Calculate temperature in degrees C from input voltage, |
whismanoid | 4:c169ba85d673 | 1971 | // using a given set of polynomial coefficients. |
whismanoid | 4:c169ba85d673 | 1972 | // For example: |
whismanoid | 4:c169ba85d673 | 1973 | // |
whismanoid | 4:c169ba85d673 | 1974 | // t = coefficients[0] + coefficients[1] * DMMavg + coefficients[2] * DmMMavg**2 |
whismanoid | 4:c169ba85d673 | 1975 | // |
whismanoid | 4:c169ba85d673 | 1976 | // @param[in] thermocouple_voltage_uV = Thermocouple voltage in microvolts |
whismanoid | 4:c169ba85d673 | 1977 | // |
whismanoid | 4:c169ba85d673 | 1978 | // @return ideal temperature in degrees C, calculated from polynomial coefficients |
whismanoid | 4:c169ba85d673 | 1979 | // |
whismanoid | 4:c169ba85d673 | 1980 | double MAX11410::temperatureDegC_polynomial(double thermocouple_voltage_uV, int num_coefficients, double coefficients[]) |
whismanoid | 4:c169ba85d673 | 1981 | { |
whismanoid | 4:c169ba85d673 | 1982 | |
whismanoid | 4:c169ba85d673 | 1983 | //---------------------------------------- |
whismanoid | 4:c169ba85d673 | 1984 | // warning -- WIP work in progress |
whismanoid | 4:c169ba85d673 | 1985 | #warning "Not Tested Yet: MAX11410::temperatureDegC_polynomial..." |
whismanoid | 4:c169ba85d673 | 1986 | |
whismanoid | 4:c169ba85d673 | 1987 | //---------------------------------------- |
whismanoid | 4:c169ba85d673 | 1988 | // Temperature from polynomial coefficients maths |
whismanoid | 4:c169ba85d673 | 1989 | double temperatureDegC = 0; |
whismanoid | 4:c169ba85d673 | 1990 | int index; |
whismanoid | 4:c169ba85d673 | 1991 | for (index = num_coefficients-1; index >= 0; index--) |
whismanoid | 4:c169ba85d673 | 1992 | { |
whismanoid | 4:c169ba85d673 | 1993 | temperatureDegC = (temperatureDegC * thermocouple_voltage_uV) + coefficients[index]; |
whismanoid | 4:c169ba85d673 | 1994 | } |
whismanoid | 4:c169ba85d673 | 1995 | return temperatureDegC; |
whismanoid | 3:658a93dfb2d8 | 1996 | } |
whismanoid | 3:658a93dfb2d8 | 1997 | |
whismanoid | 0:68e64068330f | 1998 | |
whismanoid | 0:68e64068330f | 1999 | // End of file |