Maxim Integrated MAX5171 14-bit Force/Sense DAC

Dependents:   MAX5171BOB_Tester MAX5171BOB_14bit_Remote_Sense_SPI_DAC MAX5171BOB_Serial_Tester

Revision:
6:f661c4a61207
Parent:
5:e8c0dfaeb53b
Child:
7:564b438a0448
--- a/MAX5171.h	Thu Mar 12 23:33:56 2020 +0000
+++ b/MAX5171.h	Fri Apr 03 06:27:05 2020 +0000
@@ -175,13 +175,21 @@
  * #define D13 P1_0
  * #endif
  *
- * // example code declare SPI interface
+ * // example code declare SPI interface (GPIO controlled CS)
  * #if defined(TARGET_MAX32625MBED)
  * SPI spi(SPI1_MOSI, SPI1_MISO, SPI1_SCK); // mosi, miso, sclk spi1 TARGET_MAX32625MBED: P1_1 P1_2 P1_0 Arduino 10-pin header D11 D12 D13
  * DigitalOut spi_cs(SPI1_SS); // TARGET_MAX32625MBED: P1_3 Arduino 10-pin header D10
  * #elif defined(TARGET_MAX32600MBED)
  * SPI spi(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13
  * DigitalOut spi_cs(SPI2_SS); // Generic: Arduino 10-pin header D10
+ * #elif defined(TARGET_NUCLEO_F446RE) || defined(TARGET_NUCLEO_F401RE)
+ * // TODO1: avoid resource conflict between P5_0, P5_1, P5_2 SPI and DigitalInOut
+ * // void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
+ * //
+ * // TODO1: NUCLEO_F446RE SPI not working; CS and MOSI data looks OK but no SCLK clock pulses.
+ * SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK); // mosi, miso, sclk spi1 TARGET_NUCLEO_F446RE: Arduino 10-pin header D11 D12 D13
+ * DigitalOut spi_cs(SPI_CS); // TARGET_NUCLEO_F446RE: PB_6 Arduino 10-pin header D10
+ * //
  * #else
  * SPI spi(D11, D12, D13); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13
  * DigitalOut spi_cs(D10); // Generic: Arduino 10-pin header D10
@@ -208,20 +216,29 @@
  *         uint16_t code;
  *         //
  *         // example #1
- *         code = 0x3332; // 80.0% of full scale REF(2.50V) = 2.00V
+ *         code = 0x3332; // 80.0% of full scale REF(2.50V) = 2.00V (FORCE_BIP/SENSE_BIP: 1.50V)
  *         g_MAX5171_device.CODE_LOAD(code);
+ *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
  *         //
  *         // example #2
- *         code = 0x1fff; // 50.0% of full scale REF(2.50V) = 1.25V
+ *         code = 0x1fff; // 50.0% of full scale REF(2.50V) = 1.25V (FORCE_BIP/SENSE_BIP: 0.00V)
  *         g_MAX5171_device.CODE_LOAD(code);
+ *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
  *         //
  *         // example #3
- *         code = 0x1999; // 40.0% of full scale REF(2.50V) = 1.00V
+ *         code = 0x1999; // 40.0% of full scale REF(2.50V) = 1.00V (FORCE_BIP/SENSE_BIP: -0.50V)
  *         g_MAX5171_device.CODE_LOAD(code);
+ *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
  *         //
  *         // example #4
- *         code = 0x3fff; // 100.0% of full scale REF(2.50V) = 2.50V
+ *         code = 0x0000; // 0.0% of full scale REF(2.50V) = 0.00V (FORCE_BIP/SENSE_BIP: -2.50V)
  *         g_MAX5171_device.CODE_LOAD(code);
+ *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
+ *         //
+ *         // example #5
+ *         code = 0x3fff; // 100.0% of full scale REF(2.50V) = 2.50V (FORCE_BIP/SENSE_BIP: 2.50V)
+ *         g_MAX5171_device.CODE_LOAD(code);
+ *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
  *
  *         // wait(3.0);
  *     }
@@ -237,15 +254,15 @@
     /// - dd_dddd_dddd_dddd = data field
     /// - xxxx = don't care
     typedef enum MAX5171_CMD_enum_t {
-        CMD_00dd_dddd_dddd_dddd_CODE = 0x0000, //!< 16'b0000000000000000
-        CMD_01dd_dddd_dddd_dddd_CODE_LOAD = 0x4000, //!< 16'b0100000000000000
-        CMD_10xx_xxxx_xxxx_xxxx_LOAD = 0x8000, //!< 16'b1000000000000000
-        CMD_1100_xxxx_xxxx_xxxx_NOP = 0xc000, //!< 16'b1100000000000000
-        CMD_1101_xxxx_xxxx_xxxx_SHUTDOWN = 0xd000, //!< 16'b1101000000000000
-        CMD_1110_0xxx_xxxx_xxxx_UPO_LOW = 0xe000, //!< 16'b1110000000000000
-        CMD_1110_1xxx_xxxx_xxxx_UPO_HIGH = 0xe800, //!< 16'b1110100000000000
-        CMD_1111_0xxx_xxxx_xxxx_MODE1_DOUT_SCLK_RISING_EDGE = 0xf000, //!< 16'b1111000000000000
-        CMD_1111_1xxx_xxxx_xxxx_MODE0_DOUT_SCLK_FALLING_EDGE = 0xf800, //!< 16'b1111100000000000
+        CMD_00dd_dddd_dddd_dddd_CODE = 0x0000, //!< 0b0000000000000000
+        CMD_01dd_dddd_dddd_dddd_CODE_LOAD = 0x4000, //!< 0b0100000000000000
+        CMD_10xx_xxxx_xxxx_xxxx_LOAD = 0x8000, //!< 0b1000000000000000
+        CMD_1100_xxxx_xxxx_xxxx_NOP = 0xc000, //!< 0b1100000000000000
+        CMD_1101_xxxx_xxxx_xxxx_SHUTDOWN = 0xd000, //!< 0b1101000000000000
+        CMD_1110_0xxx_xxxx_xxxx_UPO_LOW = 0xe000, //!< 0b1110000000000000
+        CMD_1110_1xxx_xxxx_xxxx_UPO_HIGH = 0xe800, //!< 0b1110100000000000
+        CMD_1111_0xxx_xxxx_xxxx_MODE1_DOUT_SCLK_RISING_EDGE = 0xf000, //!< 0b1111000000000000
+        CMD_1111_1xxx_xxxx_xxxx_MODE0_DOUT_SCLK_FALLING_EDGE = 0xf800, //!< 0b1111100000000000
     } MAX5171_CMD_enum_t;
 
     /**
@@ -390,8 +407,144 @@
     //----------------------------------------
     /// Menu item '!'
     /// Initialize device
-    /// @return 1 on success; 0 on failure
-    uint8_t Init(void);
+    ///
+    /// TODO1: #170 MAX5171 Self Test for Test Fixture Firmware
+    /// @future test group ____ // Verify function ____ (enabled by default)
+    /// @future test
+    ///     tinyTester.settle_time_msec = 250;
+    ///
+    /// @test group DACCodeOfVoltage // Verify function DACCodeOfVoltage (enabled by default)
+    /// @test group DACCodeOfVoltage tinyTester.blink_time_msec = 20 // quickly speed through the software verification
+    /// @test group DACCodeOfVoltage tinyTester.print("VRef = 2.500  MAX5171 14-bit LSB = 0.00015V")
+    /// @test group DACCodeOfVoltage VRef = 2.500
+    /// @test group DACCodeOfVoltage tinyTester.err_threshold = 0.00015259720441921504 // 14-bit LSB (2.500/16383)
+    ///     //
+    /// @test group DACCodeOfVoltage DACCodeOfVoltage(2.499847412109375) expect 0x3FFF
+    /// @test group DACCodeOfVoltage DACCodeOfVoltage(2.49969482421875) expect 0x3FFE
+    /// @test group DACCodeOfVoltage DACCodeOfVoltage(2.499542236328125) expect 0x3FFD
+    /// @test group DACCodeOfVoltage DACCodeOfVoltage(2.4993896484375) expect 0x3FFC
+    /// @test group DACCodeOfVoltage DACCodeOfVoltage(1.250152587890625) expect 0x2001
+    /// @test group DACCodeOfVoltage DACCodeOfVoltage(1.25) expect 0x2000
+    /// @test group DACCodeOfVoltage DACCodeOfVoltage(1.249847412109375) expect 0x1FFF
+    /// @test group DACCodeOfVoltage DACCodeOfVoltage(1.24969482421875) expect 0x1FFE
+    /// @test group DACCodeOfVoltage DACCodeOfVoltage(0.000457763671875) expect 0x0003
+    /// @test group DACCodeOfVoltage DACCodeOfVoltage(0.00030517578125) expect 0x0002
+    /// @test group DACCodeOfVoltage DACCodeOfVoltage(0.000152587890625) expect 0x0001
+    /// @test group DACCodeOfVoltage DACCodeOfVoltage(0.00000) expect 0x0000
+    /// @test group DACCodeOfVoltage tinyTester.blink_time_msec = 75 // default 75 resume hardware self test
+    ///     //
+    /// @test group VoltageOfCode // Verify function VoltageOfCode (enabled by default)
+    /// @test group VoltageOfCode tinyTester.blink_time_msec = 20 // quickly speed through the software verification
+    /// @test group VoltageOfCode tinyTester.print("VRef = 2.500  MAX5171 14-bit LSB = 0.00015V")
+    /// @test group VoltageOfCode VRef = 2.500
+    /// @test group VoltageOfCode tinyTester.err_threshold = 0.00015259720441921504 // 14-bit LSB (2.500/16383)
+    /// @test group VoltageOfCode VoltageOfCode(0x3FFF) expect 2.499847412109375
+    /// @test group VoltageOfCode VoltageOfCode(0x3FFE) expect 2.49969482421875
+    /// @test group VoltageOfCode VoltageOfCode(0x3FFD) expect 2.499542236328125
+    /// @test group VoltageOfCode VoltageOfCode(0x3FFC) expect 2.4993896484375
+    /// @test group VoltageOfCode VoltageOfCode(0x2001) expect 1.250152587890625
+    /// @test group VoltageOfCode VoltageOfCode(0x2000) expect 1.25
+    /// @test group VoltageOfCode VoltageOfCode(0x1FFF) expect 1.249847412109375
+    /// @test group VoltageOfCode VoltageOfCode(0x1FFE) expect 1.24969482421875
+    /// @test group VoltageOfCode VoltageOfCode(0x0003) expect 0.000457763671875
+    /// @test group VoltageOfCode VoltageOfCode(0x0002) expect 0.00030517578125
+    /// @test group VoltageOfCode VoltageOfCode(0x0001) expect 0.000152587890625
+    /// @test group VoltageOfCode VoltageOfCode(0x0000) expect 0.00000
+    /// @test group VoltageOfCode tinyTester.blink_time_msec = 75 // default 75 resume hardware self test
+    ///     //
+    ///     // Device Testing: DAC commands, verify using on-board ADC inputs
+    ///     //
+    /// @test group CODE_LOAD // Verify function CODE_LOAD (enabled by default)
+    /// @test group CODE_LOAD tinyTester.blink_time_msec = 75 // default 75 resume hardware self test
+    /// @test group CODE_LOAD tinyTester.settle_time_msec = 500
+    ///     tinyTester.blink_time_msec = 75;
+    ///     cmdLine.serial().printf("
+    ///       MAX5171.Init()");
+    ///     g_MAX5171_device.Init();
+    /// @test Init()
+    /// @test VRef expect 2.500 // Nominal Full-Scale Voltage Reference
+    ///     //
+    ///     tinyTester.err_threshold = 0.030; // 30mV
+    /// @test group CODE_LOAD tinyTester.err_threshold = 0.050
+    ///     uint16_t code = 0x3FFF;
+    ///     //~ double voltageV = 0.5;
+    ///     //
+    ///     cmdLine.serial().printf("
+    ///       MAX5171.CODE_LOAD code=%d", code);
+    ///     g_MAX5171_device.CODE_LOAD(code);
+    /// @test group CODE_LOAD tinyTester.print("100.0% of full scale REF(2.50V) = 2.50V Jumper FB=1-2")
+    /// @test group CODE_LOAD CODE_LOAD(0x3FFF) // 100.0% of full scale REF(2.50V) = 2.50V
+    ///     // tinyTester.Wait_Output_Settling replaces wait_ms
+    ///     tinyTester.Wait_Output_Settling();
+    /// @test group CODE_LOAD tinyTester.Wait_Output_Settling()
+    ///     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
+    ///     tinyTester.AnalogIn0_Read_Expect_voltageV(2.500);
+    /// @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(2.500)
+    ///     //
+    ///     code = 0x0000;
+    ///     cmdLine.serial().printf("
+    ///       MAX5171.CODE_LOAD code=%d", code);
+    ///     g_MAX5171_device.CODE_LOAD(code);
+    /// @test group CODE_LOAD tinyTester.print("0.0% of full scale REF(2.50V) = 0.000V")
+    /// @test group CODE_LOAD CODE_LOAD(0x0000) // 0.0% of full scale REF(2.50V) = 0.000V
+    ///     // tinyTester.Wait_Output_Settling replaces wait_ms
+    ///     tinyTester.Wait_Output_Settling();
+    /// @test group CODE_LOAD tinyTester.Wait_Output_Settling()
+    ///     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
+    ///     tinyTester.AnalogIn0_Read_Expect_voltageV(0.0000);
+    /// @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(0.0000)
+    ///     //
+    ///     code = 0x1FFF;
+    ///     cmdLine.serial().printf("
+    ///       MAX5171.CODE_LOAD code=%d", code);
+    ///     g_MAX5171_device.CODE_LOAD(code);
+    /// @test group CODE_LOAD tinyTester.print("50.0% of full scale REF(2.50V) = 1.25V")
+    /// @test group CODE_LOAD CODE_LOAD(0x1FFF) // 50.0% of full scale REF(2.50V) = 1.25V
+    ///     // tinyTester.Wait_Output_Settling replaces wait_ms
+    ///     tinyTester.Wait_Output_Settling();
+    /// @test group CODE_LOAD tinyTester.Wait_Output_Settling()
+    ///     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
+    ///     tinyTester.AnalogIn0_Read_Expect_voltageV(1.2500);
+    /// @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(1.2500)
+    ///     //
+    ///     // test UPO User Programmable Output, verify using digital input D2
+    ///     //
+    /// @test group UPO // Verify User Programmable Output functions UPO_HIGH and UPO_LOW (enabled by default)
+    /// @test group UPO tinyTester.blink_time_msec = 75 // default 75 resume hardware self test
+    /// @test group UPO tinyTester.settle_time_msec = 500 // default 250
+    ///     cmdLine.serial().printf("
+    ///       MAX5171.UPO_HIGH");
+    ///     g_MAX5171_device.UPO_HIGH();
+    /// @test group UPO UPO_HIGH()
+    ///     tinyTester.Wait_Output_Settling();
+    /// @test group UPO tinyTester.Wait_Output_Settling()
+    ///     // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_Expect_Input_UPO_pin
+    ///     tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command");
+    /// @test group CODE_LOAD tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command")
+    ///     //
+    ///     cmdLine.serial().printf("
+    ///       MAX5171.UPO_LOW");
+    ///     g_MAX5171_device.UPO_LOW();
+    /// @test group UPO UPO_LOW()
+    ///     tinyTester.Wait_Output_Settling();
+    /// @test group UPO tinyTester.Wait_Output_Settling()
+    ///     // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_Expect_Input_UPO_pin
+    ///     tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 0, "UPO_pin is low after MAX5171 UPO_LOW command");
+    /// @test group CODE_LOAD tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 0, "UPO_pin is low after MAX5171 UPO_LOW command")
+    ///     //
+    ///     cmdLine.serial().printf("
+    ///       MAX5171.UPO_HIGH");
+    ///     g_MAX5171_device.UPO_HIGH();
+    /// @test group UPO UPO_HIGH()
+    ///     tinyTester.Wait_Output_Settling();
+    /// @test group UPO tinyTester.Wait_Output_Settling()
+    ///     // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_Expect_Input_UPO_pin
+    ///     tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command");
+    /// @test group CODE_LOAD tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command")
+    ///     //
+    ///
+    ///
+    void Init(void);
 
     //----------------------------------------
     /// Return the DAC register value corresponding to physical voltage.