From 3f318afe2c9d61c070313dab84489cf50908aa21 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 22 Feb 2022 15:27:47 +0100 Subject: [PATCH] issues with external pl pcdu conversion --- linux/boardtest/SpiTestClass.cpp | 34 ++++++++++++++++++-------------- mission/devices/max1227.h | 4 ++-- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/linux/boardtest/SpiTestClass.cpp b/linux/boardtest/SpiTestClass.cpp index 47c7996d..53a0466f 100644 --- a/linux/boardtest/SpiTestClass.cpp +++ b/linux/boardtest/SpiTestClass.cpp @@ -320,8 +320,8 @@ void SpiTestClass::performOneShotMax1227Test() { } } - adcCfg.plPcduAdcExtConv = false; - adcCfg.plPcduAdcIntConv = true; + adcCfg.plPcduAdcExtConv = true; + adcCfg.plPcduAdcIntConv = false; performMax1227Test(); } @@ -343,8 +343,8 @@ void SpiTestClass::performMax1227Test() { << std::endl; return; } - uint32_t spiSpeed = 1'000'000; - spi::SpiModes spiMode = spi::SpiModes::MODE_3; + uint32_t spiSpeed = 976'000; + spi::SpiModes spiMode = spi::SpiModes::MODE_0; setSpiSpeedAndMode(fd, spiMode, spiSpeed); max1227RadSensorTest(fd); @@ -535,11 +535,12 @@ void SpiTestClass::max1227PlPcduTest(int fd) { adcCfg.vbatSwitch = false; // Takes a bit of time until the ADC is usable TaskFactory::delayTask(50); - } - if (adcCfg.plPcduAdcExtConv) { sendBuffer[0] = max1227::buildResetByte(false); spiTransferStruct[0].len = 1; transfer(fd, gpioIds::PLPCDU_ADC_CS); + + } + if (adcCfg.plPcduAdcExtConv) { sendBuffer[0] = max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_NO_WAKEUP, DiffSel::NONE_0); spiTransferStruct[0].len = 1; @@ -551,16 +552,20 @@ void SpiTestClass::max1227PlPcduTest(int fd) { for (uint8_t idx = 0; idx < n + 1; idx++) { adcRaw[idx] = (recvBuffer[idx * 2 + 1] << 8) | recvBuffer[idx * 2 + 2]; } - arrayprinter::print(recvBuffer.data(), spiTransferStruct[0].len, OutputType::HEX); - sif::info << "PL PCDU ADC values:" << std::endl; - for (int idx = 0; idx < n + 1; idx++) { - sif::info << "Raw Value " << idx << ": " << adcRaw[idx] << std::endl; - } + usleep(10); + spiTransferStruct[0].len = 0; max1227::prepareExternallyClockedTemperatureRead(sendBuffer.data(), spiTransferStruct[0].len); transfer(fd, gpioIds::PLPCDU_ADC_CS); int16_t tempRaw = ((recvBuffer[23] & 0x0f) << 8) | recvBuffer[24]; - float temp = max1227::getTemperature(tempRaw); - sif::info << "Temperature: " << temp << std::endl; + sif::info << "PL PCDU ADC ext conv [" << std::hex << std::setfill('0'); + for (int idx = 0; idx < n + 1; idx++) { + sif::info << std::setw(3) << adcRaw[idx]; + if(idx < n) { + sif::info << ","; + } + } + sif::info << "]" << std::endl; + sif::info << "Temperature: " << max1227::getTemperature(tempRaw) << " C" << std::endl; } if (adcCfg.plPcduAdcIntConv) { sendBuffer[0] = max1227::buildResetByte(true); @@ -583,7 +588,6 @@ void SpiTestClass::max1227PlPcduTest(int fd) { shiftOutZeros(); transfer(fd, gpioIds::PLPCDU_ADC_CS); setSendBuffer(); - //arrayprinter::print(recvBuffer.data(), 26, OutputType::HEX); uint16_t adcRaw[n + 1] = {}; int16_t tempRaw = ((recvBuffer[0] & 0x0f) << 8) | recvBuffer[1]; sif::info << "PL PCDU ADC int conv [" << std::hex << std::setfill('0'); @@ -595,7 +599,7 @@ void SpiTestClass::max1227PlPcduTest(int fd) { } } sif::info << "]" << std::endl; - sif::info << "Temperature: " << tempRaw * 0.125 << " C" << std::endl; + sif::info << "Temperature: " << max1227::getTemperature(tempRaw) << " C" << std::endl; } } diff --git a/mission/devices/max1227.h b/mission/devices/max1227.h index 1a6082fb..fc317b39 100644 --- a/mission/devices/max1227.h +++ b/mission/devices/max1227.h @@ -65,7 +65,7 @@ void prepareExternallyClockedSingleChannelRead(uint8_t* spiBuf, uint8_t channel, * the first byte (first conversion byte) the the rest of the SPI buffer. * @param spiBuf * @param n Channel number. Example: If the ADC has 6 channels, n will be 5 - * @param sz + * @param sz Will be incremented by amount which should be sent */ void prepareExternallyClockedRead0ToN(uint8_t* spiBuf, uint8_t n, size_t& sz); @@ -73,7 +73,7 @@ void prepareExternallyClockedRead0ToN(uint8_t* spiBuf, uint8_t n, size_t& sz); * Prepare an externally clocked temperature read. 25 bytes have to be sent * and the raw temperature value will appear on the last 2 bytes of the reply. * @param spiBuf - * @param sz + * @param sz Will be incremented by amount which should be sent */ void prepareExternallyClockedTemperatureRead(uint8_t* spiBuf, size_t& sz);