diff --git a/AxxSolder_firmware/Core/Inc/buzzer.h b/AxxSolder_firmware/Core/Inc/buzzer.h index 7045d3d..5bec4df 100644 --- a/AxxSolder_firmware/Core/Inc/buzzer.h +++ b/AxxSolder_firmware/Core/Inc/buzzer.h @@ -10,7 +10,7 @@ /* TypeDefs ------------------------------------------------------------------*/ /* Function prototypes -------------------------------------------------------*/ -void beep(double buzzer_enabled); -void beep_startup(double buzzer_enabled); +void beep(float buzzer_enabled); +void beep_startup(float buzzer_enabled); #endif /* INC_BUZZER_H_ */ diff --git a/AxxSolder_firmware/Core/Inc/hysteresis.h b/AxxSolder_firmware/Core/Inc/hysteresis.h index 3d7bf58..40789bf 100644 --- a/AxxSolder_firmware/Core/Inc/hysteresis.h +++ b/AxxSolder_firmware/Core/Inc/hysteresis.h @@ -6,12 +6,12 @@ /* TypeDefs ------------------------------------------------------------------*/ typedef struct{ - double previous_value; // previous value - double hysteresis; // hysteresis + float previous_value; // previous value + float hysteresis; // hysteresis }Hysteresis_FilterTypeDef; /* Function prototypes -------------------------------------------------------*/ void Hysteresis_Init(Hysteresis_FilterTypeDef* hysteresis_struct, float hysteresis); -double Hysteresis_Add(double new_value, Hysteresis_FilterTypeDef* hysteresis_struct); +float Hysteresis_Add(float new_value, Hysteresis_FilterTypeDef* hysteresis_struct); #endif diff --git a/AxxSolder_firmware/Core/Inc/main.h b/AxxSolder_firmware/Core/Inc/main.h index 4dfc06e..7778a59 100644 --- a/AxxSolder_firmware/Core/Inc/main.h +++ b/AxxSolder_firmware/Core/Inc/main.h @@ -33,28 +33,29 @@ extern "C" { /* USER CODE BEGIN Includes */ /* Struct to hold flash_data values */ typedef struct{ - double startup_temperature; - double temperature_offset; - double standby_temp; - double standby_time; - double emergency_time; - double buzzer_enabled; - double preset_temp_1; - double preset_temp_2; - double GPIO4_ON_at_run; - double screen_rotation; - double power_limit; - double current_measurement; - double startup_beep; - double deg_celsius; - double temp_cal_100; - double temp_cal_200; - double temp_cal_300; - double temp_cal_350; - double temp_cal_400; - double temp_cal_450; - double serial_debug_print; - double displayed_temp_filter; + float startup_temperature; + float temperature_offset; + float standby_temp; + float standby_time; + float emergency_time; + float buzzer_enabled; + float preset_temp_1; + float preset_temp_2; + float GPIO4_ON_at_run; + float screen_rotation; + float power_limit; + float current_measurement; + float startup_beep; + float deg_celsius; + float temp_cal_100; + float temp_cal_200; + float temp_cal_300; + float temp_cal_350; + float temp_cal_400; + float temp_cal_450; + float serial_debug_print; + float displayed_temp_filter; + float startup_temp_is_previous_temp; }Flash_values; /* USER CODE END Includes */ diff --git a/AxxSolder_firmware/Core/Inc/pid.h b/AxxSolder_firmware/Core/Inc/pid.h index 5161f37..55a01aa 100644 --- a/AxxSolder_firmware/Core/Inc/pid.h +++ b/AxxSolder_firmware/Core/Inc/pid.h @@ -34,66 +34,66 @@ typedef struct{ uint32_t updateOnEveryCall; - double DispKp; - double DispKi; - double DispKd; + float DispKp; + float DispKi; + float DispKd; - double Kp; - double Ki; - double Kd; + float Kp; + float Ki; + float Kd; - double DispKp_part; - double DispKi_part; - double DispKd_part; + float DispKp_part; + float DispKi_part; + float DispKd_part; - double *MyInput; - double *MyOutput; - double *MySetpoint; + float *MyInput; + float *MyOutput; + float *MySetpoint; - double OutputSum; - double LastInput; + float OutputSum; + float LastInput; - double OutMin; - double OutMax; + float OutMin; + float OutMax; - double IMin; - double IMax; + float IMin; + float IMax; - double IminError; + float IminError; - double NegativeErrorIgainMultiplier; - double NegativeErrorIgainBias; + float NegativeErrorIgainMultiplier; + float NegativeErrorIgainBias; }PID_TypeDef; /* Init */ void PID_Init(PID_TypeDef *uPID); -void PID(PID_TypeDef *uPID, double *Input, double *Output, double *Setpoint, double Kp, double Ki, double Kd, PIDCD_TypeDef ControllerDirection); +void PID(PID_TypeDef *uPID, float *Input, float *Output, float *Setpoint, float Kp, float Ki, float Kd, PIDCD_TypeDef ControllerDirection); /* Function to clamp d between the limits min and max */ -double double_clamp(double d, double min, double max); +float float_clamp(float d, float min, float max); /* Function to check if clamping will occur */ -uint8_t check_clamping(double d, double min, double max); +uint8_t check_clamping(float d, float min, float max); /* Computing */ uint8_t PID_Compute(PID_TypeDef *uPID); /* PID Limits */ -void PID_SetOutputLimits(PID_TypeDef *uPID, double Min, double Max); +void PID_SetOutputLimits(PID_TypeDef *uPID, float Min, float Max); /* PID I-windup Limits */ -void PID_SetILimits(PID_TypeDef *uPID, double Min, double Max); +void PID_SetILimits(PID_TypeDef *uPID, float Min, float Max); /* Minimum error where I is added */ -void PID_SetIminError(PID_TypeDef *uPID, double IminError); +void PID_SetIminError(PID_TypeDef *uPID, float IminError); /* Set the I gain multiplier for negative error*/ -void PID_SetNegativeErrorIgainMult(PID_TypeDef *uPID, double NegativeErrorIgainMultiplier, double NegativeErrorIgainBias); +void PID_SetNegativeErrorIgainMult(PID_TypeDef *uPID, float NegativeErrorIgainMultiplier, float NegativeErrorIgainBias); /* PID Tunings */ -void PID_SetTunings(PID_TypeDef *uPID, double Kp, double Ki, double Kd); +void PID_SetTunings(PID_TypeDef *uPID, float Kp, float Ki, float Kd); /* PID Direction */ void PID_SetControllerDirection(PID_TypeDef *uPID, PIDCD_TypeDef Direction); @@ -105,13 +105,13 @@ void PID_SetSampleTime(PID_TypeDef *uPID, int32_t NewSampleTime, int32_t updateO void PID_SetMode(PID_TypeDef *uPID, PIDMode_TypeDef Mode); /* Get Tunings Param */ -double PID_GetKp(PID_TypeDef *uPID); -double PID_GetKi(PID_TypeDef *uPID); -double PID_GetKd(PID_TypeDef *uPID); +float PID_GetKp(PID_TypeDef *uPID); +float PID_GetKi(PID_TypeDef *uPID); +float PID_GetKd(PID_TypeDef *uPID); /* Get current contributions */ -double PID_GetPpart(PID_TypeDef *uPID); -double PID_GetIpart(PID_TypeDef *uPID); -double PID_GetDpart(PID_TypeDef *uPID); +float PID_GetPpart(PID_TypeDef *uPID); +float PID_GetIpart(PID_TypeDef *uPID); +float PID_GetDpart(PID_TypeDef *uPID); #endif diff --git a/AxxSolder_firmware/Core/Src/buzzer.c b/AxxSolder_firmware/Core/Src/buzzer.c index 7f3a73d..072a6de 100644 --- a/AxxSolder_firmware/Core/Src/buzzer.c +++ b/AxxSolder_firmware/Core/Src/buzzer.c @@ -4,7 +4,7 @@ extern TIM_HandleTypeDef htim4; extern TIM_HandleTypeDef htim17; /* Beep the beeper */ -void beep(double buzzer_enabled){ +void beep(float buzzer_enabled){ if(buzzer_enabled == 1){ HAL_TIM_PWM_Start_IT(&htim4, TIM_CHANNEL_2); HAL_TIM_Base_Start_IT(&htim17); @@ -12,7 +12,7 @@ void beep(double buzzer_enabled){ } /* Beep the beeper twice*/ -void beep_startup(double buzzer_enabled){ +void beep_startup(float buzzer_enabled){ beep(buzzer_enabled); HAL_Delay(100); beep(buzzer_enabled); diff --git a/AxxSolder_firmware/Core/Src/hysteresis.c b/AxxSolder_firmware/Core/Src/hysteresis.c index 2ae9346..974100f 100644 --- a/AxxSolder_firmware/Core/Src/hysteresis.c +++ b/AxxSolder_firmware/Core/Src/hysteresis.c @@ -15,7 +15,7 @@ void Hysteresis_Init(Hysteresis_FilterTypeDef* hysteresis_struct, float hysteres hysteresis_struct->previous_value = 0; } -double Hysteresis_Add(double new_value, Hysteresis_FilterTypeDef* hysteresis_struct){ +float Hysteresis_Add(float new_value, Hysteresis_FilterTypeDef* hysteresis_struct){ if((new_value >= hysteresis_struct->previous_value + hysteresis_struct->hysteresis) || (new_value <= hysteresis_struct->previous_value - hysteresis_struct->hysteresis)){ hysteresis_struct->previous_value = new_value; return new_value; diff --git a/AxxSolder_firmware/Core/Src/main.c b/AxxSolder_firmware/Core/Src/main.c index a67079b..5e90f20 100644 --- a/AxxSolder_firmware/Core/Src/main.c +++ b/AxxSolder_firmware/Core/Src/main.c @@ -42,7 +42,7 @@ /* USER CODE BEGIN PTD */ uint8_t fw_version_major = 3; uint8_t fw_version_minor = 2; -uint8_t fw_version_patch = 3; +uint8_t fw_version_patch = 4; //#define PID_TUNING DEBUG_VERBOSITY_t debugLevel = DEBUG_INFO; @@ -67,8 +67,8 @@ DEBUG_VERBOSITY_t debugLevel = DEBUG_INFO; #define PID_MAX_OUTPUT 500 #define PID_UPDATE_INTERVAL 25 #define PID_ADD_I_MIN_ERROR 75 -double PID_NEG_ERROR_I_MULT = 7; -double PID_NEG_ERROR_I_BIAS = 1; +float PID_NEG_ERROR_I_MULT = 7; +float PID_NEG_ERROR_I_BIAS = 1; /* Timing constants */ uint32_t previous_millis_display = 0; @@ -129,11 +129,11 @@ uint8_t sleep_state_written_to_LCD = 0; uint8_t standby_state_written_to_LCD = 0; /* Custom tuning parameters */ -double Kp_tuning = 0; -double Ki_tuning = 0; -double Kd_tuning = 0; -double temperature_tuning = 100; -double PID_MAX_I_LIMIT_tuning = 0; +float Kp_tuning = 0; +float Ki_tuning = 0; +float Kd_tuning = 0; +float temperature_tuning = 100; +float PID_MAX_I_LIMIT_tuning = 0; /* Allow use of custom temperatue, used for tuning */ uint8_t custom_temperature_on = 0; @@ -152,15 +152,15 @@ uint16_t ADC1_BUF[ADC1_BUF_LEN]; uint16_t current_raw = 0; /* Thermocouple temperature */ -double TC_temp = 0; +float TC_temp = 0; /* Flag to indicate that startup sequence is done */ uint8_t startup_done = 0; /* Variables for thermocouple outlier detection */ -double TC_temp_from_ADC = 0; -double TC_temp_from_ADC_previous = 0; -double TC_temp_from_ADC_diff = 0; +float TC_temp_from_ADC = 0; +float TC_temp_from_ADC_previous = 0; +float TC_temp_from_ADC_diff = 0; uint16_t TC_outliers_detected = 0; #define TC_OUTLIERS_THRESHOLD 300 @@ -230,23 +230,23 @@ uint8_t UART_packet_length = 0; /* Struct to hold sensor values */ struct sensor_values_struct { - double set_temperature; - double thermocouple_temperature; - double thermocouple_temperature_previous; - double thermocouple_temperature_filtered; - double requested_power; - double requested_power_filtered; + float set_temperature; + float thermocouple_temperature; + float thermocouple_temperature_previous; + float thermocouple_temperature_filtered; + float requested_power; + float requested_power_filtered; float bus_voltage; float heater_current; uint16_t leak_current; float mcu_temperature; - double in_stand; - double handle1_sense; - double handle2_sense; + float in_stand; + float handle1_sense; + float handle2_sense; mainstates current_state; mainstates previous_state; float max_power_watt; - double USB_PD_power_limit; + float USB_PD_power_limit; }; /* Struct to hold sensor values */ @@ -291,20 +291,21 @@ Flash_values default_flash_values = {.startup_temperature = 330, .temp_cal_400 = 400, .temp_cal_450 = 450, .serial_debug_print = 0, - .displayed_temp_filter = 5}; + .displayed_temp_filter = 5, + .startup_temp_is_previous_temp = 0}; /* List of names for settings menu */ -#define menu_length 25 +#define menu_length 26 char menu_names[menu_length][30] = { "Startup Temp °C ", "Temp Offset °C ", "Standby Temp °C ", "Standby Time [min] ", "Sleep Time [min] ", "Buzzer Enabled ", - "Preset Temp 1 °C ", - "Preset Temp 2 °C ", + "Preset Temp 1 °C ", + "Preset Temp 2 °C ", "GPIO4 ON at run ", - "Screen Rotation ", + "Screen Rotation ", "Limit Power [W] ", "I Measurement ", "Startup Beep ", @@ -315,14 +316,15 @@ char menu_names[menu_length][30] = { "Startup Temp °C ", "Temp cal 350 ", "Temp cal 400 ", "Temp cal 450 ", - "Serial DEBUG ", + "Serial DEBUG ", "Disp Temp. filter ", + "Start at prev. temp ", "-Load Default- ", "-Save and Reboot- ", "-Exit no Save- "}; /* PID data */ -double PID_setpoint = 0.0; +float PID_setpoint = 0.0; /* Flags for temp and current measurements */ uint8_t current_measurement_requested = 0; @@ -410,19 +412,19 @@ static void MX_TIM16_Init(void); PID_TypeDef TPID; /* Function to clamp d between the limits min and max */ -double clamp(double d, double min, double max) { - const double t = d < min ? min : d; +float clamp(float d, float min, float max) { + const float t = d < min ? min : d; return t > max ? max : t; } /* Function to get min value of a and b */ -double min(double a, double b) { +float min(float a, float b) { return a < b ? a : b; } /* Returns the average of 100 readings of the index+3*n value in the ADC_buffer vector */ -double get_mean_ADC_reading_indexed(uint8_t index){ - double ADC_filter_mean = 0; +float get_mean_ADC_reading_indexed(uint8_t index){ + float ADC_filter_mean = 0; for(int n=index;nCNT - 1000.0) / 2.0 - (float)menu_cursor_position)) * 5; + ((float*)&flash_values)[menu_cursor_position] = (float)old_value + round(((float)(TIM2->CNT - 1000.0) / 2.0 - (float)menu_cursor_position)) * 5; } else{ - ((double*)&flash_values)[menu_cursor_position] = (float)old_value + (float)(TIM2->CNT - 1000.0) / 2.0 - (float)menu_cursor_position; + ((float*)&flash_values)[menu_cursor_position] = (float)old_value + (float)(TIM2->CNT - 1000.0) / 2.0 - (float)menu_cursor_position; } - if ((menu_cursor_position == 5) || (menu_cursor_position == 8) || (menu_cursor_position == 11) || (menu_cursor_position == 12) || (menu_cursor_position == 13) || (menu_cursor_position == 20)){ - ((double*)&flash_values)[menu_cursor_position] = fmod(round(fmod(fabs(((double*)&flash_values)[menu_cursor_position]), 2)), 2); + if ((menu_cursor_position == 5) || (menu_cursor_position == 8) || (menu_cursor_position == 11) || (menu_cursor_position == 12) || (menu_cursor_position == 13) || (menu_cursor_position == 20) || (menu_cursor_position == 22)){ + ((float*)&flash_values)[menu_cursor_position] = fmod(round(fmod(fabs(((float*)&flash_values)[menu_cursor_position]), 2)), 2); } else if (menu_cursor_position == 9){ - ((double*)&flash_values)[menu_cursor_position] = fmod(round(fmod(fabs(((double*)&flash_values)[menu_cursor_position]), 4)), 4); + ((float*)&flash_values)[menu_cursor_position] = fmod(round(fmod(fabs(((float*)&flash_values)[menu_cursor_position]), 4)), 4); } else if (menu_cursor_position == 21){ - ((double*)&flash_values)[menu_cursor_position] = 1 + fmod(round(fmod(fabs(((double*)&flash_values)[menu_cursor_position]), 10)), 10); + ((float*)&flash_values)[menu_cursor_position] = 1 + fmod(round(fmod(fabs(((float*)&flash_values)[menu_cursor_position]), 10)), 10); } else if (menu_cursor_position == 1){ - ((double*)&flash_values)[menu_cursor_position] = round(((double*)&flash_values)[menu_cursor_position]); + ((float*)&flash_values)[menu_cursor_position] = round(((float*)&flash_values)[menu_cursor_position]); } else if ((menu_cursor_position == 0) || (menu_cursor_position == 1) || (menu_cursor_position == 2) || (menu_cursor_position == 6) || (menu_cursor_position == 7)){ - ((double*)&flash_values)[menu_cursor_position] = fmod(round(fmod(fabs(((double*)&flash_values)[menu_cursor_position]), MAX_SELECTABLE_TEMPERATURE + 1)), MAX_SELECTABLE_TEMPERATURE + 1); + ((float*)&flash_values)[menu_cursor_position] = fmod(round(fmod(fabs(((float*)&flash_values)[menu_cursor_position]), MAX_SELECTABLE_TEMPERATURE + 1)), MAX_SELECTABLE_TEMPERATURE + 1); } else if (menu_cursor_position == 10){ - ((double*)&flash_values)[menu_cursor_position] = fmod(round(fmod(fabs(((double*)&flash_values)[menu_cursor_position]), MAX_POWER + 5)), MAX_POWER + 5); + ((float*)&flash_values)[menu_cursor_position] = fmod(round(fmod(fabs(((float*)&flash_values)[menu_cursor_position]), MAX_POWER + 5)), MAX_POWER + 5); } else { - ((double*)&flash_values)[menu_cursor_position] = fabs(((double*)&flash_values)[menu_cursor_position]); + ((float*)&flash_values)[menu_cursor_position] = fabs(((float*)&flash_values)[menu_cursor_position]); } } @@ -670,7 +677,7 @@ void settings_menu(){ if((HAL_GPIO_ReadPin (GPIOB, SW_1_Pin) == 1) && (menu_cursor_position < menu_length-3)){ if(menu_level == 0){ - old_value = ((double*)&flash_values)[menu_cursor_position]; + old_value = ((float*)&flash_values)[menu_cursor_position]; old_menu_cursor_position = menu_cursor_position; } if(menu_level == 1){ @@ -702,20 +709,20 @@ void settings_menu(){ } char string[10]; + memset(&string, '\0', 10); if(i < menu_length-3){ if((i == menu_cursor_position) && (menu_level == 1)){ - left_align_double(string, (((double*)&flash_values)[i]), strlen(string)); + left_align_float(string, (((float*)&flash_values)[i]), strlen(string)); LCD_PutStr(190, 45+(i-menu_start)*25, string, FONT_arial_20X23, RGB_to_BRG(C_BLACK), RGB_to_BRG(C_WHITE)); } else{ - left_align_double(string, (((double*)&flash_values)[i]), strlen(string)); + left_align_float(string, (((float*)&flash_values)[i]), strlen(string)); LCD_PutStr(190, 45+(i-menu_start)*25, string, FONT_arial_20X23, RGB_to_BRG(C_WHITE), RGB_to_BRG(C_BLACK)); } } if(i >= menu_length-3){ LCD_PutStr(190, 45+(i-menu_start)*25, " ", FONT_arial_20X23, RGB_to_BRG(C_WHITE), RGB_to_BRG(C_BLACK)); } - } } } @@ -789,13 +796,13 @@ void update_display(){ } else if((sensor_values.current_state == STANDBY) && !standby_state_written_to_LCD){ UG_FillFrame(210,66,230,268, RGB_to_BRG(C_ORANGE)); - LCD_PutStr(214, 73, "S", FONT_arial_20X23, RGB_to_BRG(C_BLACK), RGB_to_BRG(C_ORANGE)); - LCD_PutStr(214, 99, "T", FONT_arial_20X23, RGB_to_BRG(C_BLACK), RGB_to_BRG(C_ORANGE)); - LCD_PutStr(214, 129, "A", FONT_arial_20X23, RGB_to_BRG(C_BLACK), RGB_to_BRG(C_ORANGE)); - LCD_PutStr(214, 158, "N", FONT_arial_20X23, RGB_to_BRG(C_BLACK), RGB_to_BRG(C_ORANGE)); - LCD_PutStr(214, 191, "D", FONT_arial_20X23, RGB_to_BRG(C_BLACK), RGB_to_BRG(C_ORANGE)); - LCD_PutStr(214, 217, "B", FONT_arial_20X23, RGB_to_BRG(C_BLACK), RGB_to_BRG(C_ORANGE)); - LCD_PutStr(214, 247, "Y", FONT_arial_20X23, RGB_to_BRG(C_BLACK), RGB_to_BRG(C_ORANGE)); + LCD_PutStr(213, 73, "S", FONT_arial_20X23, RGB_to_BRG(C_BLACK), RGB_to_BRG(C_ORANGE)); + LCD_PutStr(213, 102, "T", FONT_arial_20X23, RGB_to_BRG(C_BLACK), RGB_to_BRG(C_ORANGE)); + LCD_PutStr(213, 131, "A", FONT_arial_20X23, RGB_to_BRG(C_BLACK), RGB_to_BRG(C_ORANGE)); + LCD_PutStr(213, 160, "N", FONT_arial_20X23, RGB_to_BRG(C_BLACK), RGB_to_BRG(C_ORANGE)); + LCD_PutStr(213, 189, "D", FONT_arial_20X23, RGB_to_BRG(C_BLACK), RGB_to_BRG(C_ORANGE)); + LCD_PutStr(213, 218, "B", FONT_arial_20X23, RGB_to_BRG(C_BLACK), RGB_to_BRG(C_ORANGE)); + LCD_PutStr(213, 247, "Y", FONT_arial_20X23, RGB_to_BRG(C_BLACK), RGB_to_BRG(C_ORANGE)); standby_state_written_to_LCD = 1; sleep_state_written_to_LCD = 0; } @@ -1458,6 +1465,8 @@ int main(void) // Check if user data in flash is valid, if not - write default parameters if(!FlashCheckCRC()){ FlashWrite(&default_flash_values); + beep(1); //Beep once to indicate default parameters written to flash + HAL_Delay(100); HAL_NVIC_SystemReset(); } @@ -1478,15 +1487,15 @@ int main(void) TIM2->CNT = flash_values.startup_temperature; /* initialize moving average functions */ - Moving_Average_Init(&thermocouple_temperature_filter_struct,2); + Moving_Average_Init(&thermocouple_temperature_filter_struct,(uint32_t)2); Moving_Average_Init(&thermocouple_temperature_filtered_filter_struct,(uint32_t)flash_values.displayed_temp_filter*10); - Moving_Average_Init(&requested_power_filtered_filter_struct,20); - Moving_Average_Init(&mcu_temperature_filter_struct,100); - Moving_Average_Init(&input_voltage_filterStruct,25); - Moving_Average_Init(¤t_filterStruct,5); - Moving_Average_Init(&stand_sense_filterStruct,20); - Moving_Average_Init(&handle1_sense_filterStruct,20); - Moving_Average_Init(&handle2_sense_filterStruct,20); + Moving_Average_Init(&requested_power_filtered_filter_struct,(uint32_t)20); + Moving_Average_Init(&mcu_temperature_filter_struct,(uint32_t)100); + Moving_Average_Init(&input_voltage_filterStruct,(uint32_t)25); + Moving_Average_Init(¤t_filterStruct,(uint32_t)5); + Moving_Average_Init(&stand_sense_filterStruct,(uint32_t)20); + Moving_Average_Init(&handle1_sense_filterStruct,(uint32_t)20); + Moving_Average_Init(&handle2_sense_filterStruct,(uint32_t)20); /* initialize hysteresis functions */ Hysteresis_Init(&thermocouple_temperature_filtered_hysteresis, 0.5); @@ -1529,7 +1538,7 @@ int main(void) //2. wait for sink to get ready while(!stusb_is_sink_ready()){ - //debug_print_str(DEBUG_INFO,"Waiting for sink to get ready"); + debug_print_str(DEBUG_INFO,"Waiting for sink to get ready"); } //if we are on USB-PD the sink needs some time to start HAL_Delay(500); @@ -2528,8 +2537,22 @@ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ + + // Stop the heater PWM and reconfigure as a GPIO and set to RESET heater_off(); - __disable_irq(); + HAL_TIMEx_PWMN_Stop_IT(&htim1, TIM_CHANNEL_3); + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /*Configure GPIO pin : CURRENT_Pin */ + GPIO_InitStruct.Pin = HEATER_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); + HAL_GPIO_WritePin(GPIOF, HEATER_Pin, GPIO_PIN_RESET); + + __disable_irq(); while (1) { } diff --git a/AxxSolder_firmware/Core/Src/pid.c b/AxxSolder_firmware/Core/Src/pid.c index 12f275c..d9ba795 100644 --- a/AxxSolder_firmware/Core/Src/pid.c +++ b/AxxSolder_firmware/Core/Src/pid.c @@ -7,10 +7,10 @@ void PID_Init(PID_TypeDef *uPID) uPID->OutputSum = *uPID->MyOutput; uPID->LastInput = *uPID->MyInput; - uPID->OutputSum = double_clamp(uPID->OutputSum, uPID->OutMin, uPID->OutMax); + uPID->OutputSum = float_clamp(uPID->OutputSum, uPID->OutMin, uPID->OutMax); } -void PID(PID_TypeDef *uPID, double *Input, double *Output, double *Setpoint, double Kp, double Ki, double Kd, PIDCD_TypeDef ControllerDirection) +void PID(PID_TypeDef *uPID, float *Input, float *Output, float *Setpoint, float Kp, float Ki, float Kd, PIDCD_TypeDef ControllerDirection) { /* Set parameters */ uPID->MyOutput = Output; @@ -28,13 +28,13 @@ void PID(PID_TypeDef *uPID, double *Input, double *Output, double *Setpoint, dou } /* Function to clamp d between the limits min and max */ -double double_clamp(double d, double min, double max) { - const double t = d < min ? min : d; +float float_clamp(float d, float min, float max) { + const float t = d < min ? min : d; return t > max ? max : t; } /* Function to check if clamping will occur */ -uint8_t check_clamping(double d, double min, double max) { +uint8_t check_clamping(float d, float min, float max) { if(d > max || d < min){ return 1; } @@ -47,12 +47,12 @@ uint8_t check_clamping(double d, double min, double max) { uint8_t PID_Compute(PID_TypeDef *uPID){ uint32_t now; uint32_t timeChange; - double timeChange_in_seconds; + float timeChange_in_seconds; - double input; - double error; - double dInput; - double output; + float input; + float error; + float dInput; + float output; /* Check PID mode */ if (!uPID->InAuto){ @@ -91,7 +91,7 @@ uint8_t PID_Compute(PID_TypeDef *uPID){ } /* Clamp Integral part */ - uPID->OutputSum = double_clamp(uPID->OutputSum, uPID->IMin, uPID->IMax); + uPID->OutputSum = float_clamp(uPID->OutputSum, uPID->IMin, uPID->IMax); /* If Setpoint is set to 0, zero integral part */ if(*uPID->MySetpoint == 0){ @@ -108,7 +108,7 @@ uint8_t PID_Compute(PID_TypeDef *uPID){ output += uPID->DispKi_part; /* Clamp output */ - output = double_clamp(output, uPID->OutMin, uPID->OutMax); + output = float_clamp(output, uPID->OutMin, uPID->OutMax); *uPID->MyOutput = output; @@ -138,7 +138,7 @@ PIDMode_TypeDef PID_GetMode(PID_TypeDef *uPID){ } /* PID Limits */ -void PID_SetOutputLimits(PID_TypeDef *uPID, double Min, double Max){ +void PID_SetOutputLimits(PID_TypeDef *uPID, float Min, float Max){ /* Check value */ if (Min >= Max){ return; @@ -149,15 +149,15 @@ void PID_SetOutputLimits(PID_TypeDef *uPID, double Min, double Max){ if (uPID->InAuto){ /* Check value */ - *uPID->MyOutput = double_clamp(*uPID->MyOutput, uPID->OutMin, uPID->OutMax); + *uPID->MyOutput = float_clamp(*uPID->MyOutput, uPID->OutMin, uPID->OutMax); /* Check out value */ - uPID->OutputSum = double_clamp(uPID->OutputSum, uPID->OutMin, uPID->OutMax); + uPID->OutputSum = float_clamp(uPID->OutputSum, uPID->OutMin, uPID->OutMax); } } /* PID I-windup Limits */ -void PID_SetILimits(PID_TypeDef *uPID, double Min, double Max){ +void PID_SetILimits(PID_TypeDef *uPID, float Min, float Max){ /* Check value */ if (Min >= Max){ return; @@ -168,7 +168,7 @@ void PID_SetILimits(PID_TypeDef *uPID, double Min, double Max){ } /* Minimum error where I is added */ -void PID_SetIminError(PID_TypeDef *uPID, double IminError){ /* Check value */ +void PID_SetIminError(PID_TypeDef *uPID, float IminError){ /* Check value */ if (IminError < 0){ return; } @@ -177,7 +177,7 @@ void PID_SetIminError(PID_TypeDef *uPID, double IminError){ /* Check value */ } /* Set the I gain multiplier for negative error*/ -void PID_SetNegativeErrorIgainMult(PID_TypeDef *uPID, double NegativeErrorIgainMultiplier, double NegativeErrorIgainBias){ +void PID_SetNegativeErrorIgainMult(PID_TypeDef *uPID, float NegativeErrorIgainMultiplier, float NegativeErrorIgainBias){ if (NegativeErrorIgainMultiplier < 0){ return; } @@ -187,7 +187,7 @@ void PID_SetNegativeErrorIgainMult(PID_TypeDef *uPID, double NegativeErrorIgainM } /* PID Tunings */ -void PID_SetTunings(PID_TypeDef *uPID, double Kp, double Ki, double Kd){ +void PID_SetTunings(PID_TypeDef *uPID, float Kp, float Ki, float Kd){ /* Check value */ if (Kp < 0 || Ki < 0 || Kd < 0){ return; @@ -232,11 +232,11 @@ void PID_SetSampleTime(PID_TypeDef *uPID, int32_t NewSampleTime, int32_t updateO updateOnCall = 1; } uPID->updateOnEveryCall = updateOnCall; - double ratio; + float ratio; /* Check value */ if (NewSampleTime > 0){ - ratio = (double)NewSampleTime / (double)uPID->SampleTime; + ratio = (float)NewSampleTime / (float)uPID->SampleTime; uPID->Ki *= ratio; uPID->Kd /= ratio; @@ -245,23 +245,23 @@ void PID_SetSampleTime(PID_TypeDef *uPID, int32_t NewSampleTime, int32_t updateO } /* Get Parameters */ -double PID_GetKp(PID_TypeDef *uPID){ +float PID_GetKp(PID_TypeDef *uPID){ return uPID->DispKp; } -double PID_GetKi(PID_TypeDef *uPID){ +float PID_GetKi(PID_TypeDef *uPID){ return uPID->DispKi; } -double PID_GetKd(PID_TypeDef *uPID){ +float PID_GetKd(PID_TypeDef *uPID){ return uPID->DispKd; } /* Get current contributions*/ -double PID_GetPpart(PID_TypeDef *uPID){ +float PID_GetPpart(PID_TypeDef *uPID){ return uPID->DispKp_part; } -double PID_GetIpart(PID_TypeDef *uPID){ +float PID_GetIpart(PID_TypeDef *uPID){ return uPID->DispKi_part; } -double PID_GetDpart(PID_TypeDef *uPID){ +float PID_GetDpart(PID_TypeDef *uPID){ return uPID->DispKd_part; } diff --git a/CAD/AxxSolder_Portable/~$Encolsure_Portable.SLDPRT b/CAD/AxxSolder_Portable/~$Encolsure_Portable.SLDPRT deleted file mode 100644 index a163e17..0000000 Binary files a/CAD/AxxSolder_Portable/~$Encolsure_Portable.SLDPRT and /dev/null differ