The question requires
an input of 10-40V, a current of 0-10A, a voltage of 100mV, and a switching frequency of 40K.
Question analysis
tips: Analyze the entire question or the main part of the question content.
Tips: Overall design scheme block diagram column:

Schematic design description
Tips: Explanation The design schematic diagram of the module in the work needs to be accompanied by a schematic diagram, preferably with a physical diagram. Each module needs to be explained. If no design is required, please indicate the source of acquisition.
CCMRAM void bcfsm(void) //CCMRAM puts the function into CCRAM memory to speed up execution { static uint16_t i=0; float temp=0.0; Next_State=Current_State=Task_0_Initial_state; while(1) { Current_State=Next_State; switch(Current_State) { case Task_0_Initial_state: { Reset_VAR(); //Reset variable PID_INT(); //Initialize compensator HAL_Delay(300); //Wait for voltage and current to return to zeroNext_State=Task_1_Get_ADC_VALUE; //Next state: read ADC value read_data( );//Update setting value if(temp_u!=SET_V||temp_i!=SET_I) { temp_u=SET_V; temp_i=SET_I; HAL_GPIO_WritePin(GPIOA,GPIO_PIN_6,GPIO_PIN_SET);//Buzzer Next_State=Task_0_Initial_state; } HAL_GPIO_WritePin( GPIOA,GPIO_PIN_6,GPIO_PIN_RESET);//Buzzer} break; case Task_1_Get_ADC_VALUE ://Get ADC voltage { //Judge whether adc conversion is completed if(Data_update_flag==STOP) Next_State=Task_2_Vin_detc; else{ PID_Callback();// Data processing Iout=ADC1_RESULT[3];//printf("
Output current: %f A
",(float)((ADC1_RESULT[1]*3300)>>12)*0.0045002f); Vin=ADC1_RESULT[0]; Next_State=Task_2_Vin_detc; Data_update_flag=STOP; } } break; case Task_2_Vin_detc://Detect input voltage { Vin_f=(float)((Vin*2500)>>12)*0.016595f; //((Vin*2500)>>12)*16.5/1000, 16.5 represents the resistor voltage division, 1000 is converted into V if(Vin_f >35.0f||Vin_f<6.0f) { Red_ON(); ERROR_flag=START; Next_State=Task_0_Initial_state; //Next state: reset break; } else Green_ON();//System indication Next_State=Task_3_Iout_detc; //Low voltage is normal , start detecting output} break; case Task_3_Iout_detc: //Detect input current{ // Iout_f=(float)((Iout*2500)>>12)*0.0011428f;//((Vin*2500)/4096)/17.5 /50;//17.5 represents the amplification factor, 50 represents the sampling resistor value//The amplification factor depends on the op amp circuit Iin_f=(float)((ADC1_RESULT[1]*2500)>>12)*0.0011428f;//(( Vin*2500)/4096)/7.407/50;//17.5 represents the amplification factor, 50 represents the sampling resistor value if (Iout_f>5.0f)/////////////////////////////////////////////////// /////////////// { Red_ON(); ERROR_flag=START;// Next_State=Task_0_Initial_state;//The output voltage is greater than 14V, triggering the output overvoltage protection break; }////// ///////////////////////////////////////////////////// ///////////////// if(flag_start_cnt!=STOP)Next_State=Task_4_Soft_start; else Next_State=Task_1_Get_ADC_VALUE; tim_f<99?tim_f++:(tim_f=0); if(tim_f==0 )//////////////////////////////////////////////////// { read_data();//Update setting value if(temp_u!=SET_V||temp_i!=SET_I) { temp_u=SET_V; temp_i=SET_I; HAL_GPIO_WritePin(GPIOA,GPIO_PIN_6,GPIO_PIN_SET);//Buzzer Target_voltage =SET_V* 1000;////mV//1000 times scaling Target_current =SET_I*1000;////0.25mA//4000 times scaling 1000-0.25mA// Next_State=Task_0_Initial_state; } else { showdata(); } } else if (tim_f==99)HAL_GPIO_WritePin(GPIOA,GPIO_PIN_6,GPIO_PIN_RESET);//beep} break; case Task_4_Soft_start ://slow start { flag_start_cnt=STOP; TIM1->CCR1=50;//TEST HAL_Delay(50); / *Add your code here!*/ Green_ON();//System instruction Next_State=Task_1_Get_ADC_VALUE; } break; default: break; } }} //ADC2_RESULT[2] saves the output voltage //ADC2_RESULT[1] saves the output current //ADC2_RESULT[3] saves the output current
Physical display instructions,

precautions
, safety
demonstration video
[stm32 CNC power supply open source PID CNC Lichuang EDA practice project - Bilibili] https://b23.tv/pnsa4CD
Other attachments upload
link: https://pan.baidu.com /s/1R8dNU8cjm95QB8AFnaMQmw?pwd=agan Extraction code: agan