Test program running on MAX32625MBED. Control through USB Serial commands using a terminal emulator such as teraterm or putty.
Dependencies: MaximTinyTester CmdLine MAX541 USBDevice
Diff: MAX11043/MAX11043.cpp
- Revision:
- 69:989e392cf635
- Parent:
- 67:5b8a495dda1c
- Child:
- 70:f44a577c9e59
--- a/MAX11043/MAX11043.cpp Thu Feb 20 10:21:21 2020 +0000 +++ b/MAX11043/MAX11043.cpp Fri Feb 21 00:45:32 2020 +0000 @@ -40,6 +40,13 @@ // System Description = Device driver example #include "MAX11043.h" +//-------------------------------------------------- +// MAX11043 ADC Read operations must be synchronized to EOC End Of Conversion +// EOC# asserts low when new data is available. +// Initiate a data read prior to the next rising edge of EOC# or the result is overwritten. +#ifndef MAX11043_EOC_INTERRUPT_POLLING +#define MAX11043_EOC_INTERRUPT_POLLING 1 +#endif // MAX11043_EOC_INTERRUPT_POLLING // Device Name = MAX11043 // Device Description = 200ksps, Low-Power, Serial SPI 24-Bit, 4-Channel, Differential/Single-Ended Input, Simultaneous-Sampling SD ADC @@ -122,7 +129,17 @@ DigitalOut &DACSTEP_pin, // Digital Configuration Input to MAX11043 device DigitalOut &UP_slash_DWNb_pin, // Digital Configuration Input to MAX11043 device // CODE GENERATOR: class constructor definition gpio OutputPin pins +// MAX11043 ADC Read operations must be synchronized to EOC End Of Conversion +#if MAX11043_EOC_INTERRUPT_POLLING +// MAX11043 EOC End Of Conversion input should be InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); +// Workaround using DigitalIn(PinName:EOC_pin) polled to sync with EOC falling edge for ADC reads +// TODO: onEOCFallingEdge: replace DigitalIn &EOC_pin with PinName EOC_pin, so that I can create an InterruptIn(PinName:EOC_pin) DigitalIn &EOC_pin, // Digital Event Output from MAX11043 device +#else // MAX11043_EOC_INTERRUPT_POLLING +// MAX11043 EOC End Of Conversion input is InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); +// TODO: onEOCFallingEdge: replace DigitalIn &EOC_pin with PinName EOC_pin, so that I can create an InterruptIn(PinName:EOC_pin) + InterruptIn &EOC_pin, // Digital Event Output from MAX11043 device +#endif // MAX11043_EOC_INTERRUPT_POLLING // CODE GENERATOR: class constructor definition ic_variant MAX11043_ic_t ic_variant) // CODE GENERATOR: class constructor initializer list @@ -133,7 +150,15 @@ m_DACSTEP_pin(DACSTEP_pin), // Digital Configuration Input to MAX11043 device m_UP_slash_DWNb_pin(UP_slash_DWNb_pin), // Digital Configuration Input to MAX11043 device // CODE GENERATOR: class constructor initializer list gpio OutputPin pins +// MAX11043 ADC Read operations must be synchronized to EOC End Of Conversion +#if MAX11043_EOC_INTERRUPT_POLLING +// MAX11043 EOC End Of Conversion input should be InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); +// Workaround using DigitalIn(PinName:EOC_pin) polled to sync with EOC falling edge for ADC reads m_EOC_pin(EOC_pin), // Digital Event Output from MAX11043 device +#else // MAX11043_EOC_INTERRUPT_POLLING +// MAX11043 EOC End Of Conversion input is InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); + // m_EOC_pin(EOC_pin), // Digital Event Output from MAX11043 device +#endif // MAX11043_EOC_INTERRUPT_POLLING // CODE GENERATOR: class constructor initializer list ic_variant m_ic_variant(ic_variant) { @@ -183,8 +208,34 @@ // CODE GENERATOR: class constructor definition gpio OutputPin (Output from MAX11043 device) initialization // // EOC Event Output from device +// MAX11043 ADC Read operations must be synchronized to EOC End Of Conversion +#if MAX11043_EOC_INTERRUPT_POLLING +// MAX11043 EOC End Of Conversion input should be InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); +// Workaround using DigitalIn(PinName:EOC_pin) polled to sync with EOC falling edge for ADC reads +#else // MAX11043_EOC_INTERRUPT_POLLING +// MAX11043 EOC End Of Conversion input is InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); + // TODO: onEOCFallingEdge: interrupt handler requires global object extern MAX11043 g_MAX11043_device + InterruptIn interruptEOC(EOC_pin); // InterruptIn constructor requires PinName, not DigitalIn -- Error: No instance of constructor "mbed::InterruptIn::InterruptIn" matches the argument list in "MAX11043/MAX11043.cpp", Line: 187, Col: 31 + // TODO: onEOCFallingEdge: replace DigitalIn &EOC_pin with PinName EOC_pin, so that I can create an InterruptIn(PinName:EOC_pin) + interruptEOC.fall(&onEOCFallingEdge); +#endif // MAX11043_EOC_INTERRUPT_POLLING + } +// MAX11043 ADC Read operations must be synchronized to EOC End Of Conversion +#if MAX11043_EOC_INTERRUPT_POLLING +// MAX11043 EOC End Of Conversion input should be InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); +// Workaround using DigitalIn(PinName:EOC_pin) polled to sync with EOC falling edge for ADC reads +#else // MAX11043_EOC_INTERRUPT_POLLING +// MAX11043 EOC End Of Conversion input is InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); +// Interrupt Handler: EOC Event Output from device +void onEOCFallingEdge(void) +{ + extern MAX11043 g_MAX11043_device; + g_MAX11043_device.Read_ADCabcd(); +} +#endif // MAX11043_EOC_INTERRUPT_POLLING + // CODE GENERATOR: class destructor definition MAX11043::~MAX11043() { @@ -281,6 +332,34 @@ // m_CONVRUN_pin.output(); // only applicable to DigitalInOut // TODO1: CODE GENERATOR: gpio function Value m_CONVRUN_pin = isLogicHigh; +//-------------------------------------------------- +// MAX11043 ADC Read operations must be synchronized to EOC End Of Conversion +// EOC# asserts low when new data is available. +// Initiate a data read prior to the next rising edge of EOC# or the result is overwritten. +#if MAX11043_EOC_INTERRUPT_POLLING +// MAX11043 EOC End Of Conversion input should be InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); +// Workaround using DigitalIn(PinName:EOC_pin) polled to sync with EOC falling edge for ADC reads + if (m_CONVRUN_pin) + { + // CONVRUN was switched high, EOC# will now begin toggling + } + else + { + // CONVRUN was switched low, so wait until EOC# returns high + #warning "MAX11043::Read_ADCabcd() Potential infinite loop if EOC pin not connected" + // possible infinite loop; need a timeout or futility countdown to escape + for (int futility_countdown = 100; + ((futility_countdown > 0) && + (m_EOC_pin != 1)); + futility_countdown--) + { + // spinlock waiting for logic high pin state (start of new conversion) + } + } +#else // MAX11043_EOC_INTERRUPT_POLLING +// MAX11043 EOC End Of Conversion input is InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); +#endif // MAX11043_EOC_INTERRUPT_POLLING +//-------------------------------------------------- } // TODO1: CODE GENERATOR: extern function GPIOoutputDACSTEP alias DACSTEPoutputValue @@ -1088,6 +1167,43 @@ // warning -- WIP work in progress #warning "Not Tested Yet: MAX11043::Read_ADCabcd..." +//-------------------------------------------------- +// MAX11043 ADC Read operations must be synchronized to EOC End Of Conversion +// EOC# asserts low when new data is available. +// Initiate a data read prior to the next rising edge of EOC# or the result is overwritten. +#if MAX11043_EOC_INTERRUPT_POLLING +// MAX11043 EOC End Of Conversion input should be InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); +// Workaround using DigitalIn(PinName:EOC_pin) polled to sync with EOC falling edge for ADC reads +// 2020-02-20 MAX11043_EOC_INTERRUPT_POLLING works on MAX32625MBED at 9us conversion rate, with 1us timing margin + // TODO: poll m_EOC_pin if CONVRUN is high + if (m_CONVRUN_pin) + { + #warning "MAX11043::Read_ADCabcd() Potential infinite loop if EOC pin not connected" + // possible infinite loop; need a timeout or futility countdown to escape + for (int futility_countdown = 100; + ((futility_countdown > 0) && + (m_EOC_pin != 1)); + futility_countdown--) + { + // spinlock waiting for logic high pin state (start of new conversion) + } + for (int futility_countdown = 100; + ((futility_countdown > 0) && + (m_EOC_pin != 0)); + futility_countdown--) + { + // spinlock waiting for logic low pin state (new data is available) + } + } + else + { + // CONVRUN pin is being driven low, so conversion result will not change, EOC# remains high + } +#else // MAX11043_EOC_INTERRUPT_POLLING +// MAX11043 EOC End Of Conversion input is InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); +#endif // MAX11043_EOC_INTERRUPT_POLLING +//-------------------------------------------------- + //---------------------------------------- // read register ADCabcd -> &adca, &adcb, &adcc, &adcd RegRead(CMD_0001_1010_d16o8_d16o8_d16o8_d16o8_Rd06_ADCabcd, 0);