diff --git a/Src/main.c b/Src/main.c index 8a705f4..8644d57 100644 --- a/Src/main.c +++ b/Src/main.c @@ -181,15 +181,28 @@ int main(void) //TIM4 -> ARR = 60; // for 1.5 MHz //TIM4 -> ARR = 91; // for 1 MHz //TIM4 -> ARR = 45; // for 2 MHz - TIM4 -> ARR = 53; // for 1.735 MHz. It`s the highest frequency for correct ADC work. At higher freq artifacts (voltage peaks) appears. +// TIM4 -> ARR = 53; // for 1.735 MHz. It`s the highest frequency for correct ADC work. At higher freq artifacts (voltage peaks) appears. + //TIM4 -> ARR = 100; // for 1.735 MHz. It`s the highest frequency for correct ADC work. At higher freq artifacts (voltage peaks) appears. + + TIM4 -> ARR = 37; //for 2.42 MHz. Highest freq for stm_ADC based on stm32G431-- 2.8 MHz TIM4 -> CCR3 = (TIM4 -> ARR +1)/2 - 1; - //Mach-Zander clock (should be 1/4 of ADC clock freq) + //for E502_ADC + + //Mach-Zander clock (should be half of ADC clock freq) + //TIM11 -> ARR = (TIM4 -> ARR +1)*2 - 1; + //TIM11 -> CCR1 = (TIM11 -> ARR +1)/2 - 1; + + + // for stm_ADC + + //Mach-Zander clock equal to ADC clock (adc triggers on rising and falling edges) + TIM11 -> ARR = TIM4 -> ARR; + TIM11 -> CCR1 = (TIM11 -> ARR +1)/2 - 1; //duty 50% + - TIM11 -> ARR = (TIM4 -> ARR +1)*4 - 1; - TIM11 -> CCR1 = (TIM11 -> ARR +1)/2 - 1; /* if (HAL_GPIO_ReadPin(INP_0_GPIO_Port, INP_0_Pin) == 0){ @@ -399,6 +412,14 @@ int main(void) //TIM11 -> CCR1 = (TIM11 -> ARR +1)/2 - 1; + //for stm_ADC + //TIM4 -- ADC clock. Rising edge -- for SYNC_DETector_ON + //TIM4 -- ADC clock. Falling edge -- for SYNC_DETector_OFF + + //TIM4 freq is equal to TIM11 + //TIM4 phase should be adjustable to get correct sampling moment + + Set_LTEC(TT_CHANGE_CURR_2, task.curr); (void) MPhD_T(TT_CHANGE_TEMP_1); @@ -411,8 +432,9 @@ int main(void) Set_LTEC(TT_CHANGE_TEMP_2, temp16);//Drive Laser TEC 2 // Toggle pin for oscilloscope - HAL_GPIO_WritePin(GPIOD, GPIO_PIN_7, GPIO_PIN_SET); //start of the whole frequency sweep procedure - HAL_GPIO_WritePin(GPIOD, GPIO_PIN_7, GPIO_PIN_RESET); + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_7, GPIO_PIN_SET); //start of the whole frequency sweep procedure (start trigger pulse) + //for (uint32_t i = 100000; i; --i){;} + st = HAL_TIM_Base_Start_IT(&htim10); if (st != HAL_OK) @@ -442,26 +464,43 @@ int main(void) TIM4 -> CNT = TIM4 -> ARR - 20; // not zero to make phase shift that will be robust to big delay in RF subsystem (up to ~400 ns) TIM11 -> CNT = 0; + uint32_t curr_step_N = 0; + uint32_t postAmpl_1_en_curr_step_N = ((task.max_param - task.current_param)/3.0 * 1.0) / task.delta_param; + uint32_t postAmpl_2_en_curr_step_N = ((task.max_param - task.current_param)/3.0 * 2.0) / task.delta_param; + while (task.current_param < task.max_param) { if (TIM10_coflag) { Set_LTEC(TT_CHANGE_CURR_1, task.current_param); + HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_9); //toggle PG9. Change indicates that current step started. + //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; - HAL_GPIO_WritePin(GPIOG, GPIO_PIN_9, GPIO_PIN_SET); // set the current step laser current trigger - HAL_GPIO_WritePin(GPIOG, GPIO_PIN_9, GPIO_PIN_RESET); + if (curr_step_N == postAmpl_1_en_curr_step_N){ + HAL_GPIO_WritePin(OUT_6_GPIO_Port, OUT_6_Pin, GPIO_PIN_SET); + } + if (curr_step_N == postAmpl_2_en_curr_step_N){ + HAL_GPIO_WritePin(OUT_7_GPIO_Port, OUT_7_Pin, GPIO_PIN_SET);; + } + + + + //HAL_GPIO_WritePin(GPIOG, GPIO_PIN_9, GPIO_PIN_SET); // set the current step laser current trigger + //HAL_GPIO_WritePin(GPIOG, GPIO_PIN_9, GPIO_PIN_RESET); //* if (step_counter % trigger_step == 0){ //trigger at every 60 step OUT_trigger(trigger_counter); ++trigger_counter; } ++step_counter; + + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_7, GPIO_PIN_RESET); //stop trigger pulse //*/ /* ++task_sheduler; @@ -497,6 +536,8 @@ int main(void) Stop_TIM10(); + HAL_GPIO_WritePin(OUT_6_GPIO_Port, OUT_6_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(OUT_7_GPIO_Port, OUT_7_Pin, GPIO_PIN_RESET); task.current_param = task.min_param; Set_LTEC(TT_CHANGE_CURR_1, task.current_param);