Once finished (deadline is end of January) this project will become open-source software and hardware.
My quadruple BDC driver for supports up to 4 brushed motors with encoders. Each motor is controlled by its individual closed loop and individual PID gain settings. Additionally, motor speed can also be individually addressed. Analog part of the driver is based on DRV8701P predriver and is controlled by STM32F4 microcontroller.
- 28 V max input voltage (recommended 24V)
- 12.5 A max motor current – not yet tested (recommended 10A)
- 50 kHz max encoder pulse frequency (recommended 30kHz)
- Serial communication
- ROS compatible with available library
- XT-60 power connector
- XT-30 motor connectors
- Adjustable current protection (0.1A – 13A)
- Adjustable current alert (LED or on serial)
- Temperature protection
- Hardware emergency stop
- Extra 24V power switch for external 24V load
The circuit is divided in two parts. The analog power part and the digital part with peripherals. Let’s talk about the power side firstly.
Everything is based on DRV8701P integrated circuit that takes care of dead times, gate currents and ensures higher voltage for opening high side n-mosfets. The DRV has four control inputs. One is sleep (it is used for emergency stop) and two are PWM signals for forward or reverse drive. The DRV also features braking (though not regenerative) with both PWM signals on at the same time. The fourth control input is reference voltage for limiting the current.
The DRV has shunt amplifier built-in with fixed gain of 20. This is ideal for current sensing with a 10 mOhm shunt resistor. Once the voltage on the output of the shunt amplifier exceeds the voltage reference set on the control pin the driver enters so called current chopping mode in which it effectively limits the motor current to set level.
The driver measures voltage drop across transistors and immediately enters fault mode when the drop is too large. It also features internal temperature protection.
The schematic (1) is only for 1 channel. The actual circuit board has 4 identical ones.
Digital side and peripherals
Digital side is based on STM32F4 microcontroller. I used one in QFN housing to make it more immune to possible mechanical vibrations. The microcontroller is generating 8 PWM signals at 21 kHz with 1000 sections (10bit). The encoders are read by interrupt active pins. All four motors work in PID closed loop. Some additional features are motor sensing motor current, input voltage, used energy and temperature sensing.
Three LED indicators are present on board to provide basic information about the driver state.
- Sleep LED indicates whether the driver (as a unit) is in sleep mode and motors drives are disabled.
- Fault LED blinks with a fault code and indicates a possible problem.
- Brake LED indicates whether one of the channels is breaking.
The board has got a connector for remote emergency stop switch. A relay or npn/n-channel transistor can also be connected on this input to work as some kind of emergeny stop with external watchdog module.
To ensue proper and correct measurements of input voltage, temperature and motor current a 2.5 V reference is present on-board for the ADC.
Small 0.5 A buck switching regulator takes care of making 3.3V from the input supply. All digital side and peripherals are powered by this IC.
Additionally another N-channel mosfet switch is implemented. It can switch currents up to 20A.
The communication with the driver is based on UART. User will have multiple write registers (to set motor speed, PID gains, etc.) and multiple read register that will contain information about temperature, used energy, encoder ticks, etc. This is not yet implemented in software.
The first prototype was thoroughly tested and initial mistakes were corrected. Some problems were as follows:
- Wrong interrupt pins (joined interrupt lines in the mcu)
- Wrong 3.3V switcher layout
- Huge button bounce (solved with a capacitor)
Some other minor mistakes that were solved with second revision
- Added 2.5 V reference for ADC
- Added forward and reverse PWM signals of a single driver to a single MCU timer
- Added a resistor in parallel with NTC to make it more linear
- Improved board layout
The power side of the circuit worked perfectly in the first revision and no correction were made there.
Prototype PCBs were manufactured by PCBWay. Their rapid prototype service is fast (5 days from gerbers to PCBs in my hands), reliable and the quality of the PCBs is completely comparable with a local manufacturer. Not to mention 20 boards with 6mil clearance were just 30$ including shipping. I’ll definitely order again.
To be continued…
Most of the software has already been written.
What can the driver do:
- Control the motors in open loop with duty cycle in both directions
- Read the motor speed from encoders
- Control the motors in closed loop in both directions
- Read temperature
- Read motor current
- Read input voltage
- Calculate used energy
- Transmit/receive data over serial port
- Register map
- Adjustable under-voltage and over-current protection
- Fault code
- Startup routine (beeping and such…)
- Active breaking (routines for active braking in PID regulation)
Click on the picture to open register map in PDF form.
Example command that sets motor 3 speed to “10”:
0x7e 0x83 0x00 0x00 0x27 0x10 0x1f 0x83 0x7e Explained: 0x7E Start of frame 0x80 Address byte - 10000011 in binary - MSB bit sets the write command, address is 6 lsb bits - in this case the address is 0x03 0x00 Data byte 0 0x00 Data byte 1 0x27 Data byte 2 0x10 Data byte 3 0x00002710 translates to 10000(dec) Note: the actual parameter is multiplied by 1000 / set speed is divided by 1000 0x1F CRC byte 1 0x83 CRC byte 2 More about CRC: https://www.lammertbies.nl/comm/info/crc-calculation.html 0x7E End of frame The driver then returns: 0xC3 or 11000011 in binary: Bit7 (msb) indicates that an write command was executed. Bit6 is acknowledge bit which is also set to 1 - the parameter was in range and set accordingly. Bit5:0 is addres - in this case it indicates which register was set.
Click on the picture to open example frame in PDF form.