-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
help wantedExtra attention is neededExtra attention is needed
Description
Not in issue yet because I popped another MCU and need to figure out how that has anything to do with anything, really.
The concept should be complete but the implementation is missing a separate folder and typedef during the prototyping stage. I was hoping that the same ISR could be reused with global static flags to adjust both the current and voltage DAC outputs.
PD_Charger/STM32CubeIDE/PD Charger/Core/Src/main.c
Lines 59 to 68 in 6ce36f3
| /* USER CODE BEGIN PV */ | |
| static double volts; | |
| static double amps; | |
| static uint32_t DAC_volts; | |
| static uint32_t DAC_amps; | |
| const int slew_volts = 1; // multiples of 12mV/us | |
| const int slew_amps = 1; //multiples of 2.4mA/us | |
| static char voltage_set; | |
| static char current_set; | |
| /* USER CODE END PV */ |
PD_Charger/STM32CubeIDE/PD Charger/Core/Src/main.c
Lines 92 to 151 in e8d0009
| /* USER CODE BEGIN 0 */ | |
| static setVoltage(double voltage){ | |
| voltage_set = 0; | |
| volts = voltage; // save local value to global for safe-keeping | |
| DAC_volts = HAL_DAC_GetValue(&hdac3, DAC_CHANNEL_1); // save starting condition from DAC | |
| HAL_TIM_Base_Start_IT(&htim3); | |
| } | |
| static setCurrent(double current){ | |
| current_set = 0; | |
| amps = current; // save local value to global for safe-keeping | |
| DAC_amps = HAL_DAC_GetValue(&hdac1, DAC_CHANNEL_1); // save starting condition from DAC | |
| HAL_TIM_Base_Start_IT(&htim3); | |
| } | |
| static int DAC_Voltage(double voltage){ // voltage to DAC scaling function | |
| int v = (int)(voltage-5.2733)/0.0119755; | |
| return (v>0) ? v : 0; | |
| } | |
| static int DAC_Current(double current){ // current to DAC scaling function | |
| int c = (int)((current*0.02*10)+0.25)*(4095/2); | |
| return (c>0) ? c : 0; | |
| } | |
| void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) | |
| { | |
| if (htim->Instance == TIM3) // 1us ISR for soft-slewing | |
| { | |
| if(voltage_set != 1) // voltage soft-slew active | |
| { | |
| if (DAC_volts < DAC_Voltage(volts)) // has not reached set-point | |
| { | |
| DAC_volts += slew_volts; // increment by constant | |
| HAL_DAC_SetValue(&hdac3, DAC_CHANNEL_1, DAC_ALIGN_12B_R, DAC_volts); // write to DAC | |
| } | |
| else | |
| { | |
| voltage_set = 1; | |
| } | |
| } | |
| if(current_set != 1) // current soft-slew active | |
| { | |
| if (DAC_amps < DAC_Current(amps)) // has not reached set-point | |
| { | |
| DAC_amps += slew_amps; // increment by constant | |
| HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, DAC_amps); // write to DAC | |
| } | |
| else | |
| { | |
| current_set = 1; | |
| } | |
| } | |
| if (current_set && voltage_set) // soft-slew complete | |
| { | |
| HAL_TIM_Base_Stop_IT(&htim3); // turn of timer | |
| } | |
| } | |
| } | |
| /* USER CODE END 0 */ |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
help wantedExtra attention is neededExtra attention is needed