mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
WiP res measurement
This commit is contained in:
@@ -15,14 +15,16 @@ volatile uint8_t pendingPWM = 0;
|
||||
uint16_t totalPWM = 255;
|
||||
const uint16_t powerPWM = 255;
|
||||
|
||||
history<uint16_t, PID_TIM_HZ> rawTempFilter = {{0}, 0, 0};
|
||||
void resetWatchdog() { HAL_IWDG_Refresh(&hiwdg); }
|
||||
history<uint16_t, PID_TIM_HZ> rawTempFilter = { { 0 }, 0, 0 };
|
||||
void resetWatchdog() {
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
}
|
||||
|
||||
#ifdef TEMP_NTC
|
||||
// Lookup table for the NTC
|
||||
// Stored as ADCReading,Temp in degC
|
||||
static const uint16_t NTCHandleLookup[] = {
|
||||
// ADC Reading , Temp in C
|
||||
// ADC Reading , Temp in C
|
||||
11292, 600, //
|
||||
12782, 550, //
|
||||
14380, 500, //
|
||||
@@ -36,8 +38,9 @@ static const uint16_t NTCHandleLookup[] = {
|
||||
27146, 100, //
|
||||
28249, 50, //
|
||||
29189, 0, //
|
||||
};
|
||||
const int NTCHandleLookupItems = sizeof(NTCHandleLookup) / (2 * sizeof(uint16_t));
|
||||
};
|
||||
const int NTCHandleLookupItems = sizeof(NTCHandleLookup)
|
||||
/ (2 * sizeof(uint16_t));
|
||||
#endif
|
||||
|
||||
// These are called by the HAL after the corresponding events from the system
|
||||
@@ -52,10 +55,13 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
||||
}
|
||||
uint16_t getHandleTemperature() {
|
||||
int32_t result = getADC(0);
|
||||
return Utils::InterpolateLookupTable(NTCHandleLookup, NTCHandleLookupItems, result);
|
||||
return Utils::InterpolateLookupTable(NTCHandleLookup, NTCHandleLookupItems,
|
||||
result);
|
||||
}
|
||||
|
||||
uint16_t getTipInstantTemperature() { return getADC(2); }
|
||||
uint16_t getTipInstantTemperature() {
|
||||
return getADC(2);
|
||||
}
|
||||
|
||||
uint16_t getTipRawTemp(uint8_t refresh) {
|
||||
if (refresh) {
|
||||
@@ -173,18 +179,90 @@ void unstick_I2C() {
|
||||
HAL_I2C_Init(&hi2c1);
|
||||
}
|
||||
|
||||
uint8_t getButtonA() { return HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET ? 1 : 0; }
|
||||
uint8_t getButtonB() { return HAL_GPIO_ReadPin(KEY_B_GPIO_Port, KEY_B_Pin) == GPIO_PIN_RESET ? 1 : 0; }
|
||||
uint8_t getButtonA() {
|
||||
return HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET ?
|
||||
1 : 0;
|
||||
}
|
||||
uint8_t getButtonB() {
|
||||
return HAL_GPIO_ReadPin(KEY_B_GPIO_Port, KEY_B_Pin) == GPIO_PIN_RESET ?
|
||||
1 : 0;
|
||||
}
|
||||
|
||||
void BSPInit(void) {}
|
||||
void BSPInit(void) {
|
||||
}
|
||||
|
||||
void reboot() { NVIC_SystemReset(); }
|
||||
void reboot() {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
void delay_ms(uint16_t count) { HAL_Delay(count); }
|
||||
void delay_ms(uint16_t count) {
|
||||
HAL_Delay(count);
|
||||
}
|
||||
|
||||
void setPlatePullup(bool pullingUp) {
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.Pin = PLATE_SENSOR_PULLUP_Pin;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
if (pullingUp) {
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
HAL_GPIO_WritePin(PLATE_SENSOR_PULLUP_GPIO_Port,
|
||||
PLATE_SENSOR_PULLUP_Pin, GPIO_PIN_SET);
|
||||
} else {
|
||||
//Hi-z
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
HAL_GPIO_WritePin(PLATE_SENSOR_PULLUP_GPIO_Port,
|
||||
PLATE_SENSOR_PULLUP_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
HAL_GPIO_Init(PLATE_SENSOR_PULLUP_GPIO_Port, &GPIO_InitStruct);
|
||||
}
|
||||
|
||||
uint16_t tipSenseResistancex10Ohms = 0;
|
||||
bool isTipDisconnected() {
|
||||
static bool lastTipDisconnectedState = true;
|
||||
static uint16_t adcReadingPD1Set = 0;
|
||||
static TickType_t lastMeas = 0;
|
||||
// For the MHP30 we want to include a little extra logic in here
|
||||
// As when the tip is first connected we want to measure the ~100 ohm resistor on the base of the tip
|
||||
// And likewise if its removed we want to clear that measurement
|
||||
/*
|
||||
* plate_sensor_res = ((adc5_value_PD1_set - adc5_value_PD1_cleared) / (adc5_value_PD1_cleared + 4096 - adc5_value_PD1_set)) * 1000.0;
|
||||
* */
|
||||
|
||||
uint16_t tipDisconnectedThres = TipThermoModel::getTipMaxInC() - 5;
|
||||
uint32_t tipTemp = TipThermoModel::getTipInC();
|
||||
return tipTemp > tipDisconnectedThres;
|
||||
bool tipDisconnected = tipTemp > tipDisconnectedThres;
|
||||
if (tipDisconnected != lastTipDisconnectedState) {
|
||||
if (tipDisconnected) {
|
||||
// Tip is now disconnected
|
||||
tipSenseResistancex10Ohms = 0; // zero out the resistance
|
||||
adcReadingPD1Set = 0;
|
||||
lastMeas = xTaskGetTickCount();
|
||||
setPlatePullup(true);
|
||||
}
|
||||
lastTipDisconnectedState = tipDisconnected;
|
||||
}
|
||||
if (!tipDisconnected) {
|
||||
if (tipSenseResistancex10Ohms == 0) {
|
||||
if (xTaskGetTickCount() - lastMeas > (TICKS_100MS / 2)) {
|
||||
lastMeas = xTaskGetTickCount();
|
||||
//We are sensing the resistance
|
||||
if (adcReadingPD1Set == 0) {
|
||||
//We will record the reading for PD1 being set
|
||||
adcReadingPD1Set = getADC(3);
|
||||
setPlatePullup(false);
|
||||
} else {
|
||||
//We have taken reading one
|
||||
uint16_t adcReadingPD1Cleared = getADC(3);
|
||||
tipSenseResistancex10Ohms = ((((int) adcReadingPD1Set
|
||||
- (int) adcReadingPD1Cleared) * 10000)
|
||||
/ ((int) adcReadingPD1Cleared
|
||||
+ (65536 - (int) adcReadingPD1Set)));
|
||||
}
|
||||
}
|
||||
return true; // we fake tip being disconnected until this is measured
|
||||
}
|
||||
}
|
||||
|
||||
return tipDisconnected;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#define TIP_TEMP_GPIO_Port GPIOA
|
||||
#define TIP_TEMP_ADC1_CHANNEL ADC_CHANNEL_2
|
||||
#define TIP_TEMP_ADC2_CHANNEL ADC_CHANNEL_2
|
||||
|
||||
#define VIN_Pin GPIO_PIN_1
|
||||
#define VIN_GPIO_Port GPIOA
|
||||
#define VIN_ADC1_CHANNEL ADC_CHANNEL_1
|
||||
@@ -44,5 +43,11 @@
|
||||
#define INT_PD_GPIO_Port GPIOB
|
||||
#define HEAT_EN_Pin GPIO_PIN_3
|
||||
#define HEAT_EN_GPIO_Port GPIOA
|
||||
#define PLATE_SENSOR_PULLUP_Pin GPIO_PIN_1
|
||||
#define PLATE_SENSOR_PULLUP_GPIO_Port GPIOD
|
||||
|
||||
#define PLATE_SENSOR_Pin GPIO_PIN_5
|
||||
#define PLATE_SENSOR_GPIO_Port GPIOA
|
||||
#define PLATE_SENSOR_ADC1_CHANNEL ADC_CHANNEL_5
|
||||
#define PLATE_SENSOR_ADC2_CHANNEL ADC_CHANNEL_5
|
||||
#endif /* BSP_MINIWARE_PINS_H_ */
|
||||
|
||||
@@ -17,7 +17,7 @@ DMA_HandleTypeDef hdma_i2c1_tx;
|
||||
IWDG_HandleTypeDef hiwdg;
|
||||
TIM_HandleTypeDef htim2;
|
||||
TIM_HandleTypeDef htim3;
|
||||
#define ADC_CHANNELS 3
|
||||
#define ADC_CHANNELS 4
|
||||
#define ADC_SAMPLES 16
|
||||
uint32_t ADCReadings[ADC_SAMPLES * ADC_CHANNELS]; // room for 32 lots of the pair of readings
|
||||
|
||||
@@ -47,8 +47,8 @@ void Setup_HAL() {
|
||||
HAL_ADC_Start(&hadc2);
|
||||
HAL_ADCEx_MultiModeStart_DMA(&hadc1, ADCReadings,
|
||||
(ADC_SAMPLES * ADC_CHANNELS)); // start DMA of normal readings
|
||||
HAL_ADCEx_InjectedStart(&hadc1); // enable injected readings
|
||||
HAL_ADCEx_InjectedStart(&hadc2); // enable injected readings
|
||||
// HAL_ADCEx_InjectedStart(&hadc1); // enable injected readings
|
||||
// HAL_ADCEx_InjectedStart(&hadc2); // enable injected readings
|
||||
}
|
||||
|
||||
// channel 0 -> temperature sensor, 1-> VIN, 2-> tip
|
||||
@@ -72,7 +72,8 @@ void SystemClock_Config(void) {
|
||||
|
||||
/**Initializes the CPU, AHB and APB busses clocks
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSI;
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI
|
||||
| RCC_OSCILLATORTYPE_LSI;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.HSICalibrationValue = 16;
|
||||
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
||||
@@ -83,7 +84,8 @@ void SystemClock_Config(void) {
|
||||
|
||||
/**Initializes the CPU, AHB and APB busses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
|
||||
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV16; // TIM
|
||||
@@ -133,7 +135,7 @@ static void MX_ADC1_Init(void) {
|
||||
*/
|
||||
sConfig.Channel = TMP36_ADC1_CHANNEL;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_1;
|
||||
sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
|
||||
sConfig.SamplingTime = ADC_SAMPLETIME_71CYCLES_5;
|
||||
HAL_ADC_ConfigChannel(&hadc1, &sConfig);
|
||||
|
||||
/**Configure Regular Channel
|
||||
@@ -144,6 +146,9 @@ static void MX_ADC1_Init(void) {
|
||||
sConfig.Channel = TIP_TEMP_ADC1_CHANNEL;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_3;
|
||||
HAL_ADC_ConfigChannel(&hadc1, &sConfig);
|
||||
sConfig.Channel = PLATE_SENSOR_ADC1_CHANNEL;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_4;
|
||||
HAL_ADC_ConfigChannel(&hadc1, &sConfig);
|
||||
|
||||
SET_BIT(hadc1.Instance->CR1, (ADC_CR1_EOSIE)); // Enable end of Normal
|
||||
// Run ADC internal calibration
|
||||
@@ -170,7 +175,7 @@ static void MX_ADC2_Init(void) {
|
||||
*/
|
||||
sConfig.Channel = TMP36_ADC2_CHANNEL;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_1;
|
||||
sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
|
||||
sConfig.SamplingTime = ADC_SAMPLETIME_71CYCLES_5;
|
||||
HAL_ADC_ConfigChannel(&hadc2, &sConfig);
|
||||
|
||||
sConfig.Channel = VIN_ADC2_CHANNEL;
|
||||
@@ -179,6 +184,9 @@ static void MX_ADC2_Init(void) {
|
||||
sConfig.Channel = TIP_TEMP_ADC1_CHANNEL;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_3;
|
||||
HAL_ADC_ConfigChannel(&hadc2, &sConfig);
|
||||
sConfig.Channel = PLATE_SENSOR_ADC2_CHANNEL;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_4;
|
||||
HAL_ADC_ConfigChannel(&hadc1, &sConfig);
|
||||
|
||||
// Run ADC internal calibration
|
||||
while (HAL_ADCEx_Calibration_Start(&hadc2) != HAL_OK)
|
||||
@@ -335,11 +343,15 @@ static void MX_GPIO_Init(void) {
|
||||
/*
|
||||
* Configure All pins as analog by default
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_15;
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3
|
||||
| GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_8
|
||||
| GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_15;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12
|
||||
| GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3
|
||||
| GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_8
|
||||
| GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13
|
||||
| GPIO_PIN_14 | GPIO_PIN_15;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : KEY_B_Pin KEY_A_Pin */
|
||||
|
||||
Reference in New Issue
Block a user