Le cœur de MTobjects
Event management for Uno, Nano, Mega
This part is more complex to understand and use. The default library settings are used in most cases. By optimally adjusting clocks, we can significantly decrease the time taken by the library, or be able to go faster for certain treatments.
100µs time base
These 100µs is the default resolution for the soft PWM and the minimum time between two steps (or micro-steps) for seppers. With 100µs you can use about 14 soft PWM or 7 stepers turning at maximum 10,000 steps/s (or a skillful mixture of the two). This is enough for many applications.
Between two steps or micro-steps you can have between 1 and 3600,000 time base . With 100µs, you can have between 100µs between steps (10,000 steps/s) and one step per hour. With a time base of 1ms, you can have a step every 10 hours.
The function MTtimeBase() allows you to choose the time base between 12µs (if you want to go fast) and 1ms (if you don't need speed and you don't want to spend too much time in the interruptions). Due to the common use with the system clock, the resolution is 4µs. We can therefore choose 12µs, 16µs, 20µs, 24µs ... If we ask for 22µs, it is the lower time which is put in place (20µs), to allow a step every 22µ on average.
MTtimeBase(100 micro_seconds); // By default MTtimeBase(10 micro_seconds); // Minimum MTtimeBase(1024 micro_seconds); // Maximum
The system time base
The system base allows you to use micro(), millis() and delay(). The delayMicroseconds(), _delay_ms() and _delay_us() would be correct without the interruptions. The system base turning to 1024µs (if the quartz was perfect), millis() sometimes increment by 1, sometimes of 2. The resolution of millis() is therefore 2ms. This time base is fixed, modifying it would modify micro(), millis() and delay().
The MTobjects library does not use this clock, and if we do not use 3 functions, we can deactivate it, which saves calculation time and allows for example to run a stepper faster.
MTstopDelayMillis(); // Disable system clock MTstartDelayMillis(); // Reactivates the system clock
As soon as we use any object of MTobjects, these functions are accessible. It is therefore not useful to put an in addition.
If you need millis() but not micro() nor delay(), you can also deactivate this clock and use MTmillis() instead.
Sharing time
Of course so that all of this is funny, certain temporal limits should not be exceeded. If this is not the case, steppers may not turn at the right speed, buttons may no longer be taken into account...
Note on buttons: in normal function, a button is taken into account, but its treatment can be delayed if the treatment of other events is long.
Here are the low limits of the time base: - without any object: 12µs - if the system clock is activated: add 6µs (to be checked, the measurements made would tell me 0µs!) - for each MTsoftPWM: add 6µs - for each MTulnStepper: add 16µs - for each MTstepStepper: add 12µs - for other objects: not adding anything
For example by deactivating the system clock:
- for 7 MTstepStepper, the low limit is 12µs + 7*12µs = 96µs. We can therefore make for each stepper 1 step every
96µs (10,400 steps/s), or take a time base of 100µs if we do less than 10000pas/s ... We can of course take a time base of 1ms if we make
less than 1000 steps/s
- with a single MTstepStepper,, the low limit is 24µs. We can then take 1 step every 24µs or approximately
41666 steps/s. With a hybrid stepper of 200 steps/turn and in 16 micro-steps mode, that is 41666/(200 * 16) = 13 rpm
- if we have 10 buttons, 2 mtsoftPWM and 3 steppers, and the system clock is not deactivated, you have to:
12µs (incompressible time for the library)
6µs (system clock)
0µs (10 buttons)
2*6µs (2 MTsoftPWM)
3*12µs (2 MTstepStepper)
━━━━━━━━━━━━━━━━━━━━━━━━
66µs
In most cases, the default 100µs are not changed.
Also note that an stepper turning at 1rps would need 200 inpulses per turn in whole mode, but if we use, as I recommend, 16 micro-steps mode, you need 3200 inpulses per turn. It is therefore useful to have a library to give a number of inpulse/s important. A stepper at 200 steps per turn in 16 micro-step mode (3200 inpulses per turn) and turning at its maximum speed (3000rpm or 50rps) would need 160,000 inpulses per second (1 inpulse_width every 6.25µs), which this library does not allow.
The hierarchy of classes
There are three basic classes:

The three basic classes regularly give time for the objects.
MTquickObjects descending objects need to intervene often (default every 100µs) and are priority. There is for example the
management of the steppers advance, signal management for a software PWM.
The descending objects of MTmediumObjects need to intervene regularly (every 16ms). This is the case of the buttons that must be
visited from time to time.
The descending objects of MTslowObjets allow treatment of events. Treatments can start every 16ms if the previous treatment is
completed. All usable objects therefore descend from this class.
The buttons:

The clocks:

The PWM:

The servomotors:

The steppers:

Examples