DesignSpark Electrical Logo

Innovation for Every Engineer

  • Brought to you by
  • RS Components
  • Allied Electronics

October 18, 2013 10:56

Simple Electro-Mechanical Simulation within Flowcode 6

In our previous DesignSpark blog article, we detailed the process of importing a simple push-to-make switch into Flowcode via DesignSpark Mechanical. This was a relatively simple example, demonstrating the simplicity with which components can be created within Flowcode. Once components are created users can create more complex electro-mechanical simulations. In this example I want to demonstrate the ability to simulate linear movement from a stepper motor, using a pre-made component within Flowcode. Stepper motors are typically used in machines such as XY plotters, 3D printers and CNC machines, due to their ability to achieve accurate movement due to the small step size. When creating a machine users now have the ability to import 3D models available from DesignSpark directly into Flowcode.

The ability to simulate the movement achieved from a stepper motor can be used to verify calculations relating to the movement that will be achieved for a certain hardware configuration, without having to physically construct the hardware. For more complex simulations, Flowcode would allow the user to create complete machines such as a simulated CNC machine with 3-axes of movement.

For this simple example a stepper motor was added to the system panel within Flowcode. The 3D drawing interface was used to create a solid bar with an 8mm diameter, the same as an M8 threaded bar. The length of the bar was set within Flowcode to be 100 mm. A basic nut was drawn as a thin hexagonal shape and placed at the end of the bar closest to the motor. The aim of this simulation was to calculate the theoretical number of rotational steps required to move the nut 100mm using a typical M8 threaded bar, and verify these calculations within a simulation. Text labels were used to show the user the distance markers along the bar. The diagram below shows the 3D model of the stepper motor connected to the bar.


The component properties of the stepper motor are separated into two sections; those which are required for physical connections if the program is ever downloaded to a microcontroller and those which are required for simulation only. For the physical properties, this is the connections Coil 1-4, and in this example they are left as default which is to connect them to PORTA 0-3. Since we are simulating only these connection properties do not matter.

For the simulation properties we have pre-configured them to allow the user to simulate either rotational or linear movement. For rotational movement the user must determine the gear ratio, which will allow the user to create a simple gearbox reduction or increase in rotational speed. For this example we want linear movement so we set Gear Ratio to 0 and adjust X, Y or Z linear movement. Since we are simulating movement along an M8 threaded bar, we implement a pitch of 1.25mm. That is, for one full rotation the nut will have travelled 1.25 mm. The final properties we set are the characteristics of the stepper motor. Here we have set the stepper motor to have 200 steps per revolution, and utilise full step movement. 200 steps pre revolution is a step angle size of 1.8°. These properties would be changed by the user depending on the specification of their stepper motor.











To calculate the theoretical number of steps required to travel 100mm we use the following equations;




Now we need to calculate the number of rotational steps required to make the nut travel 100mm;




Therefore we see that we need to rotate the motor by 16,000 steps in order to achieve 100mm of movement along an M8 threaded bar with a pitch of 1.25mm. In order to determine whether our theoretical calculations are correct we must create a flowchart program within Flowcode where the motor is rotated 16,000 times.

The flowchart for this can be seen below. First, we initialise the stepper motor. Then we set the number of steps required, determined by our theoretical calculations, to 16,000. Next we perform a loop statement which increments the motor step. We set this loop to execute 16,000 times by decrementing the count variable each time the loop executes. Once the motor has been rotated the required number of times the loop exits and jumps into a second while(1) loop where it will remain. This allows us to verify the position of the nut before the simulation ends.


















Upon running the simulation we see that the theoretical calculations were correct. A total of 16,000 steps moves an object 100 mm along a threaded bar which has a pitch of 1.25mm. A video for this has been produced and can be seen below.

 The ability to simulate movement of electro-mechanical systems in this way enables users to verify the design of systems before they are required to construct hardware. In industry this reduces development time allowing engineers more time while in a learning environment this also significantly removes the necessity for bulky, expensive hardware for each student.