Skip to content

FOC driver board based on Qfplib-m3 and STM32F103C8T6 with algorithm. Use torque, velocity and angle control. Several applications based on torque control have been realized.

License

Notifications You must be signed in to change notification settings

HangX-Ma/miniFOC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

miniFOC

This repository records my development of miniFOC. You can obtain the source files of the hardware and software in this repository.

Introduction

This FOC driver board has three control mode, Torque, Velocity, Angle. You can control the motor accurately and smoothly using Voltage Control, because I haven't solved the Current Loop Control problem.

Vofa+ can be used to control the motor conveniently. I also design a group of virtual keys to test the menu UI. You can find Vofa+ command configuration vofa+.cmds.json and foc_debugger.tab.json that can assist you build up your debug platform quickly.

I have added a Torque Ratchet Mode under torque control. You can have a try.

NOTE: Software/foc/foc.ioc is only used for configuration reference.

NOTE: ❗ The hardware design is immature, which has some line sequence mistakes.

You can check the pin set via cubemx-settings. Vofa+ debugger tab can also be found in assets/vofaplus.png.

miniFOC design(concept), HangX-Ma
miniFOC design(concept), HangX-Ma

FOC board and other components, HangX-Ma
FOC board and other components, HangX-Ma

I will try to use sensor-less control strategy if the fundamental functions all perform well.

Driver Parameters

Item Value
Input voltage range 8 V ~ 40 V
Maximum current 1.5 A
Serial port baud rate 115200
MCU STM32F103C8T6, 64 KB flash, 20 KB RAM
OLED SSD1306, 128 x 64, 7 wires SPI
Motor 2808, KV900, 12 V

Environment

Features

  • Using space vector pulse width modulation
  • Torque control without current sensor
  • Rotational speed closed loop control
  • Rotation angle closed loop control
  • Torque control with current sensor
  • Smooth UI that can be controlled by virtual keys currently via Vofa

FOC Application

  • Torque Normal Mode

       Under torque control, you can set the target torque and Kp to adjust torque feedback force.

  • Torque Ratchet Mode

       Under torque control, the motor will act like a ratchet.

       You can change Kp to adjust the stiffness.

  • Torque Rebound Mode

       Under torque control, the motor will rebound to the specific angle.

       You can set the angle or change the rebound force by adjusting the Kp value.

  • Torque Damp Mode

       Under torque control, the motor will act like a knob with damp.

       If you increase the target torque value, the damp will increase.

       If you increase the Kd value, the knob will become smoother.

Problem Found

  • SPI output pins sequence needs to be CS, SCLK, MISO, MOSI.
  • Magnetic attached to motor will affect the motor itself, my friend suggests me to use sensorless control strategy.
  • More power ports need to be reserved, such as GND, 3V3.
  • SPI OLED ports sequence needs to be GND, VCC, SCK, MOSI, RST, DC, CS.
  • nFault pin of the DRV8313 needs to be controlled and monitored by the MCU. Currently, only unplugging battery can release the DRV8313 off the fault state.

Development Logs

2023-08-10

  • Fix the problem caused by TIM3 configuration, which will lead to OLED abnormal display.

    I remove the LL_TIM_CC_EnableChannel function, which actually used in capture/compare mode! It is a coincidence that the OLED pins happened to be coincided with the configured channel.

  • Change current sampling to three phases version.
  • Move FOC state update in ADC1 DMA transfer complete interrupt. This will fit the current sampling demand and meet the inner ring frequency requirements.
  • Current sensors are combined with a strange 100 Hz sine- wave noise. I cannot fix it currently.
Strange 100 Hz sine-wave current noise
, HangX-Ma
Strange 100 Hz sine-wave current noise , HangX-Ma

2023-08-06 to 2023-08-07

  • Reconstruct GUI logic to support mult-level menu and motor app mode switch.
  • Enhance the MainUI animation logic to follow the actual angle position.
  • Add Damp Mode.
  • Add damp feeling control for Rebound Mode
  • Add High Pass Filter but it is discarded afterwards because it filters out the useful information.

2023-08-05

  • Update the voltage control with with current estimation and Back-EMF compensation. I take a reference to SimpleFOC, Torque control using voltage.
Voltage control with current estimation and Back-EMF compensation
, HangX-Ma
Voltage control with current estimation and Back-EMF compensation , HangX-Ma

2023-08-01 to 2023-08-04

  • Add OLED smooth menu UI and make control relationship between UI and motor. The motor information such that Motor Control Mode, Motor State, Control Target, Shaft Velocity, Shaft Angle. The animation in MainUI will show you the state of motor!

2023-07-31

  • Find a project procedure problem that you must reconfirm the encoder direction if you reassemble your hardware.
  • Only low speed mode can support the motor position rebound test. Otherwise, the motor will be damaged.

    😭 My motor seems to be damaged. (Update: It recovered!)

  • Replace the PWMA current sensor and the current loop start to work.

    I finally only give Q and D with Kp = 0.6 and make the current loop work. But actually current loop version performs not as good as non current loop version.

  • Torque needs to be greater than 0.6 under current loop control.
  • Add ratchet mode under torque control.

2023-07-30

  • Add current sense monitor feedback, thus, creating a current control loop.

    ❌ Current phase sequence is necessary to be identified. I haven't solve the it. Motor can not work when current feedback added.

  • Add Torque Control part, reconstruct the control logic and delete some abundant codes.

2023-07-29

  • Add velocity control loop and fix the jitter problem.
  • Add position control loop.
  • Add motion switch function and fix the motor jump problem when control type switches.
  • Remove integral part in Angle Control. Only proportional part is left.

    ❗ Integral part actually causes serious overshoot problem and affects the system response speed.

2023-07-28

  • Attach the magnetic with shaft sleeve, sticking it on the shaft.
  • Remake an encoder board because previous one seems to be damaged.
  • Ensure the UVW sequence of the Motor.
  • [Pass TEST3]: Open loop position control test passes.
  • Add printf redirection code.
  • Add sensor alignment code: Identify the sensor direction, pole pairs and calculate the zero electrical angle offset.

    The code will be trapped into a rabbit hole if the motor rotates not fluently. So check the serial output first!

2023-07-26

  • Add OLED menu base code.

2023-07-25

  • INA199x1 has been configured successfully. I use TIM3 to generate update event to trigger ADC1 to start multi-channel conversion. The conversion result will be carried by DMA and send to specific address.
  • Add get_RS_current function that can conveniently return the rotor and stator current (Id and Iq). I also write a test code for it.

2023-07-24

  • SC60228DC magnetic encoder works well. I brought 5 mm x 2 mm (d x h) magnetic but can not stick it to the motor bearing using hot-melt adhesive. I will use AB glue instead.

    Waiting for essential materials again~

2023-07-23

  • Add SVPWM control module and change PWM to center aligned mode.
  • [Pass TEST2]: SVPWM control test passes.

2023-07-22

  • [Pass TEST1]: Direct given PWM can successfully drive BLDC motor.
  • Fix transmission error of SPI2, which is linked to magnetic encoder. But I forget to buy the magnetic, so fully check hasn't been done.

2023-07-21

  • Add u8g2 OLED library and add OLED demo code.

    • ❌ OLED can not display normally, which needs further checking.
    • ✔️ Remove SPI1 DMA and the SPI OLED can display normally using u8g2.
  • Reconstruct PWMx configurations and merges it into BLDC configurations.

  • Add BLDC motor tests for checking different BLDC motor working conditions.

  • Add USART control to start or stop BLDC motor.

  • Driver board has been prepared.

2023-07-19

  • Add Qfplib-M3 float-point library and it works well!

    I use cortex-debug plugin and it shows that Qfplib-M3 is visibly faster than software float-point calculation.

  • Add Vofa+ communication protocol and configure USART1.
    • ❓ Cough... It seems that my CH340 serial communication device breaks down. Need further checking.
    • ✔️ I use logic analyzer to capture output of PB6(Tx) and it actually gives me different waveforms, which means that the CH340 is actually broken.

2023-07-18

  • Change SPI mode to (Receive Only Master) and finish the SC60228DC software logic.

    Use OOP concept to write SC60228DC, use method in g_encoder can satisfy the user's need.

2023-07-17

  • 📖 Create a mind map about miniFOC design.
  • 🚀 Finish the board design but haven't check the details. Prepare for further checking and BOM selections.

    ✔️ BOM and board have been checked. Waiting for all materials to arrive.

  • Remove TIM1_CH1N, TIM1_CH2N, TIM1_CH3N settings, because they are not used in this driver.

2023-07-15

  • ❌ I tried to use proteus 8.15 to develop the software using online simulation, but the NMOS in proteus performed abnormally. I will use Logic Analyzer instead and design the modular board.

License

Apache License Version 2

About

FOC driver board based on Qfplib-m3 and STM32F103C8T6 with algorithm. Use torque, velocity and angle control. Several applications based on torque control have been realized.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages