Vbus safety checks, slowly rising Vout, deadtime control from setpoint

This commit is contained in:
Wouter van der Vinne 2022-09-05 09:23:31 +02:00
parent 05b05bf827
commit 52fa4124d0
3 changed files with 49 additions and 7 deletions

View file

@ -87,6 +87,10 @@ typedef struct {
float freq; float freq;
float voltage; float voltage;
float fbR; float fbR;
float vbusMin;
float vbusMax;
float iMax;
uint8_t deadTime;
}solarSetPoints_t; }solarSetPoints_t;
typedef struct { typedef struct {

View file

@ -171,8 +171,13 @@ void commands_process_packet(unsigned char *data, unsigned int len) {
break; break;
case COMM_SET_SETPOINTS: case COMM_SET_SETPOINTS:
memset(&aSetPoint,0,sizeof(solarSetPoints_t));
aSetPoint.voltage = buffer_get_float32(data,10,&ind); aSetPoint.voltage = buffer_get_float32(data,10,&ind);
aSetPoint.freq = buffer_get_float32(data,10,&ind); aSetPoint.freq = buffer_get_float32(data,100,&ind);
aSetPoint.deadTime = buffer_get_float32(data,1,&ind);
aSetPoint.vbusMin = buffer_get_float32(data,1,&ind);
aSetPoint.vbusMax = buffer_get_float32(data,1,&ind);
aSetPoint.iMax = buffer_get_float32(data,10,&ind);
controlSetSetPoints(&aSetPoint); controlSetSetPoints(&aSetPoint);
break; break;
@ -182,7 +187,11 @@ void commands_process_packet(unsigned char *data, unsigned int len) {
send_buffer[ind++] = COMM_GET_SETPOINTS; send_buffer[ind++] = COMM_GET_SETPOINTS;
memcpy(&aSetPoint,getSetPoint(),sizeof(solarSetPoints_t)); memcpy(&aSetPoint,getSetPoint(),sizeof(solarSetPoints_t));
buffer_append_float32(send_buffer,aSetPoint.voltage,10,&ind); buffer_append_float32(send_buffer,aSetPoint.voltage,10,&ind);
buffer_append_float32(send_buffer,aSetPoint.freq,10,&ind); buffer_append_float32(send_buffer,aSetPoint.freq,100,&ind);
buffer_append_float32(send_buffer,aSetPoint.deadTime,1,&ind);
buffer_append_float32(send_buffer,aSetPoint.vbusMin,1,&ind);
buffer_append_float32(send_buffer,aSetPoint.vbusMax,1,&ind);
buffer_append_float32(send_buffer,aSetPoint.iMax,10,&ind);
commands_send_packet(send_buffer,ind); commands_send_packet(send_buffer,ind);
break; break;

View file

@ -29,6 +29,7 @@ PID_t capacitorPid;
bool updateControl = false; bool updateControl = false;
bool updateSetPoint = false; bool updateSetPoint = false;
uint32_t closeRelayTime=0; uint32_t closeRelayTime=0;
float voutNow= 0.0;
void calculateTemperature(void); void calculateTemperature(void);
@ -49,6 +50,7 @@ void controlLoop(void){
// pidSetTunings(&capacitorPid,setPoint.UCapP,setPoint.UCapI,setPoint.UCapD,P_ON_E); // pidSetTunings(&capacitorPid,setPoint.UCapP,setPoint.UCapI,setPoint.UCapD,P_ON_E);
// auxInputs.Vpp = syncCalculateVpp(); // auxInputs.Vpp = syncCalculateVpp();
updateSetPoint = false; updateSetPoint = false;
htim1.Instance->BDTR = (htim1.Instance->BDTR & 0xFFFFFF00) | setPoint.deadTime;
} }
calculateInputs(); calculateInputs();
calculateFilters(); calculateFilters();
@ -63,6 +65,7 @@ void controlLoop(void){
break; break;
case CONTROL_WAITFOR_SAFESTART: case CONTROL_WAITFOR_SAFESTART:
HAL_GPIO_WritePin(BRIDGES_SHUTDOWN_GPIO_Port, BRIDGES_SHUTDOWN_Pin, 0); HAL_GPIO_WritePin(BRIDGES_SHUTDOWN_GPIO_Port, BRIDGES_SHUTDOWN_Pin, 0);
voutNow = 0.0;
systemState.controlState.controlTaskState = CONTROL_RUNNING; systemState.controlState.controlTaskState = CONTROL_RUNNING;
__HAL_TIM_SetCounter(&htim2,0); __HAL_TIM_SetCounter(&htim2,0);
HAL_TIM_Base_Start(&htim2); HAL_TIM_Base_Start(&htim2);
@ -113,7 +116,19 @@ void controlLoop(void){
systemState.controlState.controlTaskState = CONTROL_IDLE; systemState.controlState.controlTaskState = CONTROL_IDLE;
} }
// HAL_GPIO_WritePin(TEST_PIN_GPIO_Port, TEST_PIN_Pin, GPIO_PIN_RESET); if (systemState.inputs.VDCBUS < setPoint.vbusMin){
setDutyCycle(0.0);
HAL_GPIO_WritePin(BRIDGES_SHUTDOWN_GPIO_Port, BRIDGES_SHUTDOWN_Pin, 1);
systemState.controlState.controlTaskState = CONTROL_SAFETY;
}
if (systemState.inputs.VDCBUS > setPoint.vbusMax){
setDutyCycle(0.0);
HAL_GPIO_WritePin(BRIDGES_SHUTDOWN_GPIO_Port, BRIDGES_SHUTDOWN_Pin, 1);
systemState.controlState.controlTaskState = CONTROL_SAFETY;
}
// HAL_GPIO_WritePin(TEST_PIN_GPIO_Port, TEST_PIN_Pin, GPIO_PIN_RESET);
} }
@ -173,7 +188,15 @@ void calculateFilters(void){
// pidCompute(&capacitorPid); // pidCompute(&capacitorPid);
break; break;
case 3: case 3:
{
float voutDiff = setPoint.voltage - voutNow;
if (fabsf(voutDiff)>1.0f){
voutNow += voutDiff/500;
}else{
voutNow = setPoint.voltage;
}
break; break;
}
default: default:
if(filterState >9){ if(filterState >9){
filterState = 0; filterState = 0;
@ -195,8 +218,10 @@ auxInputs.TEMPERATURE = 16.0f; //adcToCelsius();
void calculateState(void){ void calculateState(void){
uint32_t tick = __HAL_TIM_GET_COUNTER(&htim2); uint32_t tick = __HAL_TIM_GET_COUNTER(&htim2);
systemState.controlState.U12 = setPoint.voltage*1.41f*arm_sin_f32(50.0f*6.28f/16000.0f*tick); float vBus = fmaxf(systemState.inputs.VDCBUS,10.0f);
systemState.controlState.dutyCycle = systemState.controlState.U12/100; float maxVolt = fminf(voutNow,vBus);
systemState.controlState.U12 = maxVolt*arm_sin_f32(50.0f*6.28f/16000.0f*tick);
systemState.controlState.dutyCycle = systemState.controlState.U12/vBus;
} }
void setDutyCycle(float dutyCycle){ void setDutyCycle(float dutyCycle){
@ -273,8 +298,12 @@ void controlSetFBR(float FB){
} }
void controlInit(void){ void controlInit(void){
setPoint.voltage = 50; setPoint.voltage = 0.0;
setPoint.freq = 50.0; setPoint.freq = 50.0;
setPoint.vbusMax = 400.0;
setPoint.vbusMin = 100.0;
setPoint.iMax = 5.0;
setPoint.deadTime = 20;
// currentFIR = TM_FILTER_FIR_F32_Init(currentFilterCoefSize,currentFilterCoef,NULL,1); // currentFIR = TM_FILTER_FIR_F32_Init(currentFilterCoefSize,currentFilterCoef,NULL,1);
// currentFIR = TM_FILTER_FIR_F32_Init(uCapFilterCoeffSize,uCapFilterCoeffFloat,NULL,1); // currentFIR = TM_FILTER_FIR_F32_Init(uCapFilterCoeffSize,uCapFilterCoeffFloat,NULL,1);
// uCapFIR = TM_FILTER_FIR_F32_Init(uCapFilterCoeffSize,uCapFilterCoeffFloat,NULL,1); // uCapFIR = TM_FILTER_FIR_F32_Init(uCapFilterCoeffSize,uCapFilterCoeffFloat,NULL,1);
@ -317,7 +346,7 @@ void setupControlLoop(void){
HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_3); HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_3);
HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_3); HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_3);
htim1.Instance->BDTR = (htim1.Instance->BDTR & 0xFFFFFF00) | setPoint.deadTime;
htim1.Instance->CCMR1 |= (uint32_t) TIM_CCMR1_OC1PE; htim1.Instance->CCMR1 |= (uint32_t) TIM_CCMR1_OC1PE;
htim1.Instance->CCMR1 |= (uint32_t) TIM_CCMR1_OC1M; htim1.Instance->CCMR1 |= (uint32_t) TIM_CCMR1_OC1M;
HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_1); HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_1);