Project Introduction:
This driver board uses DRV8313PWPR as the driver chip, and uses a board-to-board connector to connect to the Liangshanpai development board to achieve the control of a low-current gimbal brushless motor.
Power module:
The power supply uses TPS5430DDA + AMS1117 to manufacture 5V and 3.3V voltages, and the 5v power supply is connected to the Liangshanpai through a pin header.

Driver module:
The driver module uses the DRV8313 driver chip, and cooperates with INA240 two-way current sampling to realize the Foc drive circuit.

Physical model display:

Driver board interface
LCD
onboard 1.1.4 inch screen, driver chip ST7789, using protocol spi4 transmission.
Port allocation
SDA <-> LCD_MOSI <-> PC9
SCL <-> LCD_SCLK <-> PC10
RESET <-> LCD_RST <-> PA15
RS <-> LCD_DC <-> PA14
CS <-> LCD_CS <-> PC11
Buttons
There are 3 buttons on the board, and capacitor debounce processing is added. The port needs to be pulled up internally
SW1 <-> PC6
SW2 <-> PD1
SW3 <-> PD5
Motor port
Motor 1
uses TIMER1 timer
U1 <-> PA0 <-> TIMER1_CH0
V1 <-> PA1 <-> TIMER1_CH1
W1 <-> PA2 <-> TIMER1_CH2
EN1 <-> PC1
Motor 2
uses TIMER0 timer
U2 <-> PB13 <-> TIMER0_CH0_ON
V2 <-> PB14 <-> TIMER0_CH1_ON
W2 <-> PB15 <-> TIMER0_CH2_ON
EN2 <-> PG7
encoder
has two encoder interfaces on board, using the I2C protocol
Interface 1
PB6 <-> I2C0_SCL
PB7 <-> I2C0_SDA
Interface 2
PA8 <-> I2C2_SCL
PC9 <-> I2C2_SDA
Current sampling ADC
M1_U_ADC <-> PF9 <-> ADC2_IN7
M1_V_ADC <-> PF7 <-> ADC2_IN5
M2_U_ADC <-> PA4 <-> ADC01_IN4
M2_V_ADC <-> PA6 <-> ADC01_IN6
The brushless open-loop program
implements simple open-loop control to make the motor rotate. The program uses SIMPLE FOC open source code with simple comments
void setPhaseVoltage(float Uq, float Ud, float angle_el){ float Uout; uint32_t sector; float T0,T1,T2; //Directly control the three-phase pwm duty cycle parameters of the motor float Ta,Tb,Tc; float U_alpha,U_beta;
angle_el =_normalizeAngle(angle_el);
U_alpha=Ud*_cos(angle_el)-Uq*_sin(angle_el); //park逆变换 U_beta=Ud*_sin(angle_el)+Uq*_cos(angle_el); Uout=_sqrt(U_alpha*U_alpha + U_beta*U_beta) / voltage_power_supply; if(Uout> 0.577)Uout= 0.577; if(Uout<-0.577)Uout=-0.577; sector = (angle_el / _PI_3) + 1; T1 = _SQRT3*_sin(sector*_PI_3 - angle_el) * Uout; T2 = _SQRT3*_sin(angle_el - (sector-1.0)*_PI_3) * Uout; T0 = 1 - T1 - T2; switch(sector) { case 1: Ta = T1 + T2 + T0/2; Tb = T2 + T0/2; Tc = T0/2; break; case 2: Ta = T1 + T0/2; Tb = T1 + T2 + T0/2; Tc = T0/2; break; case 3: Ta = T0/2; Tb = T1 + T2 + T0/2; Tc = T2 + T0/2; break; case 4: Ta = T0/2; Tb = T1+ T0/2; Tc = T1 + T2 + T0/2; break; case 5: Ta = T2 + T0/2; Tb = T0/2; Tc = T1 + T2 + T0/2; break; case 6: Ta = T1 + T2 + T0/2; Tb = T0/2; Tc = T1 + T0/2; break; default: // possible error state Ta = 0; Tb = 0; Tc = 0; } timer_channel_output_pulse_value_config(BSP_PWM_TIMER,BSP_PWM_UCHANNEL,Ta*10000); timer_channel_output_pulse_value_config(BSP_PWM_TIMER,BSP_PWM_VCHANNEL,Tb*10000); timer_channel_output_pulse_value_config(BSP_PWM_TIMER,BSP_PWM_WCHANNEL,Tc*10000);}
实现的功能
程序成功运行的模块
lcd 显示
as5600角度获取
电机开环转动