Add electrical specs to motor structs.
More #defines for PWM settings.
This commit is contained in:
		@@ -36,9 +36,12 @@
 | 
			
		||||
/* Private define ------------------------------------------------------------*/
 | 
			
		||||
/* USER CODE BEGIN PD */
 | 
			
		||||
 | 
			
		||||
#define PWM_COUNTS 2000
 | 
			
		||||
 | 
			
		||||
#define CLOCK_SPEED_MHZ 32UL
 | 
			
		||||
 | 
			
		||||
#define TIM1_PRESCALER 1
 | 
			
		||||
#define PWM_COUNTS 2000
 | 
			
		||||
#define PWM_FREQUENCY (CLOCK_SPEED_MHZ * 1000UL / (TIM1_PRESCALER + 1UL) * 1000 / PWM_COUNTS)
 | 
			
		||||
 | 
			
		||||
#define PWM_DEADTIME_NS 1000UL
 | 
			
		||||
#define PWM_DEADTIME_COUNTS (CLOCK_SPEED_MHZ * 1000UL / PWM_DEADTIME_NS)
 | 
			
		||||
 | 
			
		||||
@@ -62,6 +65,24 @@ DMA_HandleTypeDef hdma_usart1_tx;
 | 
			
		||||
 | 
			
		||||
/* USER CODE BEGIN PV */
 | 
			
		||||
 | 
			
		||||
Motor_TypeDef Motor1 = {
 | 
			
		||||
  .Electrical_Specs = {
 | 
			
		||||
    .mA_rated_current     =   4800,
 | 
			
		||||
    .v_rated_voltage      =   24,
 | 
			
		||||
    .rpm_rated_speed      =   3000,
 | 
			
		||||
    .w_rated_power        =   75,
 | 
			
		||||
    .num_poles            =   8,
 | 
			
		||||
    .vkrpm_bemf_constant  =   4.41,
 | 
			
		||||
    .Nmm_rated_torque     =   240,
 | 
			
		||||
  },
 | 
			
		||||
  .PWM_Interface = {
 | 
			
		||||
    .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,
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* USER CODE END PV */
 | 
			
		||||
 | 
			
		||||
/* Private function prototypes -----------------------------------------------*/
 | 
			
		||||
@@ -127,28 +148,17 @@ 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_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);
 | 
			
		||||
 | 
			
		||||
  //These configure overcurrent protection. TODO
 | 
			
		||||
  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);
 | 
			
		||||
 | 
			
		||||
  //Initialize the PWM for gate drivers.
 | 
			
		||||
  BLDC_PWM_Init(&Motor1.PWM_Interface);
 | 
			
		||||
 | 
			
		||||
  //Start timer with interrupt for control loop.
 | 
			
		||||
  HAL_TIM_Base_Start_IT(&htim2);
 | 
			
		||||
 | 
			
		||||
  while (1)
 | 
			
		||||
@@ -296,7 +306,7 @@ static void MX_TIM1_Init(void)
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END TIM1_Init 1 */
 | 
			
		||||
  htim1.Instance = TIM1;
 | 
			
		||||
  htim1.Init.Prescaler = 1;
 | 
			
		||||
  htim1.Init.Prescaler = TIM1_PRESCALER;
 | 
			
		||||
  htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
 | 
			
		||||
  htim1.Init.Period = PWM_COUNTS-1;
 | 
			
		||||
  htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user