applied last changes from version without git
This commit is contained in:
436
Src/main.c
436
Src/main.c
@ -47,7 +47,11 @@ ADC_HandleTypeDef hadc3;
|
||||
|
||||
SD_HandleTypeDef hsd1;
|
||||
|
||||
TIM_HandleTypeDef htim8;
|
||||
TIM_HandleTypeDef htim10;
|
||||
TIM_HandleTypeDef htim11;
|
||||
|
||||
UART_HandleTypeDef huart8;
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
uint32_t TO6, TO6_before, TO6_stop, TO6_uart, SD_SEEK, SD_SLIDE, temp32, TO7, TO7_before, TO7_PID, TO10, TO10_counter, TIM10_period;//timer 6 ticks & SD FILE COUNTER
|
||||
@ -61,8 +65,12 @@ LDx_SetupTypeDef LD1_curr_setup, LD2_curr_setup, LD1_def_setup, LD2_def_setup;
|
||||
Work_SetupTypeDef Curr_setup, Def_setup;
|
||||
LDx_ParamTypeDef LD1_param, LD2_param;
|
||||
|
||||
LD_Blinker_StateTypeDef LD_blinker;
|
||||
|
||||
task_t task;
|
||||
|
||||
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
@ -82,11 +90,14 @@ static void MX_SDMMC1_SD_Init(void);
|
||||
static void MX_TIM7_Init(void);
|
||||
static void MX_TIM6_Init(void);
|
||||
static void MX_TIM10_Init(void);
|
||||
static void MX_UART8_Init(void);
|
||||
static void MX_TIM8_Init(void);
|
||||
static void MX_TIM11_Init(void);
|
||||
/* USER CODE BEGIN PFP */
|
||||
static void Init_params(void);
|
||||
static void Decode_uart(uint16_t *Command, LDx_SetupTypeDef *LD1_curr_setup, LDx_SetupTypeDef *LD2_curr_setup, Work_SetupTypeDef *Curr_setup);
|
||||
static void Decode_task(uint16_t *Command, LDx_SetupTypeDef *LD1_curr_setup, LDx_SetupTypeDef *LD2_curr_setup, Work_SetupTypeDef *Curr_setup);
|
||||
static void Set_LTEC(uint8_t num, uint16_t DATA);
|
||||
void Set_LTEC(uint8_t num, uint16_t DATA);
|
||||
static uint16_t MPhD_T(uint8_t num);
|
||||
static uint16_t Get_ADC(uint8_t num);
|
||||
static uint16_t PID_Controller_Temp(LDx_SetupTypeDef * LDx_curr_setup, LDx_ParamTypeDef * LDx_results, uint8_t num);
|
||||
@ -100,6 +111,7 @@ int SD_REMOVE(void);
|
||||
void USART_TX (uint8_t* dt, uint16_t sz);
|
||||
void USART_TX_DMA (uint16_t sz);
|
||||
static void Stop_TIM10();
|
||||
static void OUT_trigger(uint8_t);
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
@ -151,8 +163,19 @@ int main(void)
|
||||
MX_TIM7_Init();
|
||||
MX_TIM6_Init();
|
||||
MX_TIM10_Init();
|
||||
MX_UART8_Init();
|
||||
MX_TIM8_Init();
|
||||
MX_TIM11_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
Init_params();
|
||||
HAL_TIM_Base_Start(&htim11);
|
||||
HAL_TIM_PWM_Start(&htim11, TIM_CHANNEL_1); //start modulating by Mach-Zander modulator
|
||||
/*
|
||||
if (HAL_GPIO_ReadPin(INP_0_GPIO_Port, INP_0_Pin) == 0){
|
||||
|
||||
CPU_state = DECODE_ENABLE;
|
||||
}
|
||||
*/
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
@ -271,23 +294,23 @@ int main(void)
|
||||
//Put the temperature of LD2 to Long_Data:
|
||||
temp16 = Get_ADC(0);
|
||||
temp16 = Get_ADC(1);
|
||||
Long_Data[7] = temp16;
|
||||
Long_Data[7] = temp16; // PA2 -- 3V_monitor // PB1 -- U_Rt1_ext_Gain
|
||||
|
||||
//Put the temperature of LD2 to Long_Data:
|
||||
temp16 = Get_ADC(1);
|
||||
Long_Data[8] = temp16;
|
||||
Long_Data[8] = temp16; // PB0 -- U_Rt2_ext_Gain // PB0 -- U_Rt2_ext_Gain
|
||||
|
||||
//Put the temperature of LD2 to Long_Data:
|
||||
temp16 = Get_ADC(1);
|
||||
Long_Data[9] = temp16;
|
||||
Long_Data[9] = temp16; // PB1 -- U_Rt1_ext_Gain // PA2 -- 3V_monitor
|
||||
|
||||
//Put the temperature of LD2 to Long_Data:
|
||||
temp16 = Get_ADC(1);
|
||||
Long_Data[10] = temp16;
|
||||
Long_Data[10] = temp16; // PC0 -- 5V1_monitor // PC0 -- 5V1_monitor
|
||||
|
||||
//Put the temperature of LD2 to Long_Data:
|
||||
temp16 = Get_ADC(1);
|
||||
Long_Data[11] = temp16;
|
||||
Long_Data[11] = temp16; // PC1 -- 5V2_monitor // PC1 -- 5V2_monitor
|
||||
temp16 = Get_ADC(2);
|
||||
|
||||
//Put the temperature of LD2 to Long_Data:
|
||||
@ -354,16 +377,56 @@ int main(void)
|
||||
st = HAL_TIM_Base_Start_IT(&htim10);
|
||||
if (st != HAL_OK)
|
||||
while(1);
|
||||
|
||||
uint16_t step_counter = 0;
|
||||
uint16_t trigger_counter = 0;
|
||||
uint16_t trigger_step = (uint8_t )((task.max_param - task.current_param)/task.delta_param * 10);
|
||||
uint16_t task_sheduler = 0;
|
||||
HAL_TIM_PWM_Start(&htim11, TIM_CHANNEL_1); //start modulating by Mach-Zander modulator
|
||||
while (task.current_param < task.max_param)
|
||||
{
|
||||
if (TIM10_coflag)
|
||||
{
|
||||
Set_LTEC(TT_CHANGE_CURR_1, task.current_param);
|
||||
TIM11 -> CNT = 0; // to link modulator phase
|
||||
task.current_param += task.delta_param;
|
||||
TO10 = 0;
|
||||
TIM10_coflag = 0;
|
||||
|
||||
//HAL_GPIO_WritePin(GPIOD, GPIO_PIN_7, GPIO_PIN_SET);
|
||||
//HAL_GPIO_WritePin(GPIOD, GPIO_PIN_7, GPIO_PIN_RESET);
|
||||
//*
|
||||
if (step_counter % trigger_step == 0){ //trigger at every 60 step
|
||||
OUT_trigger(trigger_counter);
|
||||
++trigger_counter;
|
||||
}
|
||||
++step_counter;
|
||||
//*/
|
||||
//*
|
||||
++task_sheduler;
|
||||
if (task_sheduler >= 10){
|
||||
task_sheduler = 0;
|
||||
}
|
||||
//maintain stable temperature of laser 2
|
||||
if (task_sheduler == 0){
|
||||
(void) MPhD_T(TT_CHANGE_TEMP_2);
|
||||
LD2_param.LD_CURR_TEMP = MPhD_T(TT_CHANGE_TEMP_2);
|
||||
temp16=PID_Controller_Temp(&LD2_curr_setup, &LD2_param, 2);
|
||||
Set_LTEC(TT_CHANGE_TEMP_2, temp16);//Drive Laser TEC 2
|
||||
}
|
||||
//maintain stable temperature of laser 1
|
||||
//*
|
||||
if (task_sheduler == 5){
|
||||
(void) MPhD_T(TT_CHANGE_TEMP_1);
|
||||
LD1_param.LD_CURR_TEMP = MPhD_T(TT_CHANGE_TEMP_1);
|
||||
temp16=PID_Controller_Temp(&LD1_curr_setup, &LD1_param, 1);
|
||||
Set_LTEC(TT_CHANGE_TEMP_1, temp16);//Drive Laser TEC 1
|
||||
}
|
||||
//*/
|
||||
}
|
||||
}
|
||||
HAL_TIM_PWM_Stop(&htim11, TIM_CHANNEL_1); //start modulating by Mach-Zander modulator
|
||||
|
||||
Stop_TIM10();
|
||||
task.current_param = task.min_param;
|
||||
Set_LTEC(TT_CHANGE_CURR_1, task.current_param);
|
||||
@ -376,6 +439,79 @@ int main(void)
|
||||
HAL_TIM_Base_Start_IT(&htim10);
|
||||
break;
|
||||
case TT_CHANGE_CURR_2:
|
||||
//Blink laser 2
|
||||
//*
|
||||
Set_LTEC(TT_CHANGE_CURR_1, task.curr);
|
||||
(void) MPhD_T(TT_CHANGE_TEMP_1);
|
||||
LD1_param.LD_CURR_TEMP = MPhD_T(TT_CHANGE_TEMP_1);
|
||||
(void) MPhD_T(TT_CHANGE_TEMP_2);
|
||||
LD2_param.LD_CURR_TEMP = MPhD_T(TT_CHANGE_TEMP_2);
|
||||
temp16=PID_Controller_Temp(&LD1_curr_setup, &LD1_param, 1);
|
||||
Set_LTEC(TT_CHANGE_TEMP_1, temp16);//Drive Laser TEC 1
|
||||
temp16=PID_Controller_Temp(&LD2_curr_setup, &LD2_param, 2);
|
||||
Set_LTEC(TT_CHANGE_TEMP_2, temp16);//Drive Laser TEC 2
|
||||
|
||||
LD_blinker.task_type = 2;
|
||||
LD_blinker.state = 0; // 0 -- disabled (do nothing); 1 -- update LD current; 2 -- blinking, LD ON now; 3 -- blinking, LD OFF now
|
||||
//LD_blinker.param = task.current_param;
|
||||
LD_blinker.param = 0;
|
||||
LD_blinker.param = 1000; // LD2 current (in unspecified units)
|
||||
LD_blinker.signal_port = OUT_10_GPIO_Port;
|
||||
LD_blinker.signal_pin = OUT_10_Pin;
|
||||
|
||||
TIM8->ARR = 10000; //zero to LD_blinker.param change frequency (also in unspecified units).
|
||||
//When it is too low -- Desktop app crashes (there is not so much compute sources on MCU to anwser to desktop`s questions)
|
||||
st = HAL_TIM_Base_Start_IT(&htim8);
|
||||
if (st != HAL_OK)
|
||||
while(1);
|
||||
// */
|
||||
|
||||
// Toggle pin for oscilloscope
|
||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_7, GPIO_PIN_SET);
|
||||
uint32_t i = 10000; while (--i){}
|
||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_7, GPIO_PIN_RESET);
|
||||
LD_blinker.state = 2;
|
||||
|
||||
st = HAL_TIM_Base_Start_IT(&htim10);
|
||||
if (st != HAL_OK)
|
||||
while(1);
|
||||
while (task.current_param < task.max_param)
|
||||
{
|
||||
if (TIM10_coflag)
|
||||
{
|
||||
//Set_LTEC(TT_CHANGE_CURR_2, task.current_param);
|
||||
//LD_blinker.param = task.current_param;
|
||||
//++LD_blinker.param;
|
||||
task.current_param += task.delta_param;
|
||||
TO10 = 0;
|
||||
TIM10_coflag = 0;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
HAL_TIM_Base_Stop(&htim10);
|
||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_7, GPIO_PIN_SET);
|
||||
|
||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_7, GPIO_PIN_RESET);
|
||||
|
||||
HAL_TIM_Base_Stop_IT(&htim8);
|
||||
TIM8->CNT = 0;
|
||||
|
||||
Stop_TIM10();
|
||||
task.current_param = task.min_param;
|
||||
Set_LTEC(TT_CHANGE_CURR_2, task.current_param);
|
||||
if (task.tau > 3)
|
||||
{
|
||||
TIM10_period = htim10.Init.Period;
|
||||
htim10.Init.Period = 9999;
|
||||
TO10_counter = (task.tau - 1) * 100;
|
||||
}
|
||||
HAL_TIM_Base_Start_IT(&htim10);
|
||||
|
||||
|
||||
//*/
|
||||
|
||||
/* // Backup
|
||||
Set_LTEC(TT_CHANGE_CURR_1, task.curr);
|
||||
(void) MPhD_T(TT_CHANGE_TEMP_1);
|
||||
LD1_param.LD_CURR_TEMP = MPhD_T(TT_CHANGE_TEMP_1);
|
||||
@ -401,6 +537,8 @@ int main(void)
|
||||
task.current_param += task.delta_param;
|
||||
TO10 = 0;
|
||||
TIM10_coflag = 0;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Stop_TIM10();
|
||||
@ -413,6 +551,9 @@ int main(void)
|
||||
TO10_counter = (task.tau - 1) * 100;
|
||||
}
|
||||
HAL_TIM_Base_Start_IT(&htim10);
|
||||
*/
|
||||
|
||||
|
||||
break;
|
||||
case TT_CHANGE_TEMP_1:
|
||||
// isn't implemented
|
||||
@ -1169,6 +1310,53 @@ static void MX_TIM7_Init(void)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TIM8 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_TIM8_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN TIM8_Init 0 */
|
||||
|
||||
/* USER CODE END TIM8_Init 0 */
|
||||
|
||||
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||
|
||||
/* USER CODE BEGIN TIM8_Init 1 */
|
||||
|
||||
/* USER CODE END TIM8_Init 1 */
|
||||
htim8.Instance = TIM8;
|
||||
htim8.Init.Prescaler = 0;
|
||||
htim8.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim8.Init.Period = 91;
|
||||
htim8.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim8.Init.RepetitionCounter = 0;
|
||||
htim8.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_Base_Init(&htim8) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
if (HAL_TIM_ConfigClockSource(&htim8, &sClockSourceConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim8, &sMasterConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN TIM8_Init 2 */
|
||||
|
||||
/* USER CODE END TIM8_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TIM10 Initialization Function
|
||||
* @param None
|
||||
@ -1200,6 +1388,87 @@ static void MX_TIM10_Init(void)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TIM11 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_TIM11_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN TIM11_Init 0 */
|
||||
|
||||
/* USER CODE END TIM11_Init 0 */
|
||||
|
||||
TIM_OC_InitTypeDef sConfigOC = {0};
|
||||
|
||||
/* USER CODE BEGIN TIM11_Init 1 */
|
||||
|
||||
/* USER CODE END TIM11_Init 1 */
|
||||
htim11.Instance = TIM11;
|
||||
htim11.Init.Prescaler = 0;
|
||||
htim11.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim11.Init.Period = 183;
|
||||
htim11.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim11.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
|
||||
if (HAL_TIM_Base_Init(&htim11) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_PWM_Init(&htim11) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 91;
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim11, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN TIM11_Init 2 */
|
||||
|
||||
/* USER CODE END TIM11_Init 2 */
|
||||
HAL_TIM_MspPostInit(&htim11);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief UART8 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_UART8_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN UART8_Init 0 */
|
||||
|
||||
/* USER CODE END UART8_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN UART8_Init 1 */
|
||||
|
||||
/* USER CODE END UART8_Init 1 */
|
||||
huart8.Instance = UART8;
|
||||
huart8.Init.BaudRate = 115200;
|
||||
huart8.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
huart8.Init.StopBits = UART_STOPBITS_1;
|
||||
huart8.Init.Parity = UART_PARITY_NONE;
|
||||
huart8.Init.Mode = UART_MODE_TX_RX;
|
||||
huart8.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||
huart8.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||
huart8.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
||||
huart8.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
||||
if (HAL_UART_Init(&huart8) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN UART8_Init 2 */
|
||||
|
||||
/* USER CODE END UART8_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USART1 Initialization Function
|
||||
* @param None
|
||||
@ -1330,6 +1599,7 @@ static void MX_GPIO_Init(void)
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOF, ADC_MPD2_CS_Pin|SPI5_CNV_Pin|ADC_ThrLD2_CS_Pin, GPIO_PIN_RESET);
|
||||
@ -1350,7 +1620,8 @@ static void MX_GPIO_Init(void)
|
||||
HAL_GPIO_WritePin(SPI4_CNV_GPIO_Port, SPI4_CNV_Pin, GPIO_PIN_SET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOB, REF0_EN_Pin|TEC1_PD_Pin|DAC_LD1_CS_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOB, REF0_EN_Pin|TEC1_PD_Pin|DAC_LD1_CS_Pin|OUT_6_Pin
|
||||
|OUT_7_Pin|OUT_8_Pin|OUT_9_Pin|OUT_10_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(DAC_TEC1_CS_GPIO_Port, DAC_TEC1_CS_Pin, GPIO_PIN_SET);
|
||||
@ -1358,6 +1629,16 @@ static void MX_GPIO_Init(void)
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOD, LD1_EN_Pin|TEST_01_Pin|GPIO_PIN_7, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_9|OUT_0_Pin|OUT_1_Pin|OUT_2_Pin
|
||||
|OUT_3_Pin|OUT_4_Pin|OUT_5_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pins : INP_0_Pin INP_1_Pin */
|
||||
GPIO_InitStruct.Pin = INP_0_Pin|INP_1_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : ADC_MPD2_CS_Pin SPI5_CNV_Pin ADC_ThrLD2_CS_Pin */
|
||||
GPIO_InitStruct.Pin = ADC_MPD2_CS_Pin|SPI5_CNV_Pin|ADC_ThrLD2_CS_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
@ -1408,8 +1689,12 @@ static void MX_GPIO_Init(void)
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
HAL_GPIO_Init(SPI4_CNV_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : REF0_EN_Pin TEC1_PD_Pin DAC_TEC1_CS_Pin DAC_LD1_CS_Pin */
|
||||
GPIO_InitStruct.Pin = REF0_EN_Pin|TEC1_PD_Pin|DAC_TEC1_CS_Pin|DAC_LD1_CS_Pin;
|
||||
/*Configure GPIO pins : REF0_EN_Pin TEC1_PD_Pin DAC_TEC1_CS_Pin DAC_LD1_CS_Pin
|
||||
OUT_6_Pin OUT_7_Pin OUT_8_Pin OUT_9_Pin
|
||||
OUT_10_Pin */
|
||||
GPIO_InitStruct.Pin = REF0_EN_Pin|TEC1_PD_Pin|DAC_TEC1_CS_Pin|DAC_LD1_CS_Pin
|
||||
|OUT_6_Pin|OUT_7_Pin|OUT_8_Pin|OUT_9_Pin
|
||||
|OUT_10_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
@ -1434,11 +1719,14 @@ static void MX_GPIO_Init(void)
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(SDMMC1_EN_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : FPGA_CONF_DONE_Pin */
|
||||
GPIO_InitStruct.Pin = FPGA_CONF_DONE_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
/*Configure GPIO pins : PG9 OUT_0_Pin OUT_1_Pin OUT_2_Pin
|
||||
OUT_3_Pin OUT_4_Pin OUT_5_Pin */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_9|OUT_0_Pin|OUT_1_Pin|OUT_2_Pin
|
||||
|OUT_3_Pin|OUT_4_Pin|OUT_5_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(FPGA_CONF_DONE_GPIO_Port, &GPIO_InitStruct);
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
||||
|
||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||
/* USER CODE END MX_GPIO_Init_2 */
|
||||
@ -1792,9 +2080,66 @@ static void Decode_task(uint16_t *Command, LDx_SetupTypeDef *LD1_curr_setup, LDx
|
||||
TO10_counter = task.dt / 10 - 1;
|
||||
}
|
||||
|
||||
void OUT_trigger(uint8_t out_n)
|
||||
{
|
||||
switch (out_n)
|
||||
{
|
||||
case 0:
|
||||
HAL_GPIO_WritePin(OUT_0_GPIO_Port, OUT_0_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(OUT_0_GPIO_Port, OUT_0_Pin, GPIO_PIN_RESET);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
HAL_GPIO_WritePin(OUT_1_GPIO_Port, OUT_1_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(OUT_1_GPIO_Port, OUT_1_Pin, GPIO_PIN_RESET);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
HAL_GPIO_WritePin(OUT_2_GPIO_Port, OUT_2_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(OUT_2_GPIO_Port, OUT_2_Pin, GPIO_PIN_RESET);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
HAL_GPIO_WritePin(OUT_3_GPIO_Port, OUT_3_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(OUT_3_GPIO_Port, OUT_3_Pin, GPIO_PIN_RESET);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
HAL_GPIO_WritePin(OUT_4_GPIO_Port, OUT_4_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(OUT_4_GPIO_Port, OUT_4_Pin, GPIO_PIN_RESET);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
HAL_GPIO_WritePin(OUT_5_GPIO_Port, OUT_5_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(OUT_5_GPIO_Port, OUT_5_Pin, GPIO_PIN_RESET);
|
||||
break;
|
||||
|
||||
case 6:
|
||||
HAL_GPIO_WritePin(OUT_6_GPIO_Port, OUT_6_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(OUT_6_GPIO_Port, OUT_6_Pin, GPIO_PIN_RESET);
|
||||
break;
|
||||
|
||||
case 7:
|
||||
HAL_GPIO_WritePin(OUT_7_GPIO_Port, OUT_7_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(OUT_7_GPIO_Port, OUT_7_Pin, GPIO_PIN_RESET);
|
||||
break;
|
||||
|
||||
case 8:
|
||||
HAL_GPIO_WritePin(OUT_8_GPIO_Port, OUT_8_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(OUT_8_GPIO_Port, OUT_8_Pin, GPIO_PIN_RESET);
|
||||
break;
|
||||
|
||||
case 9:
|
||||
HAL_GPIO_WritePin(OUT_9_GPIO_Port, OUT_9_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(OUT_9_GPIO_Port, OUT_9_Pin, GPIO_PIN_RESET);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Set_LTEC(uint8_t num, uint16_t DATA)
|
||||
{
|
||||
uint32_t tmp32;
|
||||
|
||||
switch (num)
|
||||
{
|
||||
case 1:
|
||||
@ -1809,7 +2154,8 @@ void Set_LTEC(uint8_t num, uint16_t DATA)
|
||||
(void) SPI2->DR;
|
||||
break;
|
||||
case 2:
|
||||
HAL_GPIO_WritePin(DAC_LD2_CS_GPIO_Port, DAC_LD2_CS_Pin, GPIO_PIN_RESET);//Start operation with LDAC1
|
||||
//HAL_GPIO_TogglePin(OUT_11_GPIO_Port, OUT_11_Pin); //for debug purposes
|
||||
HAL_GPIO_WritePin(DAC_LD2_CS_GPIO_Port, DAC_LD2_CS_Pin, GPIO_PIN_RESET);//Start operation with LDAC2
|
||||
//tmp32=0;
|
||||
//while(tmp32<500){tmp32++;}
|
||||
tmp32 = 0;
|
||||
@ -1820,7 +2166,7 @@ void Set_LTEC(uint8_t num, uint16_t DATA)
|
||||
(void) SPI6->DR;
|
||||
break;
|
||||
case 3:
|
||||
HAL_GPIO_WritePin(DAC_TEC1_CS_GPIO_Port, DAC_TEC1_CS_Pin, GPIO_PIN_RESET);//Start operation with LDAC1
|
||||
HAL_GPIO_WritePin(DAC_TEC1_CS_GPIO_Port, DAC_TEC1_CS_Pin, GPIO_PIN_RESET);//Start operation with TECDAC1
|
||||
//tmp32=0;
|
||||
//while(tmp32<500){tmp32++;}
|
||||
tmp32 = 0;
|
||||
@ -1831,7 +2177,7 @@ void Set_LTEC(uint8_t num, uint16_t DATA)
|
||||
(void) SPI2->DR;
|
||||
break;
|
||||
case 4:
|
||||
HAL_GPIO_WritePin(DAC_TEC2_CS_GPIO_Port, DAC_TEC2_CS_Pin, GPIO_PIN_RESET);//Start operation with LDAC1
|
||||
HAL_GPIO_WritePin(DAC_TEC2_CS_GPIO_Port, DAC_TEC2_CS_Pin, GPIO_PIN_RESET);//Start operation with TECDAC2
|
||||
//tmp32=0;
|
||||
//while(tmp32<500){tmp32++;}
|
||||
tmp32 = 0;
|
||||
@ -1990,6 +2336,64 @@ static uint16_t Get_ADC(uint8_t num)
|
||||
}
|
||||
return OUT;
|
||||
}
|
||||
|
||||
uint16_t Advanced_Controller_Temp(LDx_SetupTypeDef * LDx_curr_setup, LDx_ParamTypeDef * LDx_results, uint8_t num)
|
||||
{
|
||||
// Main idea:
|
||||
// I is responsible to maintaining constant temperature difference between laser and room temperature.
|
||||
// As room temperature can be approximated as constant at current-varying time -- I should be kept constant too.
|
||||
// As current through laser diode heats it -- we can estimate excessive power on laser diode and trim peltier current according to it.
|
||||
// So, equation should be look like this:
|
||||
// x_output = x_output_original + I(laser)*(a + (t - b)c)
|
||||
// t -- cycle phase
|
||||
// a,b,c -- constants
|
||||
//
|
||||
// How can we control laser diode temperature?
|
||||
// -- We can set laser to fixed current at the time we need to measure.
|
||||
// Then we should measure wavelength.
|
||||
// Calibration sequence:
|
||||
// 1) n
|
||||
|
||||
|
||||
|
||||
int e_pid;
|
||||
float P_coef_current;//, I_coef_current;
|
||||
float e_integral;
|
||||
int x_output;
|
||||
|
||||
e_pid = (int) LDx_results->LD_CURR_TEMP - (int) LDx_curr_setup->LD_TEMP;
|
||||
|
||||
e_integral = LDx_results->e_integral;
|
||||
|
||||
if((e_pid < 3000) && (e_pid > - 3000)){
|
||||
e_integral += LDx_curr_setup->I_coef_temp * (float)(e_pid) * (float)(TO7 - TO7_PID) / (float) 100;//100 - timer is too fast
|
||||
}
|
||||
P_coef_current = LDx_curr_setup->P_coef_temp;
|
||||
|
||||
if (e_integral > 32000){
|
||||
e_integral = 32000;
|
||||
}
|
||||
else if (e_integral < - 32000){
|
||||
e_integral = -32000;
|
||||
}
|
||||
LDx_results->e_integral = e_integral;
|
||||
|
||||
x_output = 32768 + P_coef_current * e_pid + (int)e_integral;//32768 - P_coef_current * e_pid - (int)e_integral;//
|
||||
|
||||
if(x_output < 1000){
|
||||
x_output = 8800;
|
||||
}
|
||||
else if(x_output > 56800){
|
||||
x_output = 56800;
|
||||
}
|
||||
|
||||
if (num==2)
|
||||
TO7_PID = TO7;//Save current time only on 2nd laser
|
||||
|
||||
return (uint16_t)x_output;
|
||||
}
|
||||
|
||||
|
||||
uint16_t PID_Controller_Temp(LDx_SetupTypeDef * LDx_curr_setup, LDx_ParamTypeDef * LDx_results, uint8_t num)
|
||||
{
|
||||
int e_pid;
|
||||
|
||||
Reference in New Issue
Block a user