Knowledge Base

Example: Advanced motor control with SPice10213

This example provides sophisticated control. It implements speed-up and slow-down buttons, a stop/start button and a forward/reverse button. Unlike in the previous example, the direction button is honored at all times. If the motor is running it gets slowed to a stop, reversed and re-accelerated back up to speed. One simple code modification selects between gradual slow-down or sudden dynamic braking when the motor is to stop or reverse direction.

The program is written as a full multitasking application with 3 separate tasks. The programming techniques are fully explained in the multitasking tutorial. You will need to fully understand that material if this example is going to make sense to you.

The 3 tasks are:

Drive task

This task is responsible for controlling the output PWM in order to ramp the motor up or down to the desired speed.

Speed task

This task simply monitors the speed buttons and generates a target speed value.

Motor Sequencer task

This is the main control function which decides what is to be done. It primarily takes care of sequencing operations to take place in the right order whenever a button is pressed, irrespective of when it is pressed. The SPLatMap (state diagram) for the sequencer is described in the next section.