MIAC example programs

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Post Reply

Please rate this article out of 5: (1 being the worst and 5 being the best)

1
0
No votes
2
0
No votes
3
0
No votes
4
1
33%
5
2
67%
 
Total votes: 3

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

MIAC example programs

Post by Sean »

Image

MIAC Example Programs

A collection of MIAC example programs and schematics is now available to be downloaded from our website.

http://www.matrixmultimedia.com/MIAC-X.php

Applications range from simple input and output demonstrations, to more complex motor control and CAN bus applications.

The MOTOR2 example demonstrates several useful features in a program that allows the speed and direction of two independent d.c. motors to be controlled from the MIAC keypad.

PWM speed control
Motor speed control is achieved using Pulse Width Modulation (PWM). Flowcode has a PWM component that can be used in conjunction with the MIAC component to add PWM functionality to the A and C transistor outputs.

Full-bridge connection
Connecting a motor between a PWM output and the 0V supply rail would allow control of the speed, but this 'Half Bridge' connection would only allow the motor to turn in one direction.
To allow direction control, each motor must be connected between a PWM output (A or C) and a non-PWM transistor output (B or D respectively). The non-PWM output is used to select either 0V or the positive supply voltage (M terminal) as the motor reference voltage. This 'Full Bridge' connection allows the motor to be driven in either direction.

Image

Reverse drive:
To drive the motor in reverse, one motor connection must be driven from the M supply rail by turning the appropriate B or D output on. If normal PWM speed control was used in this case, a zero duty cycle would result in the motor running in the reverse direction at full-speed. The PWM output also needs to be referenced to the M supply rail (inverted). This can be easily achieved by subtracting the required duty-cycle from the maximum duty-cycle value (255).

Image

Macros
The MIAC example folder includes a 'Macros' sub folder which contains several useful macro functions that can be imported into programs and used for other applications. Three of these macros have been used in the Motor2 example program:


MotorEnable

Input parameter: channel
Function: Configure a full bridge motor drive output for the selected channel.
(1 = outputs A,B : 2 = outputs C,D).


MotorControl

Input parameters: channel, PWM duty, direction (0 = forward : 1 = reverse)
Function: Generate the required full bridge outputs for the selected channel. Automatically adjust the supply connection and PWM duty cycle depending on direction.


GetNumber

Input parameters: number of digits, signed (negative values allowed)
Return value: integer value
Function: Use the cursor keys and OK button to select digits on the MIAC display and return a numeric value.

All the macros have been written to allow them to be imported easily into Flowcode programs by using local variables within the macros, using parameters to pass values in from the main program, and creating a return parameter if required to pass a value pack to the main program.

Speed/Direction control
The speed and direction of each motor can be controlled from the MIAC user interface (keypad and display). The motor to be controlled is selected using the appropriate function key:
F1 (Yellow) = Motor 1 (Outputs A,B)
F2 (Blue) = Motor 2 (outputs C, D)

When a function key is pressed, the GetNumber macro is called with parameters to allow a 3-digit, signed number to be entered. The left and right cursor keys can be used to select the digit position to be edited. The up and down cursor keys can be used to cycle the selected numeric digit through the values 0-9, and the leading sign character between + and -.
When the OK button is pressed, the entered value is returned to the main program and used, with the MotorControl macro, to update the speed and direction of the selected motor. A positive value drives the motor in the 'forward' direction and a negative value drives it in 'reverse' - based on the polarity of the motor connections. Entered values should be between +255 and -255.

A schematic diagram for this example, MOTOR2.jpg, is available from the Schematics folder of the MIAC examples download.

Post Reply