Browse Source

Добавли прогрев для таймера

dtelenkov 1 month ago
parent
commit
b37df37c02
7 changed files with 650 additions and 691 deletions
  1. BIN
      bin/sprut.bin
  2. 134 130
      modules/tim.c
  3. 31 30
      modules/tim.h
  4. BIN
      output/sprut.bin
  5. 370 419
      project/ewarm/drone.dep
  6. 2 2
      project/settings/muvie_string_controller.wsdt
  7. 113 110
      user/main.c

BIN
bin/sprut.bin


+ 134 - 130
modules/tim.c

@@ -1,130 +1,134 @@
-#include "stm32f0xx_hal.h"
-#include "tim.h"
-#include "led.h"
-#include "button.h"
-#include "logic.h"
-
-
-TIM_HandleTypeDef    Tim16Handle;
-TIM_HandleTypeDef    Tim17Handle;
-
-extern uint16_t freq_voltage;
-
-
-// TIM17 - индикация нажатия курка
-// TIM16 - отвечает за частоту срабатывания строки
-void tim_init(void)
-{
-    __HAL_RCC_TIM16_CLK_ENABLE();
-    __HAL_RCC_TIM17_CLK_ENABLE();  
-    
-    Tim16Handle.Instance               = TIM16;
-    Tim16Handle.Init.Period            = 1000 - 1;
-    Tim16Handle.Init.Prescaler         = 48000 - 1;
-    Tim16Handle.Init.ClockDivision     = 0;
-    Tim16Handle.Init.CounterMode       = TIM_COUNTERMODE_UP;
-    Tim16Handle.Init.RepetitionCounter = 0;
-    Tim16Handle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
-    HAL_TIM_Base_Init(&Tim16Handle);
-    
-    HAL_NVIC_SetPriority(TIM16_IRQn, 2, 0);
- 
-    HAL_NVIC_EnableIRQ(TIM16_IRQn);
-    HAL_TIM_Base_Start_IT(&Tim16Handle);
-    
-    
-    Tim17Handle.Instance               = TIM17;
-    Tim17Handle.Init.Period            = 1000 - 1;
-    Tim17Handle.Init.Prescaler         = 48000 - 1;
-    Tim17Handle.Init.ClockDivision     = 0;
-    Tim17Handle.Init.CounterMode       = TIM_COUNTERMODE_UP;
-    Tim17Handle.Init.RepetitionCounter = 0;
-    Tim17Handle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; //TIM_AUTORELOAD_PRELOAD_DISABLE;
-    HAL_TIM_Base_Init(&Tim17Handle);
-    
-    HAL_NVIC_SetPriority(TIM17_IRQn, 2, 0);
- 
-    HAL_NVIC_EnableIRQ(TIM17_IRQn);
-    //HAL_TIM_Base_Start_IT(&Tim17Handle);
-}
-
-
-//
-void tim_set_string_timer(bool state)
-{
-    if (state) {
-        TIM17->CNT = 0;
-        HAL_TIM_Base_Start_IT(&Tim17Handle);
-    }
-    else {
-        HAL_TIM_Base_Stop_IT(&Tim17Handle);
-    }
-}
-
-//
-void tim_set_string_freq(void)
-{
-    TIM16->PSC = 11.707*(float)freq_voltage + 47;
-    
-    TIM17->PSC = 11.707*(float)freq_voltage + 47;
-}
-
-
-
-//
-void tim_signal_start(void)
-{
-    __HAL_TIM_CLEAR_IT(&Tim17Handle, TIM_IT_UPDATE);
-    HAL_TIM_Base_Start_IT(&Tim17Handle);
-}
-
-
-//
-void tim_inf_set_time(uint16_t time)
-{
-    __HAL_TIM_CLEAR_IT(&Tim16Handle, TIM_IT_UPDATE);
-    TIM16->ARR = time;
-    HAL_TIM_Base_Start_IT(&Tim16Handle);
-}
-
-
-//
-void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
-{
-    if (htim->Instance == TIM16) 
-    {
-        //HAL_TIM_Base_Stop_IT(&Tim16Handle);
-#if 1      
-        if (but_is_string()) {
-            led_freq_toggle();
-        }
-#endif        
-    } 
-    else if (htim->Instance == TIM17) 
-    {
-        logic_string_next();
-        //HAL_TIM_Base_Stop_IT(&Tim17Handle);
-    }
-}
-
-
-//
-void TIM16_IRQHandler(void)
-{
-    HAL_TIM_IRQHandler(&Tim16Handle);
-}
-
-
-//
-void TIM17_IRQHandler(void)
-{
-    HAL_TIM_IRQHandler(&Tim17Handle);
-}
-
-
-#if 0
-void TIM1_BRK_UP_TRG_COM_IRQHandler(void)
-{
-    HAL_TIM_IRQHandler(&TimHandle);
-}
-#endif
+#include "stm32f0xx_hal.h"
+#include "tim.h"
+#include "led.h"
+#include "button.h"
+#include "logic.h"
+
+
+TIM_HandleTypeDef    Tim16Handle;
+TIM_HandleTypeDef    Tim17Handle;
+
+extern uint16_t freq_voltage;
+
+
+// TIM17 - индикация нажатия курка
+// TIM16 - отвечает за частоту срабатывания строки
+void tim_init(void)
+{
+    __HAL_RCC_TIM16_CLK_ENABLE();
+    __HAL_RCC_TIM17_CLK_ENABLE();  
+    
+    Tim16Handle.Instance               = TIM16;
+    Tim16Handle.Init.Period            = 1000 - 1;
+    Tim16Handle.Init.Prescaler         = 48000 - 1;
+    Tim16Handle.Init.ClockDivision     = 0;
+    Tim16Handle.Init.CounterMode       = TIM_COUNTERMODE_UP;
+    Tim16Handle.Init.RepetitionCounter = 0;
+    Tim16Handle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
+    HAL_TIM_Base_Init(&Tim16Handle);
+    
+    HAL_NVIC_SetPriority(TIM16_IRQn, 2, 0);
+ 
+    HAL_NVIC_EnableIRQ(TIM16_IRQn);
+    HAL_TIM_Base_Start_IT(&Tim16Handle);
+    
+    
+    Tim17Handle.Instance               = TIM17;
+    Tim17Handle.Init.Period            = 1000 - 1;
+    Tim17Handle.Init.Prescaler         = 48000 - 1;
+    Tim17Handle.Init.ClockDivision     = 0;
+    Tim17Handle.Init.CounterMode       = TIM_COUNTERMODE_UP;
+    Tim17Handle.Init.RepetitionCounter = 0;
+    Tim17Handle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; //TIM_AUTORELOAD_PRELOAD_DISABLE;
+    HAL_TIM_Base_Init(&Tim17Handle);
+    
+    HAL_NVIC_SetPriority(TIM17_IRQn, 2, 0);
+ 
+    HAL_NVIC_EnableIRQ(TIM17_IRQn);
+    //HAL_TIM_Base_Start_IT(&Tim17Handle);
+}
+
+
+//
+void tim_set_string_timer(bool state)
+{
+    if (state) {
+        TIM17->CNT = 0;
+        HAL_TIM_Base_Start_IT(&Tim17Handle);
+    }
+    else {
+        HAL_TIM_Base_Stop_IT(&Tim17Handle);
+    }
+}
+
+//
+void tim_set_string_freq(void)
+{
+    TIM16->PSC = 11.707*(float)freq_voltage + 47;
+    
+    TIM17->PSC = 11.707*(float)freq_voltage + 47;
+}
+
+
+
+//
+void tim_signal_start(void)
+{
+    __HAL_TIM_CLEAR_IT(&Tim17Handle, TIM_IT_UPDATE);
+    HAL_TIM_Base_Start_IT(&Tim17Handle);
+}
+
+
+//
+void tim_inf_set_time(uint16_t time)
+{
+    __HAL_TIM_CLEAR_IT(&Tim16Handle, TIM_IT_UPDATE);
+    TIM16->ARR = time;
+    HAL_TIM_Base_Start_IT(&Tim16Handle);
+}
+
+
+//
+void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
+{
+    static bool warmup = false;
+    
+    if (htim->Instance == TIM16) 
+    {
+        if (but_is_string()) {
+            led_freq_toggle();
+        }
+    } 
+    else if (htim->Instance == TIM17) 
+    {
+        if (warmup) {
+            logic_string_next();
+        }
+        else {
+            warmup = true;
+            HAL_TIM_Base_Stop_IT(&Tim17Handle);
+        }
+    }
+}
+
+
+// Сразу после настройки таймера TIM17 делаем разовое срабатывание
+void tim_warmup(void)
+{
+    TIM17->PSC = 47;
+    tim_set_string_timer(true);
+}
+
+//
+void TIM16_IRQHandler(void)
+{
+    HAL_TIM_IRQHandler(&Tim16Handle);
+}
+
+
+//
+void TIM17_IRQHandler(void)
+{
+    HAL_TIM_IRQHandler(&Tim17Handle);
+}
+

+ 31 - 30
modules/tim.h

@@ -1,31 +1,32 @@
-#ifndef __TIM_H
-#define __TIM_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-  
-#include <stdbool.h>  
-  
-//
-void tim_init(void);
-
-//
-void tim_set_string_timer(bool state);
-
-//
-void tim_set_string_freq(void);
-
-//
-void tim_signal_start(void);
-
-//
-void tim_inf_set_time(uint16_t time);
-
-
-  
-#ifdef __cplusplus
-}
-#endif
-  
+#ifndef __TIM_H
+#define __TIM_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+  
+#include <stdbool.h>  
+  
+//
+void tim_init(void);
+
+//
+void tim_set_string_timer(bool state);
+
+//
+void tim_set_string_freq(void);
+
+//
+void tim_signal_start(void);
+
+//
+void tim_inf_set_time(uint16_t time);
+
+//
+void tim_warmup(void);
+  
+#ifdef __cplusplus
+}
+#endif
+  
 #endif

BIN
output/sprut.bin


File diff suppressed because it is too large
+ 370 - 419
project/ewarm/drone.dep


File diff suppressed because it is too large
+ 2 - 2
project/settings/muvie_string_controller.wsdt


+ 113 - 110
user/main.c

@@ -1,110 +1,113 @@
-#include "stm32f0xx_hal.h"
-#include "led.h"
-#include "button.h"
-#include "adc.h"
-#include "tim.h"
-#include "misc.h"
-#include "systick.h"
-#include "usart.h"
-#include "pwm_out.h"
-#include "pwm_in.h"
-#include "gpio.h"
-#include "logic.h"
-#include <stdio.h>
-
-
-void SystemClock_Config(void);
-void Error_Handler(void);
-
-
-
-
-int main()
-{
-    HAL_Init();
-    SystemClock_Config();
-/*     
-    gpio_init();
-    tim_pwm_out_init();
-    tim_pwm_in_init();
-
-    wdt_init();
-*/    
-    channel_init();
-    led_init();
-    adc_init();
-    tim_init();
-    but_init();
-    
-    
-#if 1    
-    usart_init();
-    printf("FW started...\r\n");
-#endif    
-    
-    HAL_Delay(1000);
-    //tim_set_string_freq(1);
-    
-    timer_AddFunction(10, adc_task);
-    timer_AddFunction(10, button_run);
-    
-    timer_AddFunction(10, logic_cnt_task);
-    
-    timer_AddFunction(100, logic_led_freq);
-    
-    //bool foo;
-    //foo = but_is_string();
-    
-    while(1) 
-    {
-        timer_Main();
-        
-        //adc_print_data();
-        //adc_task();
-        //adc_task();
-        //printf("CNT: %u\r\n", counter++);
-        //HAL_Delay(1000);
-        //logic_main();
-    }
-}
-
-
-
-void SystemClock_Config(void)
-{
-    RCC_OscInitTypeDef RCC_OscInitStruct = {0};
-    RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
-    
-    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI14;
-    RCC_OscInitStruct.HSIState = RCC_HSI_ON;
-    RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
-    RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
-    RCC_OscInitStruct.HSI14CalibrationValue = 16;
-    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
-    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
-    RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12;
-    RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
-    
-    if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
-    {
-        Error_Handler();
-    }
-    
-    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
-                                |RCC_CLOCKTYPE_PCLK1;
-    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
-    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
-    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
-    
-    if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
-    {
-        Error_Handler();
-    }
-}
-
-
-void Error_Handler(void)
-{
-    __disable_irq();
-    while (1) {}
-}
+#include "stm32f0xx_hal.h"
+#include "led.h"
+#include "button.h"
+#include "adc.h"
+#include "tim.h"
+#include "misc.h"
+#include "systick.h"
+#include "usart.h"
+#include "pwm_out.h"
+#include "pwm_in.h"
+#include "gpio.h"
+#include "logic.h"
+#include <stdio.h>
+
+
+void SystemClock_Config(void);
+void Error_Handler(void);
+
+
+
+
+int main()
+{
+    HAL_Init();
+    SystemClock_Config();
+/*     
+    gpio_init();
+    tim_pwm_out_init();
+    tim_pwm_in_init();
+
+    wdt_init();
+*/    
+    channel_init();
+    led_init();
+    
+    tim_init();
+    tim_warmup();
+    
+    adc_init();
+    but_init();
+    
+    
+#if 1    
+    usart_init();
+    printf("FW started...\r\n");
+#endif    
+    
+    HAL_Delay(1000);
+    //tim_set_string_freq(1);
+    
+    timer_AddFunction(10, adc_task);
+    timer_AddFunction(10, button_run);
+    
+    timer_AddFunction(10, logic_cnt_task);
+    
+    timer_AddFunction(100, logic_led_freq);
+    
+    //bool foo;
+    //foo = but_is_string();
+    
+    while(1) 
+    {
+        timer_Main();
+        
+        //adc_print_data();
+        //adc_task();
+        //adc_task();
+        //printf("CNT: %u\r\n", counter++);
+        //HAL_Delay(1000);
+        //logic_main();
+    }
+}
+
+
+
+void SystemClock_Config(void)
+{
+    RCC_OscInitTypeDef RCC_OscInitStruct = {0};
+    RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
+    
+    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI14;
+    RCC_OscInitStruct.HSIState = RCC_HSI_ON;
+    RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
+    RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
+    RCC_OscInitStruct.HSI14CalibrationValue = 16;
+    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
+    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
+    RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12;
+    RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
+    
+    if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
+    {
+        Error_Handler();
+    }
+    
+    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
+                                |RCC_CLOCKTYPE_PCLK1;
+    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
+    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
+    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
+    
+    if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
+    {
+        Error_Handler();
+    }
+}
+
+
+void Error_Handler(void)
+{
+    __disable_irq();
+    while (1) {}
+}

Some files were not shown because too many files changed in this diff