Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档 > MATLAB技术文章
MATLAB技术文章 MATLAB Technical Articles From Mathworks
回复
 
主题工具 显示模式
旧 2008-01-06, 16:32   #1
TechnicalArticles
游客
 
帖子: n/a
默认 Using Custom Device Driver Blocks for Microcontroller- Based Motor Control

By E. N. Hartley, University of Cambridge
Send email to Tom Erkkinen

From windshield wiper motors to gas turbines for power plants, microcontrollers are key to a wide range of applications. Unless the microcontroller is designed for a particular task, such as controlling the flow through a valve, positioning a lens, operating a conveyor belt, or positioning a robotic arm, it must be programmed. This involves developing both a control algorithm and a device driver that will support specific I/O functionality.
You can use Simulink and Real-Time Workshop to develop a control algorithm and to program the microcontroller’s I/O layer (see Writing Your Own Device Driver Blocks ). The Embedded Target for Motorola® MPC555 lets you automatically generate the I/O layer specfic to the Freescale (Motorola) MPC555 series of processors and suppports a wide range of I/O, but it provides only limited support for the powerful Freescale TPU I/O device.

The MPC555 Motor Control Function Blockset was created to extend the Embedded Target for Motorola MPC555 with driver blocks that support the most common TPU microcode available for the MPC5xx series of processors. You can download the MPC555 Motor Control Function Blockset from MATLAB Central.
This article defines the control requirements of various motor types, provides guidelines on selecting a block appropriate to your microcontroller, and demonstrates a sample block in the MPC555 Motor Control Function Blockset.
Motor Control Challenges

There are many different types of motor, each presenting specific control challenges to the embedded software developer. The following summarizes key aspects of electric motor and internal combustion engine control.
In electric motors, the controller must regulate the flow of current to the coils. This current controls the torque and speed of the motor. Pulse width modulation (PWM) is used to switch the voltage across the coils on and off rapidly with a programmable duty cycle. Some microcontrollers include hardware that can handle PWM automatically, needing only a duty-cycle parameter. Others provide a more complex function that enables two or more channels to be switched alternately, with a "dead-time" where both are off for a period at the change-over point to prevent shoot-through currents when transistors with asymmetric switching times are used.
The following are the most common types of electric motors:
  • DC motors consist of a permanent magnet or a fixed electromagnet for a stator and a rotor with an armature with a set of windings. Current is conducted to the windings through a set of slip-rings and brushes. These are arranged so that, as the rotor turns to align with the magnetic field of the stator, the direction of the current in each set of windings in the rotor armature is reversed and the rotor continues turning.
  • Brushless DC motors have no mechanical commutation. Instead, coils mounted on the stator are energized sequentially to cause the rotor to turn. Sensors detect the position of the rotor. The controller uses this information, plus the desired direction for the motor, to determine the next coil to which a current should be applied.
  • Induction motors are AC devices in which the alternating current flowing through the stator windings causes a rotating magnetic flux. The windings on the rotor cut the flux, generating a current in the rotor windings that induces its own magnetic field rotating with the rotor. The torque resulting from the differences in speed causes the rotor to rotate.
  • Stepper motors are suited to open-loop, precision angular positioning—the angle rotated is controlled by the sequence in which the stator coils are energized. By monitoring the inputs applied to the motor, the controller can keep track of position relative to a given starting point.
For combustion engines, where precise timing is critical, a crankshaft-angle-interrupt-driven approach is more appropriate than a sampled-time approach. Again, your microcontroller might accommodate hardware designed to simplify the synchronization of a series of output pulses (for example, to drive fuel injectors and spark plugs) to a series of input pulses (for example, from a camshaft with a toothed gear to determine angular position).
I/O Blocks for Motor Control

The MPC555 Motor Control Function Blockset provides blocks that support the specific control requirements of each type of motor.
Motor TypeMotorola® TPU Function UsedMPC555 Motor Control Function Driver BlockAllFQMTPU3 Frequency MeasurementDC DCm (all variants)TPU3 DC Motor DriveBrushless DCHALLDTPU3 Hall Effect DecodeBrushless DCCOMMTPU3 Motor CommutationBrushless DCBLDC/BLDCmTPU3 Brushless DC Motor CommutationInduction, Synchronous3Sin (all variants)TPU3 Three-Phase Sine WaveInduction, SynchronousSVM (all variants)TPU3 Space Vector ModulationStepperTSMTPU3 Table Stepper MotorStepperSMTPU3 Stepper MotorCombustion, Stepper (zero position)ITCTPU3 Input Capture/Input Transition CounterCombustionPMATPU3 Period Measurement with Additional Transition DetectionCombustionPMMTPU3 Period Measurement with Missing Transition DetectionCombustionPSPTPU3 Position-Synchronized Pulse Generator


The TPU3 Table Stepper Motor Block



Figure 1. TPU3 Table Stepper Motor block.Click on image to see enlarged view.

The TPU3 Table Stepper block lets you configure the TPU on the MPC555 to use the Table Stepper Motor microcode function provided in ROM on the chip. Given a velocity profile for acceleration and deceleration of the motor, this function will handle the switching of the output pins to rotate a motor to a requested relative position.
You can set the requested (relative) rotor position as a block input in your Simulink model and retrieve the achieved rotor position from a block output for use in the model. The block keeps a copy of the last requested rotor position and compares this to the most recent input, so that an update request is issued to the TPU only if you change the requested position, not after every model sample period. This prevents unnecessary writes to the TPU parameter RAM and unnecessary Host Service Requests to the TPU. If there is no update to perform, such requests would compromise performance without providing any benefit. The TPU3 Table Stepper block can trigger an update of the internal representation of the "current position”. This is useful if you are using a system with a zero-position sensor. The block will write the updated "current position” value to the TPU only if a Boolean 1 signal is present on the "update” input.
The block mask dialog for the motor step timings lets you specify the speed at which the motor will operate. Configuration options include initial stepping period, slew period (stepping period at maximum angular speed), and the table that characterizes the velocity profile. These timings are fixed for the duration of the running program.

Figure 2. TPU3 Table Stepper Motor Block configuration dialog.
The blockset includes the TPU3 Stepper Motor Remote Trigger, a block that links to a Table Stepper Motor block within a model. You can use it to change parameters for a single channel synchronously with the model and asynchronously with function calls generated by interrupts. If the trigger is connected to a block that throws a function call when a transition event occurs on a TPU channel, you can use it with a zero-position detector. The current position can then be set to zero on the trigger. Alternatively, the current position can be read and used as an offset on the requested position. This capability enables the program to set the internal representation of the current position to a known value without waiting for the next sample period. It also establishes a relationship between the internal representation and the known position.
The blockset provides a wizard-style GUI that can call the Motorola® TPU microcode assembler and, given access to the microcode source files, can compile a DPTRAM image and configure the appropriate settings in the MPC555 Resource Configuration Block from the Embedded Target for Motorola MPC555 in the model.
A Demonstration of the TPU3 Table Stepper Motor Block

TSMTest, one of the demonstration models included in the blockset (Figure 3), alternates the requested position that is passed to the driver block between two values at intervals of six seconds. The driver block handles configuring the TPU for the Table Stepper Motor (TSM) function, as well as programming the velocity/acceleration profile and minimum and maximum step times into TPU parameter RAM.


Figure 3. Sample model using the TPU3 Table Stepper Motor block.
At run-time the block passes the new requested motor position to the TPU and issues an update request only when the signal to the REQ input changes.
The demonstration is intended to be run on a stepper motor with two centre-tapped coils and an inverting amplification circuit between the MPC555 TPU pins and the stepper motor. For a non-inverting switching circuit, swap the polarity of each entry in the pin sequence.


Figure 4. The setup for the TPU3 Table Stepper Motor driver block demo.
Writing Your Own Device Driver Blocks

The MPC555 Motor Control Function Blockset is based on Simulink S-functions. Before implementing a driver block for a specific module on your microcontroller using S-functions, it is useful to identify which parameters should be fixed at run-time and which should be variable. Also consider whether the driver block is required to keep any data between samples when running—that is, whether any data-type work vectors are required.
Although you will create the block as a fully inlined S-function with a TLC file, you will still need to write a basic wrapper C-MEX S-function to define the data types and dimensions of parameters and ports. You must also give them names in the TLC file that will enable values passed in to the file to be referenced at the point of code generation.
You must ensure that outputs that might be modified by an interrupt service routine in the generated code remain in the global scope, otherwise, certain optimization settings will cause the generated code to fail at the compilation stage. Parameters that need to be passed to the TLC file are most easily passed as non-tunable parameters.
To get started, you can use the C code or TLC code for any driver block or the template in MATLABROOT/simulink/src/sfuntmpl_doc.c.

更多...
  回复时引用此帖
回复

主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 03:05


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.