优化射线电流控制
This commit is contained in:
+1
-1
@@ -48,7 +48,7 @@ extern "C" {
|
|||||||
|
|
||||||
/* Exported macro ------------------------------------------------------------*/
|
/* Exported macro ------------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN EM */
|
/* USER CODE BEGIN EM */
|
||||||
#define VERSION_STR "V1.1.0"
|
#define VERSION_STR "V1.3.0"
|
||||||
#ifdef BOOTLOADER
|
#ifdef BOOTLOADER
|
||||||
#define SW_VER "BL for " VERSION_STR
|
#define SW_VER "BL for " VERSION_STR
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -14,9 +14,13 @@ static uint16_t gusPreheatDuty = 0;
|
|||||||
static uint16_t gusNormalDuty = 0;
|
static uint16_t gusNormalDuty = 0;
|
||||||
|
|
||||||
uint8_t gucWorkState = 0;
|
uint8_t gucWorkState = 0;
|
||||||
|
static uint32_t gulXrayOnTime = 0;
|
||||||
|
|
||||||
static uint16_t gusPreheatCurrent = 0;
|
static uint16_t gusPreheatCurrent = 2000;
|
||||||
static uint16_t gusLimitCurrent = 0;
|
static uint16_t gusLimitCurrent = 3500;
|
||||||
|
static uint16_t gusXrayCurrentSet = 1500;
|
||||||
|
|
||||||
|
static uint16_t gusLastXrayCurrent = 0;
|
||||||
|
|
||||||
uint16_t gusFilamentCurrent = 0;
|
uint16_t gusFilamentCurrent = 0;
|
||||||
uint16_t gusFilamentVoltage = 0;
|
uint16_t gusFilamentVoltage = 0;
|
||||||
@@ -42,6 +46,25 @@ uint16_t adc2Xray(uint16_t adcVal)
|
|||||||
return adc2voltage(adcVal) * 1000 / 3 / 250;
|
return adc2voltage(adcVal) * 1000 / 3 / 250;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t fastUpdate(void)
|
||||||
|
{
|
||||||
|
int iRet = gusDuty;
|
||||||
|
if (gusXrayCurrent > gusXrayCurrentSet + 500) {
|
||||||
|
iRet = gusDuty - 20;
|
||||||
|
} else if (gusXrayCurrent > gusXrayCurrentSet + 300) {
|
||||||
|
iRet = gusDuty - 10;
|
||||||
|
} else if (gusXrayCurrent > gusXrayCurrentSet + 100) {
|
||||||
|
iRet = gusDuty - 5;
|
||||||
|
} else if (gusXrayCurrent < gusXrayCurrentSet - 500) {
|
||||||
|
iRet = gusDuty + 20;
|
||||||
|
} else if (gusXrayCurrent < gusXrayCurrentSet - 300) {
|
||||||
|
iRet = gusDuty + 10;
|
||||||
|
} else if (gusXrayCurrent < gusXrayCurrentSet - 100) {
|
||||||
|
iRet = gusDuty + 5;
|
||||||
|
}
|
||||||
|
return iRet;
|
||||||
|
}
|
||||||
|
|
||||||
void currentUpdate(void)
|
void currentUpdate(void)
|
||||||
{
|
{
|
||||||
int iCurrent = gusFilamentCurrent;
|
int iCurrent = gusFilamentCurrent;
|
||||||
@@ -68,14 +91,54 @@ void currentUpdate(void)
|
|||||||
}
|
}
|
||||||
gusDuty = gusPreheatDuty;
|
gusDuty = gusPreheatDuty;
|
||||||
} else if (gucWorkState == 2) {
|
} else if (gucWorkState == 2) {
|
||||||
|
static uint16_t ausBuf[10];
|
||||||
|
static int iCnt = 0;
|
||||||
|
|
||||||
if (iCurrent > gusLimitCurrent + 200) {
|
if (iCurrent > gusLimitCurrent + 200) {
|
||||||
gusNormalDuty -= 5;
|
gusDuty -= 10;
|
||||||
} else if (iCurrent > gusLimitCurrent + 100) {
|
} else if (iCurrent > gusLimitCurrent + 100) {
|
||||||
gusNormalDuty -= 2;
|
gusDuty -= 5;
|
||||||
} else if (iCurrent > gusLimitCurrent) {
|
} else if (osKernelGetTickCount() < gulXrayOnTime + 800) {
|
||||||
gusNormalDuty -= 1;
|
if (gusLastXrayCurrent < gusXrayCurrentSet - 200) {
|
||||||
|
gusNormalDuty = fastUpdate();
|
||||||
|
gusDuty = gusNormalDuty;
|
||||||
|
} else {
|
||||||
|
if (gusDuty + 10 < gusNormalDuty) {
|
||||||
|
gusDuty += 10;
|
||||||
|
} else {
|
||||||
|
gusDuty = gusNormalDuty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (osKernelGetTickCount() < gulXrayOnTime + 2000) {
|
||||||
|
iCnt = 0;
|
||||||
|
} else if (osKernelGetTickCount() < gulXrayOnTime + 2500 && iCnt < 10) {
|
||||||
|
ausBuf[iCnt++] = gusXrayCurrent;
|
||||||
|
if (iCnt >= 10) {
|
||||||
|
int iSum = 0;
|
||||||
|
for (int i = 0; i < iCnt; i++) {
|
||||||
|
iSum += ausBuf[i];
|
||||||
|
}
|
||||||
|
iSum /= iCnt;
|
||||||
|
gusLastXrayCurrent = iSum;
|
||||||
|
if (iSum > gusXrayCurrentSet + 500) {
|
||||||
|
gusNormalDuty -= 20;
|
||||||
|
} else if (iSum > gusXrayCurrentSet + 300) {
|
||||||
|
gusNormalDuty -= 10;
|
||||||
|
} else if (iSum > gusXrayCurrentSet + 100) {
|
||||||
|
gusNormalDuty -= 5;
|
||||||
|
} else if (iSum > gusXrayCurrentSet + 50) {
|
||||||
|
gusNormalDuty -= 1;
|
||||||
|
} else if (iSum < gusXrayCurrentSet - 500) {
|
||||||
|
gusNormalDuty += 20;
|
||||||
|
} else if (iSum < gusXrayCurrentSet - 300) {
|
||||||
|
gusNormalDuty += 10;
|
||||||
|
} else if (iSum < gusXrayCurrentSet - 100) {
|
||||||
|
gusNormalDuty += 5;
|
||||||
|
} else if (iSum < gusXrayCurrentSet - 50) {
|
||||||
|
gusNormalDuty += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
gusDuty = gusNormalDuty;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, gusDuty);
|
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, gusDuty);
|
||||||
@@ -84,7 +147,7 @@ void currentUpdate(void)
|
|||||||
static void filamentThread(void *arg)
|
static void filamentThread(void *arg)
|
||||||
{
|
{
|
||||||
int iWorkCmd = 0;
|
int iWorkCmd = 0;
|
||||||
uint32_t ulLastTick = HAL_GetTick();
|
uint32_t ulLastTick = osKernelGetTickCount();
|
||||||
|
|
||||||
loadSysParam();
|
loadSysParam();
|
||||||
if ((gptSysParam->usPreheatCurrent < 100) || (gptSysParam->usPreheatCurrent > 5000)) {
|
if ((gptSysParam->usPreheatCurrent < 100) || (gptSysParam->usPreheatCurrent > 5000)) {
|
||||||
@@ -97,6 +160,11 @@ static void filamentThread(void *arg)
|
|||||||
} else {
|
} else {
|
||||||
gusLimitCurrent = gptSysParam->usLimitCurrent;
|
gusLimitCurrent = gptSysParam->usLimitCurrent;
|
||||||
}
|
}
|
||||||
|
if ((gptSysParam->usXrayCurrent < 1000) || (gptSysParam->usXrayCurrent > 2000)) {
|
||||||
|
gusXrayCurrentSet = 1500;
|
||||||
|
} else {
|
||||||
|
gusXrayCurrentSet = gptSysParam->usXrayCurrent;
|
||||||
|
}
|
||||||
|
|
||||||
HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED);
|
HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED);
|
||||||
|
|
||||||
@@ -109,7 +177,7 @@ static void filamentThread(void *arg)
|
|||||||
HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_1);
|
HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_1);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
osDelay(1);
|
osDelay(3);
|
||||||
SCB_InvalidateDCache_by_Addr(gausAdcBuf, ADC_CHNL_NUM * sizeof(gausAdcBuf[0]));
|
SCB_InvalidateDCache_by_Addr(gausAdcBuf, ADC_CHNL_NUM * sizeof(gausAdcBuf[0]));
|
||||||
|
|
||||||
gusXrayCurrent = adc2Xray(gausAdcBuf[0]);
|
gusXrayCurrent = adc2Xray(gausAdcBuf[0]);
|
||||||
@@ -123,20 +191,16 @@ static void filamentThread(void *arg)
|
|||||||
iWorkCmd = 3;
|
iWorkCmd = 3;
|
||||||
if (gucWorkState == 1) {
|
if (gucWorkState == 1) {
|
||||||
gucWorkState = 2;
|
gucWorkState = 2;
|
||||||
// if (gusNormalDuty < gusPreheatDuty * 1.5 ) {
|
gulXrayOnTime = osKernelGetTickCount();
|
||||||
// gusNormalDuty = gusPreheatDuty * 1.5;
|
if (gusNormalDuty < gusPreheatDuty) {
|
||||||
// }
|
gusNormalDuty = gusPreheatDuty;
|
||||||
gusNormalDuty = gusPreheatDuty * 1.5;
|
}
|
||||||
gusDuty = gusNormalDuty;
|
|
||||||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, gusDuty);
|
|
||||||
osDelay(3);
|
|
||||||
} else if (gucWorkState == 2) {
|
} else if (gucWorkState == 2) {
|
||||||
if (gusNormalDuty < 750) {
|
if (osKernelGetTickCount() > gulXrayOnTime + 5000) {
|
||||||
gusNormalDuty += 10;
|
gucWorkState = 1;
|
||||||
|
gusDuty = gusPreheatDuty;
|
||||||
|
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, gusDuty);
|
||||||
}
|
}
|
||||||
gusDuty = gusNormalDuty;
|
|
||||||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, gusDuty);
|
|
||||||
osDelay(3);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -147,20 +211,19 @@ static void filamentThread(void *arg)
|
|||||||
gucWorkState = 1;
|
gucWorkState = 1;
|
||||||
gusDuty = gusPreheatDuty;
|
gusDuty = gusPreheatDuty;
|
||||||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, gusDuty);
|
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, gusDuty);
|
||||||
osDelay(3);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
currentUpdate();
|
currentUpdate();
|
||||||
} else {
|
} else {
|
||||||
gusDuty = 0;
|
gusDuty = 0;
|
||||||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, gusDuty);
|
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, gusDuty);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HAL_GetTick() - ulLastTick < 500) {
|
if (osKernelGetTickCount() < ulLastTick + 500) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ulLastTick = HAL_GetTick();
|
ulLastTick = osKernelGetTickCount();
|
||||||
|
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user