Skip to content

Commit

Permalink
dac testing (only I_SET)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Oct 2, 2019
1 parent 8f2c2f4 commit eb63843
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 175 deletions.
10 changes: 4 additions & 6 deletions src/eez/apps/psu/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ void Channel::Value::addMonValue(float value, float prec) {
void Channel::Value::addMonDacValue(float value, float prec) {
value = roundPrec(value, prec);

mon_dac_last = value;

if (mon_dac_index == -1) {
mon_dac_index = 0;
for (int i = 0; i < NUM_ADC_AVERAGING_VALUES; ++i) {
Expand Down Expand Up @@ -790,15 +792,11 @@ void Channel::protectionCheck() {
}

void Channel::adcMeasureMonDac() {
if (isOk()) {
channelInterface->adcMeasureMonDac(subchannelIndex);
}
channelInterface->adcMeasureMonDac(subchannelIndex);
}

void Channel::adcMeasureAll() {
if (isOk()) {
channelInterface->adcMeasureAll(subchannelIndex);
}
channelInterface->adcMeasureAll(subchannelIndex);
}

void Channel::executeOutputEnable(bool enable) {
Expand Down
1 change: 1 addition & 0 deletions src/eez/apps/psu/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ class Channel {
float mon_total;

float mon_dac;
float mon_dac_last;
int8_t mon_dac_index;
float mon_dac_arr[NUM_ADC_AVERAGING_VALUES];
float mon_dac_total;
Expand Down
2 changes: 1 addition & 1 deletion src/eez/apps/psu/conf_advanced.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
#define ADC_SPS 5

/// ADC conversion should be finished after ADC_CONVERSION_MAX_TIME_MS milliseconds.
#define ADC_CONVERSION_MAX_TIME_MS 3
#define ADC_CONVERSION_MAX_TIME_MS 10

/// Maximum number of attempts to recover from ADC timeout before giving up.
#define MAX_ADC_TIMEOUT_RECOVERY_ATTEMPTS 3
Expand Down
17 changes: 17 additions & 0 deletions src/eez/apps/psu/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ void mainLoop(const void *) {
#endif
}

bool g_adcMeasureAllFinished = false;

void oneIter() {
osEvent event = osMessageGet(g_psuMessageQueueId, 1);
if (event.status == osEventMessage) {
Expand All @@ -90,11 +92,26 @@ void oneIter() {
if (channelInterface) {
channelInterface->onSpiIrq();
}
} else if (type == PSU_QUEUE_MESSAGE_ADC_MEASURE_ALL) {
eez::psu::Channel::get(param).adcMeasureAll();
g_adcMeasureAllFinished = true;
}
} else {
tick();
}
}

bool measureAllAdcValuesOnChannel(int channelIndex) {
g_adcMeasureAllFinished = false;
osMessagePut(eez::psu::g_psuMessageQueueId, PSU_QUEUE_MESSAGE(PSU_QUEUE_MESSAGE_ADC_MEASURE_ALL, channelIndex), 0);

int i;
for (i = 0; i < 100 && !g_adcMeasureAllFinished; ++i) {
osDelay(10);
}

return g_adcMeasureAllFinished;
}

} // namespace psu
} // namespace eez
3 changes: 3 additions & 0 deletions src/eez/apps/psu/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ extern osMessageQId g_psuMessageQueueId;
#define PSU_QUEUE_MESSAGE_TYPE_CHANGE_POWER_STATE 1
#define PSU_QUEUE_MESSAGE_TYPE_RESET 2
#define PSU_QUEUE_MESSAGE_SPI_IRQ 3
#define PSU_QUEUE_MESSAGE_ADC_MEASURE_ALL 4

#define PSU_QUEUE_MESSAGE(type, param) (((param) << 4) | (type))
#define PSU_QUEUE_MESSAGE_TYPE(message) ((message) & 0xF)
#define PSU_QUEUE_MESSAGE_PARAM(param) ((message) >> 4)

bool measureAllAdcValuesOnChannel(int channelIndex);

}
} // namespace eez
8 changes: 6 additions & 2 deletions src/eez/apps/psu/scpi/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
#endif

#include <eez/apps/psu/psu.h>
#include <eez/apps/psu/scpi/psu.h>
#include <eez/apps/psu/init.h>
#include <eez/apps/psu/serial_psu.h>
#include <eez/apps/psu/temperature.h>
#include <eez/apps/psu/ontime.h>
#include <eez/apps/psu/scpi/psu.h>

#if defined(EEZ_PLATFORM_STM32)
#include <eez/platform/stm32/spi.h>
Expand Down Expand Up @@ -88,7 +89,10 @@ scpi_result_t scpi_cmd_debugQ(scpi_t *context) {
char buffer[768];

for (int i = 0; i < CH_MAX; i++) {
Channel::get(i).adcMeasureAll();
if (!measureAllAdcValuesOnChannel(i)) {
SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR);
return SCPI_RES_ERR;
}
}

debug::dumpVariables(buffer);
Expand Down
15 changes: 9 additions & 6 deletions src/eez/apps/psu/scpi/diag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>

#include <eez/system.h>
#include <eez/index.h>

#include <eez/apps/psu/psu.h>

#include <stdio.h>

#include <eez/apps/psu/init.h>
#include <eez/apps/psu/calibration.h>
#include <eez/apps/psu/devices.h>
#include <eez/apps/psu/scpi/psu.h>
Expand Down Expand Up @@ -180,20 +180,23 @@ scpi_result_t scpi_cmd_diagnosticInformationAdcQ(scpi_t *context) {
return SCPI_RES_ERR;
}

channel->adcMeasureAll();
if (!measureAllAdcValuesOnChannel(channel->channelIndex)) {
SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR);
return SCPI_RES_ERR;
}

char buffer[64] = { 0 };

strcpy(buffer, "U_SET=");
strcatVoltage(buffer, channel->u.mon_dac);
strcatVoltage(buffer, channel->u.mon_dac_last);
SCPI_ResultText(context, buffer);

strcpy(buffer, "U_MON=");
strcatVoltage(buffer, channel->u.mon_last);
SCPI_ResultText(context, buffer);

strcpy(buffer, "I_SET=");
strcatCurrent(buffer, channel->i.mon_dac);
strcatCurrent(buffer, channel->i.mon_dac_last);
SCPI_ResultText(context, buffer);

strcpy(buffer, "I_MON=");
Expand Down
46 changes: 21 additions & 25 deletions src/eez/modules/dcpX05/adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,26 +143,24 @@ void updateValues(Channel &channel) {

void AnalogDigitalConverter::init() {
#if defined(EEZ_PLATFORM_STM32)
Channel &channel = Channel::getBySlotIndex(slotIndex);

uint8_t data[4];
uint8_t result[4];

spi::select(channel.slotIndex, spi::CHIP_ADC);
spi::select(slotIndex, spi::CHIP_ADC);

// Send RESET command
data[0] = ADC_RESET;
spi::transfer(channel.slotIndex, data, result, 1);
spi::transfer(slotIndex, data, result, 1);

delay(1);

data[0] = ADC_WR3S1;
data[1] = getReg1Val();
data[2] = ADC_REG2_VAL;
data[3] = ADC_REG3_VAL;
spi::transfer(channel.slotIndex, data, result, 4);
spi::transfer(slotIndex, data, result, 4);

spi::deselect(channel.slotIndex);
spi::deselect(slotIndex);
#endif

#if defined(EEZ_PLATFORM_SIMULATOR)
Expand All @@ -172,8 +170,6 @@ void AnalogDigitalConverter::init() {

bool AnalogDigitalConverter::test() {
#if defined(EEZ_PLATFORM_STM32)
Channel &channel = Channel::getBySlotIndex(slotIndex);

uint8_t data[4];
uint8_t result[4];

Expand All @@ -182,26 +178,28 @@ bool AnalogDigitalConverter::test() {
data[2] = 0;
data[3] = 0;

spi::select(channel.slotIndex, spi::CHIP_ADC);
spi::transfer(channel.slotIndex, data, result, 4);
spi::deselect(channel.slotIndex);
spi::select(slotIndex, spi::CHIP_ADC);
spi::transfer(slotIndex, data, result, 4);
spi::deselect(slotIndex);

uint8_t reg1 = result[1];
uint8_t reg2 = result[2];
uint8_t reg3 = result[3];

Channel &channel = Channel::getBySlotIndex(slotIndex);

if (reg1 != getReg1Val()) {
DebugTrace("Ch%d ADC test failed reg1: expected=%d, got=%d", channel.channelIndex + 1, getReg1Val(), reg1);
// DebugTrace("Ch%d ADC test failed reg1: expected=%d, got=%d", channel.channelIndex + 1, getReg1Val(), reg1);
g_testResult = TEST_FAILED;
}

if (reg2 != ADC_REG2_VAL) {
DebugTrace("Ch%d ADC test failed reg2: expected=%d, got=%d", channel.channelIndex + 1, ADC_REG2_VAL, reg2);
// DebugTrace("Ch%d ADC test failed reg2: expected=%d, got=%d", channel.channelIndex + 1, ADC_REG2_VAL, reg2);
g_testResult = TEST_FAILED;
}

if (reg3 != ADC_REG3_VAL) {
DebugTrace("Ch%d ADC test failed reg3: expected=%d, got=%d", channel.channelIndex + 1, ADC_REG3_VAL, reg3);
// DebugTrace("Ch%d ADC test failed reg3: expected=%d, got=%d", channel.channelIndex + 1, ADC_REG3_VAL, reg3);
g_testResult = TEST_FAILED;
}

Expand Down Expand Up @@ -237,10 +235,9 @@ void AnalogDigitalConverter::start(AdcDataType adcDataType_) {

data[2] = ADC_START;

Channel &channel = Channel::getBySlotIndex(slotIndex);
spi::select(channel.slotIndex, spi::CHIP_ADC);
spi::transfer(channel.slotIndex, data, result, 3);
spi::deselect(channel.slotIndex);
spi::select(slotIndex, spi::CHIP_ADC);
spi::transfer(slotIndex, data, result, 3);
spi::deselect(slotIndex);
}
#endif
}
Expand All @@ -254,9 +251,9 @@ float AnalogDigitalConverter::read(Channel& channel) {
data[1] = 0;
data[2] = 0;

spi::select(channel.slotIndex, spi::CHIP_ADC);
spi::transfer(channel.slotIndex, data, result, 3);
spi::deselect(channel.slotIndex);
spi::select(slotIndex, spi::CHIP_ADC);
spi::transfer(slotIndex, data, result, 3);
spi::deselect(slotIndex);

uint16_t dmsb = result[1];
uint16_t dlsb = result[2];
Expand Down Expand Up @@ -322,10 +319,9 @@ void AnalogDigitalConverter::readAllRegisters(uint8_t registers[]) {
data[3] = 0;
data[4] = 0;

Channel &channel = Channel::getBySlotIndex(slotIndex);
spi::select(channel.slotIndex, spi::CHIP_ADC);
spi::transfer(channel.slotIndex, data, result, 5);
spi::deselect(channel.slotIndex);
spi::select(slotIndex, spi::CHIP_ADC);
spi::transfer(slotIndex, data, result, 5);
spi::deselect(slotIndex);

registers[0] = result[1];
registers[1] = result[2];
Expand Down
Loading

0 comments on commit eb63843

Please sign in to comment.