mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Make adc range scalable
This commit is contained in:
@@ -234,11 +234,12 @@ uint8_t getTipResitanceX10() {
|
|||||||
return lastTipResistance;
|
return lastTipResistance;
|
||||||
}
|
}
|
||||||
void startMeasureTipResistance() {
|
void startMeasureTipResistance() {
|
||||||
|
|
||||||
if (isTipDisconnected()) {
|
if (isTipDisconnected()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (lastTipReadinguV) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// We want to calculate lastTipResistance
|
// We want to calculate lastTipResistance
|
||||||
// If tip is connected, and the tip is cold and the tip is not being heated
|
// If tip is connected, and the tip is cold and the tip is not being heated
|
||||||
// We can use the GPIO to inject a small current into the tip and measure this
|
// We can use the GPIO to inject a small current into the tip and measure this
|
||||||
@@ -277,10 +278,5 @@ void FinishMeasureTipResistance() {
|
|||||||
} else {
|
} else {
|
||||||
newRes = 80;
|
newRes = 80;
|
||||||
}
|
}
|
||||||
if (lastTipResistance != newRes) {
|
|
||||||
#ifdef POW_PD
|
|
||||||
USBPowerDelivery::triggerRenegotiation();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
lastTipResistance = newRes;
|
lastTipResistance = newRes;
|
||||||
}
|
}
|
||||||
@@ -174,4 +174,4 @@ uint16_t getADCHandleTemp(uint8_t sample) { return ADC_Temp.average(); }
|
|||||||
uint16_t getADCVin(uint8_t sample) { return ADC_Vin.average(); }
|
uint16_t getADCVin(uint8_t sample) { return ADC_Vin.average(); }
|
||||||
|
|
||||||
// Returns either average or instant value. When sample is set the samples from the injected ADC are copied to the filter and then the raw reading is returned
|
// Returns either average or instant value. When sample is set the samples from the injected ADC are copied to the filter and then the raw reading is returned
|
||||||
uint16_t getTipRawTemp(uint8_t sample) { return ADC_Tip.average() >> 1; }
|
uint16_t getTipRawTemp(uint8_t sample) { return ADC_Tip.average(); }
|
||||||
|
|||||||
@@ -29,13 +29,17 @@ void hardware_init() {
|
|||||||
gpio_set_mode(TMP36_INPUT_Pin, GPIO_INPUT_MODE);
|
gpio_set_mode(TMP36_INPUT_Pin, GPIO_INPUT_MODE);
|
||||||
gpio_set_mode(TIP_TEMP_Pin, GPIO_INPUT_MODE);
|
gpio_set_mode(TIP_TEMP_Pin, GPIO_INPUT_MODE);
|
||||||
gpio_set_mode(VIN_Pin, GPIO_INPUT_MODE);
|
gpio_set_mode(VIN_Pin, GPIO_INPUT_MODE);
|
||||||
gpio_set_mode(TIP_RESISTANCE_SENSE, GPIO_OUTPUT_PP_MODE);
|
|
||||||
|
gpio_set_mode(TIP_RESISTANCE_SENSE, GPIO_OUTPUT_MODE);
|
||||||
gpio_write(TIP_RESISTANCE_SENSE, 0);
|
gpio_write(TIP_RESISTANCE_SENSE, 0);
|
||||||
|
|
||||||
MSG((char *)"Magic Starting\r\n");
|
MSG((char *)"Magic Starting\r\n");
|
||||||
setup_timer_scheduler();
|
setup_timer_scheduler();
|
||||||
setup_adc();
|
setup_adc();
|
||||||
setup_pwm();
|
setup_pwm();
|
||||||
I2C_ClockSet(I2C0_ID, 400000); // Sets clock to around 375kHz
|
I2C_ClockSet(I2C0_ID, 400000); // Sets clock to around 375kHz
|
||||||
|
TIMER_SetCompValue(TIMER_CH0, TIMER_COMP_ID_1, 0);
|
||||||
|
PWM_Channel_Enable(PWM_Channel);
|
||||||
}
|
}
|
||||||
void setup_pwm(void) {
|
void setup_pwm(void) {
|
||||||
// Setup PWM we use for driving the tip
|
// Setup PWM we use for driving the tip
|
||||||
@@ -56,8 +60,8 @@ void setup_pwm(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ADC_Chan_Type adc_tip_pos_chans[]
|
const ADC_Chan_Type adc_tip_pos_chans[]
|
||||||
= {TIP_TEMP_ADC_CHANNEL, TIP_TEMP_ADC_CHANNEL, TIP_TEMP_ADC_CHANNEL, TIP_TEMP_ADC_CHANNEL, TMP36_ADC_CHANNEL, VIN_ADC_CHANNEL, TMP36_ADC_CHANNEL, VIN_ADC_CHANNEL};
|
= {VIN_ADC_CHANNEL, TIP_TEMP_ADC_CHANNEL, TIP_TEMP_ADC_CHANNEL, TIP_TEMP_ADC_CHANNEL, TIP_TEMP_ADC_CHANNEL, TMP36_ADC_CHANNEL, VIN_ADC_CHANNEL, TMP36_ADC_CHANNEL, VIN_ADC_CHANNEL};
|
||||||
const ADC_Chan_Type adc_tip_neg_chans[] = {ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND};
|
const ADC_Chan_Type adc_tip_neg_chans[] = {ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND};
|
||||||
static_assert(sizeof(adc_tip_pos_chans) == sizeof(adc_tip_neg_chans));
|
static_assert(sizeof(adc_tip_pos_chans) == sizeof(adc_tip_neg_chans));
|
||||||
|
|
||||||
void setup_adc(void) {
|
void setup_adc(void) {
|
||||||
@@ -71,9 +75,9 @@ void setup_adc(void) {
|
|||||||
|
|
||||||
adc_cfg.clkDiv = ADC_CLK_DIV_4;
|
adc_cfg.clkDiv = ADC_CLK_DIV_4;
|
||||||
adc_cfg.vref = ADC_VREF_3P2V;
|
adc_cfg.vref = ADC_VREF_3P2V;
|
||||||
adc_cfg.resWidth = ADC_DATA_WIDTH_12;
|
adc_cfg.resWidth = ADC_DATA_WIDTH_16_WITH_128_AVERAGE;
|
||||||
adc_cfg.inputMode = ADC_INPUT_SINGLE_END;
|
adc_cfg.inputMode = ADC_INPUT_SINGLE_END;
|
||||||
adc_cfg.v18Sel = ADC_V18_SEL_1P82V;
|
adc_cfg.v18Sel = ADC_V18_SEL_1P72V;
|
||||||
adc_cfg.v11Sel = ADC_V11_SEL_1P1V;
|
adc_cfg.v11Sel = ADC_V11_SEL_1P1V;
|
||||||
adc_cfg.gain1 = ADC_PGA_GAIN_NONE;
|
adc_cfg.gain1 = ADC_PGA_GAIN_NONE;
|
||||||
adc_cfg.gain2 = ADC_PGA_GAIN_NONE;
|
adc_cfg.gain2 = ADC_PGA_GAIN_NONE;
|
||||||
@@ -89,7 +93,7 @@ void setup_adc(void) {
|
|||||||
|
|
||||||
ADC_Init(&adc_cfg);
|
ADC_Init(&adc_cfg);
|
||||||
adc_fifo_cfg.dmaEn = DISABLE;
|
adc_fifo_cfg.dmaEn = DISABLE;
|
||||||
adc_fifo_cfg.fifoThreshold = ADC_FIFO_THRESHOLD_8;
|
adc_fifo_cfg.fifoThreshold = ADC_FIFO_THRESHOLD_4;
|
||||||
ADC_FIFO_Cfg(&adc_fifo_cfg);
|
ADC_FIFO_Cfg(&adc_fifo_cfg);
|
||||||
ADC_MIC_Bias_Disable();
|
ADC_MIC_Bias_Disable();
|
||||||
ADC_Tsen_Disable();
|
ADC_Tsen_Disable();
|
||||||
|
|||||||
@@ -68,6 +68,7 @@
|
|||||||
#define TEMP_CHANGE_LONG_STEP_MAX 90 // Temp change long step MAX value
|
#define TEMP_CHANGE_LONG_STEP_MAX 90 // Temp change long step MAX value
|
||||||
|
|
||||||
/* Power pulse for keeping power banks awake*/
|
/* Power pulse for keeping power banks awake*/
|
||||||
|
|
||||||
#define POWER_PULSE_INCREMENT 1
|
#define POWER_PULSE_INCREMENT 1
|
||||||
#define POWER_PULSE_MAX 100 // x10 max watts
|
#define POWER_PULSE_MAX 100 // x10 max watts
|
||||||
#define POWER_PULSE_WAIT_MAX 9 // 9*2.5s = 22.5 seconds
|
#define POWER_PULSE_WAIT_MAX 9 // 9*2.5s = 22.5 seconds
|
||||||
@@ -114,7 +115,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MODEL_Magic
|
#ifdef MODEL_Magic
|
||||||
#define ADC_VDD_MV 3200 // ADC max reading millivolts
|
#define ADC_VDD_MV 3300 // ADC max reading millivolts
|
||||||
|
#define ADC_MAX_READING 42000 // Maximum reading of the adc
|
||||||
#define SOLDERING_TEMP 320 // Default soldering temp is 320.0 °C
|
#define SOLDERING_TEMP 320 // Default soldering temp is 320.0 °C
|
||||||
#define VOLTAGE_DIV 600 // 600 - Default divider from schematic
|
#define VOLTAGE_DIV 600 // 600 - Default divider from schematic
|
||||||
#define CALIBRATION_OFFSET 800 // 900 - Default adc offset in uV
|
#define CALIBRATION_OFFSET 800 // 900 - Default adc offset in uV
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ uint32_t TipThermoModel::convertTipRawADCTouV(uint16_t rawADC, bool ski
|
|||||||
uint32_t vddRailmVX10 = ADC_VDD_MV * 10; // The vreg is +-2%, but we have no higher accuracy available
|
uint32_t vddRailmVX10 = ADC_VDD_MV * 10; // The vreg is +-2%, but we have no higher accuracy available
|
||||||
// 4096 * 8 readings for full scale
|
// 4096 * 8 readings for full scale
|
||||||
// Convert the input ADC reading back into mV times 10 format.
|
// Convert the input ADC reading back into mV times 10 format.
|
||||||
uint32_t rawInputmVX10 = (rawADC * vddRailmVX10) / (4096 * 8);
|
uint32_t rawInputmVX10 = (rawADC * vddRailmVX10) / (ADC_MAX_READING);
|
||||||
|
|
||||||
uint32_t valueuV = rawInputmVX10 * 100; // shift into uV
|
uint32_t valueuV = rawInputmVX10 * 100; // shift into uV
|
||||||
// Now to divide this down by the gain
|
// Now to divide this down by the gain
|
||||||
@@ -90,7 +90,7 @@ uint32_t TipThermoModel::getTipInF(bool sampleNow) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t TipThermoModel::getTipMaxInC() {
|
uint32_t TipThermoModel::getTipMaxInC() {
|
||||||
uint32_t maximumTipTemp = TipThermoModel::convertTipRawADCToDegC(0x7FFF - (21 * 3)); // back off approx 5 deg c from ADC max
|
uint32_t maximumTipTemp = TipThermoModel::convertTipRawADCToDegC(ADC_MAX_READING - (21 * 3)); // back off approx 5 deg c from ADC max
|
||||||
maximumTipTemp += getHandleTemperature(0) / 10; // Add handle offset
|
maximumTipTemp += getHandleTemperature(0) / 10; // Add handle offset
|
||||||
return maximumTipTemp - 1;
|
return maximumTipTemp - 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
template <class T, uint8_t SIZE> struct history {
|
template <class T, uint8_t SIZE> struct history {
|
||||||
static const uint8_t size = SIZE;
|
static const uint8_t size = SIZE;
|
||||||
T buf[size];
|
T buf[size];
|
||||||
int32_t sum;
|
uint32_t sum;
|
||||||
uint8_t loc;
|
uint8_t loc;
|
||||||
|
|
||||||
void update(T const val) {
|
void update(T const val) {
|
||||||
|
|||||||
Reference in New Issue
Block a user