Engee documentation
Notebook

Rapid prototyping of control algorithms on RITM CPM: stepper motor

This example shows how to use a real-time machine, the RITM, for rapid prototyping of control algorithms. The control object is a low-power stepper motor controlled by a two-arm dual MOSFET-driver, the control signals are received and transmitted via the digital I/O module of the RITM GP-LC-45.

Introduction

Rapid control prototyping of real-time control algorithms (Rapid control prototyping, RCP)is a modelling technique that allows rapid evaluation of the performance of control systems during their design process. This approach allows for rapid iterations in the development of control algorithms in a real environment without professional programming skills.

The operating principles of the control object model as well as the control system model are described in detail in the example of full-step control of a bipolar stepper motor.

The next step after modelling in Engee to develop a control system is the rapid prototyping phase. It can be seamlessly implemented in Engee by switching the modelling environment to a real-time machine. To successfully set up and get started with the RITM CPM, it is convenient to use the example Quick Start with RITM CPM

When the rapid prototyping and debugging of the control system on a real-time machine has been successfully completed, the control system can be fully ported to embedded systems. Engee allows you to automatically generate C code to embed the control system model into custom designs for embedded systems. This process is covered in the code generation for STM32 example, which continues the current example.

Example model

The original example model is split into two parts at this stage:

  1. Prototype control system (subsystem Control System)
  2. Model of the control object (the circuit from the subsystem Gate Driver to the signals Speed and Position at the motor output)

image_2.png

The input influence for the prototype model of the control system is the "Start" signal of the stepper motor rotation start. The control system receives this signal from the digital input of the general-purpose peripheral module GP-LC-45 of the RITM.

The outputs of the control system model - the driver switch-on signal as well as the driver key control signals are transmitted to the digital outputs of the same peripheral module.

In addition, the output signals from the control system model are transmitted to the control object model - for this purpose, the digital outputs of the peripheral module are connected to its digital inputs. These, in turn, feed the received signals into the control object model.

The results of the model operation - the recorded signals of speed and rotation angle of the stepper motor shaft are transmitted to the C Function blocks RITM-PLOT, which output the graphs to the application RITM Monitor.

Periphery of the RITM CPM in the model

To work with the general-purpose peripheral module GP-LC-45 and its digital I/O in particular, the model uses the corresponding blocks from the section РИТМ of the Engee block library, with the following settings

Thus, the module GP-LC-45 utilises digital inputs DI1-DI6 and digital outputs DO1-DO5

The step of block calculation corresponds to the step of model calculation (100 µs).

Blocks RITM-PLOT, as it was said above, output signal graphs: 1 block - shaft speed graph, 2 block - shaft speed and rotation angle graphs. The step of calculation of blocks is larger and is 10 ms.

Connection of the control object

The GP-LC-45 module is connected to the 37-pin terminal module GP-RT-Terminal-37 v1.0. To connect the circuits in this example, use the pinout - pin assignment table of the terminal module.

The terminals used in this example are:

  • 01 - DGND (digital ground)
  • 02 - +3.3 V (3.3 V power supply)
  • 35 - DI6 (Start signal from the pushbutton contact)
  • 08 - DO5 (driver module switch-on signal)
  • 10, 29, 09, 28 - DO1, DO2, DO3, DO4 (driver key control signals)
  • 16 - DI5 (driver module switch-on signal for the control object model)
  • 18, 37, 19, 36 - DI1, DI2, DI3, DI4 (driver key control signals for the control object model)

The wiring diagram of the terminal module and control object elements is shown below.

image.png

After preparing the model and environment, as well as disconnecting all circuits and powering up, we will move on to running the model on a real-time machine. This will allow us to debug the control algorithms during rapid prototyping.

Executing the model

Let's start the model on the RITM CPM in the "Interactive Execution" mode. Let's generate the signal "Start" by pressing the button contact. On the model graphs in Engee the following signal changes occur:

image.png

Similar graphs will be observed on a monitor screen connected to a real-time machine:

image.png

In parallel, the rotation of the stepper motor shaft can be observed with the naked eye:

rcp_ritm_sm.gif

Conclusion

In the case study, we used the approach of rapid prototyping of control algorithms on the RITM semi-natural modelling suite. The initial model of the control system and object was developed and debugged in Engee. At the current stage, we linked the control system to the peripheral modules of the real-time machine, and modelled the operation of the control object on RITM in parallel. The prototype control system reproduces identical and specified actions for motor control. Then we can move on to the transfer of the control system to the embedded system.