configured external ADC sync and Mach-Zander modulation clocks at 2 and 1 MHz respectively
This commit is contained in:
88
Src/main.c
88
Src/main.c
@ -47,6 +47,7 @@ ADC_HandleTypeDef hadc3;
|
||||
|
||||
SD_HandleTypeDef hsd1;
|
||||
|
||||
TIM_HandleTypeDef htim4;
|
||||
TIM_HandleTypeDef htim8;
|
||||
TIM_HandleTypeDef htim10;
|
||||
TIM_HandleTypeDef htim11;
|
||||
@ -93,6 +94,7 @@ static void MX_TIM10_Init(void);
|
||||
static void MX_UART8_Init(void);
|
||||
static void MX_TIM8_Init(void);
|
||||
static void MX_TIM11_Init(void);
|
||||
static void MX_TIM4_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);
|
||||
@ -166,6 +168,7 @@ int main(void)
|
||||
MX_UART8_Init();
|
||||
MX_TIM8_Init();
|
||||
MX_TIM11_Init();
|
||||
MX_TIM4_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
Init_params();
|
||||
HAL_TIM_Base_Start(&htim11);
|
||||
@ -383,12 +386,14 @@ int main(void)
|
||||
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
|
||||
HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_3); //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
|
||||
TIM4 -> CNT = 0; // to link ADC clock phase
|
||||
task.current_param += task.delta_param;
|
||||
TO10 = 0;
|
||||
TIM10_coflag = 0;
|
||||
@ -426,8 +431,10 @@ int main(void)
|
||||
}
|
||||
}
|
||||
HAL_TIM_PWM_Stop(&htim11, TIM_CHANNEL_1); //start modulating by Mach-Zander modulator
|
||||
HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_3); //start modulating by Mach-Zander modulator
|
||||
|
||||
Stop_TIM10();
|
||||
|
||||
task.current_param = task.min_param;
|
||||
Set_LTEC(TT_CHANGE_CURR_1, task.current_param);
|
||||
if (task.tau > 3)
|
||||
@ -456,8 +463,8 @@ int main(void)
|
||||
//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;
|
||||
LD_blinker.signal_port = OUT_9_GPIO_Port;
|
||||
LD_blinker.signal_pin = OUT_9_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)
|
||||
@ -1197,6 +1204,65 @@ static void MX_TIM2_Init(void)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TIM4 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_TIM4_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN TIM4_Init 0 */
|
||||
|
||||
/* USER CODE END TIM4_Init 0 */
|
||||
|
||||
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||
TIM_OC_InitTypeDef sConfigOC = {0};
|
||||
|
||||
/* USER CODE BEGIN TIM4_Init 1 */
|
||||
|
||||
/* USER CODE END TIM4_Init 1 */
|
||||
htim4.Instance = TIM4;
|
||||
htim4.Init.Prescaler = 0;
|
||||
htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim4.Init.Period = 45;
|
||||
htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_Base_Init(&htim4) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
if (HAL_TIM_ConfigClockSource(&htim4, &sClockSourceConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_PWM_Init(&htim4) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 22;
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN TIM4_Init 2 */
|
||||
|
||||
/* USER CODE END TIM4_Init 2 */
|
||||
HAL_TIM_MspPostInit(&htim4);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TIM5 Initialization Function
|
||||
* @param None
|
||||
@ -1422,7 +1488,7 @@ static void MX_TIM11_Init(void)
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 91;
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim11, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
@ -1588,8 +1654,8 @@ static void MX_DMA_Init(void)
|
||||
static void MX_GPIO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||
/* USER CODE END MX_GPIO_Init_1 */
|
||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||
/* USER CODE END MX_GPIO_Init_1 */
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||
@ -1621,7 +1687,7 @@ static void MX_GPIO_Init(void)
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
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);
|
||||
|OUT_7_Pin|OUT_8_Pin|OUT_9_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(DAC_TEC1_CS_GPIO_Port, DAC_TEC1_CS_Pin, GPIO_PIN_SET);
|
||||
@ -1690,11 +1756,9 @@ static void MX_GPIO_Init(void)
|
||||
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
|
||||
OUT_6_Pin OUT_7_Pin OUT_8_Pin OUT_9_Pin
|
||||
OUT_10_Pin */
|
||||
OUT_6_Pin OUT_7_Pin OUT_8_Pin OUT_9_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;
|
||||
|OUT_6_Pin|OUT_7_Pin|OUT_8_Pin|OUT_9_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
@ -1728,8 +1792,8 @@ static void MX_GPIO_Init(void)
|
||||
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 */
|
||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||
/* USER CODE END MX_GPIO_Init_2 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
|
||||
Reference in New Issue
Block a user