MAX11410 high speed 24-bit Delta-Sigma ADC
Dependents: MAX11410BOB_24bit_ADC MAX11410BOB_Serial_Tester
MAX11410.cpp@26:298726bd5a3f, 2020-04-20 (annotated)
- Committer:
- whismanoid
- Date:
- Mon Apr 20 00:52:36 2020 +0000
- Revision:
- 26:298726bd5a3f
- Parent:
- 25:c4be3afbfafd
- Child:
- 27:1cb6c42c6a93
On CAL_START, wait for CAL_RDY unless (cal_start=1 and pgaGain==1)
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 | 13:df96a784cda6 | 83 | if (m_cs_pin.is_connected()) { // avoid mbed runtime error if pin is NC not connected |
whismanoid | 13:df96a784cda6 | 84 | m_cs_pin = m_SPI_cs_state; |
whismanoid | 13:df96a784cda6 | 85 | } |
whismanoid | 0:68e64068330f | 86 | |
whismanoid | 0:68e64068330f | 87 | // SPI CPOL = 0 |
whismanoid | 0:68e64068330f | 88 | // SPI CPHA = 0 |
whismanoid | 0:68e64068330f | 89 | // SPI MOSI and MISO Data are both stable on Rising edge of SCLK |
whismanoid | 0:68e64068330f | 90 | // SPI SCLK Idle Low |
whismanoid | 0:68e64068330f | 91 | m_SPI_dataMode = 0; //SPI_MODE0; // CPOL=0,CPHA=0: Rising Edge stable; SCLK idle Low |
whismanoid | 0:68e64068330f | 92 | m_spi.format(8,m_SPI_dataMode); // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=0 |
whismanoid | 0:68e64068330f | 93 | |
whismanoid | 0:68e64068330f | 94 | // SPI SCLKMaxMHz = 8 |
whismanoid | 0:68e64068330f | 95 | // SPI SCLKMinMHz = 0 |
whismanoid | 0:68e64068330f | 96 | //#define SPI_SCLK_Hz 48000000 // 48MHz |
whismanoid | 0:68e64068330f | 97 | //#define SPI_SCLK_Hz 24000000 // 24MHz |
whismanoid | 0:68e64068330f | 98 | //#define SPI_SCLK_Hz 12000000 // 12MHz |
whismanoid | 0:68e64068330f | 99 | //#define SPI_SCLK_Hz 6000000 // 6MHz |
whismanoid | 0:68e64068330f | 100 | //#define SPI_SCLK_Hz 4000000 // 4MHz |
whismanoid | 0:68e64068330f | 101 | //#define SPI_SCLK_Hz 2000000 // 2MHz |
whismanoid | 0:68e64068330f | 102 | //#define SPI_SCLK_Hz 1000000 // 1MHz |
whismanoid | 0:68e64068330f | 103 | m_SPI_SCLK_Hz = 8000000; // 8MHz; MAX11410 limit is 8MHz |
whismanoid | 0:68e64068330f | 104 | m_spi.frequency(m_SPI_SCLK_Hz); |
whismanoid | 0:68e64068330f | 105 | |
whismanoid | 0:68e64068330f | 106 | } |
whismanoid | 0:68e64068330f | 107 | |
whismanoid | 0:68e64068330f | 108 | // CODE GENERATOR: class destructor definition |
whismanoid | 0:68e64068330f | 109 | MAX11410::~MAX11410() |
whismanoid | 0:68e64068330f | 110 | { |
whismanoid | 0:68e64068330f | 111 | // do nothing |
whismanoid | 0:68e64068330f | 112 | } |
whismanoid | 0:68e64068330f | 113 | |
whismanoid | 0:68e64068330f | 114 | // CODE GENERATOR: spi_frequency setter definition |
whismanoid | 0:68e64068330f | 115 | /// set SPI SCLK frequency |
whismanoid | 0:68e64068330f | 116 | void MAX11410::spi_frequency(int spi_sclk_Hz) |
whismanoid | 0:68e64068330f | 117 | { |
whismanoid | 0:68e64068330f | 118 | m_SPI_SCLK_Hz = spi_sclk_Hz; |
whismanoid | 0:68e64068330f | 119 | m_spi.frequency(m_SPI_SCLK_Hz); |
whismanoid | 0:68e64068330f | 120 | } |
whismanoid | 0:68e64068330f | 121 | |
whismanoid | 0:68e64068330f | 122 | // CODE GENERATOR: omit global g_MAX11410_device |
whismanoid | 0:68e64068330f | 123 | // CODE GENERATOR: extern function declarations |
whismanoid | 0:68e64068330f | 124 | // CODE GENERATOR: extern function requirement MAX11410::SPIoutputCS |
whismanoid | 0:68e64068330f | 125 | // Assert SPI Chip Select |
whismanoid | 0:68e64068330f | 126 | // SPI chip-select for MAX11410 |
whismanoid | 0:68e64068330f | 127 | // |
whismanoid | 12:daecd93dd33a | 128 | inline void MAX11410::SPIoutputCS(int isLogicHigh) |
whismanoid | 0:68e64068330f | 129 | { |
whismanoid | 0:68e64068330f | 130 | // CODE GENERATOR: extern function definition for function SPIoutputCS |
whismanoid | 0:68e64068330f | 131 | // CODE GENERATOR: extern function definition for standard SPI interface function SPIoutputCS(int isLogicHigh) |
whismanoid | 0:68e64068330f | 132 | m_SPI_cs_state = isLogicHigh; |
whismanoid | 13:df96a784cda6 | 133 | if (m_cs_pin.is_connected()) { // avoid mbed runtime error if pin is NC not connected |
whismanoid | 13:df96a784cda6 | 134 | m_cs_pin = m_SPI_cs_state; |
whismanoid | 13:df96a784cda6 | 135 | } |
whismanoid | 0:68e64068330f | 136 | } |
whismanoid | 0:68e64068330f | 137 | |
whismanoid | 0:68e64068330f | 138 | // CODE GENERATOR: extern function requirement MAX11410::SPIwrite16bits |
whismanoid | 0:68e64068330f | 139 | // SPI write 16 bits |
whismanoid | 0:68e64068330f | 140 | // SPI interface to MAX11410 shift 16 bits mosiData into MAX11410 DIN |
whismanoid | 0:68e64068330f | 141 | // |
whismanoid | 0:68e64068330f | 142 | void MAX11410::SPIwrite16bits(int16_t mosiData16) |
whismanoid | 0:68e64068330f | 143 | { |
whismanoid | 0:68e64068330f | 144 | // CODE GENERATOR: extern function definition for function SPIwrite16bits |
whismanoid | 0:68e64068330f | 145 | // TODO1: CODE GENERATOR: extern function definition for standard SPI interface function SPIwrite16bits(int16_t mosiData16) |
whismanoid | 0:68e64068330f | 146 | size_t byteCount = 2; |
whismanoid | 0:68e64068330f | 147 | static char mosiData[2]; |
whismanoid | 0:68e64068330f | 148 | static char misoData[2]; |
whismanoid | 0:68e64068330f | 149 | mosiData[0] = (char)((mosiData16 >> 8) & 0xFF); // MSByte |
whismanoid | 0:68e64068330f | 150 | mosiData[1] = (char)((mosiData16 >> 0) & 0xFF); // LSByte |
whismanoid | 0:68e64068330f | 151 | // |
whismanoid | 0:68e64068330f | 152 | // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() |
whismanoid | 0:68e64068330f | 153 | //~ noInterrupts(); |
whismanoid | 0:68e64068330f | 154 | // |
whismanoid | 0:68e64068330f | 155 | //~ digitalWrite(Scope_Trigger_Pin, LOW); // diagnostic Scope_Trigger_Pin |
whismanoid | 0:68e64068330f | 156 | // |
whismanoid | 0:68e64068330f | 157 | unsigned int numBytesTransferred = m_spi.write(mosiData, byteCount, misoData, byteCount); |
whismanoid | 0:68e64068330f | 158 | //~ m_spi.transfer(mosiData8_FF0000); |
whismanoid | 0:68e64068330f | 159 | //~ m_spi.transfer(mosiData16_00FF00); |
whismanoid | 0:68e64068330f | 160 | //~ m_spi.transfer(mosiData16_0000FF); |
whismanoid | 0:68e64068330f | 161 | // |
whismanoid | 0:68e64068330f | 162 | //~ digitalWrite(Scope_Trigger_Pin, HIGH); // diagnostic Scope_Trigger_Pin |
whismanoid | 0:68e64068330f | 163 | // |
whismanoid | 0:68e64068330f | 164 | // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() |
whismanoid | 0:68e64068330f | 165 | //~ interrupts(); |
whismanoid | 0:68e64068330f | 166 | // Optional Diagnostic function to print SPI transactions |
whismanoid | 0:68e64068330f | 167 | if (onSPIprint) |
whismanoid | 0:68e64068330f | 168 | { |
whismanoid | 0:68e64068330f | 169 | onSPIprint(byteCount, (uint8_t*)mosiData, (uint8_t*)misoData); |
whismanoid | 0:68e64068330f | 170 | } |
whismanoid | 0:68e64068330f | 171 | // |
whismanoid | 0:68e64068330f | 172 | // VERIFY: SPIwrite24bits print diagnostic information |
whismanoid | 0:68e64068330f | 173 | //cmdLine.serial().printf(" MOSI->")); |
whismanoid | 0:68e64068330f | 174 | //cmdLine.serial().printf(" 0x")); |
whismanoid | 0:68e64068330f | 175 | //Serial.print( (mosiData8_FF0000 & 0xFF), HEX); |
whismanoid | 0:68e64068330f | 176 | //cmdLine.serial().printf(" 0x")); |
whismanoid | 0:68e64068330f | 177 | //Serial.print( (mosiData16_00FF00 & 0xFF), HEX); |
whismanoid | 0:68e64068330f | 178 | //cmdLine.serial().printf(" 0x")); |
whismanoid | 0:68e64068330f | 179 | //Serial.print( (mosiData16_0000FF & 0xFF), HEX); |
whismanoid | 0:68e64068330f | 180 | // hex dump mosiData[0..byteCount-1] |
whismanoid | 0:68e64068330f | 181 | #if 0 // HAS_MICROUSBSERIAL |
whismanoid | 0:68e64068330f | 182 | cmdLine_microUSBserial.serial().printf("\r\nSPI"); |
whismanoid | 0:68e64068330f | 183 | if (byteCount > 7) { |
whismanoid | 0:68e64068330f | 184 | cmdLine_microUSBserial.serial().printf(" byteCount:%d", byteCount); |
whismanoid | 0:68e64068330f | 185 | } |
whismanoid | 0:68e64068330f | 186 | cmdLine_microUSBserial.serial().printf(" MOSI->"); |
whismanoid | 0:68e64068330f | 187 | for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) |
whismanoid | 0:68e64068330f | 188 | { |
whismanoid | 0:68e64068330f | 189 | cmdLine_microUSBserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); |
whismanoid | 0:68e64068330f | 190 | } |
whismanoid | 0:68e64068330f | 191 | // hex dump misoData[0..byteCount-1] |
whismanoid | 25:c4be3afbfafd | 192 | cmdLine_microUSBserial.serial().printf(" MISO<-"); |
whismanoid | 0:68e64068330f | 193 | for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) |
whismanoid | 0:68e64068330f | 194 | { |
whismanoid | 0:68e64068330f | 195 | cmdLine_microUSBserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); |
whismanoid | 0:68e64068330f | 196 | } |
whismanoid | 0:68e64068330f | 197 | cmdLine_microUSBserial.serial().printf(" "); |
whismanoid | 0:68e64068330f | 198 | #endif |
whismanoid | 0:68e64068330f | 199 | #if 0 // HAS_DAPLINK_SERIAL |
whismanoid | 0:68e64068330f | 200 | cmdLine_DAPLINKserial.serial().printf("\r\nSPI"); |
whismanoid | 0:68e64068330f | 201 | if (byteCount > 7) { |
whismanoid | 0:68e64068330f | 202 | cmdLine_DAPLINKserial.serial().printf(" byteCount:%d", byteCount); |
whismanoid | 0:68e64068330f | 203 | } |
whismanoid | 0:68e64068330f | 204 | cmdLine_DAPLINKserial.serial().printf(" MOSI->"); |
whismanoid | 0:68e64068330f | 205 | for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) |
whismanoid | 0:68e64068330f | 206 | { |
whismanoid | 0:68e64068330f | 207 | cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); |
whismanoid | 0:68e64068330f | 208 | } |
whismanoid | 0:68e64068330f | 209 | // hex dump misoData[0..byteCount-1] |
whismanoid | 25:c4be3afbfafd | 210 | cmdLine_DAPLINKserial.serial().printf(" MISO<-"); |
whismanoid | 0:68e64068330f | 211 | for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) |
whismanoid | 0:68e64068330f | 212 | { |
whismanoid | 0:68e64068330f | 213 | cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); |
whismanoid | 0:68e64068330f | 214 | } |
whismanoid | 0:68e64068330f | 215 | cmdLine_DAPLINKserial.serial().printf(" "); |
whismanoid | 0:68e64068330f | 216 | #endif |
whismanoid | 0:68e64068330f | 217 | // VERIFY: DIAGNOSTIC: print MAX5715 device register write |
whismanoid | 0:68e64068330f | 218 | // TODO: MAX5715_print_register_verbose(mosiData8_FF0000, mosiData16_00FFFF); |
whismanoid | 0:68e64068330f | 219 | // TODO: print_verbose_SPI_diagnostic(mosiData16_FF00, mosiData16_00FF, misoData16_FF00, misoData16_00FF); |
whismanoid | 0:68e64068330f | 220 | // |
whismanoid | 0:68e64068330f | 221 | // int misoData16 = (misoData16_FF00 << 8) | misoData16_00FF; |
whismanoid | 0:68e64068330f | 222 | // return misoData16; |
whismanoid | 0:68e64068330f | 223 | } |
whismanoid | 0:68e64068330f | 224 | |
whismanoid | 0:68e64068330f | 225 | // CODE GENERATOR: extern function requirement MAX11410::SPIreadWrite16bits |
whismanoid | 0:68e64068330f | 226 | // SPI read and write 16 bits |
whismanoid | 0:68e64068330f | 227 | // SPI interface to MAX11410 shift 16 bits mosiData16 into MAX11410 DIN |
whismanoid | 0:68e64068330f | 228 | // while simultaneously capturing 16 bits miso data from MAX11410 DOUT |
whismanoid | 0:68e64068330f | 229 | // |
whismanoid | 0:68e64068330f | 230 | int16_t MAX11410::SPIreadWrite16bits(int16_t mosiData16) |
whismanoid | 0:68e64068330f | 231 | { |
whismanoid | 0:68e64068330f | 232 | // CODE GENERATOR: extern function definition for function SPIreadWrite16bits |
whismanoid | 0:68e64068330f | 233 | // TODO1: CODE GENERATOR: extern function definition for standard SPI interface function SPIreadWrite16bits(int16_t mosiData16) |
whismanoid | 0:68e64068330f | 234 | size_t byteCount = 2; |
whismanoid | 0:68e64068330f | 235 | static char mosiData[2]; |
whismanoid | 0:68e64068330f | 236 | static char misoData[2]; |
whismanoid | 0:68e64068330f | 237 | mosiData[0] = (char)((mosiData16 >> 8) & 0xFF); // MSByte |
whismanoid | 0:68e64068330f | 238 | mosiData[1] = (char)((mosiData16 >> 0) & 0xFF); // LSByte |
whismanoid | 0:68e64068330f | 239 | // |
whismanoid | 0:68e64068330f | 240 | // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() |
whismanoid | 0:68e64068330f | 241 | //~ noInterrupts(); |
whismanoid | 0:68e64068330f | 242 | // |
whismanoid | 0:68e64068330f | 243 | //~ digitalWrite(Scope_Trigger_Pin, LOW); // diagnostic Scope_Trigger_Pin |
whismanoid | 0:68e64068330f | 244 | // |
whismanoid | 0:68e64068330f | 245 | unsigned int numBytesTransferred = m_spi.write(mosiData, byteCount, misoData, byteCount); |
whismanoid | 0:68e64068330f | 246 | //~ m_spi.transfer(mosiData8_FF0000); |
whismanoid | 0:68e64068330f | 247 | //~ m_spi.transfer(mosiData16_00FF00); |
whismanoid | 0:68e64068330f | 248 | //~ m_spi.transfer(mosiData16_0000FF); |
whismanoid | 0:68e64068330f | 249 | // |
whismanoid | 0:68e64068330f | 250 | //~ digitalWrite(Scope_Trigger_Pin, HIGH); // diagnostic Scope_Trigger_Pin |
whismanoid | 0:68e64068330f | 251 | // |
whismanoid | 0:68e64068330f | 252 | // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() |
whismanoid | 0:68e64068330f | 253 | //~ interrupts(); |
whismanoid | 0:68e64068330f | 254 | // Optional Diagnostic function to print SPI transactions |
whismanoid | 0:68e64068330f | 255 | if (onSPIprint) |
whismanoid | 0:68e64068330f | 256 | { |
whismanoid | 0:68e64068330f | 257 | onSPIprint(byteCount, (uint8_t*)mosiData, (uint8_t*)misoData); |
whismanoid | 0:68e64068330f | 258 | } |
whismanoid | 0:68e64068330f | 259 | // |
whismanoid | 0:68e64068330f | 260 | // VERIFY: SPIwrite24bits print diagnostic information |
whismanoid | 0:68e64068330f | 261 | //cmdLine.serial().printf(" MOSI->")); |
whismanoid | 0:68e64068330f | 262 | //cmdLine.serial().printf(" 0x")); |
whismanoid | 0:68e64068330f | 263 | //Serial.print( (mosiData8_FF0000 & 0xFF), HEX); |
whismanoid | 0:68e64068330f | 264 | //cmdLine.serial().printf(" 0x")); |
whismanoid | 0:68e64068330f | 265 | //Serial.print( (mosiData16_00FF00 & 0xFF), HEX); |
whismanoid | 0:68e64068330f | 266 | //cmdLine.serial().printf(" 0x")); |
whismanoid | 0:68e64068330f | 267 | //Serial.print( (mosiData16_0000FF & 0xFF), HEX); |
whismanoid | 0:68e64068330f | 268 | // hex dump mosiData[0..byteCount-1] |
whismanoid | 0:68e64068330f | 269 | #if 0 // HAS_MICROUSBSERIAL |
whismanoid | 0:68e64068330f | 270 | cmdLine_microUSBserial.serial().printf("\r\nSPI"); |
whismanoid | 0:68e64068330f | 271 | if (byteCount > 7) { |
whismanoid | 0:68e64068330f | 272 | cmdLine_microUSBserial.serial().printf(" byteCount:%d", byteCount); |
whismanoid | 0:68e64068330f | 273 | } |
whismanoid | 0:68e64068330f | 274 | cmdLine_microUSBserial.serial().printf(" MOSI->"); |
whismanoid | 0:68e64068330f | 275 | for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) |
whismanoid | 0:68e64068330f | 276 | { |
whismanoid | 0:68e64068330f | 277 | cmdLine_microUSBserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); |
whismanoid | 0:68e64068330f | 278 | } |
whismanoid | 0:68e64068330f | 279 | // hex dump misoData[0..byteCount-1] |
whismanoid | 25:c4be3afbfafd | 280 | cmdLine_microUSBserial.serial().printf(" MISO<-"); |
whismanoid | 0:68e64068330f | 281 | for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) |
whismanoid | 0:68e64068330f | 282 | { |
whismanoid | 0:68e64068330f | 283 | cmdLine_microUSBserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); |
whismanoid | 0:68e64068330f | 284 | } |
whismanoid | 0:68e64068330f | 285 | cmdLine_microUSBserial.serial().printf(" "); |
whismanoid | 0:68e64068330f | 286 | #endif |
whismanoid | 0:68e64068330f | 287 | #if 0 // HAS_DAPLINK_SERIAL |
whismanoid | 0:68e64068330f | 288 | cmdLine_DAPLINKserial.serial().printf("\r\nSPI"); |
whismanoid | 0:68e64068330f | 289 | if (byteCount > 7) { |
whismanoid | 0:68e64068330f | 290 | cmdLine_DAPLINKserial.serial().printf(" byteCount:%d", byteCount); |
whismanoid | 0:68e64068330f | 291 | } |
whismanoid | 0:68e64068330f | 292 | cmdLine_DAPLINKserial.serial().printf(" MOSI->"); |
whismanoid | 0:68e64068330f | 293 | for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) |
whismanoid | 0:68e64068330f | 294 | { |
whismanoid | 0:68e64068330f | 295 | cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); |
whismanoid | 0:68e64068330f | 296 | } |
whismanoid | 0:68e64068330f | 297 | // hex dump misoData[0..byteCount-1] |
whismanoid | 25:c4be3afbfafd | 298 | cmdLine_DAPLINKserial.serial().printf(" MISO<-"); |
whismanoid | 0:68e64068330f | 299 | for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) |
whismanoid | 0:68e64068330f | 300 | { |
whismanoid | 0:68e64068330f | 301 | cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); |
whismanoid | 0:68e64068330f | 302 | } |
whismanoid | 0:68e64068330f | 303 | cmdLine_DAPLINKserial.serial().printf(" "); |
whismanoid | 0:68e64068330f | 304 | #endif |
whismanoid | 0:68e64068330f | 305 | // VERIFY: DIAGNOSTIC: print MAX5715 device register write |
whismanoid | 0:68e64068330f | 306 | // TODO: MAX5715_print_register_verbose(mosiData8_FF0000, mosiData16_00FFFF); |
whismanoid | 0:68e64068330f | 307 | // TODO: print_verbose_SPI_diagnostic(mosiData16_FF00, mosiData16_00FF, misoData16_FF00, misoData16_00FF); |
whismanoid | 0:68e64068330f | 308 | // |
whismanoid | 0:68e64068330f | 309 | //int misoData16 = (misoData16_FF00 << 8) | misoData16_00FF; |
whismanoid | 0:68e64068330f | 310 | int misoData16 = (misoData[0] << 8) | misoData[1]; |
whismanoid | 0:68e64068330f | 311 | return misoData16; |
whismanoid | 0:68e64068330f | 312 | } |
whismanoid | 0:68e64068330f | 313 | |
whismanoid | 0:68e64068330f | 314 | // CODE GENERATOR: extern function requirement MAX11410::SPIreadWrite32bits |
whismanoid | 0:68e64068330f | 315 | // SPI read and write 32 bits |
whismanoid | 0:68e64068330f | 316 | // SPI interface to MAX11410 shift 32 bits mosiData into MAX11410 DIN |
whismanoid | 0:68e64068330f | 317 | // while simultaneously capturing 32 bits miso data from MAX11410 DOUT |
whismanoid | 0:68e64068330f | 318 | // |
whismanoid | 0:68e64068330f | 319 | int32_t MAX11410::SPIreadWrite32bits(int32_t mosiData32) |
whismanoid | 0:68e64068330f | 320 | { |
whismanoid | 0:68e64068330f | 321 | // CODE GENERATOR: extern function definition for function SPIreadWrite32bits |
whismanoid | 0:68e64068330f | 322 | // TODO1: CODE GENERATOR: extern function definition for standard SPI interface function SPIreadWrite32bits(int32_t mosiData32) |
whismanoid | 0:68e64068330f | 323 | size_t byteCount = 4; |
whismanoid | 0:68e64068330f | 324 | static char mosiData[4]; |
whismanoid | 0:68e64068330f | 325 | static char misoData[4]; |
whismanoid | 0:68e64068330f | 326 | mosiData[0] = (char)((mosiData32 >> 24) & 0xFF); // MSByte |
whismanoid | 0:68e64068330f | 327 | mosiData[1] = (char)((mosiData32 >> 16) & 0xFF); |
whismanoid | 0:68e64068330f | 328 | mosiData[2] = (char)((mosiData32 >> 8) & 0xFF); |
whismanoid | 0:68e64068330f | 329 | mosiData[3] = (char)((mosiData32 >> 0) & 0xFF); // LSByte |
whismanoid | 0:68e64068330f | 330 | // |
whismanoid | 0:68e64068330f | 331 | // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() |
whismanoid | 0:68e64068330f | 332 | //~ noInterrupts(); |
whismanoid | 0:68e64068330f | 333 | // |
whismanoid | 0:68e64068330f | 334 | //~ digitalWrite(Scope_Trigger_Pin, LOW); // diagnostic Scope_Trigger_Pin |
whismanoid | 0:68e64068330f | 335 | // |
whismanoid | 0:68e64068330f | 336 | unsigned int numBytesTransferred = m_spi.write(mosiData, byteCount, misoData, byteCount); |
whismanoid | 0:68e64068330f | 337 | //~ m_spi.transfer(mosiData8_FF0000); |
whismanoid | 0:68e64068330f | 338 | //~ m_spi.transfer(mosiData16_00FF00); |
whismanoid | 0:68e64068330f | 339 | //~ m_spi.transfer(mosiData16_0000FF); |
whismanoid | 0:68e64068330f | 340 | // |
whismanoid | 0:68e64068330f | 341 | //~ digitalWrite(Scope_Trigger_Pin, HIGH); // diagnostic Scope_Trigger_Pin |
whismanoid | 0:68e64068330f | 342 | // |
whismanoid | 0:68e64068330f | 343 | // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() |
whismanoid | 0:68e64068330f | 344 | //~ interrupts(); |
whismanoid | 0:68e64068330f | 345 | // Optional Diagnostic function to print SPI transactions |
whismanoid | 0:68e64068330f | 346 | if (onSPIprint) |
whismanoid | 0:68e64068330f | 347 | { |
whismanoid | 0:68e64068330f | 348 | onSPIprint(byteCount, (uint8_t*)mosiData, (uint8_t*)misoData); |
whismanoid | 0:68e64068330f | 349 | } |
whismanoid | 0:68e64068330f | 350 | // |
whismanoid | 0:68e64068330f | 351 | // VERIFY: SPIwrite24bits print diagnostic information |
whismanoid | 0:68e64068330f | 352 | //cmdLine.serial().printf(" MOSI->")); |
whismanoid | 0:68e64068330f | 353 | //cmdLine.serial().printf(" 0x")); |
whismanoid | 0:68e64068330f | 354 | //Serial.print( (mosiData8_FF0000 & 0xFF), HEX); |
whismanoid | 0:68e64068330f | 355 | //cmdLine.serial().printf(" 0x")); |
whismanoid | 0:68e64068330f | 356 | //Serial.print( (mosiData16_00FF00 & 0xFF), HEX); |
whismanoid | 0:68e64068330f | 357 | //cmdLine.serial().printf(" 0x")); |
whismanoid | 0:68e64068330f | 358 | //Serial.print( (mosiData16_0000FF & 0xFF), HEX); |
whismanoid | 0:68e64068330f | 359 | // hex dump mosiData[0..byteCount-1] |
whismanoid | 0:68e64068330f | 360 | #if 0 // HAS_MICROUSBSERIAL |
whismanoid | 0:68e64068330f | 361 | cmdLine_microUSBserial.serial().printf("\r\nSPI"); |
whismanoid | 0:68e64068330f | 362 | if (byteCount > 7) { |
whismanoid | 0:68e64068330f | 363 | cmdLine_microUSBserial.serial().printf(" byteCount:%d", byteCount); |
whismanoid | 0:68e64068330f | 364 | } |
whismanoid | 0:68e64068330f | 365 | cmdLine_microUSBserial.serial().printf(" MOSI->"); |
whismanoid | 0:68e64068330f | 366 | for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) |
whismanoid | 0:68e64068330f | 367 | { |
whismanoid | 0:68e64068330f | 368 | cmdLine_microUSBserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); |
whismanoid | 0:68e64068330f | 369 | } |
whismanoid | 0:68e64068330f | 370 | // hex dump misoData[0..byteCount-1] |
whismanoid | 25:c4be3afbfafd | 371 | cmdLine_microUSBserial.serial().printf(" MISO<-"); |
whismanoid | 0:68e64068330f | 372 | for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) |
whismanoid | 0:68e64068330f | 373 | { |
whismanoid | 0:68e64068330f | 374 | cmdLine_microUSBserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); |
whismanoid | 0:68e64068330f | 375 | } |
whismanoid | 0:68e64068330f | 376 | cmdLine_microUSBserial.serial().printf(" "); |
whismanoid | 0:68e64068330f | 377 | #endif |
whismanoid | 0:68e64068330f | 378 | #if 0 // HAS_DAPLINK_SERIAL |
whismanoid | 0:68e64068330f | 379 | cmdLine_DAPLINKserial.serial().printf("\r\nSPI"); |
whismanoid | 0:68e64068330f | 380 | if (byteCount > 7) { |
whismanoid | 0:68e64068330f | 381 | cmdLine_DAPLINKserial.serial().printf(" byteCount:%d", byteCount); |
whismanoid | 0:68e64068330f | 382 | } |
whismanoid | 0:68e64068330f | 383 | cmdLine_DAPLINKserial.serial().printf(" MOSI->"); |
whismanoid | 0:68e64068330f | 384 | for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) |
whismanoid | 0:68e64068330f | 385 | { |
whismanoid | 0:68e64068330f | 386 | cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); |
whismanoid | 0:68e64068330f | 387 | } |
whismanoid | 0:68e64068330f | 388 | // hex dump misoData[0..byteCount-1] |
whismanoid | 25:c4be3afbfafd | 389 | cmdLine_DAPLINKserial.serial().printf(" MISO<-"); |
whismanoid | 0:68e64068330f | 390 | for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) |
whismanoid | 0:68e64068330f | 391 | { |
whismanoid | 0:68e64068330f | 392 | cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); |
whismanoid | 0:68e64068330f | 393 | } |
whismanoid | 0:68e64068330f | 394 | cmdLine_DAPLINKserial.serial().printf(" "); |
whismanoid | 0:68e64068330f | 395 | #endif |
whismanoid | 0:68e64068330f | 396 | // VERIFY: DIAGNOSTIC: print MAX5715 device register write |
whismanoid | 0:68e64068330f | 397 | // TODO: MAX5715_print_register_verbose(mosiData8_FF0000, mosiData16_00FFFF); |
whismanoid | 0:68e64068330f | 398 | // TODO: print_verbose_SPI_diagnostic(mosiData16_FF00, mosiData16_00FF, misoData16_FF00, misoData16_00FF); |
whismanoid | 0:68e64068330f | 399 | // |
whismanoid | 0:68e64068330f | 400 | //int misoData32 = (misoData32_FF000000 << 24) | (misoData32_FF0000 << 16) | (misoData32_0000FF00 << 8) | misoData32_000000FF; |
whismanoid | 0:68e64068330f | 401 | int misoData32 = (misoData[0] << 24) | (misoData[1] << 16) | (misoData[2] << 8) | misoData[3]; |
whismanoid | 0:68e64068330f | 402 | return misoData32; |
whismanoid | 0:68e64068330f | 403 | } |
whismanoid | 0:68e64068330f | 404 | |
whismanoid | 0:68e64068330f | 405 | // CODE GENERATOR: class member function definitions |
whismanoid | 0:68e64068330f | 406 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 407 | // Menu item '!' |
whismanoid | 0:68e64068330f | 408 | // Initialize device |
whismanoid | 19:50cf5da53d36 | 409 | // |
whismanoid | 19:50cf5da53d36 | 410 | // TODO1: #169 MAX11410 Self Test for Test Fixture Firmware |
whismanoid | 19:50cf5da53d36 | 411 | // @test Init() expect 1 |
whismanoid | 19:50cf5da53d36 | 412 | // |
whismanoid | 19:50cf5da53d36 | 413 | // @future test xxxxxx // comment |
whismanoid | 19:50cf5da53d36 | 414 | // |
whismanoid | 19:50cf5da53d36 | 415 | // TODO1: #169 SelfTest support RegRead |
whismanoid | 22:c6812214a933 | 416 | // @test group POR // verify initial register values (enabled by default) |
whismanoid | 20:fb7527415308 | 417 | // @future test tinyTester.print("PART_ID value") |
whismanoid | 22:c6812214a933 | 418 | // @test group POR RegRead(MAX11410::CMD_r001_0001_xxxx_xxxx_xxxx_xxxx_xxxx_xddd_PART_ID, buffer) expect 1 expect-buffer 0x000F02 |
whismanoid | 20:fb7527415308 | 419 | // |
whismanoid | 20:fb7527415308 | 420 | // @future test tinyTester.print("POR value 0x04 CMD_r000_0100_dddd_xddd_GP0_CTRL") |
whismanoid | 22:c6812214a933 | 421 | // @test group POR RegRead(MAX11410::CMD_r000_0100_dddd_xddd_GP0_CTRL, buffer) expect 1 expect-buffer 0x00 |
whismanoid | 20:fb7527415308 | 422 | // |
whismanoid | 20:fb7527415308 | 423 | // @future test tinyTester.print("POR value 0x05 CMD_r000_0101_dddd_xddd_GP1_CTRL") |
whismanoid | 22:c6812214a933 | 424 | // @test group POR RegRead(MAX11410::CMD_r000_0101_dddd_xddd_GP1_CTRL, buffer) expect 1 expect-buffer 0x00 |
whismanoid | 20:fb7527415308 | 425 | // |
whismanoid | 20:fb7527415308 | 426 | // @future test tinyTester.print("POR value 0x07 CMD_r000_0111_xddd_dddd_GP_SEQ_ADDR") |
whismanoid | 22:c6812214a933 | 427 | // @test group POR RegRead(MAX11410::CMD_r000_0111_xddd_dddd_GP_SEQ_ADDR, buffer) expect 1 expect-buffer 0x00003a |
whismanoid | 19:50cf5da53d36 | 428 | // |
whismanoid | 19:50cf5da53d36 | 429 | // TODO1: #169 SelfTest support RegWrite and custom enum types |
whismanoid | 20:fb7527415308 | 430 | // @future test tinyTester.print("POR value 0x08 CMD_r000_1000_x0dd_dddd_FILTER") |
whismanoid | 22:c6812214a933 | 431 | // @test group POR RegRead(MAX11410::CMD_r000_1000_x0dd_dddd_FILTER, buffer) expect 1 expect-buffer 0x00 |
whismanoid | 20:fb7527415308 | 432 | // could also be stated as RegRead(0x08, buffer) expect 1 expect-buffer 0x00 |
whismanoid | 20:fb7527415308 | 433 | // |
whismanoid | 20:fb7527415308 | 434 | // @future test tinyTester.print("POR value 0x09 CMD_r000_1001_dddd_dddd_CTRL") |
whismanoid | 22:c6812214a933 | 435 | // @test group POR RegRead(MAX11410::CMD_r000_1001_dddd_dddd_CTRL, buffer) expect 1 expect-buffer 0x000001 |
whismanoid | 20:fb7527415308 | 436 | // |
whismanoid | 20:fb7527415308 | 437 | // @future test tinyTester.print("POR value 0x0a CMD_r000_1010_dddd_dddd_SOURCE") |
whismanoid | 22:c6812214a933 | 438 | // @test group POR RegRead(MAX11410::CMD_r000_1010_dddd_dddd_SOURCE, buffer) expect 1 expect-buffer 0x00 |
whismanoid | 20:fb7527415308 | 439 | // |
whismanoid | 20:fb7527415308 | 440 | // @future test tinyTester.print("POR value 0x0b CMD_r000_1011_dddd_dddd_MUX_CTRL0") |
whismanoid | 22:c6812214a933 | 441 | // @test group POR RegRead(MAX11410::CMD_r000_1011_dddd_dddd_MUX_CTRL0, buffer) expect 1 expect-buffer 0x0000ff |
whismanoid | 20:fb7527415308 | 442 | // |
whismanoid | 20:fb7527415308 | 443 | // @future test tinyTester.print("POR value 0x0c CMD_r000_1100_dddd_dddd_MUX_CTRL1") |
whismanoid | 22:c6812214a933 | 444 | // @test group POR RegRead(MAX11410::CMD_r000_1100_dddd_dddd_MUX_CTRL1, buffer) expect 1 expect-buffer 0x0000ff |
whismanoid | 20:fb7527415308 | 445 | // |
whismanoid | 20:fb7527415308 | 446 | // @future test tinyTester.print("POR value 0x0d CMD_r000_1101_dddd_dddd_MUX_CTRL2") |
whismanoid | 22:c6812214a933 | 447 | // @test group POR RegRead(MAX11410::CMD_r000_1101_dddd_dddd_MUX_CTRL2, buffer) expect 1 expect-buffer 0x00 |
whismanoid | 20:fb7527415308 | 448 | // |
whismanoid | 23:22e7830bcccb | 449 | // @future test tinyTester.print("POR value 0x0e CMD_r000_1110_00ss_0ggg_PGA") |
whismanoid | 23:22e7830bcccb | 450 | // @test group POR RegRead(MAX11410::CMD_r000_1110_00ss_0ggg_PGA, buffer) expect 1 expect-buffer 0x00 |
whismanoid | 20:fb7527415308 | 451 | // |
whismanoid | 20:fb7527415308 | 452 | // @future test CMD_r000_1111_dddd_dddd_WAIT_EXT = 0x0f, //!< 0b0001111 |
whismanoid | 20:fb7527415308 | 453 | // @future test CMD_r001_0000_xxxx_xxxx_WAIT_START = 0x10, //!< 0b0010000 |
whismanoid | 20:fb7527415308 | 454 | // |
whismanoid | 22:c6812214a933 | 455 | // @test group RES1KA0A1TOGND // measure a 1kohm resistor between (AIN0,AIN1) and AGND to verify ref2_v (disabled by default) |
whismanoid | 22:c6812214a933 | 456 | // @test group RES1KA0A1TOGNDMORE // measure a 1kohm resistor between (AIN0,AIN1) and AGND to verify ref2_v in more detail |
whismanoid | 22:c6812214a933 | 457 | // @test group RES1KA0A1TOGNDMORE tinyTester.print("measure a 1kohm resistor between (AIN0,AIN1) and AGND to verify ref2_v") |
whismanoid | 22:c6812214a933 | 458 | // @test group RES1KA0A1TOGND tinyTester.settle_time_msec = 1000 // default 250 |
whismanoid | 22:c6812214a933 | 459 | // @test group RES1KA0A1TOGND RegWrite(0x0C, 0xF1) expect 1 // *mux_ctrl1=0xf1 drives current source from AIN1 |
whismanoid | 22:c6812214a933 | 460 | // |
whismanoid | 22:c6812214a933 | 461 | // @test group RES1KA0A1TOGNDMORE RegWrite(0x0A, 0x03) expect 1 // *source=0x03 idac_mode=100uA, 1k resistor 0.1V |
whismanoid | 22:c6812214a933 | 462 | // @test group RES1KA0A1TOGNDMORE tinyTester.print("idac_mode=100uA, 1k resistor 0.1V") |
whismanoid | 22:c6812214a933 | 463 | // @test group RES1KA0A1TOGNDMORE tinyTester.Wait_Output_Settling() |
whismanoid | 22:c6812214a933 | 464 | // @test group RES1KA0A1TOGNDMORE Measure_Voltage(0,10) expect 0.1 |
whismanoid | 22:c6812214a933 | 465 | // @test group RES1KA0A1TOGNDMORE AINcode[0] expect (uint32_t)337731 within 33773 // idac_mode=100uA, 1k resistor 0.1V |
whismanoid | 22:c6812214a933 | 466 | // |
whismanoid | 22:c6812214a933 | 467 | // @test group RES1KA0A1TOGNDMORE RegWrite(0x0A, 0x0D) expect 1 // *source=0x0d idac_mode=800uA, 1k resistor 0.8V |
whismanoid | 22:c6812214a933 | 468 | // @test group RES1KA0A1TOGNDMORE tinyTester.print("idac_mode=800uA, 1k resistor 0.8V") |
whismanoid | 22:c6812214a933 | 469 | // @test group RES1KA0A1TOGNDMORE tinyTester.Wait_Output_Settling() |
whismanoid | 22:c6812214a933 | 470 | // @test group RES1KA0A1TOGNDMORE Measure_Voltage(0,10) expect 0.8 |
whismanoid | 22:c6812214a933 | 471 | // @test group RES1KA0A1TOGNDMORE AINcode[0] expect (uint32_t)2724467 within 33773 // idac_mode=800uA, 1k resistor 0.8V |
whismanoid | 22:c6812214a933 | 472 | // |
whismanoid | 22:c6812214a933 | 473 | // @test group RES1KA0A1TOGND RegWrite(0x0A, 0x0B) expect 1 // *source=0x0b idac_mode=400uA, 1k resistor 0.4V |
whismanoid | 22:c6812214a933 | 474 | // @test group RES1KA0A1TOGNDMORE tinyTester.print("idac_mode=400uA, 1k resistor 0.4V") |
whismanoid | 22:c6812214a933 | 475 | // @test group RES1KA0A1TOGND tinyTester.Wait_Output_Settling() |
whismanoid | 22:c6812214a933 | 476 | // @test group RES1KA0A1TOGND Measure_Voltage(0,10) expect 0.4 |
whismanoid | 22:c6812214a933 | 477 | // @test group RES1KA0A1TOGNDMORE AINcode[0] expect (uint32_t)1343163 within 33773 // idac_mode=400uA, 1k resistor 0.4V |
whismanoid | 20:fb7527415308 | 478 | // |
whismanoid | 20:fb7527415308 | 479 | // |
whismanoid | 20:fb7527415308 | 480 | // |
whismanoid | 19:50cf5da53d36 | 481 | // @test tinyTester.print("check filter register is writeable") |
whismanoid | 19:50cf5da53d36 | 482 | // @future test tinyTester.print("this is a real mess dealing with the custom types") |
whismanoid | 19:50cf5da53d36 | 483 | // @test RegWrite(0x08, 0x34) expect 1 |
whismanoid | 19:50cf5da53d36 | 484 | // @future test tinyTester.print("error: no matching function for call to 'MaximTinyTester::FunctionCall_Expect(const char [18], uint8_t (&)(MAX11410::CMD_enum_t, uint32_t), MAX11410::CMD_enum_t, uint32_t, int)'") |
whismanoid | 19:50cf5da53d36 | 485 | // @future test RegWrite(CMD_r000_1000_x0dd_dddd_FILTER, 0x34) expect 1 |
whismanoid | 19:50cf5da53d36 | 486 | // @future test RegWrite(CMD_enum_t::CMD_r000_1000_x0dd_dddd_FILTER, 0x34) expect 1 |
whismanoid | 19:50cf5da53d36 | 487 | // @future test RegWrite(MAX11410::CMD_enum_t::CMD_r000_1000_x0dd_dddd_FILTER, 0x34) expect 1 |
whismanoid | 19:50cf5da53d36 | 488 | // |
whismanoid | 19:50cf5da53d36 | 489 | // TODO1: #169 SelfTest support RegRead |
whismanoid | 19:50cf5da53d36 | 490 | // @test tinyTester.print("check filter register is readable") |
whismanoid | 19:50cf5da53d36 | 491 | // @test RegRead(0x08, buffer) expect 1 expect-buffer 0x34 |
whismanoid | 19:50cf5da53d36 | 492 | // @future test RegRead(MAX11410::CMD_enum_t::CMD_r000_1000_x0dd_dddd_FILTER, &buffer) expect 1 expect-buffer 0x34 |
whismanoid | 19:50cf5da53d36 | 493 | // |
whismanoid | 19:50cf5da53d36 | 494 | // @test tinyTester.settle_time_msec = 250 // default 250 |
whismanoid | 19:50cf5da53d36 | 495 | // @test tinyTester.blink_time_msec = 75 // default 75 resume hardware self test |
whismanoid | 19:50cf5da53d36 | 496 | // @test tinyTester.input_timeout_time_msec = 250 // default 250 |
whismanoid | 19:50cf5da53d36 | 497 | // @test tinyTester.settle_time_msec = 20 // default 250 |
whismanoid | 19:50cf5da53d36 | 498 | // @test tinyTester.blink_time_msec = 20 // quickly speed through the software verification |
whismanoid | 19:50cf5da53d36 | 499 | // @test tinyTester.input_timeout_time_msec = 100 // default 250 |
whismanoid | 19:50cf5da53d36 | 500 | // |
whismanoid | 19:50cf5da53d36 | 501 | // @test tinyTester.Wait_Output_Settling() |
whismanoid | 19:50cf5da53d36 | 502 | // |
whismanoid | 19:50cf5da53d36 | 503 | // @future test tinyTester.DigitalIn_Read_Expect_WarnOnly(DigitalIn& digitalInPin, const char* pinName, int expect_result, const char *expect_description) |
whismanoid | 19:50cf5da53d36 | 504 | // |
whismanoid | 19:50cf5da53d36 | 505 | // TODO1: #169 SelfTest support tinyTester.max541.Set_Code |
whismanoid | 19:50cf5da53d36 | 506 | // @future test tinyTester.max541.Set_Code(0x8000) |
whismanoid | 19:50cf5da53d36 | 507 | // |
whismanoid | 0:68e64068330f | 508 | // @return 1 on success; 0 on failure |
whismanoid | 0:68e64068330f | 509 | uint8_t MAX11410::Init(void) |
whismanoid | 0:68e64068330f | 510 | { |
whismanoid | 0:68e64068330f | 511 | |
whismanoid | 0:68e64068330f | 512 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 513 | // AIN0-AIN1 reference voltage, in Volts |
whismanoid | 22:c6812214a933 | 514 | ref0_v = 2.500; |
whismanoid | 1:d57c1a2cb83c | 515 | |
whismanoid | 1:d57c1a2cb83c | 516 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 517 | // REF1P-REF1N reference resistance, in Ohms |
whismanoid | 22:c6812214a933 | 518 | ref1_v = 4999; |
whismanoid | 1:d57c1a2cb83c | 519 | |
whismanoid | 1:d57c1a2cb83c | 520 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 521 | // REF2P-REF2N reference voltage, in Volts |
whismanoid | 22:c6812214a933 | 522 | ref2_v = 2.500; |
whismanoid | 1:d57c1a2cb83c | 523 | |
whismanoid | 1:d57c1a2cb83c | 524 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 525 | // AVDD-AGND supply voltage, in Volts |
whismanoid | 22:c6812214a933 | 526 | avdd_v = 3.300; |
whismanoid | 1:d57c1a2cb83c | 527 | |
whismanoid | 1:d57c1a2cb83c | 528 | //---------------------------------------- |
whismanoid | 5:a2e74357cfc0 | 529 | // RTD Resistance measurement; Thermocouple Cold Junction, in Ohms |
whismanoid | 22:c6812214a933 | 530 | rtd_ohm = 1000.0; |
whismanoid | 5:a2e74357cfc0 | 531 | |
whismanoid | 5:a2e74357cfc0 | 532 | //---------------------------------------- |
whismanoid | 3:658a93dfb2d8 | 533 | // Temperature calculated from RTD Resistance; Thermocouple Cold Junction, in degrees C |
whismanoid | 22:c6812214a933 | 534 | rtd_degc = 25.0; |
whismanoid | 3:658a93dfb2d8 | 535 | |
whismanoid | 3:658a93dfb2d8 | 536 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 537 | // shadow of register ctrl CMD_r000_1001_dddd_dddd_CTRL |
whismanoid | 1:d57c1a2cb83c | 538 | ctrl = 0x01; |
whismanoid | 1:d57c1a2cb83c | 539 | |
whismanoid | 1:d57c1a2cb83c | 540 | //---------------------------------------- |
whismanoid | 23:22e7830bcccb | 541 | // set by Configure_PGA gain index register pga CMD_r000_1110_00ss_0ggg_PGA |
whismanoid | 9:06ca88952f1c | 542 | pgaGain = 1; |
whismanoid | 9:06ca88952f1c | 543 | |
whismanoid | 9:06ca88952f1c | 544 | //---------------------------------------- |
whismanoid | 21:847b2220e96e | 545 | // When driver polls status of a pin signal or a register status bit, |
whismanoid | 21:847b2220e96e | 546 | // and there is no device physically connected, the driver must |
whismanoid | 21:847b2220e96e | 547 | // be able to halt and report failure if too many tries. Each attempt |
whismanoid | 22:c6812214a933 | 548 | // counts down until loop_limit is reached or exceeded. |
whismanoid | 21:847b2220e96e | 549 | // |
whismanoid | 21:847b2220e96e | 550 | // If driver seems to hang or takes too long to decide that device |
whismanoid | 21:847b2220e96e | 551 | // is not connected, reduce the futility countdown limit value. |
whismanoid | 21:847b2220e96e | 552 | // |
whismanoid | 21:847b2220e96e | 553 | // If driver sometimes works but sometimes intermittently fails to |
whismanoid | 21:847b2220e96e | 554 | // recognize device is attached, increase the futility countdown limit. |
whismanoid | 22:c6812214a933 | 555 | loop_limit = 30; |
whismanoid | 22:c6812214a933 | 556 | |
whismanoid | 22:c6812214a933 | 557 | //---------------------------------------- |
whismanoid | 22:c6812214a933 | 558 | // timing delay after enable RTD bias current in Measure_RTD() |
whismanoid | 22:c6812214a933 | 559 | rtd_ms = 100; |
whismanoid | 21:847b2220e96e | 560 | |
whismanoid | 21:847b2220e96e | 561 | //---------------------------------------- |
whismanoid | 23:22e7830bcccb | 562 | // filter register configuration in Measure_RTD() -- 0x34 LINEF_11_SINC4 RATE_0100 output data rate 60SPS |
whismanoid | 23:22e7830bcccb | 563 | rtd_filter = 0x34; |
whismanoid | 23:22e7830bcccb | 564 | |
whismanoid | 23:22e7830bcccb | 565 | //---------------------------------------- |
whismanoid | 23:22e7830bcccb | 566 | // ctrl register configuration in Measure_RTD() -- 0x40 unipolar, 0x01 REF_SEL_001_REF1P_REF1N |
whismanoid | 23:22e7830bcccb | 567 | rtd_ctrl = 0x41; |
whismanoid | 23:22e7830bcccb | 568 | |
whismanoid | 23:22e7830bcccb | 569 | //---------------------------------------- |
whismanoid | 23:22e7830bcccb | 570 | // source register configuration in Measure_RTD() -- 0x0B IDAC_MODE_1011_400uA |
whismanoid | 23:22e7830bcccb | 571 | rtd_source = 0x0B; |
whismanoid | 23:22e7830bcccb | 572 | |
whismanoid | 23:22e7830bcccb | 573 | //---------------------------------------- |
whismanoid | 23:22e7830bcccb | 574 | // pga register configuration in Measure_RTD() -- 0x21 SIG_PATH_10_PGA GAIN_001_2 |
whismanoid | 23:22e7830bcccb | 575 | rtd_pga = 0x21; |
whismanoid | 23:22e7830bcccb | 576 | |
whismanoid | 23:22e7830bcccb | 577 | //---------------------------------------- |
whismanoid | 21:847b2220e96e | 578 | // list of registers to be read by menu item * with no arguments |
whismanoid | 21:847b2220e96e | 579 | static MAX11410::MAX11410_CMD_enum_t readAllStatusListValues[] = { |
whismanoid | 21:847b2220e96e | 580 | MAX11410::CMD_r000_0000_xxxx_xxdd_PD, |
whismanoid | 21:847b2220e96e | 581 | MAX11410::CMD_r000_0001_xddd_xxdd_CONV_START, |
whismanoid | 21:847b2220e96e | 582 | MAX11410::CMD_r000_0010_xddd_dddd_SEQ_START, |
whismanoid | 21:847b2220e96e | 583 | MAX11410::CMD_r000_0011_xxxx_xddd_CAL_START, |
whismanoid | 21:847b2220e96e | 584 | MAX11410::CMD_r000_0100_dddd_xddd_GP0_CTRL, |
whismanoid | 21:847b2220e96e | 585 | MAX11410::CMD_r000_0101_dddd_xddd_GP1_CTRL, |
whismanoid | 21:847b2220e96e | 586 | MAX11410::CMD_r000_0110_xddd_xxdd_GP_CONV, |
whismanoid | 21:847b2220e96e | 587 | MAX11410::CMD_r000_0111_xddd_dddd_GP_SEQ_ADDR, |
whismanoid | 21:847b2220e96e | 588 | MAX11410::CMD_r000_1000_x0dd_dddd_FILTER, |
whismanoid | 21:847b2220e96e | 589 | MAX11410::CMD_r000_1001_dddd_dddd_CTRL, |
whismanoid | 21:847b2220e96e | 590 | MAX11410::CMD_r000_1010_dddd_dddd_SOURCE, |
whismanoid | 21:847b2220e96e | 591 | MAX11410::CMD_r000_1011_dddd_dddd_MUX_CTRL0, |
whismanoid | 21:847b2220e96e | 592 | MAX11410::CMD_r000_1100_dddd_dddd_MUX_CTRL1, |
whismanoid | 21:847b2220e96e | 593 | MAX11410::CMD_r000_1101_dddd_dddd_MUX_CTRL2, |
whismanoid | 23:22e7830bcccb | 594 | MAX11410::CMD_r000_1110_00ss_0ggg_PGA, |
whismanoid | 21:847b2220e96e | 595 | MAX11410::CMD_r000_1111_dddd_dddd_WAIT_EXT, |
whismanoid | 21:847b2220e96e | 596 | MAX11410::CMD_r001_0000_xxxx_xxxx_WAIT_START, |
whismanoid | 21:847b2220e96e | 597 | }; |
whismanoid | 21:847b2220e96e | 598 | readAllStatusList = readAllStatusListValues; |
whismanoid | 21:847b2220e96e | 599 | |
whismanoid | 21:847b2220e96e | 600 | //---------------------------------------- |
whismanoid | 21:847b2220e96e | 601 | // number of registers to be read by menu item * with no arguments |
whismanoid | 21:847b2220e96e | 602 | readAllStatusListLen = 17; |
whismanoid | 21:847b2220e96e | 603 | |
whismanoid | 21:847b2220e96e | 604 | //---------------------------------------- |
whismanoid | 9:06ca88952f1c | 605 | // Device ID Validation |
whismanoid | 9:06ca88952f1c | 606 | const uint32_t part_id_expect = 0x000F02; |
whismanoid | 9:06ca88952f1c | 607 | uint32_t part_id_readback; |
whismanoid | 9:06ca88952f1c | 608 | RegRead(CMD_r001_0001_xxxx_xxxx_xxxx_xxxx_xxxx_xddd_PART_ID, &part_id_readback); |
whismanoid | 9:06ca88952f1c | 609 | if (part_id_readback != part_id_expect) return 0; |
whismanoid | 9:06ca88952f1c | 610 | |
whismanoid | 9:06ca88952f1c | 611 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 612 | // write8 0x00 PD = 0x03 (Reset Registers; enter Standby mode) |
whismanoid | 1:d57c1a2cb83c | 613 | RegWrite(CMD_r000_0000_xxxx_xxdd_PD, PD_11_Reset); |
whismanoid | 1:d57c1a2cb83c | 614 | |
whismanoid | 1:d57c1a2cb83c | 615 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 616 | // write8 0x00 PD = 0x00 (NOP) |
whismanoid | 1:d57c1a2cb83c | 617 | RegWrite(CMD_r000_0000_xxxx_xxdd_PD, PD_00_Normal); |
whismanoid | 0:68e64068330f | 618 | |
whismanoid | 0:68e64068330f | 619 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 620 | // success |
whismanoid | 0:68e64068330f | 621 | return 1; |
whismanoid | 0:68e64068330f | 622 | } |
whismanoid | 0:68e64068330f | 623 | |
whismanoid | 0:68e64068330f | 624 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 625 | // Return the physical voltage corresponding to conversion result, |
whismanoid | 1:d57c1a2cb83c | 626 | // for unipolar mode. |
whismanoid | 0:68e64068330f | 627 | // Does not perform any offset or gain correction. |
whismanoid | 0:68e64068330f | 628 | // |
whismanoid | 1:d57c1a2cb83c | 629 | // @pre CTRL::U_BN = 1 -- Unipolar mode |
whismanoid | 1:d57c1a2cb83c | 630 | // @pre CTRL::FORMAT = x |
whismanoid | 0:68e64068330f | 631 | // @pre VRef = Voltage of REF input, in Volts |
whismanoid | 0:68e64068330f | 632 | // @param[in] value_u24: raw 24-bit MAX11410 code (right justified). |
whismanoid | 0:68e64068330f | 633 | // @return physical voltage corresponding to MAX11410 code. |
whismanoid | 14:b49eecf7e4d8 | 634 | // |
whismanoid | 21:847b2220e96e | 635 | // @test group UNIPOLAR // Verify function VoltageOfCode_Unipolar |
whismanoid | 21:847b2220e96e | 636 | // @test group UNIPOLAR tinyTester.blink_time_msec = 20 // quickly speed through the software verification |
whismanoid | 21:847b2220e96e | 637 | // @test group UNIPOLAR Configure_CTRL_REF(2) expect 1 // These tests require REF2 = 2.500V |
whismanoid | 21:847b2220e96e | 638 | // @test group UNIPOLAR Configure_PGA(0,0) expect 1 // These tests require PGA gain=1 |
whismanoid | 19:50cf5da53d36 | 639 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0xFFFFFF) expect 2.500 within 0.030 // Full Scale |
whismanoid | 19:50cf5da53d36 | 640 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0xFFFFFE) expect 2.500 // Full Scale |
whismanoid | 19:50cf5da53d36 | 641 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0xCCCCCC) expect 2.000 // Two Volts |
whismanoid | 19:50cf5da53d36 | 642 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0xC00000) expect 1.875 // 75% Scale |
whismanoid | 19:50cf5da53d36 | 643 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0x800000) expect 1.250 // Mid Scale |
whismanoid | 19:50cf5da53d36 | 644 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0x666666) expect 1.000 // One Volt |
whismanoid | 19:50cf5da53d36 | 645 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0x400000) expect 0.625 // 25% Scale |
whismanoid | 19:50cf5da53d36 | 646 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0x0A3D70) expect 0.100 // 100mV |
whismanoid | 19:50cf5da53d36 | 647 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0x000064) expect 0.000014901162 // 100 LSB |
whismanoid | 19:50cf5da53d36 | 648 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0x00000A) expect 0.0000014901162 // Ten LSB |
whismanoid | 19:50cf5da53d36 | 649 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0x000003) expect 0.00000044703483 // Three LSB |
whismanoid | 19:50cf5da53d36 | 650 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0x000002) expect 0.00000029802326 // Two LSB |
whismanoid | 19:50cf5da53d36 | 651 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0x000001) expect 0.00000014901162 // One LSB |
whismanoid | 19:50cf5da53d36 | 652 | // @test group UNIPOLAR VoltageOfCode_Unipolar(0x000000) expect 0.0 // Zero Scale |
whismanoid | 21:847b2220e96e | 653 | // @test group UNIPOLAR tinyTester.blink_time_msec = 75 // default 75 resume hardware self test |
whismanoid | 1:d57c1a2cb83c | 654 | // |
whismanoid | 1:d57c1a2cb83c | 655 | double MAX11410::VoltageOfCode_Unipolar(uint32_t value_u24) |
whismanoid | 0:68e64068330f | 656 | { |
whismanoid | 0:68e64068330f | 657 | |
whismanoid | 0:68e64068330f | 658 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 659 | // Linear map min and max endpoints |
whismanoid | 22:c6812214a933 | 660 | double VRef = ref2_v; |
whismanoid | 1:d57c1a2cb83c | 661 | uint8_t ref_sel = (ctrl & 0x03); // MAX11410_REF_SEL_enum_t |
whismanoid | 1:d57c1a2cb83c | 662 | switch(ref_sel) |
whismanoid | 1:d57c1a2cb83c | 663 | { |
whismanoid | 22:c6812214a933 | 664 | case REF_SEL_000_AIN0_AIN1: VRef = ref0_v; break; |
whismanoid | 22:c6812214a933 | 665 | case REF_SEL_001_REF1P_REF1N: VRef = ref1_v; break; |
whismanoid | 22:c6812214a933 | 666 | case REF_SEL_010_REF2P_REF2N: VRef = ref2_v; break; |
whismanoid | 22:c6812214a933 | 667 | case REF_SEL_011_AVDD_AGND: VRef = avdd_v; break; |
whismanoid | 22:c6812214a933 | 668 | case REF_SEL_100_AIN0_AGND: VRef = ref0_v; break; |
whismanoid | 22:c6812214a933 | 669 | case REF_SEL_101_REF1P_AGND: VRef = ref1_v; break; |
whismanoid | 22:c6812214a933 | 670 | case REF_SEL_110_REF2P_AGND: VRef = ref2_v; break; |
whismanoid | 22:c6812214a933 | 671 | case REF_SEL_111_AVDD_AGND: VRef = avdd_v; break; |
whismanoid | 1:d57c1a2cb83c | 672 | } |
whismanoid | 0:68e64068330f | 673 | double MaxScaleVoltage = VRef; // voltage of maximum code 0xffffff |
whismanoid | 0:68e64068330f | 674 | double MinScaleVoltage = 0.0; // voltage of minimum code 0x000 |
whismanoid | 0:68e64068330f | 675 | const uint32_t FULL_SCALE_CODE_24BIT = 0xffffff; |
whismanoid | 0:68e64068330f | 676 | const uint32_t MaxCode = FULL_SCALE_CODE_24BIT; |
whismanoid | 0:68e64068330f | 677 | const uint32_t MinCode = 0x000; |
whismanoid | 0:68e64068330f | 678 | double codeFraction = ((double)value_u24 - MinCode) / (MaxCode - MinCode + 1); |
whismanoid | 1:d57c1a2cb83c | 679 | return (MinScaleVoltage + ((MaxScaleVoltage - MinScaleVoltage) * codeFraction)) / pgaGain; |
whismanoid | 1:d57c1a2cb83c | 680 | } |
whismanoid | 1:d57c1a2cb83c | 681 | |
whismanoid | 1:d57c1a2cb83c | 682 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 683 | // Return the physical voltage corresponding to conversion result, |
whismanoid | 1:d57c1a2cb83c | 684 | // when conversion format is Bipolar mode, offset binary. |
whismanoid | 1:d57c1a2cb83c | 685 | // Does not perform any offset or gain correction. |
whismanoid | 1:d57c1a2cb83c | 686 | // |
whismanoid | 1:d57c1a2cb83c | 687 | // @pre CTRL::U_BN = 0 -- Bipolar mode |
whismanoid | 1:d57c1a2cb83c | 688 | // @pre CTRL::FORMAT = 1 -- offset binary |
whismanoid | 1:d57c1a2cb83c | 689 | // @pre VRef = Voltage of REF input, in Volts |
whismanoid | 1:d57c1a2cb83c | 690 | // @param[in] value_u24: raw 24-bit MAX11410 code (right justified). |
whismanoid | 1:d57c1a2cb83c | 691 | // @return physical voltage corresponding to MAX11410 code. |
whismanoid | 14:b49eecf7e4d8 | 692 | // |
whismanoid | 21:847b2220e96e | 693 | // @test group BIPOB // Verify function VoltageOfCode_Bipolar_OffsetBinary |
whismanoid | 21:847b2220e96e | 694 | // @test group BIPOB tinyTester.blink_time_msec = 20 // quickly speed through the software verification |
whismanoid | 21:847b2220e96e | 695 | // @test group BIPOB Configure_CTRL_REF(2) expect 1 // These tests require REF2 = 2.500V |
whismanoid | 21:847b2220e96e | 696 | // @test group BIPOB Configure_PGA(0,0) expect 1 // These tests require PGA gain=1 |
whismanoid | 19:50cf5da53d36 | 697 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0xFFFFFF) expect 2.5 within 0.030 // Full Scale |
whismanoid | 19:50cf5da53d36 | 698 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0xFFFFFE) expect 2.5 // Full Scale |
whismanoid | 19:50cf5da53d36 | 699 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0xC00000) expect 1.25 // Mid Scale |
whismanoid | 19:50cf5da53d36 | 700 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x800003) expect 0.00000894069671 // Three LSB |
whismanoid | 19:50cf5da53d36 | 701 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x800002) expect 0.00000596046447 // Two LSB |
whismanoid | 19:50cf5da53d36 | 702 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x800001) expect 0.0000029802326 // One LSB |
whismanoid | 19:50cf5da53d36 | 703 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x800000) expect 0.0 // Zero Scale |
whismanoid | 19:50cf5da53d36 | 704 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x7FFFFF) expect -0.0000029802326 // Negative One LSB |
whismanoid | 19:50cf5da53d36 | 705 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x7FFFFE) expect -0.0000059604644 // Negative Two LSB |
whismanoid | 19:50cf5da53d36 | 706 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x7FFFFD) expect -0.0000089406967 // Negative Three LSB |
whismanoid | 19:50cf5da53d36 | 707 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x400000) expect -1.25 // Negative Mid Scale |
whismanoid | 19:50cf5da53d36 | 708 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x000001) expect -2.5 // Negative Full Scale |
whismanoid | 19:50cf5da53d36 | 709 | // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x000000) expect -2.5 // Negative Full Scale |
whismanoid | 21:847b2220e96e | 710 | // @test group BIPOB tinyTester.blink_time_msec = 75 // default 75 resume hardware self test |
whismanoid | 1:d57c1a2cb83c | 711 | // |
whismanoid | 1:d57c1a2cb83c | 712 | double MAX11410::VoltageOfCode_Bipolar_OffsetBinary(uint32_t value_u24) |
whismanoid | 1:d57c1a2cb83c | 713 | { |
whismanoid | 1:d57c1a2cb83c | 714 | |
whismanoid | 1:d57c1a2cb83c | 715 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 716 | // Linear map min and max endpoints |
whismanoid | 22:c6812214a933 | 717 | double VRef = ref2_v; |
whismanoid | 1:d57c1a2cb83c | 718 | uint8_t ref_sel = (ctrl & 0x03); // MAX11410_REF_SEL_enum_t |
whismanoid | 1:d57c1a2cb83c | 719 | switch(ref_sel) |
whismanoid | 1:d57c1a2cb83c | 720 | { |
whismanoid | 22:c6812214a933 | 721 | case REF_SEL_000_AIN0_AIN1: VRef = ref0_v; break; |
whismanoid | 22:c6812214a933 | 722 | case REF_SEL_001_REF1P_REF1N: VRef = ref1_v; break; |
whismanoid | 22:c6812214a933 | 723 | case REF_SEL_010_REF2P_REF2N: VRef = ref2_v; break; |
whismanoid | 22:c6812214a933 | 724 | case REF_SEL_011_AVDD_AGND: VRef = avdd_v; break; |
whismanoid | 22:c6812214a933 | 725 | case REF_SEL_100_AIN0_AGND: VRef = ref0_v; break; |
whismanoid | 22:c6812214a933 | 726 | case REF_SEL_101_REF1P_AGND: VRef = ref1_v; break; |
whismanoid | 22:c6812214a933 | 727 | case REF_SEL_110_REF2P_AGND: VRef = ref2_v; break; |
whismanoid | 22:c6812214a933 | 728 | case REF_SEL_111_AVDD_AGND: VRef = avdd_v; break; |
whismanoid | 1:d57c1a2cb83c | 729 | } |
whismanoid | 1:d57c1a2cb83c | 730 | double MaxScaleVoltage = 2*VRef; // voltage of maximum code 0x7fffff |
whismanoid | 1:d57c1a2cb83c | 731 | double MinScaleVoltage = 0; // voltage of minimum code 0x800000; |
whismanoid | 1:d57c1a2cb83c | 732 | const uint32_t FULL_SCALE_CODE_24BIT = 0x7fffff; |
whismanoid | 1:d57c1a2cb83c | 733 | const uint32_t MaxCode = FULL_SCALE_CODE_24BIT; |
whismanoid | 1:d57c1a2cb83c | 734 | const int32_t CodeSpan = 0x1000000; |
whismanoid | 1:d57c1a2cb83c | 735 | const uint32_t MinCode = 0x800000; |
whismanoid | 1:d57c1a2cb83c | 736 | double codeFraction = ((double)value_u24 - MinCode) / CodeSpan; |
whismanoid | 1:d57c1a2cb83c | 737 | return (MinScaleVoltage + ((MaxScaleVoltage - MinScaleVoltage) * codeFraction)) / pgaGain; |
whismanoid | 1:d57c1a2cb83c | 738 | } |
whismanoid | 1:d57c1a2cb83c | 739 | |
whismanoid | 1:d57c1a2cb83c | 740 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 741 | // Return the physical voltage corresponding to conversion result, |
whismanoid | 1:d57c1a2cb83c | 742 | // when conversion format is Bipolar mode, 2's complement. |
whismanoid | 1:d57c1a2cb83c | 743 | // Does not perform any offset or gain correction. |
whismanoid | 1:d57c1a2cb83c | 744 | // |
whismanoid | 1:d57c1a2cb83c | 745 | // @pre CTRL::U_BN = 0 -- Bipolar mode |
whismanoid | 1:d57c1a2cb83c | 746 | // @pre CTRL::FORMAT = 0 -- 2's complement |
whismanoid | 1:d57c1a2cb83c | 747 | // @pre VRef = Voltage of REF input, in Volts |
whismanoid | 1:d57c1a2cb83c | 748 | // @param[in] value_u24: raw 24-bit MAX11410 code (right justified). |
whismanoid | 1:d57c1a2cb83c | 749 | // @return physical voltage corresponding to MAX11410 code. |
whismanoid | 14:b49eecf7e4d8 | 750 | // |
whismanoid | 21:847b2220e96e | 751 | // @test group BIP2C // Verify function VoltageOfCode_Bipolar_2sComplement |
whismanoid | 21:847b2220e96e | 752 | // @test group BIP2C tinyTester.blink_time_msec = 20 // quickly speed through the software verification |
whismanoid | 21:847b2220e96e | 753 | // @test group BIP2C Configure_CTRL_REF(2) expect 1 // These tests require REF2 = 2.500V |
whismanoid | 21:847b2220e96e | 754 | // @test group BIP2C Configure_PGA(0,0) expect 1 // These tests require PGA gain=1 |
whismanoid | 19:50cf5da53d36 | 755 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x7FFFFF) expect 2.500 within 0.030 // Full Scale |
whismanoid | 19:50cf5da53d36 | 756 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x7FFFFE) expect 2.500 // Full Scale |
whismanoid | 19:50cf5da53d36 | 757 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x666666) expect 2.000 // Two Volts |
whismanoid | 19:50cf5da53d36 | 758 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x600000) expect 1.875 // 75% Scale |
whismanoid | 19:50cf5da53d36 | 759 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x400000) expect 1.250 // Mid Scale |
whismanoid | 19:50cf5da53d36 | 760 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x333333) expect 1.000 // One Volt |
whismanoid | 19:50cf5da53d36 | 761 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x200000) expect 0.625 // 25% Scale |
whismanoid | 19:50cf5da53d36 | 762 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x051eb8) expect 0.100 // 100mV |
whismanoid | 19:50cf5da53d36 | 763 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x000003) expect 0.00000894069671 // Three LSB |
whismanoid | 19:50cf5da53d36 | 764 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x000002) expect 0.00000596046447 // Two LSB |
whismanoid | 19:50cf5da53d36 | 765 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x000001) expect 0.0000029802326 // One LSB |
whismanoid | 19:50cf5da53d36 | 766 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x000000) expect 0.0 // Zero Scale |
whismanoid | 19:50cf5da53d36 | 767 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0xFFFFFF) expect -0.0000029802326 // Negative One LSB |
whismanoid | 19:50cf5da53d36 | 768 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0xFFFFFE) expect -0.0000059604644 // Negative Two LSB |
whismanoid | 19:50cf5da53d36 | 769 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0xFFFFFD) expect -0.0000089406967 // Negative Three LSB |
whismanoid | 19:50cf5da53d36 | 770 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0xFAE148) expect -0.100 // Negative 100mV |
whismanoid | 19:50cf5da53d36 | 771 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0xE00000) expect -0.625 // Negative 25% Scale |
whismanoid | 19:50cf5da53d36 | 772 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0xCCCCCD) expect -1.000 // Negative One Volt |
whismanoid | 19:50cf5da53d36 | 773 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0xC00000) expect -1.250 // Negative Mid Scale |
whismanoid | 19:50cf5da53d36 | 774 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0xA00000) expect -1.875 // Negative 75% Scale |
whismanoid | 19:50cf5da53d36 | 775 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x99999A) expect -2.000 // Negative Two Volts |
whismanoid | 19:50cf5da53d36 | 776 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x800001) expect -2.500 // Negative Full Scale |
whismanoid | 19:50cf5da53d36 | 777 | // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x800000) expect -2.500 // Negative Full Scale |
whismanoid | 21:847b2220e96e | 778 | // @test group BIP2C tinyTester.blink_time_msec = 75 // default 75 resume hardware self test |
whismanoid | 1:d57c1a2cb83c | 779 | // |
whismanoid | 1:d57c1a2cb83c | 780 | double MAX11410::VoltageOfCode_Bipolar_2sComplement(uint32_t value_u24) |
whismanoid | 1:d57c1a2cb83c | 781 | { |
whismanoid | 1:d57c1a2cb83c | 782 | |
whismanoid | 1:d57c1a2cb83c | 783 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 784 | // Linear map min and max endpoints |
whismanoid | 22:c6812214a933 | 785 | double VRef = ref2_v; |
whismanoid | 1:d57c1a2cb83c | 786 | uint8_t ref_sel = (ctrl & 0x03); // MAX11410_REF_SEL_enum_t |
whismanoid | 1:d57c1a2cb83c | 787 | switch(ref_sel) |
whismanoid | 1:d57c1a2cb83c | 788 | { |
whismanoid | 22:c6812214a933 | 789 | case REF_SEL_000_AIN0_AIN1: VRef = ref0_v; break; |
whismanoid | 22:c6812214a933 | 790 | case REF_SEL_001_REF1P_REF1N: VRef = ref1_v; break; |
whismanoid | 22:c6812214a933 | 791 | case REF_SEL_010_REF2P_REF2N: VRef = ref2_v; break; |
whismanoid | 22:c6812214a933 | 792 | case REF_SEL_011_AVDD_AGND: VRef = avdd_v; break; |
whismanoid | 22:c6812214a933 | 793 | case REF_SEL_100_AIN0_AGND: VRef = ref0_v; break; |
whismanoid | 22:c6812214a933 | 794 | case REF_SEL_101_REF1P_AGND: VRef = ref1_v; break; |
whismanoid | 22:c6812214a933 | 795 | case REF_SEL_110_REF2P_AGND: VRef = ref2_v; break; |
whismanoid | 22:c6812214a933 | 796 | case REF_SEL_111_AVDD_AGND: VRef = avdd_v; break; |
whismanoid | 1:d57c1a2cb83c | 797 | } |
whismanoid | 1:d57c1a2cb83c | 798 | double MaxScaleVoltage = 2 * VRef; // voltage of maximum code 0x7fffff |
whismanoid | 1:d57c1a2cb83c | 799 | double MinScaleVoltage = 0; // voltage of minimum code 0x800000 |
whismanoid | 1:d57c1a2cb83c | 800 | const int32_t FULL_SCALE_CODE_24BIT_2S_COMPLEMENT = 0x7fffff; |
whismanoid | 1:d57c1a2cb83c | 801 | const int32_t SIGN_BIT_24BIT_2S_COMPLEMENT = 0x800000; |
whismanoid | 1:d57c1a2cb83c | 802 | if (value_u24 >= SIGN_BIT_24BIT_2S_COMPLEMENT) { value_u24 = value_u24 - (2 * SIGN_BIT_24BIT_2S_COMPLEMENT); } |
whismanoid | 1:d57c1a2cb83c | 803 | const int32_t MaxCode = FULL_SCALE_CODE_24BIT_2S_COMPLEMENT; |
whismanoid | 1:d57c1a2cb83c | 804 | const int32_t CodeSpan = 0x1000000; |
whismanoid | 1:d57c1a2cb83c | 805 | const int32_t MinCode = 0; |
whismanoid | 1:d57c1a2cb83c | 806 | double codeFraction = ((double)((int32_t)value_u24) - MinCode) / CodeSpan; |
whismanoid | 1:d57c1a2cb83c | 807 | return (MinScaleVoltage + ((MaxScaleVoltage - MinScaleVoltage) * codeFraction)) / pgaGain; |
whismanoid | 1:d57c1a2cb83c | 808 | } |
whismanoid | 1:d57c1a2cb83c | 809 | |
whismanoid | 1:d57c1a2cb83c | 810 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 811 | // Return the physical voltage corresponding to conversion result, |
whismanoid | 1:d57c1a2cb83c | 812 | // when conversion format is determined by the CTRL register. |
whismanoid | 1:d57c1a2cb83c | 813 | // Does not perform any offset or gain correction. |
whismanoid | 1:d57c1a2cb83c | 814 | // |
whismanoid | 1:d57c1a2cb83c | 815 | // @pre CTRL::U_BN and CTRL::FORMAT = 0 select offset binary, 2's complement, or straight binary |
whismanoid | 1:d57c1a2cb83c | 816 | // @pre VRef = Voltage of REF input, in Volts |
whismanoid | 1:d57c1a2cb83c | 817 | // @param[in] value_u24: raw 24-bit MAX11410 code (right justified). |
whismanoid | 1:d57c1a2cb83c | 818 | // @return physical voltage corresponding to MAX11410 code. |
whismanoid | 1:d57c1a2cb83c | 819 | double MAX11410::VoltageOfCode(uint32_t value_u24) |
whismanoid | 1:d57c1a2cb83c | 820 | { |
whismanoid | 1:d57c1a2cb83c | 821 | |
whismanoid | 1:d57c1a2cb83c | 822 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 823 | // Determine format from CTRL register U_BN and FORMAT |
whismanoid | 1:d57c1a2cb83c | 824 | uint8_t u_bn_bitmask = (1 << 6); |
whismanoid | 1:d57c1a2cb83c | 825 | uint8_t format_bitmask = (1 << 5); |
whismanoid | 1:d57c1a2cb83c | 826 | if ((ctrl & u_bn_bitmask) != 0) |
whismanoid | 1:d57c1a2cb83c | 827 | { |
whismanoid | 1:d57c1a2cb83c | 828 | return VoltageOfCode_Unipolar(value_u24); |
whismanoid | 1:d57c1a2cb83c | 829 | } |
whismanoid | 1:d57c1a2cb83c | 830 | if ((ctrl & format_bitmask) != 0) |
whismanoid | 1:d57c1a2cb83c | 831 | { |
whismanoid | 1:d57c1a2cb83c | 832 | return VoltageOfCode_Bipolar_OffsetBinary(value_u24); |
whismanoid | 1:d57c1a2cb83c | 833 | } |
whismanoid | 1:d57c1a2cb83c | 834 | return VoltageOfCode_Bipolar_2sComplement(value_u24); |
whismanoid | 0:68e64068330f | 835 | } |
whismanoid | 0:68e64068330f | 836 | |
whismanoid | 0:68e64068330f | 837 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 838 | // Write a MAX11410 register. |
whismanoid | 0:68e64068330f | 839 | // |
whismanoid | 11:abde565b8497 | 840 | // CMDOP_1aaa_aaaa_ReadRegister bit is cleared 0 indicating a write operation. |
whismanoid | 0:68e64068330f | 841 | // |
whismanoid | 0:68e64068330f | 842 | // MAX11410 register length can be determined by function RegSize. |
whismanoid | 0:68e64068330f | 843 | // |
whismanoid | 0:68e64068330f | 844 | // For 8-bit register size: |
whismanoid | 0:68e64068330f | 845 | // |
whismanoid | 0:68e64068330f | 846 | // SPI 16-bit transfer |
whismanoid | 0:68e64068330f | 847 | // |
whismanoid | 0:68e64068330f | 848 | // SPI MOSI = 0aaa_aaaa_dddd_dddd |
whismanoid | 0:68e64068330f | 849 | // |
whismanoid | 0:68e64068330f | 850 | // SPI MISO = xxxx_xxxx_xxxx_xxxx |
whismanoid | 0:68e64068330f | 851 | // |
whismanoid | 0:68e64068330f | 852 | // For 16-bit register size: |
whismanoid | 0:68e64068330f | 853 | // |
whismanoid | 0:68e64068330f | 854 | // SPI 24-bit or 32-bit transfer |
whismanoid | 0:68e64068330f | 855 | // |
whismanoid | 0:68e64068330f | 856 | // SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd |
whismanoid | 0:68e64068330f | 857 | // |
whismanoid | 0:68e64068330f | 858 | // SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx |
whismanoid | 0:68e64068330f | 859 | // |
whismanoid | 0:68e64068330f | 860 | // For 24-bit register size: |
whismanoid | 0:68e64068330f | 861 | // |
whismanoid | 0:68e64068330f | 862 | // SPI 32-bit transfer |
whismanoid | 0:68e64068330f | 863 | // |
whismanoid | 0:68e64068330f | 864 | // SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd_dddd_dddd |
whismanoid | 0:68e64068330f | 865 | // |
whismanoid | 0:68e64068330f | 866 | // SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx |
whismanoid | 0:68e64068330f | 867 | // |
whismanoid | 0:68e64068330f | 868 | // @return 1 on success; 0 on failure |
whismanoid | 10:7adee48a7f82 | 869 | uint8_t MAX11410::RegWrite(MAX11410_CMD_enum_t commandByte, uint32_t regData) |
whismanoid | 0:68e64068330f | 870 | { |
whismanoid | 0:68e64068330f | 871 | |
whismanoid | 0:68e64068330f | 872 | //---------------------------------------- |
whismanoid | 21:847b2220e96e | 873 | // switch based on register address size RegSize(commandByte) |
whismanoid | 11:abde565b8497 | 874 | commandByte = (MAX11410_CMD_enum_t)((commandByte &~ CMDOP_1aaa_aaaa_ReadRegister) & 0xFF); |
whismanoid | 10:7adee48a7f82 | 875 | switch(RegSize(commandByte)) |
whismanoid | 0:68e64068330f | 876 | { |
whismanoid | 0:68e64068330f | 877 | case 8: // 8-bit register size |
whismanoid | 0:68e64068330f | 878 | { |
whismanoid | 0:68e64068330f | 879 | // SPI 16-bit transfer |
whismanoid | 0:68e64068330f | 880 | // SPI MOSI = 0aaa_aaaa_dddd_dddd |
whismanoid | 0:68e64068330f | 881 | // SPI MISO = xxxx_xxxx_xxxx_xxxx |
whismanoid | 10:7adee48a7f82 | 882 | int16_t mosiData16 = ((int16_t)commandByte << 8) | ((int16_t)regData & 0xFF); |
whismanoid | 0:68e64068330f | 883 | SPIoutputCS(0); |
whismanoid | 0:68e64068330f | 884 | SPIwrite16bits(mosiData16); |
whismanoid | 0:68e64068330f | 885 | SPIoutputCS(1); |
whismanoid | 24:428b7670e45f | 886 | // |
whismanoid | 26:298726bd5a3f | 887 | if (commandByte == CMD_r000_1110_00ss_0ggg_PGA) |
whismanoid | 26:298726bd5a3f | 888 | { |
whismanoid | 26:298726bd5a3f | 889 | // update pgaGain with 1, 2, 4, 8, 16, 32, 64, or 128 based on gain index |
whismanoid | 26:298726bd5a3f | 890 | static uint8_t pgaGainTable[8] = {1, 2, 4, 8, 16, 32, 64, 128}; |
whismanoid | 26:298726bd5a3f | 891 | pgaGain = (((regData >> 4) & 2) == SIG_PATH_10_PGA) |
whismanoid | 26:298726bd5a3f | 892 | ? pgaGainTable[(uint8_t)(regData & 7)] |
whismanoid | 26:298726bd5a3f | 893 | : 1; |
whismanoid | 26:298726bd5a3f | 894 | } |
whismanoid | 24:428b7670e45f | 895 | if (commandByte == CMD_r000_0011_xxxx_xddd_CAL_START) |
whismanoid | 24:428b7670e45f | 896 | { |
whismanoid | 24:428b7670e45f | 897 | // after RegWrite CMD_r000_0011_xxxx_xddd_CAL_START, poll status until 0x000004 CAL_RDY |
whismanoid | 24:428b7670e45f | 898 | RegRead(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); |
whismanoid | 24:428b7670e45f | 899 | // wait until /* MAX11410_STATUS_enum_t:: */ STATUS_000004_CAL_RDY indicates calibration is ready |
whismanoid | 25:c4be3afbfafd | 900 | // Two conversions will execute at the rate |
whismanoid | 25:c4be3afbfafd | 901 | // controlled by the FILTER register. The SELF_OFFSET and SELF_GAIN_1 |
whismanoid | 25:c4be3afbfafd | 902 | // registers will be updated. |
whismanoid | 25:c4be3afbfafd | 903 | // Worst-case (longest) calibration time = 2 x 1 sample/second = 2 seconds |
whismanoid | 24:428b7670e45f | 904 | // A bad SPI interface can cause bit slippage, which makes this loop get stuck. Expect *PART_ID? = 0x000F02 |
whismanoid | 24:428b7670e45f | 905 | // while ((status & /* MAX11410_STATUS_enum_t:: */ STATUS_000010_DATA_RDY) == 0) { |
whismanoid | 24:428b7670e45f | 906 | // possible infinite loop; need a timeout or futility countdown to escape |
whismanoid | 26:298726bd5a3f | 907 | // with one exception: skip the wait loop in the corner case where |
whismanoid | 26:298726bd5a3f | 908 | // cal_start=1 and pga is either buffer, bypass, or GAIN_000_1 -- |
whismanoid | 26:298726bd5a3f | 909 | // these are effectively 1V/V gain path, and since it's already handled |
whismanoid | 26:298726bd5a3f | 910 | // by self calibration, the pga calibration command behaves as a no-operation. |
whismanoid | 26:298726bd5a3f | 911 | if ((regData != 1) || (pgaGain != 1)) |
whismanoid | 24:428b7670e45f | 912 | { |
whismanoid | 26:298726bd5a3f | 913 | // wait for CAL_RDY unless (cal_start=1 and pgaGain==1) |
whismanoid | 26:298726bd5a3f | 914 | for (int futility_countdown = loop_limit; |
whismanoid | 26:298726bd5a3f | 915 | ((futility_countdown > 0) && |
whismanoid | 25:c4be3afbfafd | 916 | ((status & /* MAX11410_STATUS_enum_t:: */ STATUS_000004_CAL_RDY) == 0)); |
whismanoid | 26:298726bd5a3f | 917 | futility_countdown--) |
whismanoid | 25:c4be3afbfafd | 918 | { |
whismanoid | 26:298726bd5a3f | 919 | for (int futility_countdown_inner = 32767; |
whismanoid | 26:298726bd5a3f | 920 | ((futility_countdown_inner > 0) && |
whismanoid | 26:298726bd5a3f | 921 | ((status & /* MAX11410_STATUS_enum_t:: */ STATUS_000004_CAL_RDY) == 0)); |
whismanoid | 26:298726bd5a3f | 922 | futility_countdown_inner--) |
whismanoid | 26:298726bd5a3f | 923 | { |
whismanoid | 26:298726bd5a3f | 924 | RegRead(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); |
whismanoid | 26:298726bd5a3f | 925 | } |
whismanoid | 25:c4be3afbfafd | 926 | } |
whismanoid | 24:428b7670e45f | 927 | } |
whismanoid | 24:428b7670e45f | 928 | } |
whismanoid | 0:68e64068330f | 929 | } |
whismanoid | 0:68e64068330f | 930 | break; |
whismanoid | 0:68e64068330f | 931 | case 16: // 16-bit register size |
whismanoid | 0:68e64068330f | 932 | #warning "Not Verified Yet: MAX11410::RegWrite 16-bit SPIreadWrite32bits" |
whismanoid | 0:68e64068330f | 933 | { |
whismanoid | 0:68e64068330f | 934 | // SPI 24-bit or 32-bit transfer |
whismanoid | 0:68e64068330f | 935 | // SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd |
whismanoid | 0:68e64068330f | 936 | // SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx |
whismanoid | 0:68e64068330f | 937 | // SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd_0000_0000 |
whismanoid | 0:68e64068330f | 938 | // SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx |
whismanoid | 10:7adee48a7f82 | 939 | int32_t mosiData32 = ((int32_t)commandByte << 24) | (((int32_t)regData & 0xFFFF) << 8); |
whismanoid | 0:68e64068330f | 940 | SPIoutputCS(0); |
whismanoid | 0:68e64068330f | 941 | SPIreadWrite32bits(mosiData32); |
whismanoid | 0:68e64068330f | 942 | SPIoutputCS(1); |
whismanoid | 0:68e64068330f | 943 | } |
whismanoid | 0:68e64068330f | 944 | break; |
whismanoid | 0:68e64068330f | 945 | case 24: // 24-bit register size |
whismanoid | 0:68e64068330f | 946 | { |
whismanoid | 0:68e64068330f | 947 | // SPI 32-bit transfer |
whismanoid | 0:68e64068330f | 948 | // SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd_dddd_dddd |
whismanoid | 0:68e64068330f | 949 | // SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx |
whismanoid | 10:7adee48a7f82 | 950 | int32_t mosiData32 = ((int32_t)commandByte << 24) | ((int32_t)regData & 0x00FFFFFF); |
whismanoid | 0:68e64068330f | 951 | SPIoutputCS(0); |
whismanoid | 0:68e64068330f | 952 | SPIreadWrite32bits(mosiData32); |
whismanoid | 0:68e64068330f | 953 | SPIoutputCS(1); |
whismanoid | 0:68e64068330f | 954 | } |
whismanoid | 0:68e64068330f | 955 | break; |
whismanoid | 0:68e64068330f | 956 | } |
whismanoid | 0:68e64068330f | 957 | |
whismanoid | 0:68e64068330f | 958 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 959 | // success |
whismanoid | 0:68e64068330f | 960 | return 1; |
whismanoid | 0:68e64068330f | 961 | } |
whismanoid | 0:68e64068330f | 962 | |
whismanoid | 0:68e64068330f | 963 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 964 | // Read an 8-bit MAX11410 register |
whismanoid | 0:68e64068330f | 965 | // |
whismanoid | 11:abde565b8497 | 966 | // CMDOP_1aaa_aaaa_ReadRegister bit is set 1 indicating a read operation. |
whismanoid | 0:68e64068330f | 967 | // |
whismanoid | 0:68e64068330f | 968 | // MAX11410 register length can be determined by function RegSize. |
whismanoid | 0:68e64068330f | 969 | // |
whismanoid | 0:68e64068330f | 970 | // For 8-bit register size: |
whismanoid | 0:68e64068330f | 971 | // |
whismanoid | 0:68e64068330f | 972 | // SPI 16-bit transfer |
whismanoid | 0:68e64068330f | 973 | // |
whismanoid | 0:68e64068330f | 974 | // SPI MOSI = 1aaa_aaaa_0000_0000 |
whismanoid | 0:68e64068330f | 975 | // |
whismanoid | 0:68e64068330f | 976 | // SPI MISO = xxxx_xxxx_dddd_dddd |
whismanoid | 0:68e64068330f | 977 | // |
whismanoid | 0:68e64068330f | 978 | // For 16-bit register size: |
whismanoid | 0:68e64068330f | 979 | // |
whismanoid | 0:68e64068330f | 980 | // SPI 24-bit or 32-bit transfer |
whismanoid | 0:68e64068330f | 981 | // |
whismanoid | 0:68e64068330f | 982 | // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000 |
whismanoid | 0:68e64068330f | 983 | // |
whismanoid | 0:68e64068330f | 984 | // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd |
whismanoid | 0:68e64068330f | 985 | // |
whismanoid | 0:68e64068330f | 986 | // For 24-bit register size: |
whismanoid | 0:68e64068330f | 987 | // |
whismanoid | 0:68e64068330f | 988 | // SPI 32-bit transfer |
whismanoid | 0:68e64068330f | 989 | // |
whismanoid | 0:68e64068330f | 990 | // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000 |
whismanoid | 0:68e64068330f | 991 | // |
whismanoid | 0:68e64068330f | 992 | // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_dddd_dddd |
whismanoid | 0:68e64068330f | 993 | // |
whismanoid | 0:68e64068330f | 994 | // |
whismanoid | 0:68e64068330f | 995 | // @return 1 on success; 0 on failure |
whismanoid | 10:7adee48a7f82 | 996 | uint8_t MAX11410::RegRead(MAX11410_CMD_enum_t commandByte, uint32_t* ptrRegData) |
whismanoid | 0:68e64068330f | 997 | { |
whismanoid | 0:68e64068330f | 998 | |
whismanoid | 0:68e64068330f | 999 | //---------------------------------------- |
whismanoid | 21:847b2220e96e | 1000 | // switch based on register address size RegSize(regAddress) |
whismanoid | 11:abde565b8497 | 1001 | commandByte = (MAX11410_CMD_enum_t)((commandByte &~ CMDOP_1aaa_aaaa_ReadRegister) & 0xFF); |
whismanoid | 10:7adee48a7f82 | 1002 | switch(RegSize(commandByte)) |
whismanoid | 0:68e64068330f | 1003 | { |
whismanoid | 0:68e64068330f | 1004 | case 8: // 8-bit register size |
whismanoid | 0:68e64068330f | 1005 | { |
whismanoid | 0:68e64068330f | 1006 | // SPI 16-bit transfer |
whismanoid | 0:68e64068330f | 1007 | // SPI MOSI = 1aaa_aaaa_0000_0000 |
whismanoid | 0:68e64068330f | 1008 | // SPI MISO = xxxx_xxxx_dddd_dddd |
whismanoid | 11:abde565b8497 | 1009 | int16_t mosiData16 = ((CMDOP_1aaa_aaaa_ReadRegister | (int16_t)commandByte) << 8) | ((int16_t)0); |
whismanoid | 0:68e64068330f | 1010 | SPIoutputCS(0); |
whismanoid | 0:68e64068330f | 1011 | int16_t misoData16 = SPIreadWrite16bits(mosiData16); |
whismanoid | 0:68e64068330f | 1012 | SPIoutputCS(1); |
whismanoid | 0:68e64068330f | 1013 | (*ptrRegData) = (misoData16 & 0x00FF); |
whismanoid | 0:68e64068330f | 1014 | } |
whismanoid | 0:68e64068330f | 1015 | break; |
whismanoid | 0:68e64068330f | 1016 | case 16: // 16-bit register size |
whismanoid | 0:68e64068330f | 1017 | #warning "Not Verified Yet: MAX11410::RegRead 16-bit SPIreadWrite32bits" |
whismanoid | 0:68e64068330f | 1018 | { |
whismanoid | 0:68e64068330f | 1019 | // SPI 24-bit or 32-bit transfer |
whismanoid | 0:68e64068330f | 1020 | // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000 |
whismanoid | 0:68e64068330f | 1021 | // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd |
whismanoid | 0:68e64068330f | 1022 | // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000 |
whismanoid | 0:68e64068330f | 1023 | // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_xxxx_xxxx |
whismanoid | 11:abde565b8497 | 1024 | int32_t mosiData32 = ((CMDOP_1aaa_aaaa_ReadRegister | (int32_t)commandByte) << 24); |
whismanoid | 0:68e64068330f | 1025 | SPIoutputCS(0); |
whismanoid | 0:68e64068330f | 1026 | int32_t misoData32 = SPIreadWrite32bits(mosiData32); |
whismanoid | 0:68e64068330f | 1027 | SPIoutputCS(1); |
whismanoid | 0:68e64068330f | 1028 | (*ptrRegData) = ((misoData32 >> 8) & 0x00FFFF); |
whismanoid | 0:68e64068330f | 1029 | } |
whismanoid | 0:68e64068330f | 1030 | break; |
whismanoid | 0:68e64068330f | 1031 | case 24: // 24-bit register size |
whismanoid | 0:68e64068330f | 1032 | { |
whismanoid | 0:68e64068330f | 1033 | // SPI 32-bit transfer |
whismanoid | 0:68e64068330f | 1034 | // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000 |
whismanoid | 0:68e64068330f | 1035 | // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_dddd_dddd |
whismanoid | 11:abde565b8497 | 1036 | int32_t mosiData32 = ((CMDOP_1aaa_aaaa_ReadRegister | (int32_t)commandByte) << 24); |
whismanoid | 0:68e64068330f | 1037 | SPIoutputCS(0); |
whismanoid | 0:68e64068330f | 1038 | int32_t misoData32 = SPIreadWrite32bits(mosiData32); |
whismanoid | 0:68e64068330f | 1039 | SPIoutputCS(1); |
whismanoid | 0:68e64068330f | 1040 | (*ptrRegData) = (misoData32 & 0x00FFFFFF); |
whismanoid | 0:68e64068330f | 1041 | } |
whismanoid | 0:68e64068330f | 1042 | break; |
whismanoid | 0:68e64068330f | 1043 | } |
whismanoid | 0:68e64068330f | 1044 | |
whismanoid | 0:68e64068330f | 1045 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1046 | // success |
whismanoid | 0:68e64068330f | 1047 | return 1; |
whismanoid | 0:68e64068330f | 1048 | } |
whismanoid | 0:68e64068330f | 1049 | |
whismanoid | 0:68e64068330f | 1050 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1051 | // Return the size of a MAX11410 register |
whismanoid | 0:68e64068330f | 1052 | // |
whismanoid | 0:68e64068330f | 1053 | // @return 8 for 8-bit, 16 for 16-bit, 24 for 24-bit, else 0 for undefined register size |
whismanoid | 10:7adee48a7f82 | 1054 | uint8_t MAX11410::RegSize(MAX11410_CMD_enum_t commandByte) |
whismanoid | 0:68e64068330f | 1055 | { |
whismanoid | 0:68e64068330f | 1056 | |
whismanoid | 0:68e64068330f | 1057 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1058 | // switch based on register address value regAddress |
whismanoid | 11:abde565b8497 | 1059 | commandByte = (MAX11410_CMD_enum_t)((commandByte &~ CMDOP_1aaa_aaaa_ReadRegister) & 0xFF); |
whismanoid | 10:7adee48a7f82 | 1060 | switch(commandByte) |
whismanoid | 0:68e64068330f | 1061 | { |
whismanoid | 0:68e64068330f | 1062 | default: |
whismanoid | 0:68e64068330f | 1063 | return 0; // undefined register size |
whismanoid | 0:68e64068330f | 1064 | case CMD_r000_0000_xxxx_xxdd_PD: |
whismanoid | 0:68e64068330f | 1065 | case CMD_r000_0001_xddd_xxdd_CONV_START: |
whismanoid | 0:68e64068330f | 1066 | case CMD_r000_0010_xddd_dddd_SEQ_START: |
whismanoid | 0:68e64068330f | 1067 | case CMD_r000_0011_xxxx_xddd_CAL_START: |
whismanoid | 0:68e64068330f | 1068 | case CMD_r000_0100_dddd_xddd_GP0_CTRL: |
whismanoid | 0:68e64068330f | 1069 | case CMD_r000_0101_dddd_xddd_GP1_CTRL: |
whismanoid | 0:68e64068330f | 1070 | case CMD_r000_0110_xddd_xxdd_GP_CONV: |
whismanoid | 0:68e64068330f | 1071 | case CMD_r000_0111_xddd_dddd_GP_SEQ_ADDR: |
whismanoid | 0:68e64068330f | 1072 | case CMD_r000_1000_x0dd_dddd_FILTER: |
whismanoid | 0:68e64068330f | 1073 | case CMD_r000_1001_dddd_dddd_CTRL: |
whismanoid | 0:68e64068330f | 1074 | case CMD_r000_1010_dddd_dddd_SOURCE: |
whismanoid | 0:68e64068330f | 1075 | case CMD_r000_1011_dddd_dddd_MUX_CTRL0: |
whismanoid | 0:68e64068330f | 1076 | case CMD_r000_1100_dddd_dddd_MUX_CTRL1: |
whismanoid | 0:68e64068330f | 1077 | case CMD_r000_1101_dddd_dddd_MUX_CTRL2: |
whismanoid | 23:22e7830bcccb | 1078 | case CMD_r000_1110_00ss_0ggg_PGA: |
whismanoid | 0:68e64068330f | 1079 | case CMD_r000_1111_dddd_dddd_WAIT_EXT: |
whismanoid | 0:68e64068330f | 1080 | case CMD_r001_0000_xxxx_xxxx_WAIT_START: |
whismanoid | 0:68e64068330f | 1081 | return 8; // 8-bit register size |
whismanoid | 0:68e64068330f | 1082 | case CMD_r001_0001_xxxx_xxxx_xxxx_xxxx_xxxx_xddd_PART_ID: |
whismanoid | 0:68e64068330f | 1083 | case CMD_r001_0010_xxxx_xxxx_dddd_xxdd_dddd_dddd_SYSC_SEL: |
whismanoid | 0:68e64068330f | 1084 | case CMD_r001_0011_dddd_dddd_dddd_dddd_dddd_dddd_SYS_OFF_A: |
whismanoid | 0:68e64068330f | 1085 | case CMD_r001_0100_dddd_dddd_dddd_dddd_dddd_dddd_SYS_OFF_B: |
whismanoid | 0:68e64068330f | 1086 | case CMD_r001_0101_dddd_dddd_dddd_dddd_dddd_dddd_SYS_GAIN_A: |
whismanoid | 0:68e64068330f | 1087 | case CMD_r001_0110_dddd_dddd_dddd_dddd_dddd_dddd_SYS_GAIN_B: |
whismanoid | 0:68e64068330f | 1088 | case CMD_r001_0111_dddd_dddd_dddd_dddd_dddd_dddd_SELF_OFF: |
whismanoid | 0:68e64068330f | 1089 | case CMD_r001_1000_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_1: |
whismanoid | 0:68e64068330f | 1090 | case CMD_r001_1001_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_2: |
whismanoid | 0:68e64068330f | 1091 | case CMD_r001_1010_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_4: |
whismanoid | 0:68e64068330f | 1092 | case CMD_r001_1011_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_8: |
whismanoid | 0:68e64068330f | 1093 | case CMD_r001_1100_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_16: |
whismanoid | 0:68e64068330f | 1094 | case CMD_r001_1101_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_32: |
whismanoid | 0:68e64068330f | 1095 | case CMD_r001_1110_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_64: |
whismanoid | 0:68e64068330f | 1096 | case CMD_r001_1111_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_128: |
whismanoid | 0:68e64068330f | 1097 | case CMD_r010_0000_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH0: |
whismanoid | 0:68e64068330f | 1098 | case CMD_r010_0001_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH1: |
whismanoid | 0:68e64068330f | 1099 | case CMD_r010_0010_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH2: |
whismanoid | 0:68e64068330f | 1100 | case CMD_r010_0011_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH3: |
whismanoid | 0:68e64068330f | 1101 | case CMD_r010_0100_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH4: |
whismanoid | 0:68e64068330f | 1102 | case CMD_r010_0101_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH5: |
whismanoid | 0:68e64068330f | 1103 | case CMD_r010_0110_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH6: |
whismanoid | 0:68e64068330f | 1104 | case CMD_r010_0111_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH7: |
whismanoid | 0:68e64068330f | 1105 | case CMD_r010_1000_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH0: |
whismanoid | 0:68e64068330f | 1106 | case CMD_r010_1001_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH1: |
whismanoid | 0:68e64068330f | 1107 | case CMD_r010_1010_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH2: |
whismanoid | 0:68e64068330f | 1108 | case CMD_r010_1011_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH3: |
whismanoid | 0:68e64068330f | 1109 | case CMD_r010_1100_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH4: |
whismanoid | 0:68e64068330f | 1110 | case CMD_r010_1101_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH5: |
whismanoid | 0:68e64068330f | 1111 | case CMD_r010_1110_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH6: |
whismanoid | 0:68e64068330f | 1112 | case CMD_r010_1111_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH7: |
whismanoid | 0:68e64068330f | 1113 | case CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0: |
whismanoid | 0:68e64068330f | 1114 | case CMD_r011_0001_dddd_dddd_dddd_dddd_dddd_dddd_DATA1: |
whismanoid | 0:68e64068330f | 1115 | case CMD_r011_0010_dddd_dddd_dddd_dddd_dddd_dddd_DATA2: |
whismanoid | 0:68e64068330f | 1116 | case CMD_r011_0011_dddd_dddd_dddd_dddd_dddd_dddd_DATA3: |
whismanoid | 0:68e64068330f | 1117 | case CMD_r011_0100_dddd_dddd_dddd_dddd_dddd_dddd_DATA4: |
whismanoid | 0:68e64068330f | 1118 | case CMD_r011_0101_dddd_dddd_dddd_dddd_dddd_dddd_DATA5: |
whismanoid | 0:68e64068330f | 1119 | case CMD_r011_0110_dddd_dddd_dddd_dddd_dddd_dddd_DATA6: |
whismanoid | 0:68e64068330f | 1120 | case CMD_r011_0111_dddd_dddd_dddd_dddd_dddd_dddd_DATA7: |
whismanoid | 0:68e64068330f | 1121 | case CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS: |
whismanoid | 0:68e64068330f | 1122 | case CMD_r011_1001_dddd_dddd_dddd_dddd_dxxd_dddd_STATUS_IE: |
whismanoid | 0:68e64068330f | 1123 | return 24; // 24-bit register size |
whismanoid | 0:68e64068330f | 1124 | case CMD_r011_1010_xaaa_aaaa_dddd_dddd_UC_0: |
whismanoid | 0:68e64068330f | 1125 | case CMD_r011_1011_xaaa_aaaa_dddd_dddd_UC_1: |
whismanoid | 0:68e64068330f | 1126 | case CMD_r011_1100_xaaa_aaaa_dddd_dddd_UC_2: |
whismanoid | 0:68e64068330f | 1127 | case CMD_r011_1101_xaaa_aaaa_dddd_dddd_UC_3: |
whismanoid | 0:68e64068330f | 1128 | case CMD_r011_1110_xaaa_aaaa_dddd_dddd_UC_4: |
whismanoid | 0:68e64068330f | 1129 | case CMD_r011_1111_xaaa_aaaa_dddd_dddd_UC_5: |
whismanoid | 0:68e64068330f | 1130 | case CMD_r100_0000_xaaa_aaaa_dddd_dddd_UC_6: |
whismanoid | 0:68e64068330f | 1131 | case CMD_r100_0001_xaaa_aaaa_dddd_dddd_UC_7: |
whismanoid | 0:68e64068330f | 1132 | case CMD_r100_0010_xaaa_aaaa_dddd_dddd_UC_8: |
whismanoid | 0:68e64068330f | 1133 | case CMD_r100_0011_xaaa_aaaa_dddd_dddd_UC_9: |
whismanoid | 0:68e64068330f | 1134 | case CMD_r100_0100_xaaa_aaaa_dddd_dddd_UC_10: |
whismanoid | 0:68e64068330f | 1135 | case CMD_r100_0101_xaaa_aaaa_dddd_dddd_UC_11: |
whismanoid | 0:68e64068330f | 1136 | case CMD_r100_0110_xaaa_aaaa_dddd_dddd_UC_12: |
whismanoid | 0:68e64068330f | 1137 | case CMD_r100_0111_xaaa_aaaa_dddd_dddd_UC_13: |
whismanoid | 0:68e64068330f | 1138 | case CMD_r100_1000_xaaa_aaaa_dddd_dddd_UC_14: |
whismanoid | 0:68e64068330f | 1139 | case CMD_r100_1001_xaaa_aaaa_dddd_dddd_UC_15: |
whismanoid | 0:68e64068330f | 1140 | case CMD_r100_1010_xaaa_aaaa_dddd_dddd_UC_16: |
whismanoid | 0:68e64068330f | 1141 | case CMD_r100_1011_xaaa_aaaa_dddd_dddd_UC_17: |
whismanoid | 0:68e64068330f | 1142 | case CMD_r100_1100_xaaa_aaaa_dddd_dddd_UC_18: |
whismanoid | 0:68e64068330f | 1143 | case CMD_r100_1101_xaaa_aaaa_dddd_dddd_UC_19: |
whismanoid | 0:68e64068330f | 1144 | case CMD_r100_1110_xaaa_aaaa_dddd_dddd_UC_20: |
whismanoid | 0:68e64068330f | 1145 | case CMD_r100_1111_xaaa_aaaa_dddd_dddd_UC_21: |
whismanoid | 0:68e64068330f | 1146 | case CMD_r101_0000_xaaa_aaaa_dddd_dddd_UC_22: |
whismanoid | 0:68e64068330f | 1147 | case CMD_r101_0001_xaaa_aaaa_dddd_dddd_UC_23: |
whismanoid | 0:68e64068330f | 1148 | case CMD_r101_0010_xaaa_aaaa_dddd_dddd_UC_24: |
whismanoid | 0:68e64068330f | 1149 | case CMD_r101_0011_xaaa_aaaa_dddd_dddd_UC_25: |
whismanoid | 0:68e64068330f | 1150 | case CMD_r101_0100_xaaa_aaaa_dddd_dddd_UC_26: |
whismanoid | 0:68e64068330f | 1151 | case CMD_r101_0101_xaaa_aaaa_dddd_dddd_UC_27: |
whismanoid | 0:68e64068330f | 1152 | case CMD_r101_0110_xaaa_aaaa_dddd_dddd_UC_28: |
whismanoid | 0:68e64068330f | 1153 | case CMD_r101_0111_xaaa_aaaa_dddd_dddd_UC_29: |
whismanoid | 0:68e64068330f | 1154 | case CMD_r101_1000_xaaa_aaaa_dddd_dddd_UC_30: |
whismanoid | 0:68e64068330f | 1155 | case CMD_r101_1001_xaaa_aaaa_dddd_dddd_UC_31: |
whismanoid | 0:68e64068330f | 1156 | case CMD_r101_1010_xaaa_aaaa_dddd_dddd_UC_32: |
whismanoid | 0:68e64068330f | 1157 | case CMD_r101_1011_xaaa_aaaa_dddd_dddd_UC_33: |
whismanoid | 0:68e64068330f | 1158 | case CMD_r101_1100_xaaa_aaaa_dddd_dddd_UC_34: |
whismanoid | 0:68e64068330f | 1159 | case CMD_r101_1101_xaaa_aaaa_dddd_dddd_UC_35: |
whismanoid | 0:68e64068330f | 1160 | case CMD_r101_1110_xaaa_aaaa_dddd_dddd_UC_36: |
whismanoid | 0:68e64068330f | 1161 | case CMD_r101_1111_xaaa_aaaa_dddd_dddd_UC_37: |
whismanoid | 0:68e64068330f | 1162 | case CMD_r110_0000_xaaa_aaaa_dddd_dddd_UC_38: |
whismanoid | 0:68e64068330f | 1163 | case CMD_r110_0001_xaaa_aaaa_dddd_dddd_UC_39: |
whismanoid | 0:68e64068330f | 1164 | case CMD_r110_0010_xaaa_aaaa_dddd_dddd_UC_40: |
whismanoid | 0:68e64068330f | 1165 | case CMD_r110_0011_xaaa_aaaa_dddd_dddd_UC_41: |
whismanoid | 0:68e64068330f | 1166 | case CMD_r110_0100_xaaa_aaaa_dddd_dddd_UC_42: |
whismanoid | 0:68e64068330f | 1167 | case CMD_r110_0101_xaaa_aaaa_dddd_dddd_UC_43: |
whismanoid | 0:68e64068330f | 1168 | case CMD_r110_0110_xaaa_aaaa_dddd_dddd_UC_44: |
whismanoid | 0:68e64068330f | 1169 | case CMD_r110_0111_xaaa_aaaa_dddd_dddd_UC_45: |
whismanoid | 0:68e64068330f | 1170 | case CMD_r110_1000_xaaa_aaaa_dddd_dddd_UC_46: |
whismanoid | 0:68e64068330f | 1171 | case CMD_r110_1001_xaaa_aaaa_dddd_dddd_UC_47: |
whismanoid | 0:68e64068330f | 1172 | case CMD_r110_1010_xaaa_aaaa_dddd_dddd_UC_48: |
whismanoid | 0:68e64068330f | 1173 | case CMD_r110_1011_xaaa_aaaa_dddd_dddd_UC_49: |
whismanoid | 0:68e64068330f | 1174 | case CMD_r110_1100_xaaa_aaaa_dddd_dddd_UC_50: |
whismanoid | 0:68e64068330f | 1175 | case CMD_r110_1101_xaaa_aaaa_dddd_dddd_UC_51: |
whismanoid | 0:68e64068330f | 1176 | case CMD_r110_1110_xaaa_aaaa_dddd_dddd_UC_52: |
whismanoid | 0:68e64068330f | 1177 | case CMD_r110_1111_xxxx_xxxx_xaaa_aaaa_UCADDR: |
whismanoid | 0:68e64068330f | 1178 | return 16; // 16-bit register size |
whismanoid | 0:68e64068330f | 1179 | } |
whismanoid | 0:68e64068330f | 1180 | } |
whismanoid | 0:68e64068330f | 1181 | |
whismanoid | 0:68e64068330f | 1182 | //---------------------------------------- |
whismanoid | 11:abde565b8497 | 1183 | // Decode operation from commandByte |
whismanoid | 11:abde565b8497 | 1184 | // |
whismanoid | 11:abde565b8497 | 1185 | // @return operation such as idle, read register, write register, etc. |
whismanoid | 11:abde565b8497 | 1186 | MAX11410::MAX11410_CMDOP_enum_t MAX11410::DecodeCommand(MAX11410_CMD_enum_t commandByte) |
whismanoid | 11:abde565b8497 | 1187 | { |
whismanoid | 11:abde565b8497 | 1188 | |
whismanoid | 11:abde565b8497 | 1189 | //---------------------------------------- |
whismanoid | 11:abde565b8497 | 1190 | // decode operation from command byte |
whismanoid | 11:abde565b8497 | 1191 | switch (commandByte & 0x80) |
whismanoid | 11:abde565b8497 | 1192 | { |
whismanoid | 11:abde565b8497 | 1193 | default: |
whismanoid | 11:abde565b8497 | 1194 | case CMDOP_0aaa_aaaa_WriteRegister: |
whismanoid | 11:abde565b8497 | 1195 | return CMDOP_0aaa_aaaa_WriteRegister; |
whismanoid | 11:abde565b8497 | 1196 | case CMDOP_1aaa_aaaa_ReadRegister: |
whismanoid | 11:abde565b8497 | 1197 | return CMDOP_1aaa_aaaa_ReadRegister; |
whismanoid | 11:abde565b8497 | 1198 | } |
whismanoid | 11:abde565b8497 | 1199 | } |
whismanoid | 11:abde565b8497 | 1200 | |
whismanoid | 11:abde565b8497 | 1201 | //---------------------------------------- |
whismanoid | 10:7adee48a7f82 | 1202 | // Return the address field of a MAX11410 register |
whismanoid | 10:7adee48a7f82 | 1203 | // |
whismanoid | 10:7adee48a7f82 | 1204 | // @return register address field as given in datasheet |
whismanoid | 10:7adee48a7f82 | 1205 | uint8_t MAX11410::RegAddrOfCommand(MAX11410_CMD_enum_t commandByte) |
whismanoid | 10:7adee48a7f82 | 1206 | { |
whismanoid | 10:7adee48a7f82 | 1207 | |
whismanoid | 10:7adee48a7f82 | 1208 | //---------------------------------------- |
whismanoid | 10:7adee48a7f82 | 1209 | // extract register address value from command byte |
whismanoid | 11:abde565b8497 | 1210 | return (uint8_t)((commandByte &~ CMDOP_1aaa_aaaa_ReadRegister) & 0xFF); |
whismanoid | 10:7adee48a7f82 | 1211 | } |
whismanoid | 10:7adee48a7f82 | 1212 | |
whismanoid | 10:7adee48a7f82 | 1213 | //---------------------------------------- |
whismanoid | 10:7adee48a7f82 | 1214 | // Test whether a command byte is a register read command |
whismanoid | 10:7adee48a7f82 | 1215 | // |
whismanoid | 10:7adee48a7f82 | 1216 | // @return true if command byte is a register read command |
whismanoid | 10:7adee48a7f82 | 1217 | uint8_t MAX11410::IsRegReadCommand(MAX11410_CMD_enum_t commandByte) |
whismanoid | 10:7adee48a7f82 | 1218 | { |
whismanoid | 10:7adee48a7f82 | 1219 | |
whismanoid | 10:7adee48a7f82 | 1220 | //---------------------------------------- |
whismanoid | 10:7adee48a7f82 | 1221 | // Test whether a command byte is a register read command |
whismanoid | 11:abde565b8497 | 1222 | return (commandByte & CMDOP_1aaa_aaaa_ReadRegister) ? 1 : 0; |
whismanoid | 10:7adee48a7f82 | 1223 | } |
whismanoid | 10:7adee48a7f82 | 1224 | |
whismanoid | 10:7adee48a7f82 | 1225 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1226 | // Return the name of a MAX11410 register |
whismanoid | 0:68e64068330f | 1227 | // |
whismanoid | 0:68e64068330f | 1228 | // @return null-terminated constant C string containing register name or empty string |
whismanoid | 10:7adee48a7f82 | 1229 | const char* MAX11410::RegName(MAX11410_CMD_enum_t commandByte) |
whismanoid | 0:68e64068330f | 1230 | { |
whismanoid | 0:68e64068330f | 1231 | |
whismanoid | 0:68e64068330f | 1232 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1233 | // switch based on register address value regAddress |
whismanoid | 11:abde565b8497 | 1234 | commandByte = (MAX11410_CMD_enum_t)((commandByte &~ CMDOP_1aaa_aaaa_ReadRegister) & 0xFF); |
whismanoid | 10:7adee48a7f82 | 1235 | switch(commandByte) |
whismanoid | 0:68e64068330f | 1236 | { |
whismanoid | 0:68e64068330f | 1237 | default: |
whismanoid | 0:68e64068330f | 1238 | return ""; // undefined register |
whismanoid | 0:68e64068330f | 1239 | case CMD_r000_0000_xxxx_xxdd_PD: return "PD"; |
whismanoid | 0:68e64068330f | 1240 | case CMD_r000_0001_xddd_xxdd_CONV_START: return "CONV_START"; |
whismanoid | 0:68e64068330f | 1241 | case CMD_r000_0010_xddd_dddd_SEQ_START: return "SEQ_START"; |
whismanoid | 0:68e64068330f | 1242 | case CMD_r000_0011_xxxx_xddd_CAL_START: return "CAL_START"; |
whismanoid | 0:68e64068330f | 1243 | case CMD_r000_0100_dddd_xddd_GP0_CTRL: return "GP0_CTRL"; |
whismanoid | 0:68e64068330f | 1244 | case CMD_r000_0101_dddd_xddd_GP1_CTRL: return "GP1_CTRL"; |
whismanoid | 0:68e64068330f | 1245 | case CMD_r000_0110_xddd_xxdd_GP_CONV: return "GP_CONV"; |
whismanoid | 0:68e64068330f | 1246 | case CMD_r000_0111_xddd_dddd_GP_SEQ_ADDR: return "GP_SEQ_ADDR"; |
whismanoid | 0:68e64068330f | 1247 | case CMD_r000_1000_x0dd_dddd_FILTER: return "FILTER"; |
whismanoid | 0:68e64068330f | 1248 | case CMD_r000_1001_dddd_dddd_CTRL: return "CTRL"; |
whismanoid | 0:68e64068330f | 1249 | case CMD_r000_1010_dddd_dddd_SOURCE: return "SOURCE"; |
whismanoid | 0:68e64068330f | 1250 | case CMD_r000_1011_dddd_dddd_MUX_CTRL0: return "MUX_CTRL0"; |
whismanoid | 0:68e64068330f | 1251 | case CMD_r000_1100_dddd_dddd_MUX_CTRL1: return "MUX_CTRL1"; |
whismanoid | 0:68e64068330f | 1252 | case CMD_r000_1101_dddd_dddd_MUX_CTRL2: return "MUX_CTRL2"; |
whismanoid | 23:22e7830bcccb | 1253 | case CMD_r000_1110_00ss_0ggg_PGA: return "PGA"; |
whismanoid | 0:68e64068330f | 1254 | case CMD_r000_1111_dddd_dddd_WAIT_EXT: return "WAIT_EXT"; |
whismanoid | 0:68e64068330f | 1255 | case CMD_r001_0000_xxxx_xxxx_WAIT_START: return "WAIT_START"; |
whismanoid | 0:68e64068330f | 1256 | case CMD_r001_0001_xxxx_xxxx_xxxx_xxxx_xxxx_xddd_PART_ID: return "PART_ID"; |
whismanoid | 0:68e64068330f | 1257 | case CMD_r001_0010_xxxx_xxxx_dddd_xxdd_dddd_dddd_SYSC_SEL: return "SYSC_SEL"; |
whismanoid | 0:68e64068330f | 1258 | case CMD_r001_0011_dddd_dddd_dddd_dddd_dddd_dddd_SYS_OFF_A: return "SYS_OFF_A"; |
whismanoid | 0:68e64068330f | 1259 | case CMD_r001_0100_dddd_dddd_dddd_dddd_dddd_dddd_SYS_OFF_B: return "SYS_OFF_B"; |
whismanoid | 0:68e64068330f | 1260 | case CMD_r001_0101_dddd_dddd_dddd_dddd_dddd_dddd_SYS_GAIN_A: return "SYS_GAIN_A"; |
whismanoid | 0:68e64068330f | 1261 | case CMD_r001_0110_dddd_dddd_dddd_dddd_dddd_dddd_SYS_GAIN_B: return "SYS_GAIN_B"; |
whismanoid | 0:68e64068330f | 1262 | case CMD_r001_0111_dddd_dddd_dddd_dddd_dddd_dddd_SELF_OFF: return "SELF_OFF"; |
whismanoid | 0:68e64068330f | 1263 | case CMD_r001_1000_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_1: return "SELF_GAIN_1"; |
whismanoid | 0:68e64068330f | 1264 | case CMD_r001_1001_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_2: return "SELF_GAIN_2"; |
whismanoid | 0:68e64068330f | 1265 | case CMD_r001_1010_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_4: return "SELF_GAIN_4"; |
whismanoid | 0:68e64068330f | 1266 | case CMD_r001_1011_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_8: return "SELF_GAIN_8"; |
whismanoid | 0:68e64068330f | 1267 | case CMD_r001_1100_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_16: return "SELF_GAIN_16"; |
whismanoid | 0:68e64068330f | 1268 | case CMD_r001_1101_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_32: return "SELF_GAIN_32"; |
whismanoid | 0:68e64068330f | 1269 | case CMD_r001_1110_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_64: return "SELF_GAIN_64"; |
whismanoid | 0:68e64068330f | 1270 | case CMD_r001_1111_dddd_dddd_dddd_dddd_dddd_dddd_SELF_GAIN_128: return "SELF_GAIN_128"; |
whismanoid | 0:68e64068330f | 1271 | case CMD_r010_0000_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH0: return "LTHRESH0"; |
whismanoid | 0:68e64068330f | 1272 | case CMD_r010_0001_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH1: return "LTHRESH1"; |
whismanoid | 0:68e64068330f | 1273 | case CMD_r010_0010_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH2: return "LTHRESH2"; |
whismanoid | 0:68e64068330f | 1274 | case CMD_r010_0011_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH3: return "LTHRESH3"; |
whismanoid | 0:68e64068330f | 1275 | case CMD_r010_0100_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH4: return "LTHRESH4"; |
whismanoid | 0:68e64068330f | 1276 | case CMD_r010_0101_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH5: return "LTHRESH5"; |
whismanoid | 0:68e64068330f | 1277 | case CMD_r010_0110_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH6: return "LTHRESH6"; |
whismanoid | 0:68e64068330f | 1278 | case CMD_r010_0111_dddd_dddd_dddd_dddd_dddd_dddd_LTHRESH7: return "LTHRESH7"; |
whismanoid | 0:68e64068330f | 1279 | case CMD_r010_1000_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH0: return "UTHRESH0"; |
whismanoid | 0:68e64068330f | 1280 | case CMD_r010_1001_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH1: return "UTHRESH1"; |
whismanoid | 0:68e64068330f | 1281 | case CMD_r010_1010_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH2: return "UTHRESH2"; |
whismanoid | 0:68e64068330f | 1282 | case CMD_r010_1011_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH3: return "UTHRESH3"; |
whismanoid | 0:68e64068330f | 1283 | case CMD_r010_1100_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH4: return "UTHRESH4"; |
whismanoid | 0:68e64068330f | 1284 | case CMD_r010_1101_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH5: return "UTHRESH5"; |
whismanoid | 0:68e64068330f | 1285 | case CMD_r010_1110_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH6: return "UTHRESH6"; |
whismanoid | 0:68e64068330f | 1286 | case CMD_r010_1111_dddd_dddd_dddd_dddd_dddd_dddd_UTHRESH7: return "UTHRESH7"; |
whismanoid | 0:68e64068330f | 1287 | case CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0: return "DATA0"; |
whismanoid | 0:68e64068330f | 1288 | case CMD_r011_0001_dddd_dddd_dddd_dddd_dddd_dddd_DATA1: return "DATA1"; |
whismanoid | 0:68e64068330f | 1289 | case CMD_r011_0010_dddd_dddd_dddd_dddd_dddd_dddd_DATA2: return "DATA2"; |
whismanoid | 0:68e64068330f | 1290 | case CMD_r011_0011_dddd_dddd_dddd_dddd_dddd_dddd_DATA3: return "DATA3"; |
whismanoid | 0:68e64068330f | 1291 | case CMD_r011_0100_dddd_dddd_dddd_dddd_dddd_dddd_DATA4: return "DATA4"; |
whismanoid | 0:68e64068330f | 1292 | case CMD_r011_0101_dddd_dddd_dddd_dddd_dddd_dddd_DATA5: return "DATA5"; |
whismanoid | 0:68e64068330f | 1293 | case CMD_r011_0110_dddd_dddd_dddd_dddd_dddd_dddd_DATA6: return "DATA6"; |
whismanoid | 0:68e64068330f | 1294 | case CMD_r011_0111_dddd_dddd_dddd_dddd_dddd_dddd_DATA7: return "DATA7"; |
whismanoid | 0:68e64068330f | 1295 | case CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS: return "STATUS"; |
whismanoid | 0:68e64068330f | 1296 | case CMD_r011_1001_dddd_dddd_dddd_dddd_dxxd_dddd_STATUS_IE: return "STATUS_IE"; |
whismanoid | 0:68e64068330f | 1297 | case CMD_r011_1010_xaaa_aaaa_dddd_dddd_UC_0: return "UC_0"; |
whismanoid | 0:68e64068330f | 1298 | case CMD_r011_1011_xaaa_aaaa_dddd_dddd_UC_1: return "UC_1"; |
whismanoid | 0:68e64068330f | 1299 | case CMD_r011_1100_xaaa_aaaa_dddd_dddd_UC_2: return "UC_2"; |
whismanoid | 0:68e64068330f | 1300 | case CMD_r011_1101_xaaa_aaaa_dddd_dddd_UC_3: return "UC_3"; |
whismanoid | 0:68e64068330f | 1301 | case CMD_r011_1110_xaaa_aaaa_dddd_dddd_UC_4: return "UC_4"; |
whismanoid | 0:68e64068330f | 1302 | case CMD_r011_1111_xaaa_aaaa_dddd_dddd_UC_5: return "UC_5"; |
whismanoid | 0:68e64068330f | 1303 | case CMD_r100_0000_xaaa_aaaa_dddd_dddd_UC_6: return "UC_6"; |
whismanoid | 0:68e64068330f | 1304 | case CMD_r100_0001_xaaa_aaaa_dddd_dddd_UC_7: return "UC_7"; |
whismanoid | 0:68e64068330f | 1305 | case CMD_r100_0010_xaaa_aaaa_dddd_dddd_UC_8: return "UC_8"; |
whismanoid | 0:68e64068330f | 1306 | case CMD_r100_0011_xaaa_aaaa_dddd_dddd_UC_9: return "UC_9"; |
whismanoid | 0:68e64068330f | 1307 | case CMD_r100_0100_xaaa_aaaa_dddd_dddd_UC_10: return "UC_10"; |
whismanoid | 0:68e64068330f | 1308 | case CMD_r100_0101_xaaa_aaaa_dddd_dddd_UC_11: return "UC_11"; |
whismanoid | 0:68e64068330f | 1309 | case CMD_r100_0110_xaaa_aaaa_dddd_dddd_UC_12: return "UC_12"; |
whismanoid | 0:68e64068330f | 1310 | case CMD_r100_0111_xaaa_aaaa_dddd_dddd_UC_13: return "UC_13"; |
whismanoid | 0:68e64068330f | 1311 | case CMD_r100_1000_xaaa_aaaa_dddd_dddd_UC_14: return "UC_14"; |
whismanoid | 0:68e64068330f | 1312 | case CMD_r100_1001_xaaa_aaaa_dddd_dddd_UC_15: return "UC_15"; |
whismanoid | 0:68e64068330f | 1313 | case CMD_r100_1010_xaaa_aaaa_dddd_dddd_UC_16: return "UC_16"; |
whismanoid | 0:68e64068330f | 1314 | case CMD_r100_1011_xaaa_aaaa_dddd_dddd_UC_17: return "UC_17"; |
whismanoid | 0:68e64068330f | 1315 | case CMD_r100_1100_xaaa_aaaa_dddd_dddd_UC_18: return "UC_18"; |
whismanoid | 0:68e64068330f | 1316 | case CMD_r100_1101_xaaa_aaaa_dddd_dddd_UC_19: return "UC_19"; |
whismanoid | 0:68e64068330f | 1317 | case CMD_r100_1110_xaaa_aaaa_dddd_dddd_UC_20: return "UC_20"; |
whismanoid | 0:68e64068330f | 1318 | case CMD_r100_1111_xaaa_aaaa_dddd_dddd_UC_21: return "UC_21"; |
whismanoid | 0:68e64068330f | 1319 | case CMD_r101_0000_xaaa_aaaa_dddd_dddd_UC_22: return "UC_22"; |
whismanoid | 0:68e64068330f | 1320 | case CMD_r101_0001_xaaa_aaaa_dddd_dddd_UC_23: return "UC_23"; |
whismanoid | 0:68e64068330f | 1321 | case CMD_r101_0010_xaaa_aaaa_dddd_dddd_UC_24: return "UC_24"; |
whismanoid | 0:68e64068330f | 1322 | case CMD_r101_0011_xaaa_aaaa_dddd_dddd_UC_25: return "UC_25"; |
whismanoid | 0:68e64068330f | 1323 | case CMD_r101_0100_xaaa_aaaa_dddd_dddd_UC_26: return "UC_26"; |
whismanoid | 0:68e64068330f | 1324 | case CMD_r101_0101_xaaa_aaaa_dddd_dddd_UC_27: return "UC_27"; |
whismanoid | 0:68e64068330f | 1325 | case CMD_r101_0110_xaaa_aaaa_dddd_dddd_UC_28: return "UC_28"; |
whismanoid | 0:68e64068330f | 1326 | case CMD_r101_0111_xaaa_aaaa_dddd_dddd_UC_29: return "UC_29"; |
whismanoid | 0:68e64068330f | 1327 | case CMD_r101_1000_xaaa_aaaa_dddd_dddd_UC_30: return "UC_30"; |
whismanoid | 0:68e64068330f | 1328 | case CMD_r101_1001_xaaa_aaaa_dddd_dddd_UC_31: return "UC_31"; |
whismanoid | 0:68e64068330f | 1329 | case CMD_r101_1010_xaaa_aaaa_dddd_dddd_UC_32: return "UC_32"; |
whismanoid | 0:68e64068330f | 1330 | case CMD_r101_1011_xaaa_aaaa_dddd_dddd_UC_33: return "UC_33"; |
whismanoid | 0:68e64068330f | 1331 | case CMD_r101_1100_xaaa_aaaa_dddd_dddd_UC_34: return "UC_34"; |
whismanoid | 0:68e64068330f | 1332 | case CMD_r101_1101_xaaa_aaaa_dddd_dddd_UC_35: return "UC_35"; |
whismanoid | 0:68e64068330f | 1333 | case CMD_r101_1110_xaaa_aaaa_dddd_dddd_UC_36: return "UC_36"; |
whismanoid | 0:68e64068330f | 1334 | case CMD_r101_1111_xaaa_aaaa_dddd_dddd_UC_37: return "UC_37"; |
whismanoid | 0:68e64068330f | 1335 | case CMD_r110_0000_xaaa_aaaa_dddd_dddd_UC_38: return "UC_38"; |
whismanoid | 0:68e64068330f | 1336 | case CMD_r110_0001_xaaa_aaaa_dddd_dddd_UC_39: return "UC_39"; |
whismanoid | 0:68e64068330f | 1337 | case CMD_r110_0010_xaaa_aaaa_dddd_dddd_UC_40: return "UC_40"; |
whismanoid | 0:68e64068330f | 1338 | case CMD_r110_0011_xaaa_aaaa_dddd_dddd_UC_41: return "UC_41"; |
whismanoid | 0:68e64068330f | 1339 | case CMD_r110_0100_xaaa_aaaa_dddd_dddd_UC_42: return "UC_42"; |
whismanoid | 0:68e64068330f | 1340 | case CMD_r110_0101_xaaa_aaaa_dddd_dddd_UC_43: return "UC_43"; |
whismanoid | 0:68e64068330f | 1341 | case CMD_r110_0110_xaaa_aaaa_dddd_dddd_UC_44: return "UC_44"; |
whismanoid | 0:68e64068330f | 1342 | case CMD_r110_0111_xaaa_aaaa_dddd_dddd_UC_45: return "UC_45"; |
whismanoid | 0:68e64068330f | 1343 | case CMD_r110_1000_xaaa_aaaa_dddd_dddd_UC_46: return "UC_46"; |
whismanoid | 0:68e64068330f | 1344 | case CMD_r110_1001_xaaa_aaaa_dddd_dddd_UC_47: return "UC_47"; |
whismanoid | 0:68e64068330f | 1345 | case CMD_r110_1010_xaaa_aaaa_dddd_dddd_UC_48: return "UC_48"; |
whismanoid | 0:68e64068330f | 1346 | case CMD_r110_1011_xaaa_aaaa_dddd_dddd_UC_49: return "UC_49"; |
whismanoid | 0:68e64068330f | 1347 | case CMD_r110_1100_xaaa_aaaa_dddd_dddd_UC_50: return "UC_50"; |
whismanoid | 0:68e64068330f | 1348 | case CMD_r110_1101_xaaa_aaaa_dddd_dddd_UC_51: return "UC_51"; |
whismanoid | 0:68e64068330f | 1349 | case CMD_r110_1110_xaaa_aaaa_dddd_dddd_UC_52: return "UC_52"; |
whismanoid | 0:68e64068330f | 1350 | case CMD_r110_1111_xxxx_xxxx_xaaa_aaaa_UCADDR: return "UCADDR"; |
whismanoid | 0:68e64068330f | 1351 | } |
whismanoid | 0:68e64068330f | 1352 | } |
whismanoid | 0:68e64068330f | 1353 | |
whismanoid | 0:68e64068330f | 1354 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1355 | // Menu item 'XF' |
whismanoid | 1:d57c1a2cb83c | 1356 | // |
whismanoid | 1:d57c1a2cb83c | 1357 | // FILTER Select Filter and Rate. |
whismanoid | 1:d57c1a2cb83c | 1358 | // Sets conversion rate based on RATE, LINEF, and CONV_TYPE value. See Table 9a through Table 9d for details. |
whismanoid | 1:d57c1a2cb83c | 1359 | // For CONV_TYPE_01_Continuous, linef=LINEF_11_SINC4, rate=RATE_0100 selects output data rate 60SPS. |
whismanoid | 1:d57c1a2cb83c | 1360 | // |
whismanoid | 1:d57c1a2cb83c | 1361 | // @param[in] linef = filter type, default=MAX11410::LINEF_enum_t::LINEF_11_SINC4 |
whismanoid | 1:d57c1a2cb83c | 1362 | // @param[in] rate = output data rate selection, default=MAX11410::RATE_enum_t::RATE_0100 |
whismanoid | 1:d57c1a2cb83c | 1363 | // |
whismanoid | 1:d57c1a2cb83c | 1364 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1365 | uint8_t MAX11410::Configure_FILTER(uint8_t linef, uint8_t rate) |
whismanoid | 1:d57c1a2cb83c | 1366 | { |
whismanoid | 1:d57c1a2cb83c | 1367 | |
whismanoid | 1:d57c1a2cb83c | 1368 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1369 | // write8 0x08 FILTER |
whismanoid | 1:d57c1a2cb83c | 1370 | RegWrite(CMD_r000_1000_x0dd_dddd_FILTER, (uint8_t)(0 |
whismanoid | 1:d57c1a2cb83c | 1371 | | (((uint8_t)linef & 3) << 4) |
whismanoid | 1:d57c1a2cb83c | 1372 | | (((uint8_t)rate & 15) << 0) |
whismanoid | 1:d57c1a2cb83c | 1373 | )); |
whismanoid | 1:d57c1a2cb83c | 1374 | |
whismanoid | 1:d57c1a2cb83c | 1375 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1376 | // success |
whismanoid | 1:d57c1a2cb83c | 1377 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1378 | } |
whismanoid | 1:d57c1a2cb83c | 1379 | |
whismanoid | 1:d57c1a2cb83c | 1380 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1381 | // Menu item 'XP' |
whismanoid | 1:d57c1a2cb83c | 1382 | // |
whismanoid | 1:d57c1a2cb83c | 1383 | // PGA Select Gain and Signal Path. |
whismanoid | 1:d57c1a2cb83c | 1384 | // |
whismanoid | 1:d57c1a2cb83c | 1385 | // @param[in] sigpath = signal path, default=MAX11410::SIG_PATH_enum_t::SIG_PATH_00_BUFFERED |
whismanoid | 1:d57c1a2cb83c | 1386 | // @param[in] gain = gain selection, default=MAX11410::GAIN_enum_t::GAIN_000_1 |
whismanoid | 1:d57c1a2cb83c | 1387 | // |
whismanoid | 1:d57c1a2cb83c | 1388 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1389 | uint8_t MAX11410::Configure_PGA(uint8_t sigpath, uint8_t gain) |
whismanoid | 1:d57c1a2cb83c | 1390 | { |
whismanoid | 1:d57c1a2cb83c | 1391 | |
whismanoid | 1:d57c1a2cb83c | 1392 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1393 | // write8 0x0E PGA |
whismanoid | 23:22e7830bcccb | 1394 | RegWrite(CMD_r000_1110_00ss_0ggg_PGA, (uint8_t)(0 |
whismanoid | 1:d57c1a2cb83c | 1395 | | (((uint8_t)sigpath & 2) << 4) |
whismanoid | 1:d57c1a2cb83c | 1396 | | (((uint8_t)gain & 7) << 0) |
whismanoid | 1:d57c1a2cb83c | 1397 | )); |
whismanoid | 1:d57c1a2cb83c | 1398 | |
whismanoid | 1:d57c1a2cb83c | 1399 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1400 | // success |
whismanoid | 1:d57c1a2cb83c | 1401 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1402 | } |
whismanoid | 1:d57c1a2cb83c | 1403 | |
whismanoid | 1:d57c1a2cb83c | 1404 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1405 | // Menu item 'XC' |
whismanoid | 1:d57c1a2cb83c | 1406 | // |
whismanoid | 1:d57c1a2cb83c | 1407 | // CTRL Select clock, format, and reference. |
whismanoid | 1:d57c1a2cb83c | 1408 | // |
whismanoid | 1:d57c1a2cb83c | 1409 | // @param[in] extclk = external clock enable, default=0 |
whismanoid | 1:d57c1a2cb83c | 1410 | // @param[in] u_bn = unipolar input range enable, default=0 |
whismanoid | 1:d57c1a2cb83c | 1411 | // @param[in] format = offset binary format enable, default=0 |
whismanoid | 1:d57c1a2cb83c | 1412 | // @param[in] refbufp_en = REFP reference buffer enable, default=0 |
whismanoid | 1:d57c1a2cb83c | 1413 | // @param[in] refbufn_en = REFN reference buffer enable, default=0 |
whismanoid | 1:d57c1a2cb83c | 1414 | // @param[in] ref_sel = reference selection, default=MAX11410::REF_SEL_enum_t::REF_SEL_001_REF1P_REF1N |
whismanoid | 1:d57c1a2cb83c | 1415 | // |
whismanoid | 1:d57c1a2cb83c | 1416 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1417 | 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 | 1418 | { |
whismanoid | 1:d57c1a2cb83c | 1419 | |
whismanoid | 1:d57c1a2cb83c | 1420 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1421 | // shadow of register CMD_r000_1001_dddd_dddd_CTRL |
whismanoid | 1:d57c1a2cb83c | 1422 | ctrl = (uint8_t)(0 |
whismanoid | 1:d57c1a2cb83c | 1423 | | (((uint8_t)extclk & 1) << 7) |
whismanoid | 1:d57c1a2cb83c | 1424 | | (((uint8_t)u_bn & 1) << 6) |
whismanoid | 1:d57c1a2cb83c | 1425 | | (((uint8_t)format & 1) << 5) |
whismanoid | 1:d57c1a2cb83c | 1426 | | (((uint8_t)refbufp_en & 1) << 4) |
whismanoid | 1:d57c1a2cb83c | 1427 | | (((uint8_t)refbufn_en & 1) << 3) |
whismanoid | 1:d57c1a2cb83c | 1428 | | (((uint8_t)ref_sel & 7) << 0) |
whismanoid | 1:d57c1a2cb83c | 1429 | ); |
whismanoid | 1:d57c1a2cb83c | 1430 | |
whismanoid | 1:d57c1a2cb83c | 1431 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1432 | // write8 0x09 CTRL |
whismanoid | 1:d57c1a2cb83c | 1433 | RegWrite(CMD_r000_1001_dddd_dddd_CTRL, ctrl); |
whismanoid | 1:d57c1a2cb83c | 1434 | |
whismanoid | 1:d57c1a2cb83c | 1435 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1436 | // success |
whismanoid | 1:d57c1a2cb83c | 1437 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1438 | } |
whismanoid | 1:d57c1a2cb83c | 1439 | |
whismanoid | 1:d57c1a2cb83c | 1440 | //---------------------------------------- |
whismanoid | 14:b49eecf7e4d8 | 1441 | // Menu item 'XR' |
whismanoid | 14:b49eecf7e4d8 | 1442 | // |
whismanoid | 14:b49eecf7e4d8 | 1443 | // CTRL select reference, without changing the other fields. |
whismanoid | 14:b49eecf7e4d8 | 1444 | // |
whismanoid | 14:b49eecf7e4d8 | 1445 | // @pre ctrl = shadow of CTRL register |
whismanoid | 14:b49eecf7e4d8 | 1446 | // @param[in] ref_sel = reference selection, default=MAX11410::REF_SEL_enum_t::REF_SEL_001_REF1P_REF1N |
whismanoid | 14:b49eecf7e4d8 | 1447 | // |
whismanoid | 14:b49eecf7e4d8 | 1448 | // @return 1 on success; 0 on failure |
whismanoid | 14:b49eecf7e4d8 | 1449 | uint8_t MAX11410::Configure_CTRL_REF(uint8_t ref_sel) |
whismanoid | 14:b49eecf7e4d8 | 1450 | { |
whismanoid | 14:b49eecf7e4d8 | 1451 | |
whismanoid | 14:b49eecf7e4d8 | 1452 | //---------------------------------------- |
whismanoid | 14:b49eecf7e4d8 | 1453 | // shadow of register CMD_r000_1001_dddd_dddd_CTRL |
whismanoid | 14:b49eecf7e4d8 | 1454 | ctrl = (ctrl & ((~ 7) << 0)) |
whismanoid | 14:b49eecf7e4d8 | 1455 | | (((uint8_t)ref_sel & 7) << 0); |
whismanoid | 14:b49eecf7e4d8 | 1456 | |
whismanoid | 14:b49eecf7e4d8 | 1457 | //---------------------------------------- |
whismanoid | 14:b49eecf7e4d8 | 1458 | // write8 0x09 CTRL |
whismanoid | 14:b49eecf7e4d8 | 1459 | RegWrite(CMD_r000_1001_dddd_dddd_CTRL, ctrl); |
whismanoid | 14:b49eecf7e4d8 | 1460 | |
whismanoid | 14:b49eecf7e4d8 | 1461 | //---------------------------------------- |
whismanoid | 14:b49eecf7e4d8 | 1462 | // success |
whismanoid | 14:b49eecf7e4d8 | 1463 | return 1; |
whismanoid | 14:b49eecf7e4d8 | 1464 | } |
whismanoid | 14:b49eecf7e4d8 | 1465 | |
whismanoid | 14:b49eecf7e4d8 | 1466 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1467 | // Menu item 'XS' |
whismanoid | 1:d57c1a2cb83c | 1468 | // |
whismanoid | 1:d57c1a2cb83c | 1469 | // SOURCE Configure voltage bias source, current source, burnout mode |
whismanoid | 1:d57c1a2cb83c | 1470 | // |
whismanoid | 1:d57c1a2cb83c | 1471 | // @param[in] vbias_mode = _______, default=MAX11410::VBIAS_MODE_enum_t::VBIAS_MODE_00_Active |
whismanoid | 1:d57c1a2cb83c | 1472 | // @param[in] brn_mode = _______, default=MAX11410::BRN_MODE_enum_t::BRN_MODE_00_disabled |
whismanoid | 1:d57c1a2cb83c | 1473 | // @param[in] idac_mode = _______, default=MAX11410::IDAC_MODE_enum_t::IDAC_MODE_0000_10uA |
whismanoid | 1:d57c1a2cb83c | 1474 | // |
whismanoid | 1:d57c1a2cb83c | 1475 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1476 | uint8_t MAX11410::Configure_SOURCE(uint8_t vbias_mode, uint8_t brn_mode, uint8_t idac_mode) |
whismanoid | 1:d57c1a2cb83c | 1477 | { |
whismanoid | 1:d57c1a2cb83c | 1478 | |
whismanoid | 1:d57c1a2cb83c | 1479 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1480 | // warning -- WIP work in progress |
whismanoid | 1:d57c1a2cb83c | 1481 | #warning "Not Tested Yet: MAX11410::Configure_SOURCE..." |
whismanoid | 1:d57c1a2cb83c | 1482 | |
whismanoid | 1:d57c1a2cb83c | 1483 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1484 | // write8 0x0A SOURCE |
whismanoid | 1:d57c1a2cb83c | 1485 | RegWrite(CMD_r000_1010_dddd_dddd_SOURCE, (uint8_t)(0 |
whismanoid | 1:d57c1a2cb83c | 1486 | | (((uint8_t)vbias_mode & 3) << 6) |
whismanoid | 1:d57c1a2cb83c | 1487 | | (((uint8_t)brn_mode & 3) << 4) |
whismanoid | 1:d57c1a2cb83c | 1488 | | (((uint8_t)idac_mode & 15) << 0) |
whismanoid | 1:d57c1a2cb83c | 1489 | )); |
whismanoid | 1:d57c1a2cb83c | 1490 | |
whismanoid | 1:d57c1a2cb83c | 1491 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1492 | // success |
whismanoid | 1:d57c1a2cb83c | 1493 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1494 | } |
whismanoid | 1:d57c1a2cb83c | 1495 | |
whismanoid | 1:d57c1a2cb83c | 1496 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1497 | // Menu item 'XM' |
whismanoid | 1:d57c1a2cb83c | 1498 | // |
whismanoid | 1:d57c1a2cb83c | 1499 | // MUX_CTRL0 Select pins for analog input AINP and AINN |
whismanoid | 1:d57c1a2cb83c | 1500 | // |
whismanoid | 1:d57c1a2cb83c | 1501 | // @param[in] ainp = channel high side, default=MAX11410::AINP_SEL_enum_t::AINP_SEL_0000_AIN0 |
whismanoid | 1:d57c1a2cb83c | 1502 | // @param[in] ainn = channel low side, default=MAX11410::AINN_SEL_enum_t::AINN_SEL_1010_GND |
whismanoid | 1:d57c1a2cb83c | 1503 | // |
whismanoid | 1:d57c1a2cb83c | 1504 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1505 | uint8_t MAX11410::Configure_MUX_CTRL0(uint8_t ainp, uint8_t ainn) |
whismanoid | 1:d57c1a2cb83c | 1506 | { |
whismanoid | 1:d57c1a2cb83c | 1507 | |
whismanoid | 1:d57c1a2cb83c | 1508 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1509 | // warning -- WIP work in progress |
whismanoid | 1:d57c1a2cb83c | 1510 | #warning "Not Tested Yet: MAX11410::Configure_MUX_CTRL0..." |
whismanoid | 1:d57c1a2cb83c | 1511 | |
whismanoid | 1:d57c1a2cb83c | 1512 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1513 | // write8 0x0B MUX_CTRL0 |
whismanoid | 1:d57c1a2cb83c | 1514 | RegWrite(CMD_r000_1011_dddd_dddd_MUX_CTRL0, (uint8_t)(0 |
whismanoid | 1:d57c1a2cb83c | 1515 | | (((uint8_t)ainp & 15) << 4) |
whismanoid | 1:d57c1a2cb83c | 1516 | | (((uint8_t)ainn & 15) << 0) |
whismanoid | 1:d57c1a2cb83c | 1517 | )); |
whismanoid | 1:d57c1a2cb83c | 1518 | |
whismanoid | 1:d57c1a2cb83c | 1519 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1520 | // success |
whismanoid | 1:d57c1a2cb83c | 1521 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1522 | } |
whismanoid | 1:d57c1a2cb83c | 1523 | |
whismanoid | 1:d57c1a2cb83c | 1524 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1525 | // Menu item 'XI' |
whismanoid | 1:d57c1a2cb83c | 1526 | // |
whismanoid | 1:d57c1a2cb83c | 1527 | // MUX_CTRL1 Select pins for current source |
whismanoid | 1:d57c1a2cb83c | 1528 | // |
whismanoid | 1:d57c1a2cb83c | 1529 | // @param[in] idac1_sel = channel high side, default=MAX11410::IDAC1_SEL_enum_t::IDAC1_SEL_1111_unconnected |
whismanoid | 1:d57c1a2cb83c | 1530 | // @param[in] idac0_sel = channel low side, default=MAX11410::IDAC0_SEL_enum_t::IDAC0_SEL_1111_unconnected |
whismanoid | 1:d57c1a2cb83c | 1531 | // |
whismanoid | 1:d57c1a2cb83c | 1532 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1533 | uint8_t MAX11410::Configure_MUX_CTRL1(uint8_t idac1_sel, uint8_t idac0_sel) |
whismanoid | 1:d57c1a2cb83c | 1534 | { |
whismanoid | 1:d57c1a2cb83c | 1535 | |
whismanoid | 1:d57c1a2cb83c | 1536 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1537 | // warning -- WIP work in progress |
whismanoid | 1:d57c1a2cb83c | 1538 | #warning "Not Tested Yet: MAX11410::Configure_MUX_CTRL1..." |
whismanoid | 1:d57c1a2cb83c | 1539 | |
whismanoid | 1:d57c1a2cb83c | 1540 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1541 | // write8 0x0C MUX_CTRL1 |
whismanoid | 1:d57c1a2cb83c | 1542 | RegWrite(CMD_r000_1100_dddd_dddd_MUX_CTRL1, (uint8_t)(0 |
whismanoid | 1:d57c1a2cb83c | 1543 | | (((uint8_t)idac1_sel & 15) << 4) |
whismanoid | 1:d57c1a2cb83c | 1544 | | (((uint8_t)idac0_sel & 15) << 0) |
whismanoid | 1:d57c1a2cb83c | 1545 | )); |
whismanoid | 1:d57c1a2cb83c | 1546 | |
whismanoid | 1:d57c1a2cb83c | 1547 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1548 | // success |
whismanoid | 1:d57c1a2cb83c | 1549 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1550 | } |
whismanoid | 1:d57c1a2cb83c | 1551 | |
whismanoid | 1:d57c1a2cb83c | 1552 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1553 | // Menu item 'XV' |
whismanoid | 1:d57c1a2cb83c | 1554 | // |
whismanoid | 1:d57c1a2cb83c | 1555 | // MUX_CTRL2 Select pins for voltage bias source |
whismanoid | 1:d57c1a2cb83c | 1556 | // |
whismanoid | 1:d57c1a2cb83c | 1557 | // @param[in] vbias_ain7_ain0_bitmap = bit map of AIN7..AIN0 enables for voltage bias, default=0 |
whismanoid | 1:d57c1a2cb83c | 1558 | // |
whismanoid | 1:d57c1a2cb83c | 1559 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1560 | uint8_t MAX11410::Configure_MUX_CTRL2(uint8_t vbias_ain7_ain0_bitmap) |
whismanoid | 1:d57c1a2cb83c | 1561 | { |
whismanoid | 1:d57c1a2cb83c | 1562 | |
whismanoid | 1:d57c1a2cb83c | 1563 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1564 | // warning -- WIP work in progress |
whismanoid | 1:d57c1a2cb83c | 1565 | #warning "Not Tested Yet: MAX11410::Configure_MUX_CTRL2..." |
whismanoid | 1:d57c1a2cb83c | 1566 | |
whismanoid | 1:d57c1a2cb83c | 1567 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1568 | // write8 0x0D MUX_CTRL2 |
whismanoid | 1:d57c1a2cb83c | 1569 | RegWrite(CMD_r000_1101_dddd_dddd_MUX_CTRL2, vbias_ain7_ain0_bitmap); |
whismanoid | 1:d57c1a2cb83c | 1570 | |
whismanoid | 1:d57c1a2cb83c | 1571 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1572 | // success |
whismanoid | 1:d57c1a2cb83c | 1573 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1574 | } |
whismanoid | 1:d57c1a2cb83c | 1575 | |
whismanoid | 1:d57c1a2cb83c | 1576 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1577 | // Menu item 'X0' |
whismanoid | 1:d57c1a2cb83c | 1578 | // |
whismanoid | 1:d57c1a2cb83c | 1579 | // CAL_START Calibrate Self Offset and Gain. |
whismanoid | 1:d57c1a2cb83c | 1580 | // |
whismanoid | 1:d57c1a2cb83c | 1581 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1582 | uint8_t MAX11410::Calibrate_Self_Offset_Gain(void) |
whismanoid | 1:d57c1a2cb83c | 1583 | { |
whismanoid | 1:d57c1a2cb83c | 1584 | |
whismanoid | 1:d57c1a2cb83c | 1585 | //---------------------------------------- |
whismanoid | 25:c4be3afbfafd | 1586 | // write8 0x03 CAL_START -- RegWrite will poll status until CAL_RDY |
whismanoid | 1:d57c1a2cb83c | 1587 | RegWrite(CMD_r000_0011_xxxx_xddd_CAL_START, (uint8_t)CAL_TYPE_000_SELF_CAL); |
whismanoid | 1:d57c1a2cb83c | 1588 | |
whismanoid | 1:d57c1a2cb83c | 1589 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1590 | // success |
whismanoid | 1:d57c1a2cb83c | 1591 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1592 | } |
whismanoid | 1:d57c1a2cb83c | 1593 | |
whismanoid | 1:d57c1a2cb83c | 1594 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1595 | // Menu item 'X1' |
whismanoid | 1:d57c1a2cb83c | 1596 | // |
whismanoid | 1:d57c1a2cb83c | 1597 | // CAL_START Calibrate Selected PGA. |
whismanoid | 1:d57c1a2cb83c | 1598 | // |
whismanoid | 1:d57c1a2cb83c | 1599 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1600 | uint8_t MAX11410::Calibrate_PGA_Gain(void) |
whismanoid | 1:d57c1a2cb83c | 1601 | { |
whismanoid | 1:d57c1a2cb83c | 1602 | |
whismanoid | 1:d57c1a2cb83c | 1603 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1604 | // warning -- WIP work in progress |
whismanoid | 1:d57c1a2cb83c | 1605 | #warning "Not Tested Yet: MAX11410::Calibrate_PGA_Gain..." |
whismanoid | 1:d57c1a2cb83c | 1606 | |
whismanoid | 1:d57c1a2cb83c | 1607 | //---------------------------------------- |
whismanoid | 25:c4be3afbfafd | 1608 | // write8 0x03 CAL_START -- RegWrite will poll status until CAL_RDY |
whismanoid | 1:d57c1a2cb83c | 1609 | RegWrite(CMD_r000_0011_xxxx_xddd_CAL_START, (uint8_t)CAL_TYPE_001_PGA_GAIN); |
whismanoid | 1:d57c1a2cb83c | 1610 | |
whismanoid | 1:d57c1a2cb83c | 1611 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1612 | // success |
whismanoid | 1:d57c1a2cb83c | 1613 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1614 | } |
whismanoid | 1:d57c1a2cb83c | 1615 | |
whismanoid | 1:d57c1a2cb83c | 1616 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1617 | // Menu item 'X4' |
whismanoid | 1:d57c1a2cb83c | 1618 | // |
whismanoid | 1:d57c1a2cb83c | 1619 | // CAL_START Calibrate System Offset A. |
whismanoid | 1:d57c1a2cb83c | 1620 | // |
whismanoid | 1:d57c1a2cb83c | 1621 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1622 | uint8_t MAX11410::Calibrate_System_Offset_A(void) |
whismanoid | 1:d57c1a2cb83c | 1623 | { |
whismanoid | 1:d57c1a2cb83c | 1624 | |
whismanoid | 1:d57c1a2cb83c | 1625 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1626 | // warning -- WIP work in progress |
whismanoid | 1:d57c1a2cb83c | 1627 | #warning "Not Tested Yet: MAX11410::Calibrate_System_Offset_A..." |
whismanoid | 1:d57c1a2cb83c | 1628 | |
whismanoid | 1:d57c1a2cb83c | 1629 | //---------------------------------------- |
whismanoid | 25:c4be3afbfafd | 1630 | // write8 0x03 CAL_START -- RegWrite will poll status until CAL_RDY |
whismanoid | 1:d57c1a2cb83c | 1631 | RegWrite(CMD_r000_0011_xxxx_xddd_CAL_START, (uint8_t)CAL_TYPE_100_SYS_OFF_A); |
whismanoid | 1:d57c1a2cb83c | 1632 | |
whismanoid | 1:d57c1a2cb83c | 1633 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1634 | // success |
whismanoid | 1:d57c1a2cb83c | 1635 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1636 | } |
whismanoid | 1:d57c1a2cb83c | 1637 | |
whismanoid | 1:d57c1a2cb83c | 1638 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1639 | // Menu item 'X5' |
whismanoid | 1:d57c1a2cb83c | 1640 | // |
whismanoid | 1:d57c1a2cb83c | 1641 | // X6 0x03 CAL_START 0x06 Calibrate System Offset B |
whismanoid | 1:d57c1a2cb83c | 1642 | // X7 0x03 CAL_START 0x07 Calibrate System Gain B |
whismanoid | 1:d57c1a2cb83c | 1643 | // CAL_START Calibrate System Gain A. |
whismanoid | 1:d57c1a2cb83c | 1644 | // |
whismanoid | 1:d57c1a2cb83c | 1645 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1646 | uint8_t MAX11410::Calibrate_System_Gain_A(void) |
whismanoid | 1:d57c1a2cb83c | 1647 | { |
whismanoid | 1:d57c1a2cb83c | 1648 | |
whismanoid | 1:d57c1a2cb83c | 1649 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1650 | // warning -- WIP work in progress |
whismanoid | 1:d57c1a2cb83c | 1651 | #warning "Not Tested Yet: MAX11410::Calibrate_System_Gain_A..." |
whismanoid | 1:d57c1a2cb83c | 1652 | |
whismanoid | 1:d57c1a2cb83c | 1653 | //---------------------------------------- |
whismanoid | 25:c4be3afbfafd | 1654 | // write8 0x03 CAL_START -- RegWrite will poll status until CAL_RDY |
whismanoid | 1:d57c1a2cb83c | 1655 | RegWrite(CMD_r000_0011_xxxx_xddd_CAL_START, (uint8_t)CAL_TYPE_101_SYS_GAIN_A); |
whismanoid | 1:d57c1a2cb83c | 1656 | |
whismanoid | 1:d57c1a2cb83c | 1657 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1658 | // success |
whismanoid | 1:d57c1a2cb83c | 1659 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1660 | } |
whismanoid | 1:d57c1a2cb83c | 1661 | |
whismanoid | 1:d57c1a2cb83c | 1662 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1663 | // Menu item 'X6' |
whismanoid | 1:d57c1a2cb83c | 1664 | // |
whismanoid | 1:d57c1a2cb83c | 1665 | // CAL_START Calibrate System Offset B. |
whismanoid | 1:d57c1a2cb83c | 1666 | // |
whismanoid | 1:d57c1a2cb83c | 1667 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1668 | uint8_t MAX11410::Calibrate_System_Offset_B(void) |
whismanoid | 1:d57c1a2cb83c | 1669 | { |
whismanoid | 1:d57c1a2cb83c | 1670 | |
whismanoid | 1:d57c1a2cb83c | 1671 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1672 | // warning -- WIP work in progress |
whismanoid | 1:d57c1a2cb83c | 1673 | #warning "Not Tested Yet: MAX11410::Calibrate_System_Offset_B..." |
whismanoid | 1:d57c1a2cb83c | 1674 | |
whismanoid | 1:d57c1a2cb83c | 1675 | //---------------------------------------- |
whismanoid | 25:c4be3afbfafd | 1676 | // write8 0x03 CAL_START -- RegWrite will poll status until CAL_RDY |
whismanoid | 1:d57c1a2cb83c | 1677 | RegWrite(CMD_r000_0011_xxxx_xddd_CAL_START, (uint8_t)CAL_TYPE_110_SYS_OFF_B); |
whismanoid | 1:d57c1a2cb83c | 1678 | |
whismanoid | 1:d57c1a2cb83c | 1679 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1680 | // success |
whismanoid | 1:d57c1a2cb83c | 1681 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1682 | } |
whismanoid | 1:d57c1a2cb83c | 1683 | |
whismanoid | 1:d57c1a2cb83c | 1684 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1685 | // Menu item 'X7' |
whismanoid | 1:d57c1a2cb83c | 1686 | // |
whismanoid | 1:d57c1a2cb83c | 1687 | // CAL_START Calibrate System Gain B. |
whismanoid | 1:d57c1a2cb83c | 1688 | // |
whismanoid | 1:d57c1a2cb83c | 1689 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1690 | uint8_t MAX11410::Calibrate_System_Gain_B(void) |
whismanoid | 1:d57c1a2cb83c | 1691 | { |
whismanoid | 1:d57c1a2cb83c | 1692 | |
whismanoid | 1:d57c1a2cb83c | 1693 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1694 | // warning -- WIP work in progress |
whismanoid | 1:d57c1a2cb83c | 1695 | #warning "Not Tested Yet: MAX11410::Calibrate_System_Gain_B..." |
whismanoid | 1:d57c1a2cb83c | 1696 | |
whismanoid | 1:d57c1a2cb83c | 1697 | //---------------------------------------- |
whismanoid | 25:c4be3afbfafd | 1698 | // write8 0x03 CAL_START -- RegWrite will poll status until CAL_RDY |
whismanoid | 1:d57c1a2cb83c | 1699 | RegWrite(CMD_r000_0011_xxxx_xddd_CAL_START, (uint8_t)CAL_TYPE_111_SYS_GAIN_B); |
whismanoid | 1:d57c1a2cb83c | 1700 | |
whismanoid | 1:d57c1a2cb83c | 1701 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1702 | // success |
whismanoid | 1:d57c1a2cb83c | 1703 | return 1; |
whismanoid | 1:d57c1a2cb83c | 1704 | } |
whismanoid | 1:d57c1a2cb83c | 1705 | |
whismanoid | 1:d57c1a2cb83c | 1706 | //---------------------------------------- |
whismanoid | 13:df96a784cda6 | 1707 | // Menu item '$' -> AINcode[0], AINcode[1], AINcode[2], AINcode[3], AINcode[4], AINcode[5], AINcode[6], AINcode[7], AINcode[8], AINcode[9], AINcode[10] |
whismanoid | 17:0e9f2dfc2a30 | 1708 | // |
whismanoid | 1:d57c1a2cb83c | 1709 | // Measure all ADC channels in sequence. |
whismanoid | 17:0e9f2dfc2a30 | 1710 | // Diagnostic output pulse on GP0 for each channel's measurement. |
whismanoid | 17:0e9f2dfc2a30 | 1711 | // Diagnostic output pulse on GP1 for entire loop. |
whismanoid | 17:0e9f2dfc2a30 | 1712 | // |
whismanoid | 8:3a9dfa2e8234 | 1713 | // @post AINcode[0..10]: measurement result LSB code |
whismanoid | 0:68e64068330f | 1714 | // |
whismanoid | 0:68e64068330f | 1715 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 1716 | uint8_t MAX11410::Read_All_Voltages(void) |
whismanoid | 0:68e64068330f | 1717 | { |
whismanoid | 0:68e64068330f | 1718 | |
whismanoid | 0:68e64068330f | 1719 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1720 | // scan AIN0..AIN9 |
whismanoid | 17:0e9f2dfc2a30 | 1721 | // |
whismanoid | 17:0e9f2dfc2a30 | 1722 | // diagnostic GPIO pulse on MAX11410 GP1 pin (0xc3 = logic 0, 0xc4 = logic 1) |
whismanoid | 17:0e9f2dfc2a30 | 1723 | RegWrite(CMD_r000_0101_dddd_xddd_GP1_CTRL, 0xc3); // GP1 = 0 |
whismanoid | 17:0e9f2dfc2a30 | 1724 | // |
whismanoid | 1:d57c1a2cb83c | 1725 | const MAX11410_AINN_SEL_enum_t ainn = AINN_SEL_1010_GND; |
whismanoid | 2:eac67184cc0c | 1726 | 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 | 1727 | { |
whismanoid | 17:0e9f2dfc2a30 | 1728 | // diagnostic GPIO pulse on MAX11410 GP0 pin (0xc3 = logic 0, 0xc4 = logic 1) |
whismanoid | 17:0e9f2dfc2a30 | 1729 | RegWrite(CMD_r000_0100_dddd_xddd_GP0_CTRL, 0xc3); // GP0 = 0 |
whismanoid | 17:0e9f2dfc2a30 | 1730 | // |
whismanoid | 1:d57c1a2cb83c | 1731 | Measure_Voltage((MAX11410_AINP_SEL_enum_t)ainp, ainn); |
whismanoid | 17:0e9f2dfc2a30 | 1732 | // @post AINcode[ainp]: measurement result LSB code |
whismanoid | 17:0e9f2dfc2a30 | 1733 | // |
whismanoid | 17:0e9f2dfc2a30 | 1734 | // diagnostic GPIO pulse on MAX11410 GP0 pin (0xc3 = logic 0, 0xc4 = logic 1) |
whismanoid | 17:0e9f2dfc2a30 | 1735 | RegWrite(CMD_r000_0100_dddd_xddd_GP0_CTRL, 0xc4); // GP0 = 1 |
whismanoid | 17:0e9f2dfc2a30 | 1736 | // |
whismanoid | 1:d57c1a2cb83c | 1737 | } |
whismanoid | 17:0e9f2dfc2a30 | 1738 | // diagnostic GPIO pulse on MAX11410 GP1 pin (0xc3 = logic 0, 0xc4 = logic 1) |
whismanoid | 17:0e9f2dfc2a30 | 1739 | RegWrite(CMD_r000_0101_dddd_xddd_GP1_CTRL, 0xc4); // GP1 = 1 |
whismanoid | 17:0e9f2dfc2a30 | 1740 | // |
whismanoid | 0:68e64068330f | 1741 | |
whismanoid | 0:68e64068330f | 1742 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1743 | // success |
whismanoid | 0:68e64068330f | 1744 | return 1; |
whismanoid | 0:68e64068330f | 1745 | } |
whismanoid | 0:68e64068330f | 1746 | |
whismanoid | 0:68e64068330f | 1747 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1748 | // Menu item 'V' |
whismanoid | 0:68e64068330f | 1749 | // Trigger Measurement for voltage input. |
whismanoid | 0:68e64068330f | 1750 | // |
whismanoid | 0:68e64068330f | 1751 | // Example code for typical voltage measurement. |
whismanoid | 0:68e64068330f | 1752 | // |
whismanoid | 1:d57c1a2cb83c | 1753 | // @pre external connection REF2P-REF2N is a reference voltage |
whismanoid | 1:d57c1a2cb83c | 1754 | // @pre VRef = Voltage of REF input, in Volts |
whismanoid | 1:d57c1a2cb83c | 1755 | // @param[in] ainp = channel high side, default=AINP_SEL_0000_AIN0 |
whismanoid | 1:d57c1a2cb83c | 1756 | // @param[in] ainn = channel low side, default=AINN_SEL_1010_GND |
whismanoid | 1:d57c1a2cb83c | 1757 | // @post AINcode[ainp]: measurement result LSB code |
whismanoid | 0:68e64068330f | 1758 | // |
whismanoid | 1:d57c1a2cb83c | 1759 | // @return ideal voltage calculated from raw LSB code and reference voltage |
whismanoid | 1:d57c1a2cb83c | 1760 | double MAX11410::Measure_Voltage(MAX11410_AINP_SEL_enum_t ainp, MAX11410_AINN_SEL_enum_t ainn) |
whismanoid | 0:68e64068330f | 1761 | { |
whismanoid | 0:68e64068330f | 1762 | |
whismanoid | 0:68e64068330f | 1763 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 1764 | // restrict channel selection to valid index range |
whismanoid | 8:3a9dfa2e8234 | 1765 | if ((uint8_t)ainp > /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD) |
whismanoid | 8:3a9dfa2e8234 | 1766 | { |
whismanoid | 8:3a9dfa2e8234 | 1767 | ainp = /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD; |
whismanoid | 8:3a9dfa2e8234 | 1768 | } |
whismanoid | 8:3a9dfa2e8234 | 1769 | |
whismanoid | 8:3a9dfa2e8234 | 1770 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 1771 | // restrict channel selection to valid index range |
whismanoid | 8:3a9dfa2e8234 | 1772 | if ((uint8_t)ainn > /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND) |
whismanoid | 8:3a9dfa2e8234 | 1773 | { |
whismanoid | 8:3a9dfa2e8234 | 1774 | ainn = /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND; |
whismanoid | 8:3a9dfa2e8234 | 1775 | } |
whismanoid | 8:3a9dfa2e8234 | 1776 | |
whismanoid | 8:3a9dfa2e8234 | 1777 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1778 | // write8 0x0B MUX_CTRL0 = 0x0A to select AINP=AIN0 and AINN=GND |
whismanoid | 1:d57c1a2cb83c | 1779 | Configure_MUX_CTRL0((uint8_t)ainp, (uint8_t)ainn); |
whismanoid | 1:d57c1a2cb83c | 1780 | |
whismanoid | 1:d57c1a2cb83c | 1781 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1782 | // write8 0x09 CTRL to select reference REF2P/REF2N; Data Format = Bipolar 2's Complement |
whismanoid | 1:d57c1a2cb83c | 1783 | Configure_CTRL(/*extclk*/ 0, /*u_bn*/ 0, /*format*/ 0, |
whismanoid | 1:d57c1a2cb83c | 1784 | /*refbufp_en*/ 0, /*refbufn_en*/ 0, |
whismanoid | 1:d57c1a2cb83c | 1785 | /*ref_sel*/ (uint8_t)REF_SEL_010_REF2P_REF2N); |
whismanoid | 1:d57c1a2cb83c | 1786 | |
whismanoid | 1:d57c1a2cb83c | 1787 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1788 | // write8 0x0E PGA |
whismanoid | 2:eac67184cc0c | 1789 | Configure_PGA((uint8_t) /* MAX11410_SIG_PATH_enum_t:: */ SIG_PATH_00_BUFFERED, |
whismanoid | 2:eac67184cc0c | 1790 | (uint8_t) /* MAX11410_GAIN_enum_t:: */ GAIN_000_1); |
whismanoid | 1:d57c1a2cb83c | 1791 | |
whismanoid | 1:d57c1a2cb83c | 1792 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1793 | // write8 0x08 FILTER = 0x34 to select RATE_0100, LINEF_11_SINC4 60SPS (given CONV_TYPE_01_Continuous) |
whismanoid | 2:eac67184cc0c | 1794 | Configure_FILTER((uint8_t) /* MAX11410::MAX11410_LINEF_enum_t:: */ LINEF_11_SINC4, |
whismanoid | 2:eac67184cc0c | 1795 | (uint8_t) /* MAX11410::MAX11410_RATE_enum_t:: */ RATE_0100); |
whismanoid | 1:d57c1a2cb83c | 1796 | |
whismanoid | 1:d57c1a2cb83c | 1797 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1798 | // write8 0x01 CONV_START = 0x01 to set Conversion Mode = Continuous |
whismanoid | 1:d57c1a2cb83c | 1799 | RegWrite(CMD_r000_0001_xddd_xxdd_CONV_START, 0x01); |
whismanoid | 0:68e64068330f | 1800 | |
whismanoid | 0:68e64068330f | 1801 | //---------------------------------------- |
whismanoid | 25:c4be3afbfafd | 1802 | // purge old data from data0 register |
whismanoid | 22:c6812214a933 | 1803 | RegRead(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &AINcode[((int)ainp & 0x0F)]); |
whismanoid | 22:c6812214a933 | 1804 | data0 = AINcode[((int)ainp & 0x0F)]; |
whismanoid | 22:c6812214a933 | 1805 | |
whismanoid | 22:c6812214a933 | 1806 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1807 | // read24 0x80|0x38 STATUS (%SW 0xB8 0 0 0) |
whismanoid | 0:68e64068330f | 1808 | RegRead(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); |
whismanoid | 0:68e64068330f | 1809 | |
whismanoid | 0:68e64068330f | 1810 | //---------------------------------------- |
whismanoid | 25:c4be3afbfafd | 1811 | // wait until STATUS_enum_t::STATUS_000010_DATA_RDY indicates data is available |
whismanoid | 13:df96a784cda6 | 1812 | // A bad SPI interface can cause bit slippage, which makes this loop get stuck. Expect *PART_ID? = 0x000F02 |
whismanoid | 13:df96a784cda6 | 1813 | // while ((status & /* MAX11410_STATUS_enum_t:: */ STATUS_000010_DATA_RDY) == 0) { |
whismanoid | 13:df96a784cda6 | 1814 | // possible infinite loop; need a timeout or futility countdown to escape |
whismanoid | 22:c6812214a933 | 1815 | for (int futility_countdown = loop_limit; |
whismanoid | 13:df96a784cda6 | 1816 | ((futility_countdown > 0) && |
whismanoid | 13:df96a784cda6 | 1817 | ((status & /* MAX11410_STATUS_enum_t:: */ STATUS_000010_DATA_RDY) == 0)); |
whismanoid | 13:df96a784cda6 | 1818 | futility_countdown--) |
whismanoid | 13:df96a784cda6 | 1819 | { |
whismanoid | 9:06ca88952f1c | 1820 | RegRead(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); |
whismanoid | 9:06ca88952f1c | 1821 | } |
whismanoid | 9:06ca88952f1c | 1822 | |
whismanoid | 9:06ca88952f1c | 1823 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1824 | // read24 0x80|0x30 DATA0 (%SW 0xB0 0 0 0): AINcode[ainp] = measurement |
whismanoid | 1:d57c1a2cb83c | 1825 | RegRead(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &AINcode[((int)ainp & 0x0F)]); |
whismanoid | 1:d57c1a2cb83c | 1826 | data0 = AINcode[((int)ainp & 0x0F)]; |
whismanoid | 0:68e64068330f | 1827 | |
whismanoid | 0:68e64068330f | 1828 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1829 | // ideal voltage calculated from raw LSB code and reference voltage |
whismanoid | 1:d57c1a2cb83c | 1830 | return VoltageOfCode(AINcode[((int)ainp & 0x0F)]); |
whismanoid | 0:68e64068330f | 1831 | } |
whismanoid | 0:68e64068330f | 1832 | |
whismanoid | 0:68e64068330f | 1833 | //---------------------------------------- |
whismanoid | 22:c6812214a933 | 1834 | // Menu item 'R' -> rtd_ohm, rtd_degc |
whismanoid | 0:68e64068330f | 1835 | // Trigger Measurement for Resistive Temperature Device (RTD). |
whismanoid | 0:68e64068330f | 1836 | // |
whismanoid | 0:68e64068330f | 1837 | // Example code for typical RTD measurement. |
whismanoid | 0:68e64068330f | 1838 | // |
whismanoid | 1:d57c1a2cb83c | 1839 | // @pre external connection REF1P-REF1N is a reference resistor |
whismanoid | 22:c6812214a933 | 1840 | // @pre ref1_v = reference resistance in ohms, default=4999 |
whismanoid | 23:22e7830bcccb | 1841 | // @pre rtd_filter = filter register configuration, 0x34 for LINEF_11_SINC4 RATE_0100 output data rate 60SPS |
whismanoid | 23:22e7830bcccb | 1842 | // @pre rtd_ctrl = ctrl register configuration, 0x40 for ref0_v, 0x41 for ref1_v, 0x42 for ref2_v |
whismanoid | 1:d57c1a2cb83c | 1843 | // @param[in] rtd_iout = channel RTD high side force, default=AINP_SEL_0111_AIN7 |
whismanoid | 1:d57c1a2cb83c | 1844 | // @param[in] rtd_ainp = channel RTD high side sense, default=AINP_SEL_1000_AIN8 |
whismanoid | 1:d57c1a2cb83c | 1845 | // @param[in] rtd_ainn = channel RTD low side, default=AINN_SEL_1001_AIN9 |
whismanoid | 1:d57c1a2cb83c | 1846 | // @post AINcode[rtd_ainp]: measurement result LSB code |
whismanoid | 22:c6812214a933 | 1847 | // @post rtd_ohm: measurement result resistance in Ohms |
whismanoid | 22:c6812214a933 | 1848 | // @post rtd_degc: Temperature calculated from RTD Resistance; Thermocouple Cold Junction, in degrees C |
whismanoid | 0:68e64068330f | 1849 | // |
whismanoid | 3:658a93dfb2d8 | 1850 | // @return resistance calculated from raw LSB code and reference resistance |
whismanoid | 1:d57c1a2cb83c | 1851 | 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 | 1852 | { |
whismanoid | 0:68e64068330f | 1853 | |
whismanoid | 0:68e64068330f | 1854 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 1855 | // restrict channel selection to valid index range |
whismanoid | 8:3a9dfa2e8234 | 1856 | if ((uint8_t)rtd_iout > /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD) |
whismanoid | 8:3a9dfa2e8234 | 1857 | { |
whismanoid | 8:3a9dfa2e8234 | 1858 | rtd_iout = /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD; |
whismanoid | 8:3a9dfa2e8234 | 1859 | } |
whismanoid | 8:3a9dfa2e8234 | 1860 | |
whismanoid | 8:3a9dfa2e8234 | 1861 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 1862 | // restrict channel selection to valid index range |
whismanoid | 8:3a9dfa2e8234 | 1863 | if ((uint8_t)rtd_ainp > /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD) |
whismanoid | 8:3a9dfa2e8234 | 1864 | { |
whismanoid | 8:3a9dfa2e8234 | 1865 | rtd_ainp = /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD; |
whismanoid | 8:3a9dfa2e8234 | 1866 | } |
whismanoid | 8:3a9dfa2e8234 | 1867 | |
whismanoid | 8:3a9dfa2e8234 | 1868 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 1869 | // restrict channel selection to valid index range |
whismanoid | 8:3a9dfa2e8234 | 1870 | if ((uint8_t)rtd_ainn > /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND) |
whismanoid | 8:3a9dfa2e8234 | 1871 | { |
whismanoid | 8:3a9dfa2e8234 | 1872 | rtd_ainn = /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND; |
whismanoid | 8:3a9dfa2e8234 | 1873 | } |
whismanoid | 8:3a9dfa2e8234 | 1874 | |
whismanoid | 8:3a9dfa2e8234 | 1875 | //---------------------------------------- |
whismanoid | 23:22e7830bcccb | 1876 | // write8 0x08 FILTER to select output data rate |
whismanoid | 23:22e7830bcccb | 1877 | RegWrite(CMD_r000_1000_x0dd_dddd_FILTER, rtd_filter); |
whismanoid | 1:d57c1a2cb83c | 1878 | |
whismanoid | 1:d57c1a2cb83c | 1879 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1880 | // write8 0x09 CTRL to select reference resistor REF1P/REF1N; Data Format = Unipolar |
whismanoid | 23:22e7830bcccb | 1881 | RegWrite(CMD_r000_1001_dddd_dddd_CTRL, rtd_ctrl); |
whismanoid | 23:22e7830bcccb | 1882 | ctrl = rtd_ctrl; |
whismanoid | 1:d57c1a2cb83c | 1883 | |
whismanoid | 1:d57c1a2cb83c | 1884 | //---------------------------------------- |
whismanoid | 23:22e7830bcccb | 1885 | // write8 0x0A SOURCE to select IDAC_MODE 400uA; AIN9=2.000V, AIN8(PT100)=2.040V, AIN8(PT1000)=2.400V |
whismanoid | 23:22e7830bcccb | 1886 | RegWrite(CMD_r000_1010_dddd_dddd_SOURCE, rtd_source); |
whismanoid | 1:d57c1a2cb83c | 1887 | |
whismanoid | 1:d57c1a2cb83c | 1888 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1889 | // write8 0x0B MUX_CTRL0 = 0x89 to select AINP=AIN8 and AINN=AIN9 |
whismanoid | 1:d57c1a2cb83c | 1890 | Configure_MUX_CTRL0((uint8_t)rtd_ainp, (uint8_t)rtd_ainn); |
whismanoid | 1:d57c1a2cb83c | 1891 | |
whismanoid | 1:d57c1a2cb83c | 1892 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1893 | // write8 0x0C MUX_CTRL1 = 0xF7 to select IDAC1_SEL=NC, IDAC0_SEL=AIN7 |
whismanoid | 1:d57c1a2cb83c | 1894 | Configure_MUX_CTRL1((uint8_t)IDAC1_SEL_1111_unconnected, (uint8_t)rtd_iout); |
whismanoid | 1:d57c1a2cb83c | 1895 | |
whismanoid | 1:d57c1a2cb83c | 1896 | //---------------------------------------- |
whismanoid | 23:22e7830bcccb | 1897 | // write8 0x0E PGA and update pgaGain |
whismanoid | 23:22e7830bcccb | 1898 | Configure_PGA( |
whismanoid | 23:22e7830bcccb | 1899 | ((rtd_pga >> 4) & 2), // sigpath |
whismanoid | 23:22e7830bcccb | 1900 | ( rtd_pga & 7)); // gain |
whismanoid | 1:d57c1a2cb83c | 1901 | |
whismanoid | 1:d57c1a2cb83c | 1902 | //---------------------------------------- |
whismanoid | 22:c6812214a933 | 1903 | // diagnostic GPIO pulse on GP1 during RTD power-up interval rtd_ms |
whismanoid | 16:00aa1e5a6843 | 1904 | RegWrite(CMD_r000_0101_dddd_xddd_GP1_CTRL, 0xc3); // diagnostic GPIO pulse GP1 |
whismanoid | 16:00aa1e5a6843 | 1905 | // write8 0x05 GP1_CTRL (%SW 0x05 0xc3) 11000 output 011 logic 0 |
whismanoid | 16:00aa1e5a6843 | 1906 | |
whismanoid | 16:00aa1e5a6843 | 1907 | //---------------------------------------- |
whismanoid | 21:847b2220e96e | 1908 | // timing delay after enable RTD bias current |
whismanoid | 22:c6812214a933 | 1909 | wait_ms(rtd_ms); // timing delay function, platform-specific |
whismanoid | 9:06ca88952f1c | 1910 | |
whismanoid | 9:06ca88952f1c | 1911 | //---------------------------------------- |
whismanoid | 22:c6812214a933 | 1912 | // diagnostic GPIO pulse on GP1 during RTD power-up interval rtd_ms |
whismanoid | 16:00aa1e5a6843 | 1913 | RegWrite(CMD_r000_0101_dddd_xddd_GP1_CTRL, 0xc4); // diagnostic GPIO pulse GP1 |
whismanoid | 16:00aa1e5a6843 | 1914 | // write8 0x05 GP1_CTRL (%SW 0x05 0xc4) 11000 output 100 logic 1 |
whismanoid | 16:00aa1e5a6843 | 1915 | |
whismanoid | 16:00aa1e5a6843 | 1916 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1917 | // write8 0x01 CONV_START = 0x01 to set Conversion Mode = Continuous |
whismanoid | 1:d57c1a2cb83c | 1918 | RegWrite(CMD_r000_0001_xddd_xxdd_CONV_START, 0x01); |
whismanoid | 1:d57c1a2cb83c | 1919 | |
whismanoid | 1:d57c1a2cb83c | 1920 | //---------------------------------------- |
whismanoid | 25:c4be3afbfafd | 1921 | // purge old data from data0 register |
whismanoid | 25:c4be3afbfafd | 1922 | RegRead(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &AINcode[((int)rtd_ainp & 0x0F)]); |
whismanoid | 25:c4be3afbfafd | 1923 | data0 = AINcode[((int)rtd_ainp & 0x0F)]; |
whismanoid | 25:c4be3afbfafd | 1924 | |
whismanoid | 25:c4be3afbfafd | 1925 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 1926 | // read24 0x80|0x38 STATUS (%SW 0xB8 0 0 0) |
whismanoid | 0:68e64068330f | 1927 | RegRead(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); |
whismanoid | 0:68e64068330f | 1928 | |
whismanoid | 0:68e64068330f | 1929 | //---------------------------------------- |
whismanoid | 25:c4be3afbfafd | 1930 | // wait until STATUS_enum_t::STATUS_000010_DATA_RDY indicates data is available |
whismanoid | 16:00aa1e5a6843 | 1931 | // A bad SPI interface can cause bit slippage, which makes this loop get stuck. Expect *PART_ID? = 0x000F02 |
whismanoid | 16:00aa1e5a6843 | 1932 | // while ((status & /* MAX11410_STATUS_enum_t:: */ STATUS_000010_DATA_RDY) == 0) { |
whismanoid | 16:00aa1e5a6843 | 1933 | // possible infinite loop; need a timeout or futility countdown to escape |
whismanoid | 22:c6812214a933 | 1934 | for (int futility_countdown = loop_limit; |
whismanoid | 16:00aa1e5a6843 | 1935 | ((futility_countdown > 0) && |
whismanoid | 16:00aa1e5a6843 | 1936 | ((status & /* MAX11410_STATUS_enum_t:: */ STATUS_000010_DATA_RDY) == 0)); |
whismanoid | 16:00aa1e5a6843 | 1937 | futility_countdown--) |
whismanoid | 16:00aa1e5a6843 | 1938 | { |
whismanoid | 16:00aa1e5a6843 | 1939 | RegRead(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); |
whismanoid | 16:00aa1e5a6843 | 1940 | } |
whismanoid | 16:00aa1e5a6843 | 1941 | |
whismanoid | 16:00aa1e5a6843 | 1942 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 1943 | // read24 0x80|0x30 DATA0 (%SW 0xB0 0 0 0): AINcode[ainp] = measurement |
whismanoid | 1:d57c1a2cb83c | 1944 | RegRead(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &AINcode[((int)rtd_ainp & 0x0F)]); |
whismanoid | 1:d57c1a2cb83c | 1945 | data0 = AINcode[((int)rtd_ainp & 0x0F)]; |
whismanoid | 0:68e64068330f | 1946 | |
whismanoid | 0:68e64068330f | 1947 | //---------------------------------------- |
whismanoid | 25:c4be3afbfafd | 1948 | // turn off RTD bias current to avoid self-heating (unless rtd_ms is 0) |
whismanoid | 25:c4be3afbfafd | 1949 | if (rtd_ms != 0) |
whismanoid | 25:c4be3afbfafd | 1950 | { |
whismanoid | 25:c4be3afbfafd | 1951 | // write8 0x0C MUX_CTRL1 = 0xFF to select IDAC1_SEL=NC, IDAC0_SEL=NC |
whismanoid | 25:c4be3afbfafd | 1952 | Configure_MUX_CTRL1((uint8_t)IDAC1_SEL_1111_unconnected, (uint8_t)IDAC0_SEL_1111_unconnected); |
whismanoid | 25:c4be3afbfafd | 1953 | } |
whismanoid | 9:06ca88952f1c | 1954 | |
whismanoid | 9:06ca88952f1c | 1955 | //---------------------------------------- |
whismanoid | 22:c6812214a933 | 1956 | // resistance calculated from raw LSB code and ref1_v reference resistance in ohms |
whismanoid | 22:c6812214a933 | 1957 | rtd_ohm = VoltageOfCode(AINcode[((int)rtd_ainp & 0x0F)]); |
whismanoid | 22:c6812214a933 | 1958 | TemperatureOfRTD(rtd_ohm); // calculate rtd_degc |
whismanoid | 22:c6812214a933 | 1959 | return rtd_ohm; |
whismanoid | 0:68e64068330f | 1960 | } |
whismanoid | 0:68e64068330f | 1961 | |
whismanoid | 0:68e64068330f | 1962 | //---------------------------------------- |
whismanoid | 3:658a93dfb2d8 | 1963 | // Return the physical temperature corresponding to measured resistance |
whismanoid | 3:658a93dfb2d8 | 1964 | // of a PT1000 type Resistive Temperature Device (RTD). |
whismanoid | 3:658a93dfb2d8 | 1965 | // |
whismanoid | 22:c6812214a933 | 1966 | // @param[in] rtd_ohm = RTD resistance in ohms, default=1000 |
whismanoid | 22:c6812214a933 | 1967 | // @post rtd_degc: Temperature calculated from RTD Resistance; Thermocouple Cold Junction, in degrees C |
whismanoid | 3:658a93dfb2d8 | 1968 | // |
whismanoid | 3:658a93dfb2d8 | 1969 | // @return ideal temperature in degrees C, calculated from RTD resistance in ohms |
whismanoid | 21:847b2220e96e | 1970 | // @test group RTD_PT1000 // PT1000 type Resistive Temperature Device (RTD) |
whismanoid | 21:847b2220e96e | 1971 | // @test group RTD_PT1000 tinyTester.blink_time_msec = 20 // quickly speed through the software verification |
whismanoid | 19:50cf5da53d36 | 1972 | // @test group RTD_PT1000 TemperatureOfRTD_PT1000(842.94) expect -40.0 within 0.1 // PT-1000 RTD at -40C |
whismanoid | 19:50cf5da53d36 | 1973 | // @test group RTD_PT1000 TemperatureOfRTD_PT1000(1000.0) expect 0.0 within 0.1 // PT-1000 RTD at 0C |
whismanoid | 19:50cf5da53d36 | 1974 | // @test group RTD_PT1000 TemperatureOfRTD_PT1000(1097.3) expect 25.0 within 0.1 // PT-1000 RTD at 25C |
whismanoid | 19:50cf5da53d36 | 1975 | // @test group RTD_PT1000 TemperatureOfRTD_PT1000(1328.1) expect 85.0 within 0.1 // PT-1000 RTD at 85C |
whismanoid | 19:50cf5da53d36 | 1976 | // @test group RTD_PT1000 TemperatureOfRTD_PT1000(1479.5) expect 125.0 within 0.1 // PT-1000 RTD at 125C |
whismanoid | 21:847b2220e96e | 1977 | // @test group RTD_PT1000 tinyTester.blink_time_msec = 75 // default 75 resume hardware self test |
whismanoid | 3:658a93dfb2d8 | 1978 | // |
whismanoid | 22:c6812214a933 | 1979 | double MAX11410::TemperatureOfRTD_PT1000(double rtd_ohm) |
whismanoid | 3:658a93dfb2d8 | 1980 | { |
whismanoid | 3:658a93dfb2d8 | 1981 | |
whismanoid | 3:658a93dfb2d8 | 1982 | //---------------------------------------- |
whismanoid | 3:658a93dfb2d8 | 1983 | // Temperature from RTD Resistance maths |
whismanoid | 4:c169ba85d673 | 1984 | // ITS-90 PT-1000 RTD |
whismanoid | 4:c169ba85d673 | 1985 | double R0 = 1000.0; |
whismanoid | 4:c169ba85d673 | 1986 | double a = 3.9083e-3; |
whismanoid | 4:c169ba85d673 | 1987 | double b = -5.7750e-7; |
whismanoid | 5:a2e74357cfc0 | 1988 | // calculate T from R and R0 |
whismanoid | 22:c6812214a933 | 1989 | double sqrtTerm = sqrt(R0*R0 * a*a - 4*R0*b*(R0 - rtd_ohm)); |
whismanoid | 4:c169ba85d673 | 1990 | double denominator = 2 * R0 * b; |
whismanoid | 22:c6812214a933 | 1991 | rtd_degc = ((-R0 * a) + (sqrtTerm)) / denominator; |
whismanoid | 22:c6812214a933 | 1992 | return rtd_degc; |
whismanoid | 3:658a93dfb2d8 | 1993 | } |
whismanoid | 3:658a93dfb2d8 | 1994 | |
whismanoid | 3:658a93dfb2d8 | 1995 | //---------------------------------------- |
whismanoid | 16:00aa1e5a6843 | 1996 | // Return the physical temperature corresponding to measured resistance |
whismanoid | 16:00aa1e5a6843 | 1997 | // of a PT100 type Resistive Temperature Device (RTD). |
whismanoid | 16:00aa1e5a6843 | 1998 | // |
whismanoid | 22:c6812214a933 | 1999 | // @param[in] rtd_ohm = RTD resistance in ohms, default=100 |
whismanoid | 22:c6812214a933 | 2000 | // @post rtd_degc: Temperature calculated from RTD Resistance; Thermocouple Cold Junction, in degrees C |
whismanoid | 16:00aa1e5a6843 | 2001 | // |
whismanoid | 16:00aa1e5a6843 | 2002 | // @return ideal temperature in degrees C, calculated from RTD resistance in ohms |
whismanoid | 21:847b2220e96e | 2003 | // @test group RTD_PT100 // PT100 type Resistive Temperature Device (RTD) |
whismanoid | 21:847b2220e96e | 2004 | // @test group RTD_PT100 tinyTester.blink_time_msec = 20 // quickly speed through the software verification |
whismanoid | 19:50cf5da53d36 | 2005 | // @test group RTD_PT100 TemperatureOfRTD_PT100(84.294) expect -40.0 within 0.1 // PT-100 RTD at -40C |
whismanoid | 19:50cf5da53d36 | 2006 | // @test group RTD_PT100 TemperatureOfRTD_PT100(100.00) expect 0.0 within 0.1 // PT-100 RTD at 0C |
whismanoid | 19:50cf5da53d36 | 2007 | // @test group RTD_PT100 TemperatureOfRTD_PT100(109.73) expect 25.0 within 0.1 // PT-100 RTD at 25C |
whismanoid | 19:50cf5da53d36 | 2008 | // @test group RTD_PT100 TemperatureOfRTD_PT100(132.81) expect 85.0 within 0.1 // PT-100 RTD at 85C |
whismanoid | 19:50cf5da53d36 | 2009 | // @test group RTD_PT100 TemperatureOfRTD_PT100(147.95) expect 125.0 within 0.1 // PT-100 RTD at 125C |
whismanoid | 21:847b2220e96e | 2010 | // @test group RTD_PT100 tinyTester.blink_time_msec = 75 // default 75 resume hardware self test |
whismanoid | 16:00aa1e5a6843 | 2011 | // |
whismanoid | 22:c6812214a933 | 2012 | double MAX11410::TemperatureOfRTD_PT100(double rtd_ohm) |
whismanoid | 16:00aa1e5a6843 | 2013 | { |
whismanoid | 16:00aa1e5a6843 | 2014 | |
whismanoid | 16:00aa1e5a6843 | 2015 | //---------------------------------------- |
whismanoid | 16:00aa1e5a6843 | 2016 | // Temperature from RTD Resistance maths |
whismanoid | 16:00aa1e5a6843 | 2017 | // ITS-90 PT-100 RTD |
whismanoid | 16:00aa1e5a6843 | 2018 | double R0 = 100.0; |
whismanoid | 16:00aa1e5a6843 | 2019 | double a = 3.9083e-3; |
whismanoid | 16:00aa1e5a6843 | 2020 | double b = -5.7750e-7; |
whismanoid | 16:00aa1e5a6843 | 2021 | // calculate T from R and R0 |
whismanoid | 22:c6812214a933 | 2022 | double sqrtTerm = sqrt(R0*R0 * a*a - 4*R0*b*(R0 - rtd_ohm)); |
whismanoid | 16:00aa1e5a6843 | 2023 | double denominator = 2 * R0 * b; |
whismanoid | 22:c6812214a933 | 2024 | rtd_degc = ((-R0 * a) + (sqrtTerm)) / denominator; |
whismanoid | 22:c6812214a933 | 2025 | return rtd_degc; |
whismanoid | 16:00aa1e5a6843 | 2026 | } |
whismanoid | 16:00aa1e5a6843 | 2027 | |
whismanoid | 16:00aa1e5a6843 | 2028 | //---------------------------------------- |
whismanoid | 16:00aa1e5a6843 | 2029 | // Return the physical temperature corresponding to measured resistance |
whismanoid | 16:00aa1e5a6843 | 2030 | // of a PT100 or PT1000 type Resistive Temperature Device (RTD). |
whismanoid | 16:00aa1e5a6843 | 2031 | // |
whismanoid | 22:c6812214a933 | 2032 | // @param[in] rtd_ohm = RTD resistance in ohms, default=100 |
whismanoid | 22:c6812214a933 | 2033 | // @post rtd_degc: Temperature calculated from RTD Resistance; Thermocouple Cold Junction, in degrees C |
whismanoid | 16:00aa1e5a6843 | 2034 | // |
whismanoid | 16:00aa1e5a6843 | 2035 | // @return ideal temperature in degrees C, calculated from RTD resistance in ohms |
whismanoid | 19:50cf5da53d36 | 2036 | // @test group RTD // Verify function TemperatureOfRTD |
whismanoid | 19:50cf5da53d36 | 2037 | // @test group RTD tinyTester.blink_time_msec = 20 // quickly speed through the software verification |
whismanoid | 19:50cf5da53d36 | 2038 | // @test group RTD TemperatureOfRTD(84.294) expect -40.0 within 0.1 // PT-100 RTD at -40C |
whismanoid | 19:50cf5da53d36 | 2039 | // @test group RTD TemperatureOfRTD(100.00) expect 0.0 within 0.1 // PT-100 RTD at 0C |
whismanoid | 19:50cf5da53d36 | 2040 | // @test group RTD TemperatureOfRTD(109.73) expect 25.0 within 0.1 // PT-100 RTD at 25C |
whismanoid | 19:50cf5da53d36 | 2041 | // @test group RTD TemperatureOfRTD(132.81) expect 85.0 within 0.1 // PT-100 RTD at 85C |
whismanoid | 19:50cf5da53d36 | 2042 | // @test group RTD TemperatureOfRTD(147.95) expect 125.0 within 0.1 // PT-100 RTD at 125C |
whismanoid | 19:50cf5da53d36 | 2043 | // @test group RTD TemperatureOfRTD(842.94) expect -40.0 within 0.1 // PT-1000 RTD at -40C |
whismanoid | 19:50cf5da53d36 | 2044 | // @test group RTD TemperatureOfRTD(1000.0) expect 0.0 within 0.1 // PT-1000 RTD at 0C |
whismanoid | 19:50cf5da53d36 | 2045 | // @test group RTD TemperatureOfRTD(1097.3) expect 25.0 within 0.1 // PT-1000 RTD at 25C |
whismanoid | 19:50cf5da53d36 | 2046 | // @test group RTD TemperatureOfRTD(1328.1) expect 85.0 within 0.1 // PT-1000 RTD at 85C |
whismanoid | 19:50cf5da53d36 | 2047 | // @test group RTD TemperatureOfRTD(1479.5) expect 125.0 within 0.1 // PT-1000 RTD at 125C |
whismanoid | 21:847b2220e96e | 2048 | // @test group RTD tinyTester.blink_time_msec = 75 // default 75 resume hardware self test |
whismanoid | 16:00aa1e5a6843 | 2049 | // |
whismanoid | 22:c6812214a933 | 2050 | double MAX11410::TemperatureOfRTD(double rtd_ohm) |
whismanoid | 16:00aa1e5a6843 | 2051 | { |
whismanoid | 16:00aa1e5a6843 | 2052 | |
whismanoid | 16:00aa1e5a6843 | 2053 | //---------------------------------------- |
whismanoid | 16:00aa1e5a6843 | 2054 | // return TemperatureOfRTD_PT100 or TemperatureOfRTD_PT1000 |
whismanoid | 22:c6812214a933 | 2055 | if (rtd_ohm > 500.0) |
whismanoid | 16:00aa1e5a6843 | 2056 | { |
whismanoid | 22:c6812214a933 | 2057 | return TemperatureOfRTD_PT1000(rtd_ohm); |
whismanoid | 16:00aa1e5a6843 | 2058 | } |
whismanoid | 16:00aa1e5a6843 | 2059 | else |
whismanoid | 16:00aa1e5a6843 | 2060 | { |
whismanoid | 22:c6812214a933 | 2061 | return TemperatureOfRTD_PT100(rtd_ohm); |
whismanoid | 16:00aa1e5a6843 | 2062 | } |
whismanoid | 16:00aa1e5a6843 | 2063 | } |
whismanoid | 16:00aa1e5a6843 | 2064 | |
whismanoid | 16:00aa1e5a6843 | 2065 | //---------------------------------------- |
whismanoid | 22:c6812214a933 | 2066 | // Menu item 'TM' -> tc_v, tc_delta_degc, tc_degc |
whismanoid | 0:68e64068330f | 2067 | // Trigger Measurement for Thermocouple |
whismanoid | 0:68e64068330f | 2068 | // |
whismanoid | 0:68e64068330f | 2069 | // Example code for typical Thermocouple measurement. |
whismanoid | 1:d57c1a2cb83c | 2070 | // An RTD measures the "cold junction" where TC connects to the board, |
whismanoid | 1:d57c1a2cb83c | 2071 | // and the TC measures the temperature difference above the cold junction. |
whismanoid | 0:68e64068330f | 2072 | // |
whismanoid | 1:d57c1a2cb83c | 2073 | // @param[in] tc_ainp = channel of Thermocouple high side, default=AINP_SEL_0101_AIN5 |
whismanoid | 1:d57c1a2cb83c | 2074 | // @param[in] tc_ainn = channel of Thermocouple low side, default=AINN_SEL_0110_AIN6 |
whismanoid | 1:d57c1a2cb83c | 2075 | // @param[in] rtd_iout = channel RTD high side force, default=AINP_SEL_0111_AIN7 |
whismanoid | 1:d57c1a2cb83c | 2076 | // @param[in] rtd_ainp = channel RTD high side sense, default=AINP_SEL_1000_AIN8 |
whismanoid | 1:d57c1a2cb83c | 2077 | // @param[in] rtd_ainn = channel RTD low side, default=AINN_SEL_1001_AIN9 |
whismanoid | 1:d57c1a2cb83c | 2078 | // @post AINcode[tc_ainp]: measurement result LSB code |
whismanoid | 22:c6812214a933 | 2079 | // @post tc_v: raw thermocouple voltage in Volts |
whismanoid | 22:c6812214a933 | 2080 | // @post tc_delta_degc: temperature in degC above cold junction |
whismanoid | 22:c6812214a933 | 2081 | // @post tc_degc: temperature in degC |
whismanoid | 0:68e64068330f | 2082 | // |
whismanoid | 0:68e64068330f | 2083 | // @return 1 on success; 0 on failure |
whismanoid | 1:d57c1a2cb83c | 2084 | 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 | 2085 | { |
whismanoid | 0:68e64068330f | 2086 | |
whismanoid | 0:68e64068330f | 2087 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 2088 | // restrict channel selection to valid index range |
whismanoid | 8:3a9dfa2e8234 | 2089 | if ((uint8_t)tc_ainp > /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD) |
whismanoid | 8:3a9dfa2e8234 | 2090 | { |
whismanoid | 8:3a9dfa2e8234 | 2091 | tc_ainp = /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD; |
whismanoid | 8:3a9dfa2e8234 | 2092 | } |
whismanoid | 8:3a9dfa2e8234 | 2093 | |
whismanoid | 8:3a9dfa2e8234 | 2094 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 2095 | // restrict channel selection to valid index range |
whismanoid | 8:3a9dfa2e8234 | 2096 | if ((uint8_t)tc_ainn > /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND) |
whismanoid | 8:3a9dfa2e8234 | 2097 | { |
whismanoid | 8:3a9dfa2e8234 | 2098 | tc_ainn = /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND; |
whismanoid | 8:3a9dfa2e8234 | 2099 | } |
whismanoid | 8:3a9dfa2e8234 | 2100 | |
whismanoid | 8:3a9dfa2e8234 | 2101 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 2102 | // restrict channel selection to valid index range |
whismanoid | 8:3a9dfa2e8234 | 2103 | if ((uint8_t)rtd_iout > /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD) |
whismanoid | 8:3a9dfa2e8234 | 2104 | { |
whismanoid | 8:3a9dfa2e8234 | 2105 | rtd_iout = /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD; |
whismanoid | 8:3a9dfa2e8234 | 2106 | } |
whismanoid | 8:3a9dfa2e8234 | 2107 | |
whismanoid | 8:3a9dfa2e8234 | 2108 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 2109 | // restrict channel selection to valid index range |
whismanoid | 8:3a9dfa2e8234 | 2110 | if ((uint8_t)rtd_ainp > /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD) |
whismanoid | 8:3a9dfa2e8234 | 2111 | { |
whismanoid | 8:3a9dfa2e8234 | 2112 | rtd_ainp = /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD; |
whismanoid | 8:3a9dfa2e8234 | 2113 | } |
whismanoid | 8:3a9dfa2e8234 | 2114 | |
whismanoid | 8:3a9dfa2e8234 | 2115 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 2116 | // restrict channel selection to valid index range |
whismanoid | 8:3a9dfa2e8234 | 2117 | if ((uint8_t)rtd_ainn > /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND) |
whismanoid | 8:3a9dfa2e8234 | 2118 | { |
whismanoid | 8:3a9dfa2e8234 | 2119 | rtd_ainn = /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND; |
whismanoid | 8:3a9dfa2e8234 | 2120 | } |
whismanoid | 8:3a9dfa2e8234 | 2121 | |
whismanoid | 8:3a9dfa2e8234 | 2122 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 2123 | // write8 0x0B MUX_CTRL0 = 0x0A to select AINP=AIN0 and AINN=GND |
whismanoid | 8:3a9dfa2e8234 | 2124 | Configure_MUX_CTRL0((uint8_t)tc_ainp, (uint8_t)tc_ainn); |
whismanoid | 8:3a9dfa2e8234 | 2125 | |
whismanoid | 8:3a9dfa2e8234 | 2126 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 2127 | // write8 0x09 CTRL to select reference REF2P/REF2N; Data Format = Bipolar 2's Complement |
whismanoid | 8:3a9dfa2e8234 | 2128 | Configure_CTRL(/*extclk*/ 0, /*u_bn*/ 0, /*format*/ 0, |
whismanoid | 8:3a9dfa2e8234 | 2129 | /*refbufp_en*/ 0, /*refbufn_en*/ 0, |
whismanoid | 8:3a9dfa2e8234 | 2130 | /*ref_sel*/ (uint8_t)REF_SEL_010_REF2P_REF2N); |
whismanoid | 8:3a9dfa2e8234 | 2131 | |
whismanoid | 8:3a9dfa2e8234 | 2132 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 2133 | // write8 0x0E PGA |
whismanoid | 8:3a9dfa2e8234 | 2134 | Configure_PGA((uint8_t) /* MAX11410_SIG_PATH_enum_t:: */ SIG_PATH_00_BUFFERED, |
whismanoid | 8:3a9dfa2e8234 | 2135 | (uint8_t) /* MAX11410_GAIN_enum_t:: */ GAIN_000_1); |
whismanoid | 8:3a9dfa2e8234 | 2136 | |
whismanoid | 8:3a9dfa2e8234 | 2137 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 2138 | // write8 0x08 FILTER = 0x34 to select RATE_0100, LINEF_11_SINC4 60SPS (given CONV_TYPE_01_Continuous) |
whismanoid | 8:3a9dfa2e8234 | 2139 | Configure_FILTER((uint8_t) /* MAX11410::MAX11410_LINEF_enum_t:: */ LINEF_11_SINC4, |
whismanoid | 8:3a9dfa2e8234 | 2140 | (uint8_t) /* MAX11410::MAX11410_RATE_enum_t:: */ RATE_0100); |
whismanoid | 8:3a9dfa2e8234 | 2141 | |
whismanoid | 8:3a9dfa2e8234 | 2142 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 2143 | // write8 0x01 CONV_START = 0x01 to set Conversion Mode = Continuous |
whismanoid | 8:3a9dfa2e8234 | 2144 | RegWrite(CMD_r000_0001_xddd_xxdd_CONV_START, 0x01); |
whismanoid | 8:3a9dfa2e8234 | 2145 | |
whismanoid | 8:3a9dfa2e8234 | 2146 | //---------------------------------------- |
whismanoid | 25:c4be3afbfafd | 2147 | // purge old data from data0 register |
whismanoid | 25:c4be3afbfafd | 2148 | RegRead(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &AINcode[((int)tc_ainp & 0x0F)]); |
whismanoid | 25:c4be3afbfafd | 2149 | data0 = AINcode[((int)tc_ainp & 0x0F)]; |
whismanoid | 25:c4be3afbfafd | 2150 | |
whismanoid | 25:c4be3afbfafd | 2151 | //---------------------------------------- |
whismanoid | 0:68e64068330f | 2152 | // read24 0x80|0x38 STATUS (%SW 0xB8 0 0 0) |
whismanoid | 0:68e64068330f | 2153 | RegRead(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); |
whismanoid | 0:68e64068330f | 2154 | |
whismanoid | 0:68e64068330f | 2155 | //---------------------------------------- |
whismanoid | 25:c4be3afbfafd | 2156 | // wait until STATUS_enum_t::STATUS_000010_DATA_RDY indicates data is available |
whismanoid | 16:00aa1e5a6843 | 2157 | // A bad SPI interface can cause bit slippage, which makes this loop get stuck. Expect *PART_ID? = 0x000F02 |
whismanoid | 16:00aa1e5a6843 | 2158 | // while ((status & /* MAX11410_STATUS_enum_t:: */ STATUS_000010_DATA_RDY) == 0) { |
whismanoid | 16:00aa1e5a6843 | 2159 | // possible infinite loop; need a timeout or futility countdown to escape |
whismanoid | 22:c6812214a933 | 2160 | for (int futility_countdown = loop_limit; |
whismanoid | 16:00aa1e5a6843 | 2161 | ((futility_countdown > 0) && |
whismanoid | 16:00aa1e5a6843 | 2162 | ((status & /* MAX11410_STATUS_enum_t:: */ STATUS_000010_DATA_RDY) == 0)); |
whismanoid | 16:00aa1e5a6843 | 2163 | futility_countdown--) |
whismanoid | 16:00aa1e5a6843 | 2164 | { |
whismanoid | 16:00aa1e5a6843 | 2165 | RegRead(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); |
whismanoid | 16:00aa1e5a6843 | 2166 | } |
whismanoid | 16:00aa1e5a6843 | 2167 | |
whismanoid | 16:00aa1e5a6843 | 2168 | //---------------------------------------- |
whismanoid | 8:3a9dfa2e8234 | 2169 | // read24 0x80|0x30 DATA0 (%SW 0xB0 0 0 0): AINcode[tc_ainp] = measurement |
whismanoid | 8:3a9dfa2e8234 | 2170 | RegRead(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &AINcode[((int)tc_ainp & 0x0F)]); |
whismanoid | 8:3a9dfa2e8234 | 2171 | data0 = AINcode[((int)tc_ainp & 0x0F)]; |
whismanoid | 0:68e64068330f | 2172 | |
whismanoid | 0:68e64068330f | 2173 | //---------------------------------------- |
whismanoid | 1:d57c1a2cb83c | 2174 | // ideal voltage calculated from raw LSB code and reference voltage |
whismanoid | 22:c6812214a933 | 2175 | tc_v = VoltageOfCode(AINcode[((int)tc_ainp & 0x0F)]); |
whismanoid | 21:847b2220e96e | 2176 | |
whismanoid | 21:847b2220e96e | 2177 | //---------------------------------------- |
whismanoid | 21:847b2220e96e | 2178 | // ideal voltage calculated from raw LSB code and reference voltage |
whismanoid | 22:c6812214a933 | 2179 | tc_delta_degc = TemperatureOfTC_TypeK(tc_v); |
whismanoid | 21:847b2220e96e | 2180 | |
whismanoid | 21:847b2220e96e | 2181 | //---------------------------------------- |
whismanoid | 21:847b2220e96e | 2182 | // ideal voltage calculated from raw LSB code and reference voltage |
whismanoid | 22:c6812214a933 | 2183 | tc_degc = rtd_degc + tc_delta_degc; |
whismanoid | 21:847b2220e96e | 2184 | |
whismanoid | 21:847b2220e96e | 2185 | //---------------------------------------- |
whismanoid | 21:847b2220e96e | 2186 | // ideal voltage calculated from raw LSB code and reference voltage |
whismanoid | 22:c6812214a933 | 2187 | return tc_v; |
whismanoid | 0:68e64068330f | 2188 | } |
whismanoid | 0:68e64068330f | 2189 | |
whismanoid | 3:658a93dfb2d8 | 2190 | //---------------------------------------- |
whismanoid | 3:658a93dfb2d8 | 2191 | // Return the physical temperature corresponding to measured voltage |
whismanoid | 3:658a93dfb2d8 | 2192 | // of a type K Thermocouple (TC). |
whismanoid | 3:658a93dfb2d8 | 2193 | // |
whismanoid | 22:c6812214a933 | 2194 | // @pre {0}.rtd_degc = cold junction temperature, in degrees C |
whismanoid | 22:c6812214a933 | 2195 | // @param[in] tc_v = Thermocouple voltage in volts, default=0.0254 |
whismanoid | 3:658a93dfb2d8 | 2196 | // |
whismanoid | 3:658a93dfb2d8 | 2197 | // @return ideal temperature in degrees C, calculated from RTD resistance in ohms |
whismanoid | 21:847b2220e96e | 2198 | // @test group TC_1 // Verify Thermocouple function TemperatureOfTC_TypeK |
whismanoid | 21:847b2220e96e | 2199 | // @test group TC_2 // Verify Thermocouple function TemperatureOfTC_TypeK in more detail |
whismanoid | 21:847b2220e96e | 2200 | // @test group TC_1 tinyTester.blink_time_msec = 20 // quickly speed through the software verification |
whismanoid | 19:50cf5da53d36 | 2201 | // @test group TC_1 TemperatureOfTC_TypeK(0.000e-3) expect 0.0 within 0.1 // TC_TypeK at 0C = 0.000mV |
whismanoid | 19:50cf5da53d36 | 2202 | // @test group TC_1 TemperatureOfTC_TypeK(0.039e-3) expect 1.0 within 0.1 // TC_TypeK at 1C = 0.039mV |
whismanoid | 19:50cf5da53d36 | 2203 | // @test group TC_1 TemperatureOfTC_TypeK(0.079e-3) expect 2.0 within 0.1 // TC_TypeK at 2C = 0.079mV |
whismanoid | 19:50cf5da53d36 | 2204 | // @test group TC_1 TemperatureOfTC_TypeK(0.119e-3) expect 3.0 within 0.1 // TC_TypeK at 3C = 0.119mV |
whismanoid | 19:50cf5da53d36 | 2205 | // @test group TC_2 TemperatureOfTC_TypeK(0.158e-3) expect 4.0 within 0.1 // TC_TypeK at 4C = 0.158mV |
whismanoid | 19:50cf5da53d36 | 2206 | // @test group TC_2 TemperatureOfTC_TypeK(0.198e-3) expect 5.0 within 0.1 // TC_TypeK at 5C = 0.198mV |
whismanoid | 19:50cf5da53d36 | 2207 | // @test group TC_2 TemperatureOfTC_TypeK(0.238e-3) expect 6.0 within 0.1 // TC_TypeK at 6C = 0.238mV |
whismanoid | 19:50cf5da53d36 | 2208 | // @test group TC_2 TemperatureOfTC_TypeK(0.2775e-3) expect 7.0 within 0.1 // TC_TypeK at 7C = 0.2775mV |
whismanoid | 19:50cf5da53d36 | 2209 | // @test group TC_2 TemperatureOfTC_TypeK(0.317e-3) expect 8.0 within 0.1 // TC_TypeK at 8C = 0.317mV |
whismanoid | 19:50cf5da53d36 | 2210 | // @test group TC_2 TemperatureOfTC_TypeK(0.357e-3) expect 9.0 within 0.1 // TC_TypeK at 9C = 0.357mV |
whismanoid | 19:50cf5da53d36 | 2211 | // @test group TC_1 TemperatureOfTC_TypeK(0.397e-3) expect 10.0 within 0.1 // TC_TypeK at 10C = 0.397mV |
whismanoid | 19:50cf5da53d36 | 2212 | // @test group TC_1 TemperatureOfTC_TypeK(0.798e-3) expect 20.0 within 0.1 // TC_TypeK at 20C = 0.798mV |
whismanoid | 19:50cf5da53d36 | 2213 | // @test group TC_1 TemperatureOfTC_TypeK(1.081e-3) expect 27.0 within 0.1 // TC_TypeK at 27C = 1.081mV |
whismanoid | 19:50cf5da53d36 | 2214 | // @test group TC_1 TemperatureOfTC_TypeK(1.203e-3) expect 30.0 within 0.1 // TC_TypeK at 30C = 1.203mV |
whismanoid | 19:50cf5da53d36 | 2215 | // @test group TC_1 TemperatureOfTC_TypeK(1.612e-3) expect 40.0 within 0.1 // TC_TypeK at 40C = 1.612mV |
whismanoid | 19:50cf5da53d36 | 2216 | // @test group TC_1 TemperatureOfTC_TypeK(2.023e-3) expect 50.0 within 0.1 // TC_TypeK at 50C = 2.023mV |
whismanoid | 19:50cf5da53d36 | 2217 | // @test group TC_1 TemperatureOfTC_TypeK(2.436e-3) expect 60.0 within 0.1 // TC_TypeK at 60C = 2.436mV |
whismanoid | 19:50cf5da53d36 | 2218 | // @test group TC_1 TemperatureOfTC_TypeK(2.851e-3) expect 70.0 within 0.1 // TC_TypeK at 70C = 2.851mV |
whismanoid | 19:50cf5da53d36 | 2219 | // @test group TC_1 TemperatureOfTC_TypeK(3.267e-3) expect 80.0 within 0.1 // TC_TypeK at 80C = 3.267mV |
whismanoid | 19:50cf5da53d36 | 2220 | // @test group TC_1 TemperatureOfTC_TypeK(3.682e-3) expect 90.0 within 0.1 // TC_TypeK at 90C = 3.682mV |
whismanoid | 19:50cf5da53d36 | 2221 | // @test group TC_1 TemperatureOfTC_TypeK(4.096e-3) expect 100.0 within 0.1 // TC_TypeK at 100C = 4.096mV |
whismanoid | 19:50cf5da53d36 | 2222 | // @test group TC_2 TemperatureOfTC_TypeK(4.509e-3) expect 110.0 within 0.1 // TC_TypeK at 110C = 4.509mV |
whismanoid | 19:50cf5da53d36 | 2223 | // @test group TC_2 TemperatureOfTC_TypeK(4.920e-3) expect 120.0 within 0.1 // TC_TypeK at 120C = 4.920mV |
whismanoid | 19:50cf5da53d36 | 2224 | // @test group TC_2 TemperatureOfTC_TypeK(5.328e-3) expect 130.0 within 0.1 // TC_TypeK at 130C = 5.328mV |
whismanoid | 19:50cf5da53d36 | 2225 | // @test group TC_2 TemperatureOfTC_TypeK(5.735e-3) expect 140.0 within 0.1 // TC_TypeK at 140C = 5.735mV |
whismanoid | 19:50cf5da53d36 | 2226 | // @test group TC_2 TemperatureOfTC_TypeK(6.138e-3) expect 150.0 within 0.1 // TC_TypeK at 150C = 6.138mV |
whismanoid | 19:50cf5da53d36 | 2227 | // @test group TC_2 TemperatureOfTC_TypeK(6.540e-3) expect 160.0 within 0.1 // TC_TypeK at 160C = 6.540mV |
whismanoid | 19:50cf5da53d36 | 2228 | // @test group TC_2 TemperatureOfTC_TypeK(6.941e-3) expect 170.0 within 0.1 // TC_TypeK at 170C = 6.941mV |
whismanoid | 19:50cf5da53d36 | 2229 | // @test group TC_2 TemperatureOfTC_TypeK(7.340e-3) expect 180.0 within 0.1 // TC_TypeK at 180C = 7.340mV |
whismanoid | 19:50cf5da53d36 | 2230 | // @test group TC_1 TemperatureOfTC_TypeK(7.739e-3) expect 190.0 within 0.1 // TC_TypeK at 190C = 7.739mV |
whismanoid | 19:50cf5da53d36 | 2231 | // @test group TC_1 TemperatureOfTC_TypeK(8.138e-3) expect 200.0 within 0.1 // TC_TypeK at 200C = 8.138mV |
whismanoid | 19:50cf5da53d36 | 2232 | // @test group TC_1 TemperatureOfTC_TypeK(8.539e-3) expect 210.0 within 0.1 // TC_TypeK at 210C = 8.539mV |
whismanoid | 19:50cf5da53d36 | 2233 | // @test group TC_1 TemperatureOfTC_TypeK(8.940e-3) expect 220.0 within 0.1 // TC_TypeK at 220C = 8.940mV |
whismanoid | 19:50cf5da53d36 | 2234 | // @test group TC_2 TemperatureOfTC_TypeK(9.343e-3) expect 230.0 within 0.1 // TC_TypeK at 230C = 9.343mV |
whismanoid | 19:50cf5da53d36 | 2235 | // @test group TC_2 TemperatureOfTC_TypeK(9.747e-3) expect 240.0 within 0.1 // TC_TypeK at 240C = 9.747mV |
whismanoid | 19:50cf5da53d36 | 2236 | // @test group TC_2 TemperatureOfTC_TypeK(10.153e-3) expect 250.0 within 0.1 // TC_TypeK at 250C = 10.153mV |
whismanoid | 19:50cf5da53d36 | 2237 | // @test group TC_2 TemperatureOfTC_TypeK(10.561e-3) expect 260.0 within 0.1 // TC_TypeK at 260C = 10.561mV |
whismanoid | 19:50cf5da53d36 | 2238 | // @test group TC_2 TemperatureOfTC_TypeK(10.971e-3) expect 270.0 within 0.1 // TC_TypeK at 270C = 10.971mV |
whismanoid | 19:50cf5da53d36 | 2239 | // @test group TC_2 TemperatureOfTC_TypeK(11.382e-3) expect 280.0 within 0.1 // TC_TypeK at 280C = 11.382mV |
whismanoid | 19:50cf5da53d36 | 2240 | // @test group TC_2 TemperatureOfTC_TypeK(11.795e-3) expect 290.0 within 0.1 // TC_TypeK at 290C = 11.795mV |
whismanoid | 19:50cf5da53d36 | 2241 | // @test group TC_1 TemperatureOfTC_TypeK(12.209e-3) expect 300.0 within 0.1 // TC_TypeK at 300C = 12.209mV |
whismanoid | 19:50cf5da53d36 | 2242 | // @test group TC_2 TemperatureOfTC_TypeK(14.293e-3) expect 350.0 within 0.1 // TC_TypeK at 350C = 14.293mV |
whismanoid | 19:50cf5da53d36 | 2243 | // @test group TC_1 TemperatureOfTC_TypeK(16.397e-3) expect 400.0 within 0.1 // TC_TypeK at 400C = 16.397mV |
whismanoid | 19:50cf5da53d36 | 2244 | // @test group TC_1 TemperatureOfTC_TypeK(18.516e-3) expect 450.0 within 0.1 // TC_TypeK at 450C = 18.516mV |
whismanoid | 19:50cf5da53d36 | 2245 | // @test group TC_1 TemperatureOfTC_TypeK(20.218e-3) expect 490.0 // TC_TypeK at 490C = 20.218mV |
whismanoid | 21:847b2220e96e | 2246 | // @test group TC_1 tinyTester.blink_time_msec = 75 // default 75 resume hardware self test |
whismanoid | 3:658a93dfb2d8 | 2247 | // |
whismanoid | 22:c6812214a933 | 2248 | double MAX11410::TemperatureOfTC_TypeK(double tc_v) |
whismanoid | 3:658a93dfb2d8 | 2249 | { |
whismanoid | 3:658a93dfb2d8 | 2250 | |
whismanoid | 3:658a93dfb2d8 | 2251 | //---------------------------------------- |
whismanoid | 3:658a93dfb2d8 | 2252 | // Temperature from TC_TypeK voltage maths |
whismanoid | 5:a2e74357cfc0 | 2253 | // define standard TC_TypeK coefficients |
whismanoid | 4:c169ba85d673 | 2254 | // ITS-90 Thermocouple Inverse Polynomial for a Type K thermocouple |
whismanoid | 22:c6812214a933 | 2255 | // calculate deltaT from tc_v |
whismanoid | 4:c169ba85d673 | 2256 | // |
whismanoid | 22:c6812214a933 | 2257 | // Voltage range -5891uV < tc_v < 0uV, |
whismanoid | 4:c169ba85d673 | 2258 | // Temperature Range -200 deg C to 0 deg C |
whismanoid | 4:c169ba85d673 | 2259 | static double coefficients_TCtypeK_V_lt_0[] = { |
whismanoid | 4:c169ba85d673 | 2260 | 0.00000, |
whismanoid | 4:c169ba85d673 | 2261 | 2.5173462e-2, |
whismanoid | 4:c169ba85d673 | 2262 | -1.1662878e-6, |
whismanoid | 4:c169ba85d673 | 2263 | -1.0833638e-9, |
whismanoid | 4:c169ba85d673 | 2264 | -8.9773540e-13, |
whismanoid | 4:c169ba85d673 | 2265 | -3.7342377e-16, |
whismanoid | 4:c169ba85d673 | 2266 | -8.6632643e-20, |
whismanoid | 4:c169ba85d673 | 2267 | -1.0450598e-23, |
whismanoid | 4:c169ba85d673 | 2268 | -5.1920577e-28, |
whismanoid | 4:c169ba85d673 | 2269 | }; |
whismanoid | 4:c169ba85d673 | 2270 | // |
whismanoid | 22:c6812214a933 | 2271 | // Voltage range 0uV < tc_v < 20.644uV, |
whismanoid | 4:c169ba85d673 | 2272 | // Temperature Range 0 deg C to 500 deg C |
whismanoid | 4:c169ba85d673 | 2273 | static double coefficients_TCtypeK_0_lt_V_lt_20u644V[] = { |
whismanoid | 4:c169ba85d673 | 2274 | 0.00000, |
whismanoid | 4:c169ba85d673 | 2275 | 2.508355e-2, |
whismanoid | 4:c169ba85d673 | 2276 | 7.860106e-8, |
whismanoid | 4:c169ba85d673 | 2277 | -2.503131e-10, |
whismanoid | 4:c169ba85d673 | 2278 | 8.315270e-14, |
whismanoid | 4:c169ba85d673 | 2279 | -1.228034e-17, |
whismanoid | 4:c169ba85d673 | 2280 | 9.804036e-22, |
whismanoid | 4:c169ba85d673 | 2281 | -4.413030e-26, |
whismanoid | 4:c169ba85d673 | 2282 | 1.057734e-30, |
whismanoid | 4:c169ba85d673 | 2283 | -1.052755e-35, |
whismanoid | 4:c169ba85d673 | 2284 | }; |
whismanoid | 4:c169ba85d673 | 2285 | // |
whismanoid | 22:c6812214a933 | 2286 | // Voltage range 20.6440uV < tc_v < 54.886uV, |
whismanoid | 4:c169ba85d673 | 2287 | // Temperature Range 500 deg C to 1372 deg C |
whismanoid | 4:c169ba85d673 | 2288 | static double coefficients_TCtypeK_20u644V_lt_V_lt_54u886V[] = { |
whismanoid | 4:c169ba85d673 | 2289 | -1.318058e2, |
whismanoid | 4:c169ba85d673 | 2290 | 4.830222e-2, |
whismanoid | 4:c169ba85d673 | 2291 | -1.646031e-6, |
whismanoid | 4:c169ba85d673 | 2292 | 5.464731e-11, |
whismanoid | 4:c169ba85d673 | 2293 | -9.650715e-16, |
whismanoid | 4:c169ba85d673 | 2294 | 8.802193e-21, |
whismanoid | 4:c169ba85d673 | 2295 | -3.110810e-26, |
whismanoid | 4:c169ba85d673 | 2296 | }; |
whismanoid | 4:c169ba85d673 | 2297 | // |
whismanoid | 3:658a93dfb2d8 | 2298 | double deltaT = 0; |
whismanoid | 22:c6812214a933 | 2299 | double thermocouple_voltage_uV = tc_v * 1e6; |
whismanoid | 4:c169ba85d673 | 2300 | if (thermocouple_voltage_uV < 0) |
whismanoid | 4:c169ba85d673 | 2301 | { |
whismanoid | 4:c169ba85d673 | 2302 | // Voltage range -5891uV < DMMavg < 0uV, Temperature Range -200 deg C to 0 deg C |
whismanoid | 4:c169ba85d673 | 2303 | deltaT = temperatureDegC_polynomial(thermocouple_voltage_uV, 9, coefficients_TCtypeK_V_lt_0); |
whismanoid | 4:c169ba85d673 | 2304 | } |
whismanoid | 4:c169ba85d673 | 2305 | else if (thermocouple_voltage_uV > 20644) |
whismanoid | 4:c169ba85d673 | 2306 | { |
whismanoid | 4:c169ba85d673 | 2307 | // Voltage range 206440uV < DMMavg < 54886uV, Temperature Range 500 deg C to 1372 deg C |
whismanoid | 4:c169ba85d673 | 2308 | deltaT = temperatureDegC_polynomial(thermocouple_voltage_uV, 7, coefficients_TCtypeK_20u644V_lt_V_lt_54u886V); |
whismanoid | 4:c169ba85d673 | 2309 | } |
whismanoid | 4:c169ba85d673 | 2310 | else |
whismanoid | 4:c169ba85d673 | 2311 | { |
whismanoid | 4:c169ba85d673 | 2312 | // Voltage range 0uV < DMMavg < 20.644uV, Temperature Range 0 deg C to 500 deg C |
whismanoid | 4:c169ba85d673 | 2313 | deltaT = temperatureDegC_polynomial(thermocouple_voltage_uV, 10, coefficients_TCtypeK_0_lt_V_lt_20u644V); |
whismanoid | 4:c169ba85d673 | 2314 | } |
whismanoid | 22:c6812214a933 | 2315 | return deltaT; // + rtd_degc; // cold junction |
whismanoid | 4:c169ba85d673 | 2316 | } |
whismanoid | 4:c169ba85d673 | 2317 | |
whismanoid | 4:c169ba85d673 | 2318 | //---------------------------------------- |
whismanoid | 4:c169ba85d673 | 2319 | // Calculate temperature in degrees C from input voltage, |
whismanoid | 4:c169ba85d673 | 2320 | // using a given set of polynomial coefficients. |
whismanoid | 4:c169ba85d673 | 2321 | // For example: |
whismanoid | 4:c169ba85d673 | 2322 | // |
whismanoid | 4:c169ba85d673 | 2323 | // t = coefficients[0] + coefficients[1] * DMMavg + coefficients[2] * DmMMavg**2 |
whismanoid | 4:c169ba85d673 | 2324 | // |
whismanoid | 4:c169ba85d673 | 2325 | // @param[in] thermocouple_voltage_uV = Thermocouple voltage in microvolts |
whismanoid | 4:c169ba85d673 | 2326 | // |
whismanoid | 4:c169ba85d673 | 2327 | // @return ideal temperature in degrees C, calculated from polynomial coefficients |
whismanoid | 4:c169ba85d673 | 2328 | // |
whismanoid | 4:c169ba85d673 | 2329 | double MAX11410::temperatureDegC_polynomial(double thermocouple_voltage_uV, int num_coefficients, double coefficients[]) |
whismanoid | 4:c169ba85d673 | 2330 | { |
whismanoid | 4:c169ba85d673 | 2331 | |
whismanoid | 4:c169ba85d673 | 2332 | //---------------------------------------- |
whismanoid | 4:c169ba85d673 | 2333 | // Temperature from polynomial coefficients maths |
whismanoid | 4:c169ba85d673 | 2334 | double temperatureDegC = 0; |
whismanoid | 4:c169ba85d673 | 2335 | int index; |
whismanoid | 4:c169ba85d673 | 2336 | for (index = num_coefficients-1; index >= 0; index--) |
whismanoid | 4:c169ba85d673 | 2337 | { |
whismanoid | 4:c169ba85d673 | 2338 | temperatureDegC = (temperatureDegC * thermocouple_voltage_uV) + coefficients[index]; |
whismanoid | 4:c169ba85d673 | 2339 | } |
whismanoid | 4:c169ba85d673 | 2340 | return temperatureDegC; |
whismanoid | 3:658a93dfb2d8 | 2341 | } |
whismanoid | 3:658a93dfb2d8 | 2342 | |
whismanoid | 0:68e64068330f | 2343 | |
whismanoid | 0:68e64068330f | 2344 | // End of file |