Component: DC Motor (Mechatronics)

From Flowcode Help
Revision as of 21:01, 23 December 2025 by Wiki bot (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
Author Matrix TSL
Version 1.2
Category Mechatronics


DC Motor component

DC Motor that can be driven in one or both directions using digital output pins, PWM or HBRIDGE peripherals.

Version information

Library Version, Component Version, Date, Author, Info
2, 1.2, 13-11-24, BR, Altered property tooltips to make them more meaningful

Detailed description

No detailed description exists yet for this component

Examples

Simple example showing how to drive the motor component by only using Enable and two port pins.

FC6 Icon.png DC Motor pin control

Macro reference

Break

Fc9-comp-macro.png Break
Actively drives both ends of the motor by setting the pins according to the 'Brake Pattern' property. 
Fc9-void-icon.png - VOID Return


Coast

Fc9-comp-macro.png Coast
Turn off power to the motor by setting the pins according to the 'Coast Pattern' property. 
Fc9-void-icon.png - VOID Return


Disable

Fc9-comp-macro.png Disable
Disable the motor output 
Fc9-void-icon.png - VOID Return


Enable

Fc9-comp-macro.png Enable
Enables the motor output 
Fc9-void-icon.png - VOID Return


Forwards

Fc9-comp-macro.png Forwards
Set the motor turning in the forwards direction by setting the pins according to the 'Forwards Pattern' property. 
Fc9-u16-icon.png - UINT Duty
Sets the motor power for PWM or H-Bridge outputs 
Fc9-void-icon.png - VOID Return


GetSimAngle

Fc9-comp-macro.png GetSimAngle
Gets the angle of the simulated motor shaft in degrees. 
Fc9-f32-icon.png - FLOAT Return


Reverse

Fc9-comp-macro.png Reverse
Set the motor turning in the reverse direction by setting the pins according to the 'Reverse Pattern' property. 
Fc9-u16-icon.png - UINT Duty
Sets the motor power for PWM or H-Bridge outputs 
Fc9-void-icon.png - VOID Return


Property reference

Fc9-prop-icon.png Properties
Fc9-conn-icon.png Control Type
Fc9-type-16-icon.png Control Method
Controls how the motor is controlled. On/Off requires basic output pins, motor is full speed or stopped. PWM requires a hardware PWM channel and allows the motor speed to be controlled. H-Bridge requires a hardware H-Bridge channel and allows the motor speed to be controlled. 
Fc9-type-16-icon.png Bridge Type
Half Bridge - Motor can only be controlled in one direction. Full Bridge - Motor can be controlled in both directions. 
Fc9-type-16-icon.png Enable Method
Decides how the motor outputs are enabled. 
Fc9-conn-icon.png Connections
Fc9-type-5-icon.png PinA
First control pin - set 'pattern' properties below to set the pin's function. 
Fc9-type-5-icon.png PinB
Second control pin - set 'pattern' properties below to set the pin's function. 
Fc9-type-16-icon.png Forwards Pattern
The state of pins A and B required to drive the motor in a forwards direction. 
Fc9-type-16-icon.png Reverse Pattern
States of pins A and B required to drive the motor in a reverse direction. 
Fc9-type-16-icon.png Coast Pattern
States of pins A and B required to stop the motor. 
Fc9-type-16-icon.png Brake Pattern
States of pins A and B required to stop the motor. 
Fc9-conn-icon.png Software PWM Settings
Fc9-type-16-icon.png Timer
Timer Peripheral to use to monitor the passage of time. 
Fc9-type-16-icon.png Prescaler
Scaler applied to the timer, Small scalers allow for finer resolution but will limit the max time and also put more load on the microcontroller. Recommended to use as large a setting as possible which still provides enough accuracy.  
Fc9-type-21-icon.png Resolution
Number of discrete values that the duty can have. e.g. 16 would allow duty values of 0-15 Recommend keeping this value low to avoid excessive amounts of interrupts. 
Fc9-type-21-icon.png Frequency (Hz)
The frequency of the PWM output in Hz. Recommend keeping this low as possible to avoid having excessive amounts of interrupts. 
Fc9-type-21-icon.png Required Interrupt Rate (Hz)
The calculated required rate of interrupts 
Fc9-type-15-icon.png Accuracy
How close we can get to the required timings with the selected timer and prescaler 
Fc9-type-16-icon.png Off Time Setting
Decides what to do when output PWM output is low. 
Fc9-conn-icon.png Simulation Settings
Fc9-type-2-icon.png Label Colour
 
Fc9-type-15-icon.png Speed
Speed of the motor when turned on. Positive speed -> Counter-clockwsie Negative speed -> Clockwise  

Component Source Code

Please click here to download the component source project: FC_Comp_Source_DCMotor_2d.fcfx

Please click here to view the component source code (Beta): FC_Comp_Source_DCMotor_2d.fcfx