38 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
#include <stdio.h>
 | 
						|
#include <stdint.h>
 | 
						|
 | 
						|
#include "motor_controller.h"
 | 
						|
 | 
						|
void BLDC_PWM_Init(Cont_Mot_PWMInterface_TypeDef* PWM_Interface) {
 | 
						|
 | 
						|
    //Start High-Side and Low-Side PWM Drivers
 | 
						|
    HAL_TIM_PWM_Start(PWM_Interface->Driver_PWM_TIM, PWM_Interface->U_Phase_TIM_Channel);
 | 
						|
    HAL_TIMEx_PWMN_Start(PWM_Interface->Driver_PWM_TIM, PWM_Interface->U_Phase_TIM_Channel);
 | 
						|
    HAL_TIM_PWM_Start(PWM_Interface->Driver_PWM_TIM, PWM_Interface->V_Phase_TIM_Channel);
 | 
						|
    HAL_TIMEx_PWMN_Start(PWM_Interface->Driver_PWM_TIM, PWM_Interface->V_Phase_TIM_Channel);
 | 
						|
    HAL_TIM_PWM_Start(PWM_Interface->Driver_PWM_TIM, PWM_Interface->W_Phase_TIM_Channel);
 | 
						|
    HAL_TIMEx_PWMN_Start(PWM_Interface->Driver_PWM_TIM, PWM_Interface->W_Phase_TIM_Channel);
 | 
						|
}
 | 
						|
 | 
						|
void BLDC_Loop() {
 | 
						|
    static uint32_t int_count;
 | 
						|
    
 | 
						|
    int_count++;
 | 
						|
    static uint32_t seconds;
 | 
						|
 | 
						|
    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);
 | 
						|
      //HAL_UART_Transmit_DMA(&huart1, txMsg1, strlen(txMsg1));
 | 
						|
 | 
						|
      uint8_t txMsg2[20] = "";
 | 
						|
      //snprintf(txMsg2, sizeof(txMsg2), "CNT: %8lu\n\0", htim->Instance->CNT);
 | 
						|
      //HAL_UART_Transmit(&huart1, txMsg2, strlen(txMsg2), 100);
 | 
						|
      //HAL_UART_Transmit_DMA(&huart1, txMsg2, strlen(txMsg2));
 | 
						|
 | 
						|
    }
 | 
						|
 | 
						|
} |