Add gitignore
create motor_controller source files.
This commit is contained in:
		@@ -24,6 +24,7 @@
 | 
			
		||||
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include "motor_controller.h"
 | 
			
		||||
 | 
			
		||||
/* USER CODE END Includes */
 | 
			
		||||
 | 
			
		||||
@@ -37,8 +38,9 @@
 | 
			
		||||
 | 
			
		||||
#define PWM_COUNTS 2000
 | 
			
		||||
 | 
			
		||||
#define CLOCK_SPEED_MHZ 32
 | 
			
		||||
#define PWM_DEADTIME_NS 1000
 | 
			
		||||
#define CLOCK_SPEED_MHZ 32UL
 | 
			
		||||
#define PWM_DEADTIME_NS 1000UL
 | 
			
		||||
#define PWM_DEADTIME_COUNTS (CLOCK_SPEED_MHZ * 1000UL / PWM_DEADTIME_NS)
 | 
			
		||||
 | 
			
		||||
/* USER CODE END PD */
 | 
			
		||||
 | 
			
		||||
@@ -124,22 +126,30 @@ int main(void)
 | 
			
		||||
 | 
			
		||||
  static uint32_t loops;
 | 
			
		||||
  HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_4);
 | 
			
		||||
  HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
 | 
			
		||||
  HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_1);
 | 
			
		||||
  HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2);
 | 
			
		||||
  HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_2);
 | 
			
		||||
  HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3);
 | 
			
		||||
  HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_2);
 | 
			
		||||
 | 
			
		||||
  HAL_TIM_Base_Start_IT(&htim2);
 | 
			
		||||
  
 | 
			
		||||
  //TIM1->BDTR |= TIM_BDTR_MOE;
 | 
			
		||||
  // HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
 | 
			
		||||
  // HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_1);
 | 
			
		||||
  // HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2);
 | 
			
		||||
  // HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_2);
 | 
			
		||||
  // HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3);
 | 
			
		||||
  // HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_3);
 | 
			
		||||
  Cont_Mot_Interface_TypeDef MotorInterface = {
 | 
			
		||||
    .Driver_PWM_TIM = &htim1,
 | 
			
		||||
    .U_Phase_TIM_Channel = TIM_CHANNEL_1,
 | 
			
		||||
    .V_Phase_TIM_Channel = TIM_CHANNEL_2,
 | 
			
		||||
    .W_Phase_TIM_Channel = TIM_CHANNEL_3,
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  BLDC_Init(MotorInterface);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  HAL_ADC_Start(&hadc);
 | 
			
		||||
 | 
			
		||||
  HAL_GPIO_WritePin(OC_TH_STBY1_GPIO_Port, OC_TH_STBY1_Pin, GPIO_PIN_SET);
 | 
			
		||||
  HAL_GPIO_WritePin(OC_TH_STBY2_GPIO_Port, OC_TH_STBY2_Pin, GPIO_PIN_SET);
 | 
			
		||||
  HAL_GPIO_WritePin(PWM_LSW_GPIO_Port, PWM_LSW_Pin, GPIO_PIN_SET);
 | 
			
		||||
  //HAL_Delay(2000);
 | 
			
		||||
 | 
			
		||||
  HAL_TIM_Base_Start_IT(&htim2);
 | 
			
		||||
 | 
			
		||||
  while (1)
 | 
			
		||||
  {
 | 
			
		||||
@@ -324,7 +334,7 @@ static void MX_TIM1_Init(void)
 | 
			
		||||
  sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_ENABLE;
 | 
			
		||||
  sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_ENABLE;
 | 
			
		||||
  sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
 | 
			
		||||
  sBreakDeadTimeConfig.DeadTime = 32;
 | 
			
		||||
  sBreakDeadTimeConfig.DeadTime = PWM_DEADTIME_COUNTS;
 | 
			
		||||
  sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
 | 
			
		||||
  sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
 | 
			
		||||
  sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
 | 
			
		||||
@@ -449,7 +459,7 @@ static void MX_USART1_UART_Init(void)
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END USART1_Init 1 */
 | 
			
		||||
  huart1.Instance = USART1;
 | 
			
		||||
  huart1.Init.BaudRate = 38400;
 | 
			
		||||
  huart1.Init.BaudRate = 115200;
 | 
			
		||||
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
 | 
			
		||||
  huart1.Init.StopBits = UART_STOPBITS_1;
 | 
			
		||||
  huart1.Init.Parity = UART_PARITY_NONE;
 | 
			
		||||
@@ -550,33 +560,15 @@ static void MX_GPIO_Init(void)
 | 
			
		||||
 | 
			
		||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
 | 
			
		||||
 | 
			
		||||
  static uint32_t int_count;
 | 
			
		||||
  
 | 
			
		||||
 | 
			
		||||
  if (htim->Instance == TIM2) {
 | 
			
		||||
    int_count++;
 | 
			
		||||
    static uint32_t seconds;
 | 
			
		||||
    BLDC_Loop();
 | 
			
		||||
 | 
			
		||||
    if (int_count/1000u > seconds) {
 | 
			
		||||
      seconds = int_count/1000u;
 | 
			
		||||
 | 
			
		||||
      uint8_t txMsg1[20] = "";
 | 
			
		||||
      snprintf(txMsg1, sizeof(txMsg1), "IRQ: %8lu\n\0", int_count);
 | 
			
		||||
      HAL_UART_Transmit(&huart1, txMsg1, strlen(txMsg1), 100);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // static uint32_t loops;
 | 
			
		||||
 | 
			
		||||
  // if (HAL_GetTick()/1000 > loops) {
 | 
			
		||||
  //   loops = HAL_GetTick()/1000;
 | 
			
		||||
  //   uint8_t txMsg[20] = "";
 | 
			
		||||
  //   snprintf(txMsg, sizeof(txMsg), "IRQ: %8lu\n\0", HAL_GetTick());
 | 
			
		||||
  //   HAL_UART_Transmit(&huart1, txMsg, strlen(txMsg), 100);
 | 
			
		||||
  // }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* USER CODE END 4 */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user