Skip to content
Open-source simulation model

Stepper Motor Modelin Scilab/Xcos

Stepper-Lab runs the real C code of Stepper-C, or a Scilab prototype of it, against a model of the motor and its power stage: drive it with any signal, read labelled results, and see a fault before the hardware does.

  • Real C code
    in the loop
  • Any Xcos
    input signal
  • 433 checks
    0 failures
  • Apache-2.0
    open source
A block diagram on a board: signal sources drive the Stepper-C chip, which drives a motor model in a loop, and a scope shows the two phase currents.
The problem

A controller is hard to judge on the bench

On real hardware a current loop runs at 20 kHz, a lost step takes milliseconds, and the first test of a new controller can burn a power stage. You see a few probes at a time and cannot repeat a stall exactly. A model that runs the same code lets you study all of it first, at any signal and on every run the same way.

Test the code that ships

The Stepper-C library runs inside an Xcos block, with ADC counts in and PWM compare values out. It matches the Scilab prototype within 1.28 mA in a move of 640 microsteps.

  • SIL
  • MIL
  • FIXED and FLOAT

Any input, readable output

Step, sine, ramp or your own signal on the motion command, run current and load torque. Named scopes and a report with titles, units and the first fault replace unlabelled traces.

  • Four superblocks
  • Eight scenarios
  • Report

Results with a source

The power stage comes from ngspice, the model is checked against theory and a separate Python twin, and MIL and SIL report the same fault at the same time: 204.9 ms in the load step test.

  • ngspice stage
  • Python twin
  • 433 checks
What you get

One window from configuration to results

Select the library folder and the stage file, choose MIL or SIL and a scenario, then run, report, compare or test. The same steps are available as Scilab functions.

433checks passed on the final run
8ready scenarios
1.28 mAlargest MIL and SIL difference in a move
0.40 mssettling of a 2 A current step

Quick start

A first simulation in five steps

  1. Install Scilab 2027 and, on Windows, Visual Studio or the Build Tools with the workload Desktop development with C++.
  2. Clone Stepper-Lab and Stepper-C next to each other.
  3. In Scilab, open start_lab.sce and press F5.
  4. Choose the scenario Velocity step to 1 rev/s and press Run. The first run compiles the library.
  5. Press Report to see the currents, speed, position and load angle.

The same run from a script:

exec("loader.sce", -1);         // from the root of the repository
res = lab_run("SIL", 3);
d = sil_report_data(res);
mprintf("%d samples, %d panels\n", size(res.values, 1), size(d.panels));

Part of a family

Stepper-Lab tests Stepper-C, the control library, and takes its power stage values from sfs-stepper-power-spice, the ngspice models.

Find your way

If you want to… Read
Understand what the model does and does not do Introduction
Install it and run it the first time Getting Started
Use the window, the diagrams and your own signals The Lab Window and Diagrams
Choose between the C library and the Scilab prototype MIL and SIL
Set the motor, the board or the stage file Configuration
See the equations Motor and Control Model
See what the model shows Measured Results
Look up a column, a block or a function Reference
Run the tests Verification
Read everything offline or print it PDF user manual
SystemFromScratch®

Part of an open-source embedded portfolio

Stepper-Lab is developed by Anton Vynohradov under SystemFromScratch® — embedded software and hardware built from the first schematic to certification.

SystemFromScratch® is a registered trademark. STM32 is a registered trademark of STMicroelectronics International N.V.; Stepper-Lab is not affiliated with or endorsed by STMicroelectronics.