diff --git a/usrc/config_service.c b/usrc/config_service.c index e8c102b..47812c5 100644 --- a/usrc/config_service.c +++ b/usrc/config_service.c @@ -6,13 +6,13 @@ static config_t _default_val_config; #define TAG "config" static void create_default_config(config_t *default_cfg) { // - default_cfg->light_intensity = 50; - default_cfg->pulse_width_x25ns = 30 * 4; - default_cfg->pulse_interval_x25ns = 1 * 4; - default_cfg->shutter_delay_x25ns = 1 * 4; - default_cfg->shutter_delay_x25ns = 1 * 4; - default_cfg->trigger_mirror = 1; - default_cfg->cmd_echo = 1; + default_cfg->light_intensity = 50; + default_cfg->pulse_width_x250ns = 30 * 4; + default_cfg->pulse_interval_x250ns = 1 * 4; + default_cfg->shutter_delay_x250ns = 1 * 4; + default_cfg->shutter_delay_x250ns = 1 * 4; + default_cfg->trigger_mirror = 1; + default_cfg->cmd_echo = 1; } void config_init(void) { diff --git a/usrc/config_service.h b/usrc/config_service.h index 3a82c46..c0221cf 100644 --- a/usrc/config_service.h +++ b/usrc/config_service.h @@ -9,9 +9,9 @@ extern "C" { typedef struct { uint32_t config_mark; uint32_t light_intensity; // 光强 0->100 - uint32_t pulse_width_x25ns; // 脉冲宽度 - uint32_t pulse_interval_x25ns; // 脉冲间隔 - uint32_t shutter_delay_x25ns; // 快门延时 + uint32_t pulse_width_x250ns; // 脉冲宽度 + uint32_t pulse_interval_x250ns; // 脉冲间隔 + uint32_t shutter_delay_x250ns; // 快门延时 uint32_t trigger_mirror; // 触发镜像 uint32_t cmd_echo; // 命令回显 uint32_t checksum; // diff --git a/usrc/light_intensity_ctrl.c b/usrc/light_intensity_ctrl.c index 655ca3f..9b7f440 100644 --- a/usrc/light_intensity_ctrl.c +++ b/usrc/light_intensity_ctrl.c @@ -23,10 +23,13 @@ void LightIntensityCtrl_start() { uint32_t autoreload = 0; // 设置频率 - uint32_t timClkFreq = chip_get_timer_clock_sorce_freq(m_htim); - ZASSERT(timClkFreq = 72000000); - prescaler = 71; - autoreload = 999; + // uint32_t timClkFreq = chip_get_timer_clock_sorce_freq(m_htim); + // ZASSERT(timClkFreq = 72000000); + // prescaler = 0; + // autoreload = 1000; + prescaler = 0; + autoreload = 143; + // ZASSERT(chip_calculate_prescaler_and_autoreload_by_expect_freq(timClkFreq, m_freq, &prescaler, &autoreload)); // m_htim-> @@ -55,7 +58,7 @@ void LightIntensityCtrl_start() { ZSTM32_CHECK(HAL_TIM_PWM_Start(m_htim, TIM_CHANNEL_1)); ZSTM32_CHECK(HAL_TIM_PWM_Start(m_htim, TIM_CHANNEL_2)); ZSTM32_CHECK(HAL_TIM_PWM_Start(m_htim, TIM_CHANNEL_3)); - ZSTM32_CHECK(HAL_TIM_PWM_Start(m_htim, TIM_CHANNEL_4)); + ZSTM32_CHECK(HAL_TIM_PWM_Start(m_htim, TIM_CHANNEL_4)); } void LightIntensityCtrl_updatePraram() { diff --git a/usrc/pluse_generator.c b/usrc/pluse_generator.c index 9912956..3c3ebff 100644 --- a/usrc/pluse_generator.c +++ b/usrc/pluse_generator.c @@ -23,11 +23,11 @@ void PluseGenerator_cfg_update() { uint32_t timClkFreq; ZASSERT(&PLUSE_CTRL_TIMER == &htim5); - cfg = config_get(); + cfg = config_get(); // timClkFreq = chip_get_timer_clock_sorce_freq(&PLUSE_CTRL_TIMER); // ZASSERT(timClkFreq = 36000000); - prescaler = 17; // 4M 0.25us + prescaler = 17; // 4M 0.25us autoreload = 4 * 1000; // 1ms // m_htim-> @@ -47,11 +47,11 @@ void PluseGenerator_cfg_update() { sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET; sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET; - sConfigOC.Pulse = cfg->pulse_width_x25ns; + sConfigOC.Pulse = cfg->pulse_width_x250ns; ZSTM32_CHECK(HAL_TIM_PWM_ConfigChannel(m_htim, &sConfigOC, TIM_CHANNEL_1)); - sConfigOC.Pulse = cfg->pulse_interval_x25ns; + sConfigOC.Pulse = cfg->pulse_interval_x250ns; ZSTM32_CHECK(HAL_TIM_PWM_ConfigChannel(m_htim, &sConfigOC, TIM_CHANNEL_2)); - sConfigOC.Pulse = cfg->shutter_delay_x25ns; + sConfigOC.Pulse = cfg->shutter_delay_x250ns; ZSTM32_CHECK(HAL_TIM_PWM_ConfigChannel(m_htim, &sConfigOC, TIM_CHANNEL_3)); ZSTM32_CHECK(HAL_TIM_PWM_Start(m_htim, TIM_CHANNEL_1)); @@ -60,4 +60,9 @@ void PluseGenerator_cfg_update() { // TRIGGER_MIRROR_CTRL_PIN zgpio_write(&trigger_mirror_ctrl_io, cfg->trigger_mirror); + + HAL_Delay(1000); + ZSTM32_CHECK(HAL_TIM_PWM_Stop(m_htim, TIM_CHANNEL_1)); + ZSTM32_CHECK(HAL_TIM_PWM_Stop(m_htim, TIM_CHANNEL_2)); + ZSTM32_CHECK(HAL_TIM_PWM_Stop(m_htim, TIM_CHANNEL_3)); } diff --git a/usrc/umain.c b/usrc/umain.c index 404afbe..b272056 100644 --- a/usrc/umain.c +++ b/usrc/umain.c @@ -75,28 +75,28 @@ void prv_process_uart_rx_data() { cfg->light_intensity = val; LightIntensityCtrl_updatePraram(); printf("OK\n"); - } else if (strcmp(param, "pulse_width_x25ns") == 0) { + } else if (strcmp(param, "pulse_width_x250ns") == 0) { if (val <= 0 || val > 100 * 8) { - printf("FAIL,pulse_width_x25ns should be in range 1-800\n"); + printf("FAIL,pulse_width_x250ns should be in range 1-800\n"); return; } - cfg->pulse_width_x25ns = val; + cfg->pulse_width_x250ns = val; PluseGenerator_cfg_update(); printf("OK\n"); - } else if (strcmp(param, "pulse_interval_x25ns") == 0) { + } else if (strcmp(param, "pulse_interval_x250ns") == 0) { if (val <= 0 || val > 100 * 8) { - printf("FAIL,pulse_interval_x25ns should be in range 1-800\n"); + printf("FAIL,pulse_interval_x250ns should be in range 1-800\n"); return; } - cfg->pulse_interval_x25ns = val; + cfg->pulse_interval_x250ns = val; PluseGenerator_cfg_update(); printf("OK\n"); - } else if (strcmp(param, "shutter_delay_x25ns") == 0) { + } else if (strcmp(param, "shutter_delay_x250ns") == 0) { if (val <= 0 || val > 100 * 8) { - printf("FAIL,shutter_delay_x25ns should be in range 1-800\n"); + printf("FAIL,shutter_delay_x250ns should be in range 1-800\n"); return; } - cfg->shutter_delay_x25ns = val; + cfg->shutter_delay_x250ns = val; PluseGenerator_cfg_update(); printf("OK\n"); } @@ -127,12 +127,12 @@ void prv_process_uart_rx_data() { const char *param = argc[1]; if (strcmp(param, "light_intensity") == 0) { printf("OK,%ld\n", cfg->light_intensity); - } else if (strcmp(param, "pulse_width_x25ns") == 0) { - printf("OK,%ld\n", cfg->pulse_width_x25ns); - } else if (strcmp(param, "pulse_interval_x25ns") == 0) { - printf("OK,%ld\n", cfg->pulse_interval_x25ns); - } else if (strcmp(param, "shutter_delay_x25ns") == 0) { - printf("OK,%ld\n", cfg->shutter_delay_x25ns); + } else if (strcmp(param, "pulse_width_x250ns") == 0) { + printf("OK,%ld\n", cfg->pulse_width_x250ns); + } else if (strcmp(param, "pulse_interval_x250ns") == 0) { + printf("OK,%ld\n", cfg->pulse_interval_x250ns); + } else if (strcmp(param, "shutter_delay_x250ns") == 0) { + printf("OK,%ld\n", cfg->shutter_delay_x250ns); } else if (strcmp(param, "trigger_mirror") == 0) { printf("OK,%ld\n", cfg->trigger_mirror); } else if (strcmp(param, "cmd_echo") == 0) { @@ -158,9 +158,9 @@ void prv_process_uart_rx_data() { config_t *cfg = config_get(); printf("------ param list ------\n"); printf(" light_intensity : %ld\n", cfg->light_intensity); - printf(" pulse_width_x25ns : %ld\n", cfg->pulse_width_x25ns); - printf(" pulse_interval_x25ns : %ld\n", cfg->pulse_interval_x25ns); - printf(" shutter_delay_x25ns : %ld\n", cfg->shutter_delay_x25ns); + printf(" pulse_width_x250ns : %ld\n", cfg->pulse_width_x250ns); + printf(" pulse_interval_x250ns : %ld\n", cfg->pulse_interval_x250ns); + printf(" shutter_delay_x250ns : %ld\n", cfg->shutter_delay_x250ns); printf(" trigger_mirror : %ld\n", cfg->trigger_mirror); printf(" cmd_echo : %ld\n", cfg->cmd_echo); diff --git a/zlib/ztim.c b/zlib/ztim.c index 2798724..80bb7d1 100644 --- a/zlib/ztim.c +++ b/zlib/ztim.c @@ -39,46 +39,50 @@ bool chip_calculate_prescaler_and_autoreload_by_expect_freq(uint32_t timerInClk, return true; } -uint32_t chip_get_timer_clock_sorce_freq(TIM_HandleTypeDef* tim) { - uint32_t timClkFreq = 0; -#if 0 - uint32_t pclk1Freq = HAL_RCC_GetPCLK1Freq(); - uint32_t pclk2Freq = HAL_RCC_GetPCLK2Freq(); - uint32_t sysClkFreq = HAL_RCC_GetSysClockFreq(); -#endif +/******************************************************************************* + * 下面这个方法不适用于F103 * + *******************************************************************************/ - uint32_t pFLatency; - RCC_ClkInitTypeDef clkconfig; - HAL_RCC_GetClockConfig(&clkconfig, &pFLatency); - bool isAPB2 = false; +// uint32_t chip_get_timer_clock_sorce_freq(TIM_HandleTypeDef* tim) { +// uint32_t timClkFreq = 0; +// #if 0 +// uint32_t pclk1Freq = HAL_RCC_GetPCLK1Freq(); +// uint32_t pclk2Freq = HAL_RCC_GetPCLK2Freq(); +// uint32_t sysClkFreq = HAL_RCC_GetSysClockFreq(); +// #endif -#ifdef TIM1 - if (tim->Instance == TIM1) isAPB2 = true; -#endif -#ifdef TIM8 - if (tim->Instance == TIM8) isAPB2 = true; -#endif -#ifdef TIM9 - if (tim->Instance == TIM9) isAPB2 = true; -#endif -#ifdef TIM10 - if (tim->Instance == TIM10) isAPB2 = true; -#endif -#ifdef TIM11 - if (tim->Instance == TIM11) isAPB2 = true; -#endif - if (isAPB2) { - if (clkconfig.APB2CLKDivider == RCC_HCLK_DIV1) { - timClkFreq = HAL_RCC_GetPCLK2Freq(); - } else { - timClkFreq = 2 * HAL_RCC_GetPCLK2Freq(); - } - } else { - if (clkconfig.APB1CLKDivider == RCC_HCLK_DIV1) { - timClkFreq = HAL_RCC_GetPCLK1Freq(); - } else { - timClkFreq = 2 * HAL_RCC_GetPCLK1Freq(); - } - } - return timClkFreq; -} +// uint32_t pFLatency; +// RCC_ClkInitTypeDef clkconfig; +// HAL_RCC_GetClockConfig(&clkconfig, &pFLatency); +// bool isAPB2 = false; + +// #ifdef TIM1 +// if (tim->Instance == TIM1) isAPB2 = true; +// #endif +// #ifdef TIM8 +// if (tim->Instance == TIM8) isAPB2 = true; +// #endif +// #ifdef TIM9 +// if (tim->Instance == TIM9) isAPB2 = true; +// #endif +// #ifdef TIM10 +// if (tim->Instance == TIM10) isAPB2 = true; +// #endif +// #ifdef TIM11 +// if (tim->Instance == TIM11) isAPB2 = true; +// #endif +// if (isAPB2) { +// if (clkconfig.APB2CLKDivider == RCC_HCLK_DIV1) { +// timClkFreq = HAL_RCC_GetPCLK2Freq(); +// } else { +// timClkFreq = 2 * HAL_RCC_GetPCLK2Freq(); +// } +// } else { +// if (clkconfig.APB1CLKDivider == RCC_HCLK_DIV1) { +// timClkFreq = HAL_RCC_GetPCLK1Freq(); +// } else { +// timClkFreq = 2 * HAL_RCC_GetPCLK1Freq(); +// } +// } +// return timClkFreq; +// } diff --git a/zlib/ztim.h b/zlib/ztim.h index 6e11a3b..a04d353 100644 --- a/zlib/ztim.h +++ b/zlib/ztim.h @@ -6,4 +6,4 @@ #include "main.h" bool chip_calculate_prescaler_and_autoreload_by_expect_freq(uint32_t timerInClk, float infreqhz, uint32_t* prescaler, uint32_t* autoreload); -uint32_t chip_get_timer_clock_sorce_freq(TIM_HandleTypeDef* tim); +// uint32_t chip_get_timer_clock_sorce_freq(TIM_HandleTypeDef* tim);