can_motor_controller

Public

wjklimek1/can-motor-controller

Loading…

Description

Imported from GitHub: wjklimek1/CAN_motor_controller · commit 8830bf3 · license MIT

Description

H-bridge for DC motor controlled by CAN or PWM

README

CAN motor controller

This project is a device that allows control of DC motor by commands on CAN bus. It is based on STM32F103 microcontroller that interprets CAN messages and drives motor using two BTN8982 half-bridges configured as a single H-bridge.

Motor driving capabilities

DC motor is controlled with 21kHz PWM signal with 0-100% duty. PWM can be regulated in 0.1% steps - from 0 to 1000. Theoretically max current that MOSFETs can handle is 55A, but it can be futher limited by traces width and connectors. It was tested up to 10A, but should handle much more without any problems. Power supply voltage range is 5-24V.

ParameterMinMax
voltage5V24V
motor current55A (10A tested)

Motor is accelerated slowly by changing PWM duty. If received command orders to immediately set PWM to 100% from 0%, duty is increased slowly in default 10ms intervals. Therefore spinning motor to top speed will take 10s. This property can be disabled by setting "motor inertia" parameter to 0 (see CAN commands table).

CAN configuration

CAN bus in STM32F103 runs on 250kb/s by default. It can be set to other, hard coded value in the initialization function. Other supported baudrates are 500kb/s and 1Mb/s.

Heartbeat

Device emits "heartbeat" frame every 1s. It is an empty frame with ID = 0x444. Heartbeat can be disabled or it's period can be changed in 1s steps up to 255s.

CAN message structure

Device utilizes two identifiers - 0x444 for commands and 0x445 for requesting data. This values are hard coded too, but can be changed in canbus.h file. DLC of CAN messages is not really important, but it cannot be shorter than expected. In both commands and data requests first byte of message is code of command or data request. In commands next bytes represent values of command parameters. When data request is received by device, it will respond with frame of the same ID and data request code. Next bytes will contain requested data.

Commands

Following table shows available commands:

Commandframe IDDLCbyte 0 (command code)byte 1byte 2byte 3
Set speed0x44441rotation direction (0 or 1)MSB of speedLSB of speed
Set max temperature internal0x44422max internal temperature (uint8_t) in Celcius--
Set max temperature external0x44423max external temperature (uint8_t) in Celcius--
Set max current0x44444MSB of max current (mA)LSB of max current (mA)-
Emergency stop0x44415---
Set inertia0x44426Inertia (ms delay between changing PWM duty)--
Set heartbeat0x44427heartbeat interval (0 for disabled)--

Data requests

To request data, frame of ID = 0x445 and first byte containing data request code can be sent. Device will respond with similar frame, but containing data in next bytes.

Following table shows available data requests:

Data requestframe IDDLCbyte 0 (data request code)byte 1byte 2byte 3byte 4byte 5
Internal temperature0x44521Internal temperature (uint8_t) inCelcius---
External temperature0x44522External temperature (uint8_t) inCelcius---
Power supply voltage0x44533MSB of voltage in mVLSB of voltage in mV---
Motor current0x44534MSB of current in mALSB of current in mA---
Speed0x44545rotation direction (0 or 1)MSB of speedLSB of speed--
Target speed0x44546rotation direction (0 or 1)MSB of speedLSB of speed--
Errors0x44557MOSFET faultovercurrentovertemperature internalovertemperature externalemergency stop
Comments

No comments yet. Be the first to ask about this board.

Askabout this board