Link here

Quick Start
Using the Motor Control Wildcard with the Mosaic PDQ Board or QCard Controller

The Motor Control Wildcard provides full motor control functionality when mated to a PDQ Board or QCard Controller. In that case a full-featured software driver gives you complete control of motor speed and direction with a very simple API. On this page we'll show you how to connect your motor and control it.


Installing the Motor Control Wildcard

On the QCard Controller, the Motor Control Wildcard will stack on top of the QCard with an aluminum standoff in each corner. On the PDQ Board or QScreen Controller, it will stack on top of either Module Port 0 or Module Port 1. For the sake of this demo, install the Motor Control Wildcard on Module Port 0.

With the power off, connect the female 24-pin side of the stacking go-through Wildcard bus header on the bottom of the Motor Control Wildcard to Wildcard Port 0 on the controller board. The corner mounting holes on the module should line up with the standoffs on the controller board. The module ports are labeled on the silkscreen of the controller board. Note that the Motor Control Wildcard headers are configured to allow direct stacking onto the Wildcard bus, even if other Wildcards are also installed. Do not use ribbon cables to connect the Motor Control Wildcard to the Wildcard bus.

Be careful; the Wildcard bus is not keyed!
The Wildcard bus does not have keyed connectors. Be sure to insert the Wildcard so that all pins are connected. The Wildcard bus and the Motor Control Wildcard can be permanently damaged if the connection is done incorrectly.

An onboard jumper, designated J3, determines whether the programmed setpoint controls the motor PWM or its speed using a proportional-integral control loop. Remove this jumper for the purposes of this demo. Two other jumpers, J1 and J2, set the module address; see the User's Guide for more information about selecting a module address, but for the purposes of this demo, if there are no other Wildcards installed on the QCard or PDQ Board, leave J1 and J2 uninstalled, for module address 0 on module port 0. On the QScreen, module address 0 may not be used; so install J1 to select module address 1 on module port 0.


Installing the driver and demo program

For Mosaic's PDQ line controllers, the demo is included in Mosaic IDE Plus at revision numbers later than 1430. Close any open projects in Mosaic IDE Plus to get to the start screen, then click on the box marked "Click Here to open a demo project" and select the "Wildcard Motor Control" Demo. Then open the "Build" menu and select "Build", and load the demo onto the PDQ-line controller using Mosaic Terminal.

In writing application software to use the Motor Control Wildcard driver software in Mosaic IDE Plus, it is only necessary to add the following line to the top of your source code, and the Mosaic IDE Plus will handle linking the driver code with your application:

#include <wmch.h>

For Mosaic's Q-line controllers, in addition to the demo program below you will also need a kernel extension package that includes the Motor Control Wildcard driver, generated using Mosaic's Kernel Extension Manager. Click the download link on the code below, and save the file with a short filename and .c extension into the same folder as the files extracted from the zip file produced by the Kernel Extension Manager. Then open the demo program in Mosaic IDE, and click the single-page build icon in the top toolbar. Finally, load install.txt and the DLF file, i.e. wmch-demo.dlf onto the Q-line controller using Mosaic Terminal.


  1: // This is a demonstration program for the Motor Control Wildcard.
  3: // Copyright 2014 Mosaic Industries, Inc.
  9: #include  <mosaic\allqed.h>    // include the standard library functions
 11: #ifdef _MOSAIC_LITE
 12: #error "The PDQ Board Lite does not support addressable Wildcards, so this demo is not applicable.  Go to Project -> Project Compiler Options and select the kernel version without the 'L' suffix to compile for the full PDQ Board."
 13: #endif
 15: #ifdef __GNUC__
 16: #include <wmch.h>
 17: #else
 18: #include "library.h"
 19: #include "library.c"
 20: #endif
 24: unsigned char modulenum = '\xff';
 28: unsigned char Get_User_Modulenum()
 29: {
 30:     unsigned char result;
 32: #ifdef __GNUC__
 33:     // Disable libc output buffering, which causes unexpected behavior on embedded systems.
 34:     // If I/O buffering would benefit your application, see the Queued Serial demo.
 35:     setbuf( stdout, NULL );
 36: #endif
 38:     printf( "\nEnter the module number of the Motor Control Wildcard\n"
 39:             "( With J1 and J2 *not* installed, the module number is 0\n"
 40:             "  if the Wildcard is installed on top of a QCard or on\n"
 41:             "  Module Port 0 of a Docking Panel or PDQ Board ) [0-7]: " );
 43:     // Module numbers are 0 - 7, meaning only the lower three bits are used,
 44:     // and all combinations of the lower three bits are valid module numbers.
 45:     // ( The reason for this is the selection of Module Port 0 or 1, plus J1
 46:     //   and J2 jumpers on each board, comprises three bits of information. )
 47:     // This makes checking for valid module numbers very straightforward.
 48:     do result = Key() - '0';
 49:     while( result & '\xf8' );
 51:     Emit( result + '0' );
 52:     Emit( '\n' );
 54:     return result;
 55: }
 57: _Q void Help( void )
 58: {
 59: #ifdef __GNUC__
 60:     // Disable libc output buffering, which causes unexpected behavior on embedded systems.
 61:     // If I/O buffering would benefit your application, see the Queued Serial demo.
 62:     setbuf( stdout, NULL );
 63: #endif
 65:     printf( "\nOther functions defined with _Q and executable at the command line\n"
 66:             "include (note you must enter a space after the open parenthesis):\n"
 67:             "  MSTOP( )   --  Brake motor, both outputs low.\n" );
 68:     printf( "  MCOAST( )  --  Both outputs disabled, motor coasts.\n"
 69:             "  MCW( N )   --  Spin motor clockwise.\n"
 70:             "  MCCW( N )  --  Spin motor counter-clockwise.\n"
 71:             "where N is a number from 0 to 31 indicating PWM duty cycle\n" );
 72:     printf( "without feedback from an optical encoder, or indicating fraction\n"
 73:             "of full speed if an optical encoder is used for closed-loop feedback\n"
 74:             "and the PI control jumper J3 is installed.\n" );
 75: }
 79: _Q void MStop( void )
 80: {
 81:     if( modulenum & '\xf8' ) modulenum = Get_User_Modulenum();
 82:     To_Motor( MOTOR_DIR_BRAKE_L, MOTOR_DECAY_SLOW, 0, modulenum );
 83: }
 85: _Q void MCoast( void )
 86: {
 87:     if( modulenum & '\xf8' ) modulenum = Get_User_Modulenum();
 88:     To_Motor( MOTOR_DIR_COAST, 0, 0, modulenum );
 89: }
 91: _Q void MCW( int duty_cycle )
 92: {
 93:     if( modulenum & '\xf8' ) modulenum = Get_User_Modulenum();
 94:     To_Motor( MOTOR_DIR_CW, MOTOR_DECAY_SLOW, duty_cycle, modulenum );
 95: }
 97: _Q void MCCW( int duty_cycle )
 98: {
 99:     if( modulenum & '\xf8' ) modulenum = Get_User_Modulenum();
100:     To_Motor( MOTOR_DIR_CCW, MOTOR_DECAY_SLOW, duty_cycle, modulenum );
101: }
105: int main( void )
106: {
107:     // Loop conditions below require that i be signed.
108:     int i;
110: #ifdef __GNUC__
111:     // Disable libc output buffering, which causes unexpected behavior on embedded systems.
112:     // If I/O buffering would benefit your application, see the Queued Serial demo.
113:     setbuf( stdout, NULL );
114: #endif
116:     modulenum = Get_User_Modulenum();
118:     printf( "\nTurning motor clockwise.\n" );
120:     for( i = 0; i <= MOTOR_PWM_MAX; ++i )
121:     {
122:         MOTOR_ON_CW( i, modulenum );
123:         MicrosecDelay( 62500u );
124:     }
126:     for( i = MOTOR_PWM_MAX; i >= 0; --i )
127:     {
128:         MOTOR_ON_CW( i, modulenum );
129:         MicrosecDelay( 62500u );
130:     }
132:     MOTOR_STOP( modulenum );
133:     MicrosecDelay( 62500u );
135:     printf( "\nTurning motor counter-clockwise.\n" );
137:     for( i = 0; i <= MOTOR_PWM_MAX; ++i )
138:     {
139:         MOTOR_ON_CCW( i, modulenum );
140:         MicrosecDelay( 62500u );
141:     }
143:     for( i = MOTOR_PWM_MAX; i >= 0; --i )
144:     {
145:         MOTOR_ON_CCW( i, modulenum );
146:         MicrosecDelay( 62500u );
147:     }
149:     MOTOR_COAST( modulenum );
151:     Help();
153:     return 0;
154: }

Running the demo program

If you have not installed an optical encoder for speed feedback, ensure the PI control jumper J3 is not installed before running the demo program.

With the demo program loaded onto the controller, type main and press Enter. You will be prompted for the module address of the Motor Control Wildcard; if the Motor Control Wildcard is installed on the QCard or on Module Port 0 / Wildcard Bus 0 of other controllers with neither module select jumper J1 or J2 installed, the module address is 0.

If you are using the QScreen, module address 0 is not available and you will need to install jumper J1, setting the module address to 1; then, enter 1 at the module address prompt.

After you enter the module address, if the motor and power supply are connected to the correct screw terminal headers and the power supply is on, the motor will ramp up its speed from zero to full in the "clockwise" direction over two seconds, ramp the speed back down to zero over two seconds, then repeat the same ramp-up and ramp-down in the counterclockwise direction.

Finally, a message will be printed listing other commands you can use to set specific speeds in the range of 0 to 31. These commands are debugging functions defined in the demo code using the _Q designator. The syntax of calling these debuggging functions is similar to that for C function calls, except that there is no semicolon, a space is required after the open parenthesis, and there must be no space before the open parenthesis.

If you are able to successfully run the demo program to control your motor, you are ready to integrate the Motor Control Wildcard into your software application. We recommend starting with the "Turnkey" demo, either from the demo selection page of Mosaic IDE Plus for the PDQ Board, or from the demo code included with the documentation on this site for Q-line controllers.

This page is about: Quick Start to Using Motor Control Wildcard – Simple H-Bridge driver board and firmware library gets you controlling the speed and direction of DC motors