tip measurement

This commit is contained in:
Ben V. Brown
2022-06-20 20:23:11 +10:00
parent 60f9931b6e
commit 6e062bfa59
5 changed files with 81 additions and 20 deletions

View File

@@ -8,6 +8,7 @@
#include "TipThermoModel.h" #include "TipThermoModel.h"
#include "USBPD.h" #include "USBPD.h"
#include "configuration.h" #include "configuration.h"
#include "crc16.hpp"
#include "history.hpp" #include "history.hpp"
#include "main.hpp" #include "main.hpp"
@@ -233,9 +234,7 @@ uint8_t getTipResitanceX10() {
return lastTipResistance; return lastTipResistance;
} }
void startMeasureTipResistance() { void startMeasureTipResistance() {
if (isTipDisconnected()) {
return;
}
if (lastTipReadinguV) { if (lastTipReadinguV) {
return; return;
} }
@@ -257,9 +256,6 @@ void startMeasureTipResistance() {
void FinishMeasureTipResistance() { void FinishMeasureTipResistance() {
gpio_write(TIP_RESISTANCE_SENSE, 0); gpio_write(TIP_RESISTANCE_SENSE, 0);
if (isTipDisconnected()) {
return;
}
// read the tip uV with the current source on // read the tip uV with the current source on
uint32_t newReading = (TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0))); uint32_t newReading = (TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0)));
if (newReading < lastTipReadinguV) { if (newReading < lastTipReadinguV) {
@@ -279,11 +275,44 @@ void FinishMeasureTipResistance() {
} }
lastTipResistance = newRes; lastTipResistance = newRes;
} }
volatile bool tipMeasurementOccuring = false;
volatile uint8_t tipSenseResistancex10Ohms = 0;
void performTipMeasurementStep(bool start) {
static TickType_t lastMeas = 0;
// Inter state that performs the steps to measure the resistor on the tip
// Return 1 if a measurement is ongoing
// We want to perform our startup measurements of the tip resistance until we detect one fitted
// Step 1; if not setup, we turn on pullup and then wait
if (tipMeasurementOccuring == false && (start || tipSenseResistancex10Ohms == 0 || lastMeas == 0)) {
// Block starting if tip removed
if (isTipDisconnected()) {
return;
}
tipMeasurementOccuring = true;
tipSenseResistancex10Ohms = 0;
lastMeas = xTaskGetTickCount();
startMeasureTipResistance();
return;
}
// Wait 100ms for settle time
if ((xTaskGetTickCount() - lastMeas) < (TICKS_100MS)) {
return;
}
lastMeas = xTaskGetTickCount();
// We are sensing the resistance
FinishMeasureTipResistance();
tipMeasurementOccuring = false;
}
uint8_t preStartChecks() { uint8_t preStartChecks() {
// startMeasureTipResistance(); performTipMeasurementStep(false);
// TODO return tipMeasurementOccuring ? 1 : 0;
return 0;
} }
// Return hardware unique ID if possible // Return hardware unique ID if possible
@@ -299,20 +328,32 @@ uint64_t getDeviceID() {
return __builtin_bswap64(tmp); return __builtin_bswap64(tmp);
} }
uint16_t gethash() {
uint32_t userData = 0;
EF_Ctrl_Read_Sw_Usage(0, &userData);
userData &= 0xFFFF; // We only want the lower two bytes
// TODO FOR TESTING OVERRIDE
userData = 0xDEAD;
const uint16_t crcInitialVector = 0xCAFE;
uint8_t crcPayload[] = {userData & 0xFF, (userData >> 8) & 0xFF, 0, 0, 0, 0, 0, 0, 0, 0};
EF_Ctrl_Read_Chip_ID(crcPayload + 2);
uint32_t result = crcInitialVector;
for (int i = 0; i < 10; i++) {
result = crc16(result, crcPayload[i]);
}
return result & 0xFFFF;
}
uint32_t getDeviceValidation() { uint32_t getDeviceValidation() {
uint32_t userData = 0; uint32_t userData = 0;
EF_Ctrl_Read_Sw_Usage(0, &userData); EF_Ctrl_Read_Sw_Usage(0, &userData);
// 4 byte user data burned in at factory // 4 byte user data burned in at factory
// TODO TESTING
// userData |= gethash() << 16;
return userData; return userData;
} }
uint8_t getDeviceValidationStatus() { uint8_t getDeviceValidationStatus() {
uint32_t userData = 0;
EF_Ctrl_Read_Sw_Usage(0, &userData);
userData &= 0xFFFF; // We only want the lower two bytes
userData = 0xDEAD; // TODO TESTING KEY
return 1; // Device is OK return 1; // Device is OK
} }

View File

@@ -0,0 +1,19 @@
#include "crc16.hpp"
#define POLYNOM 0x8005
unsigned int crc16(unsigned int crcValue, unsigned char newByte) {
unsigned char i;
for (i = 0; i < 8; i++) {
if (((crcValue & 0x8000) >> 8) ^ (newByte & 0x80)) {
crcValue = (crcValue << 1) ^ POLYNOM;
} else {
crcValue = (crcValue << 1);
}
newByte <<= 1;
}
return crcValue;
}

View File

@@ -0,0 +1,6 @@
#ifndef DRIVERS_CRC16_H_
#define DRIVERS_CRC16_H_
unsigned int crc16(unsigned int crcValue, unsigned char newByte);
#endif

View File

@@ -969,7 +969,7 @@ void startGUITask(void const *argument) {
} }
#endif #endif
#endif #endif
BootLogo::handleShowingLogo((uint8_t *)FLASH_LOGOADDR); // BootLogo::handleShowingLogo((uint8_t *)FLASH_LOGOADDR);
showWarnings(); showWarnings();
if (getSettingValue(SettingsOptions::AutoStartMode)) { if (getSettingValue(SettingsOptions::AutoStartMode)) {

View File

@@ -77,11 +77,6 @@ void startPIDTask(void const *argument __unused) {
detectThermalRunaway(currentTipTempInC, 0); detectThermalRunaway(currentTipTempInC, 0);
} }
setOutputx10WattsViaFilters(x10WattsOut); setOutputx10WattsViaFilters(x10WattsOut);
// If the output is off, take tip measurement reading
// if (x10WattsOut == 0 && PIDTempTarget == 0) {
// startMeasureTipResistance();
// measuringTipResistance = true;
// }
} else { } else {
// ADC interrupt timeout // ADC interrupt timeout
setTipPWM(0, false); setTipPWM(0, false);