MCP Series Brushed DC Motor Controllers MCP233 MCP236 MCP263 MCP266 MCP2163 MCP2126 MCP2166 MCP2206 MCP2128 MCP2168 User Manual Firmware V1.1 and Newer Hardware V2 and Newer User Manual Revision 1.2 (c) 2014, 2015 Ion Motion Control.
MCP Series Brushed DC Motor Controllers Contents Firmware History................................................................................................. 9 Warnings........................................................................................................... 10 1.0 Introduction................................................................................................. 11 1.0.1 Motor Selection....................................................................................
MCP Series Brushed DC Motor Controllers 1.6 Status LEDs.................................................................................................. 37 1.6.1 Status and Error LEDs........................................................................... 37 1.6.2 Message Types..................................................................................... 37 1.6.3 LED Blink Sequences............................................................................. 38 1.7 Regenerative Voltage Clamping..
MCP Series Brushed DC Motor Controllers 252 - Read User EEProm Word....................................................................... 84 253 - Write User EEProm Word...................................................................... 84 2.4 Encoders...................................................................................................... 85 2.4.1 Cloosed Loop Modes.............................................................................. 85 2.4.2 Quadrature Encoders...................
MCP Series Brushed DC Motor Controllers 3.1 MCL Language............................................................................................ 105 3.1.1 Variables............................................................................................105 3.1.2 Variable Types.....................................................................................105 3.1.3 Variable Locations................................................................................105 3.1.4 Defining Variables.......
MCP Series Brushed DC Motor Controllers MOTORENCPIN (2).......................................................................................120 MOTORBUFFER (2).......................................................................................120 STREAMTYPE (4).........................................................................................120 STREAMRATE (4).........................................................................................120 STREAMTIMEOUT (4).............................
MCP Series Brushed DC Motor Controllers DIG...........................................................................................................135 Shift Left (<<)............................................................................................136 Shift Right (>>)..........................................................................................136 AND (&).....................................................................................................136 OR ( | ).................
MCP Series Brushed DC Motor Controllers END...........................................................................................................159 FOR...NEXT.................................................................................................160 GETS.........................................................................................................161 GOSUB.......................................................................................................162 GOTO..................
MCP Series Brushed DC Motor Controllers Firmware History MCP is an actively maintained product. New firmware features will be available from time to time. The table below outlines key revisions that could affect the version of MCP you currently own. Revision 1.0.
MCP Series Brushed DC Motor Controllers Warnings There are several warnings that should be noted before getting started. Damage can easily result if the motor controller is not properly wired. Injury can occur due to inadequate planning for emergency situations. Any time mechanical movement is involved the potential for injury is present. The following information can help avoid damage to the motor controller, connected devices and help reduce the potential for injury.
MCP Series Brushed DC Motor Controllers 1.0 Introduction 1.0.1 Motor Selection When selecting a motor controller several factors should be considered. All DC brushed motors will have two current ratings, maximum stall current and continuous current. The most important rating is the stall current. Choose a model that can support the stall current of the motor selected to insure the motor can be driven properly without damage to the motor controller. 1.0.
MCP Series Brushed DC Motor Controllers 1.0.8 Power Sources A battery or DC power supply can be used as the main power source for the MCP motor controller. When using a DC power supplies, motor deceleration can cause excessive regenerative voltages. Typically excessive regenerative voltage must be bleed off using a voltage clamp circuit. This can also be resolved by limiting motor deceleration. This will reduce the regenerative voltages.
MCP Series Brushed DC Motor Controllers 1.1 Hardware Overview 1.1.1 Control Inputs All digital input are 15V tolerant. The MCP outputs can interface to both 5V and 3.3V logic with no voltage translation required. The MCP inputs are internally current limited and voltage cliped to 3.3V. This method also protects the MCP I/O from damage. The digital output pins can drive up to 3Amps at 40VDC. The CAN interface and RS232 pins are duplexed. When a duplex function is used the other is set to a high Z state.
MCP Series Brushed DC Motor Controllers 1.2 Ion Studio Overview 1.2.1 Ion Studio Setup Utility The Ion Studio software suite is designed to update firmware, configure I/O functions, configure MCP modes and create MCL programs. Ion Studio includes an editor for creating MCL programs to customize the MCP motor controller. The Ion Studio application can be downloaded from the ionmc.com downloads page. 1.2.2 Device Connection This first screen shown is the Ion Studio connection screen.
MCP Series Brushed DC Motor Controllers 1.2.3 Device Status Once a connection is established, the device status screen becomes active (1). All status indicators (3,4) and monitored parameter fields (2) will update to reflect the current status of the connected motor controller. When a motor controller is connected the Stop All (5) button becomes active. There is a small check box to activate the Stop All function by using the space bar on an attached keyboard.
MCP Series Brushed DC Motor Controllers 1.2.5 Status Indicator The status indicators (4) shown at the bottom of the screen are an abbreviated duplication of the main status indicators (3) shown on the device status screen. Label Description M1OC Motor 1 over current. M2OC Motor 2 over current. MBHI Main battery over voltage. MBLO Main battery under voltage. LBHI Logic battery over voltage. LBLO Logic battery under voltage. TMP1 Temperature 1 TMP2 Optional temperature 2 on some models.
MCP Series Brushed DC Motor Controllers 1.2.6 File Menu Label Description New Create a new MCL program file. Open Open an existing MCL program file. Save Save an open MCL program file. Save As Save an open MCL progam file to a new filename. Exit Disconnects from the unit and close Ion Motion. 1.2.7 Edit Menu Label Description Undo Undo last edit in MCL editor. Redo Redo last edit in MCL editor. Cut Cut selected text in MCL editor. Copy Copy selected text in MCL editor.
MCP Series Brushed DC Motor Controllers 1.2.8 Device Menu Label Description Connect CANOpen Bus Connects or Disconnects from a GridConnect CANUSB Bus controller. Read Settings Reads the settings saved in non-volatile memory on the controller. Default Settings Loads the factory default settings to the controller. Save Settings Writes current settings to non-volatile memory on the controller. Check MCL Compiles and checks the open MCL script for errors.
MCP Series Brushed DC Motor Controllers 1.2.10 General Settings Screen The general settings screen is used to configure the connected motor controller. 1 7 6 2 3 4 5 (1) Unit Settings Function Description Packet Serial Address Set the attached units address for bussed serial. E-Stop Soft Reset Select E-Stop Reset option. Defaults to hardware reset. Control Mixing Mixes two motor control channels for differential steering control. PWM Mode Locked Anti Phase or Sign Magnitude.
MCP Series Brushed DC Motor Controllers (3) Current Limits Function Description Main Battery Set minimum and maximum voltage cut off. Logic Battery Set minimum and maximum voltage cut off. (4) Priority Levels Function Description Priority Level 1 Sets input signal priorities. Level 1 is the master input. Level 2 inputs will override level 3. Used to time out a control input and move to a backup. Priority Level 2 Sets input signal priorities. Level 1 is the master input.
MCP Series Brushed DC Motor Controllers 1.2.11 PWM Settings The PWM settings screen is used testing a connected motor controller. Sliders are provided to control each motor channel. This screen can also be used to determine the QPPS of attached encoders. 1 4 3 2 (1) Graph Function Grid Description Displays channel data with 100mS update rate and one second horizontal divisions. (2) PWM/Torque Settings Function Description L MCP only. Motor Inductance in Henries. R MCP only.
MCP Series Brushed DC Motor Controllers (3) Control Function Description Motor 1 Controls motor 1 duty percentage forward and reverse. Motor 2 Controls motor 2 duty percentage forward and reverse. Sync Motors Synchronises Motor 1 and Motor 2 Sliders. Accel Acceleration rate used when moving the sliders. Duty Displays the numberic value of the motor slider in 10ths of a Percent (0 to +/1000).
MCP Series Brushed DC Motor Controllers 1.2.12 Velocity Control Settings The Velocity settings screen is used to set the encoder and PID settings for speed control. The screen can also used for testing and plotting. 1 2 4 3 (1) Graph Function Grid Description Displays channel data with 100mS update rate and one second horizontal divisions. (2) Velocity Settings Function Description Velocity P Proportional setting for PID. Velocity I Integral setting for PID.
MCP Series Brushed DC Motor Controllers (3) Control Function Description Motor 1 Motor 1 velocity control (0 to +/- maximum motor speed). Motor 2 Motor 2 velocity control (0 to +/- maximum motor speed). Sync Motors Synchronises Motor 1 and Motor 2 Sliders. On Release Will not update new speed until the slider is released. Accel Acceleration rate used when moving the sliders. Velocity Shows the numeric value for the sliders current position. Tune M1 Start motor 1 velocity auto tune.
MCP Series Brushed DC Motor Controllers 1.2.13 Position Control Settings The Position settings screen is used to set the encoder and PID settings for position control. The screen can also be used for testing and plotting. 1 2 3 4 (1) Graph Function Grid Description Displays channel data with 100mS update rate and one second horizontal divisions.
MCP Series Brushed DC Motor Controllers (2) Graph Channels Function Description Scale Sets vertical scale to fit the range of the specified Channel. Channels Select data to display on the channel. The channel is graphed in the color shown.
MCP Series Brushed DC Motor Controllers (4) Control Function Description Motor 1 Motor 1 velocity control (0 to +/- maximum motor speed). Motor 2 Motor 2 velocity control (0 to +/- maximum motor speed). Sync Motors Synchronises Motor 1 and Motor 2 Sliders. On Release Will not update new speed until the slider is released. Accel Acceleration rate used when moving the sliders. Deccel Decceleration rate used when moving the sliders. Speed Speed to use with slide move.
MCP Series Brushed DC Motor Controllers 1.2.14 MCL Editor The MCP editor is used to create MCL programs which are then download and ran on the MCP motor controller. 2 1 (1) MCL Editor The built in program editor is a single document intereface. Mulitple files can be opened at a time and will be shown as tabs. The highlted tab is the working file. (2) Control Toolbar The editor toolbar controls all the fucntions for the MCL editor.
MCP Series Brushed DC Motor Controllers Function Description Paste Standard paste text function. Shown Hidden Characters Shows hidden characters that are typically left over from a copy / paste function. Highlight Current Line Highlights current selected line. Show Folding Lines Start motor 1 velocity auto tune. Undo Undo changes. Redo Redo changes. Add Remove Goto Bookmarks Check Check current script for syntax errors. Upload Uploaded current program to attached motor controller.
MCP Series Brushed DC Motor Controllers 1.3 Firmware Updates 1.3.1 Ion Studio Setup Download and install the Ion Studio application. Win7 or newer is required. When opening Ion Studio, it will check for updates and search for a USB Windows Driver to verify installation. If the USB driver is not found, Ion Studio will install it. 1. Open the Ion Studio application. 2. Apply a reliable power source such as a fully charge battery to power the motor controller. 3.
MCP Series Brushed DC Motor Controllers 1. When a new version of firmware is shown click the update button (3) to start the process. 2. Ion Studio will begin to update the firmware. While the firmware update is in progress the onboard LEDs will begin to flash. The onboard flash memory will first be erased. It is important power is not lost during this process or the motor controller will no longer function. There is no recovery if power fails during the erase process. 3.
MCP Series Brushed DC Motor Controllers 1.4 DC Power Settings 1.4.1 Automatic Battery Detection on Startup Auto detect will sample the main battery voltage on power up or after a reset. All Lipo batteries, depending on cell count will have a minimum and maximum safe voltage range. The attached battery must be within this acceptable voltage range to be correctly detected. Undercharged or overcharged batteries will cause false readings and the MCP will not properly protect the battery.
MCP Series Brushed DC Motor Controllers 1.5 Wiring 1.5.1 Basic Wiring The MCP has many control modes and each mode may have unique wiring requirements to ensure safe and reliable operation. The diagram below illustrates a very basic wiring configuration used in a small motor system where safety concerns are minimal. This is the most basic wiring configuration possible. Any wiring of MCP controllers should include a main battery shut off switch, even when safety concerns are minimal.
MCP Series Brushed DC Motor Controllers 1.5.2 Wiring Safety In all system with movement, safety is a concern. The wiring diagram below illustrates a properly wired system with several safety features. An external main power cut off is required for safety. When the RoboClaw is switched off or the fuse is blown, a high current diode (D1) is required to create a return path to the battery for any regenerative voltages.
MCP Series Brushed DC Motor Controllers 1.5.4 Backup Power An optional backup battery is supported. Under heavy loads the main power can suffer voltage drops, causing potential logic brown outs if the voltage dips below approximately 8VDC, which may result in uncontrolled behavior. A separate power source for the motor controllers logic circuits, can remedy potential problems from main power voltage drops. The backup battery maximum input voltage is 15VDC with a minimum input voltage of 6VDC.
MCP Series Brushed DC Motor Controllers 1.5.5 Limit, Home and E-Stop Wiring Digital or Analog inputs can be used for Limit, Home or E-Stop signalling. A pull-up resistor to 5VDC or 3.3VDC should be used as shown. The circuit below shows a NO (normally open) style switch. Connect the NO to the specific input pin and the COM end to a ground shared with the MCP.
MCP Series Brushed DC Motor Controllers 1.6 Status LEDs 1.6.1 Status and Error LEDs MCP includes 3 LEDs to indicate status. Two green status LEDs labeled STAT1 and STAT2 and one red error LED labeled ERR. When the motor controller is first powered on all 3 LEDs should blink briefly to indicate all LEDs are functional. The LEDs will behave differently depending on the mode. During normal operation the status 1 LED will remain on continuously or blink when data is received in RC Mode or Serial Modes.
MCP Series Brushed DC Motor Controllers 1.6.3 LED Blink Sequences When a warning or fault occurs RoboClaw will use the LEDs to blink a sequence. The below table details each sequence and the cause. LED Status Condition Type Description All three LEDs lit. E-Stop Error Motors are stopped by braking. Error LED lit while condition is active. Over 85c Temperature Warning Motor current limit is recalculated based on temperature. Error LED blinks once with short delay. Other LEDs off.
MCP Series Brushed DC Motor Controllers 1.7 Regenerative Voltage Clamping 1.7.1 Voltage Clamp When using power supplies regenerative voltage spikes will need to be dissipated. A power resistor in the range of 10 Ohms at 50 watts for small motors and down to 1 Ohms or lower for larger motors may be required. 50 watts will likely cover most situations however smaller wattage resistor may also work depending on the application. The regenerative energy will be dissipated as heat. 1.7.
MCP Series Brushed DC Motor Controllers 1.7.3 MOSFET Voltage Clamp Setup When using DOUT to drive an N-Channel MOSFET set the specific DOUT pin action to "Over Voltage" and check the "inverted" option in Ion Studio. 1.7.4 MOSFET Voltage Clamp Wiring Alternatively a solid state switch (Q1) can be used along with the power resistor(R3) for higher current requirements. Wire the circuit as shown below. Q1 should be a 5v logic level N-Channel MOSFET. An example would be the FQP30N06L.
MCP Series Brushed DC Motor Controllers 1.7.5 Voltage Clamp Setup and Testing The circuits shown will need to be modified for each application to make sure it properly dissipates the regenerative voltages. Testing should consist of running the motor up to 25% of its speed and then quickly slowing down without braking or E-Stop while checking the voltage spike generated. Repeat, increasing the speed and power by 5% each time and checking the voltage spike again.
MCP Series Brushed DC Motor Controllers 1.8 Bridged Channel Mode 1.8.1 Bridging Channels The dual channels on an MCP can be bridged to run as one channel, effectively doubling its current capability for one motor. The MCP can be damaged if it is not set to bridged channel mode before wiring up the single motor as show. Download and install Ion Studio setup utility. Connect the motor controller to the computer using an available USB port.
MCP Series Brushed DC Motor Controllers 1.9 I/O Configuration 1.9.1 I/O Types There are several I/O types available on the MCP. This includes Digital Input, Pulse Inputs, Analog, CAN, TTL Serial, RS-232 and USB. The I/O types can be set using Ion Studio. Under the general settings screen all available pin settings will be listed for the connected motor controller. Refer to the data sheet for pin locations of the specific model of motor controller. 2 3 1 1.9.
MCP Series Brushed DC Motor Controllers 1.9.3 USB The USB has two modes and a timeout function. The USB can be access from an MCL program with a priority timeout. To configure the USB control settings select USB from the pin settings list. Modes Pins can have multiple functions. The mode drop down menu under input settings is used to set the main fuction of the selected pin from the pin settings list. After the mode is set the available settings for that mode will be active and can be set.
MCP Series Brushed DC Motor Controllers 1.9.4 CANOpen To configure the CANopen control settings select the CAN pins from the pin settings list. Then select CANopen from the mode drop down menu to enable the CAN buss feature. Priority Timeout - Disabled, CANOpen functions will execute at all priority levels. Rate - Bit rate for CANopen. Show in bits per secopnd. Default value is 250000.
MCP Series Brushed DC Motor Controllers 1.9.5 RS-232 The RS-232 port is hardware level converted. It can be directly interfaced with any standard RS232 equipment. CANopen pins are typically shared and when not in use are set to a high Z state. To configure the RS-232 control settings select RS-232 from the pin settings list. Modes Pins can have multiple functions. The mode drop down menu under input settings is used to set the main fuction of the selected pin from the pin settings list.
MCP Series Brushed DC Motor Controllers • MCL Serial - Give an MCL script access to the UART. Can be used with the CDC ACM virtual comport over the USB connection. Rate - The bit rate to communicate at. Default value is 115200. Valid Range is 300 to 1000000 bps.
MCP Series Brushed DC Motor Controllers 1.9.6 I2C Enable the I2C bus control settings. MCP supports one I2C master bus which can be used for controlling sensors and memory I2C slave devices. I2C is only accessable from a user MCL script. Rate - I2C Bit Rate used to communicated to slave devices. Valid bit rates for I2C Master is 100000, 400000 and 1000000.
MCP Series Brushed DC Motor Controllers 1.9.7 TTL UARTx Configure UARTx control settings. TTL UARTs are buffered. There are a total of three TTL UARTS available. Modes Pins can have multiple functions. The mode drop down menu under input settings is used to set the main fuction of the selected pin from the pin settings list. After the mode is set the available settings for that mode will be active and can be set. If the setting is not applicable to the selected mode it will be grayed out.
MCP Series Brushed DC Motor Controllers • MCL Serial - Give an MCL script access to the UART. Can be used with the CDC ACM virtual comport over the USB connection. Rate - The bit rate to communicate at. Default value is 115200. Valid Range is 300 to 1000000 bps. Multi Unit Mode - Sets TTL output into open-drain mode, allowing multiple MCP units to use the same RX connection to the external controller.
MCP Series Brushed DC Motor Controllers 1.9.8 Digital, Analog, Pulsed and Encoder Inputs Pins with a DINx can be configured as digital inputs. Pins with ANx can be configure as analog inputs. Pins with a Px can be configred as pulse inputs. Pins with an ENCx are can be configured as encoder inputs. The encoder inputs must be grouped. ENC1A and ENC1B are used for encoder one which corresponds to motor channel one. Not all pins are capable of all three functions.
MCP Series Brushed DC Motor Controllers Low Pass - Sets the low pass digital filter for the input. The digital filter takes a running average of 2^N samples at 10khz. By default the low pass filter is disabled on digital inputs. To use the digital input with a PWM signal (without using pulse measurement) the low pass filter must be enabled. Note this method of reading a PWM signal supports PWM frequecnies up to 5khz (half the sample rate).
MCP Series Brushed DC Motor Controllers M1/M2 Forward Limit - The controlled motor will be stopped at the maximum decceleration rate allowed. After stopped the motor will be prevented from moving forward, however reverse commands will be allowed until the action is cleared. M1/M2 Backward Limit - The controlled motor will be stopped at the maximum decceleration rate allowed. After stopped the motor will be prevented from moving backward, however forward commands will be allowed until the action is cleared.
MCP Series Brushed DC Motor Controllers 1.9.9 DOUTx The DOUTx pins are sinking only. They can be used to drive loads such as contactors or braking systems. Configure the MCP digital output pins. Mode Sets the action that will trigger the output pin. MCL scripts can override the set action Motor1 On - Turns the selected DOUTx pin on when motor channel 1 turns on. Motor2 On - Turns the selected DOUTx pin on when motor channel 2 turns on.
MCP Series Brushed DC Motor Controllers Over Temperature - Turns the selected DOUTx pin on when the motor controller has an over temperature condition. Status1 LED - Turns the selected DOUTx pin on when the led goes active. Can be used to add remotely located duplicate LEDs. Status2 LED - Turns the selected DOUTx pin on when the led goes active. Can be used to add remotely located duplicate LEDs. Error LED - Turns the selected DOUTx pin on when the led goes active.
MCP Series Brushed DC Motor Controllers 1.9.10 Signal Graph The signal graph shows how the input signal is modified by the input settings. If no settings are changed and the Min, Center and Max ranges are set to their defaults a straight slope will be shown. The graph below shows the default signal slope. Deadband If an R/C signal is used to control a motor and deadband is added so the R/C controller stick doesn't need to be exactly centered to stop the controlled motor.
MCP Series Brushed DC Motor Controllers Power Minimum In another example, some motors may need an offset in the minimum power to start rotating. After adjusting the Power Min to the required minimum value to start rotating the graph would show a vertical offset of the sloped lines above and below the center / zero point.
MCP Series Brushed DC Motor Controllers 1.9.11 Command Settings The signal graph shows how the input signal is modified by the input settings. If no settings are changed and the Min, Center and Max ranges range and set to their defaults a straight slope will be shown. Modes Inputs can be used to control one or both motors by duty cycle, velocity control or position control depending on the PID settings for that particular motor.
MCP Series Brushed DC Motor Controllers Match Input The Match Input option calculates the input range with center being 0 and sets the Min and Max value range to match it.
MCP Series Brushed DC Motor Controllers 1.9.12 Status The status displays the current input signal parameters. The status display is updated continiously and can be used to verify the input signal. Command Displays the scaled command value based on the Command Min,Max range and Mode Position Displays the input signals value after ranging, filtering, deadband, Power Exp and Power Min offset have been calciulated.
MCP Series Brushed DC Motor Controllers 2.0 Communications 2.0.1 Communication and Input Types The MCP offers several methods of communications. User generated MCL programs can access each type. During initial development USB is best suited due to its simplicity and speed. USB is not immune to electrically noisy environments and RS-232 serial or CANopen are recommended for the final application. • USB Packet Serial - A USB connection can be used to control the MCP controller an interface to an MCL program.
MCP Series Brushed DC Motor Controllers 2.1 USB Communications 2.1.1 USB Connection A USB connection can be used to control the MCP. The USB connection use packet serial commands. The USB connection can also interface to a running MCL script. The MCP can communicate over USB using packet serial commands at any time. 2.1.2 USB Power The MCP USB port is self powered. This means it receives no power from the USB cable. The controller must be externally powered to function. 2.1.
MCP Series Brushed DC Motor Controllers 2.2 Packet Serial Mode 2.2.1 Packet Serial Communications Packet serial is a buffered bidirectional serial mode. Sophisticated instructions can be sent to the controller. The basic command structures consist of an address byte, command byte, data bytes and a CRC16 16bit checksum. The amount of data each command will send or receive can vary. 2.2.2 Address Packet serial requires a unique address.
MCP Series Brushed DC Motor Controllers 2.2.6 CRC16 Checksum Calculation MCP uses a CRC(Cyclic Redundancy Check) to validate each packet it receives. This is more complex than a simple checksum but prevents errors that could otherwise cause unexpected actions to execute on the controller.
MCP Series Brushed DC Motor Controllers 2.2.9 Handling values larger than a byte Many Packet Serial commands require values larger than a byte can hold. In order to send or receive those values they need to be broken up into 2 or more bytes. There are two ways this can be done, high byte first or low byte first. Roboclaw expects the high byte first. All command arguments and values are either single bytes, words (2 bytes) or longs (4 bytes). All arguments and values are integers (signed or unsigned).
MCP Series Brushed DC Motor Controllers 2.2.10 Packet Serial Wiring In packet serial mode the MCP can transmit and receive serial data. A microcontroller with a UART is recommended. The UART will buffer the data received from controller. When a request for data is made to the MCP the return data will have at least a 1ms delay after the command is received if the baudrate is set at or below 38400. This will allow slower processors and processors without UARTs to communicate with the controller.
MCP Series Brushed DC Motor Controllers 2.2.11 Multi-Unit Packet Serial Wiring In packet serial mode up to eight MCP units can be controlled from a single serial port. The wiring diaghram below illustrates how this is done. Each controller must have multi-unit mode enabled and have a unique packet serial address set (see General Settings in IonMotion). Wire the S1 and S2 pins directly to the MCU TX and RX pins. Install a pullup resistor (R1) on the MCU RX pin. A 1K to 4.7K resistor value is recommended.
MCP Series Brushed DC Motor Controllers 2.2.12 Commands 0 - 7 Compatibility Commands The following commands are used in packet serial mode.
MCP Series Brushed DC Motor Controllers 3 - Set Maximum Main Voltage (Command 57 Preferred) Sets main battery (B- / B+) maximum voltage level. The valid data range is 30 - 175 (6V 34V). During regenerative breaking a back voltage is applied to charge the battery. When using a power supply, by setting the maximum voltage level, RoboClaw will, before exceeding it, go into hard braking mode until the voltage drops below the maximum value set. This will prevent overvoltage conditions when using power supplies.
MCP Series Brushed DC Motor Controllers 2.2.13 Commands 8 - 13 Mixed Mode Compatibility Commands The following commands are mix mode compatibility commands used to control speed and turn using differential steering. Before a command is executed valid drive and turn data is required. You only need to send both data packets once. After receiving both valid drive and turn data RoboClaw will begin to operate the motors. At this point you only need to update turn or drive data as needed.
MCP Series Brushed DC Motor Controllers 2.3 Advance Packet Serial Mode 2.3.1 Command List The following commands are used to read board status, version information and set/read configuration values.
MCP Series Brushed DC Motor Controllers Command Description 146 Get All Stream Properties 147 Get Signal Values 148 Set PWM Mode 149 Read PWM Mode 200 E-Stop Reset 201 Lock/Unlock E-Stop Reset 202 Get E-Stop Lock 246 Set Script Autorun Delay 247 Get Script Autorun Delay 248 Start Script 249 Stop Script 252 Read User NVM Word 253 Write User NVM Word 21 - Read Firmware Version Read RoboClaw firmware version.
MCP Series Brushed DC Motor Controllers 26 - Set Minimum Logic Voltage Level Note: This command is included for backwards compatibility. We recommend you use command 58 instead. Sets logic input (LB- / LB+) minimum voltage level. RoboClaw will shut down with an error if the voltage is below this level. The voltage is set in .2 volt increments. A value of 0 sets the minimum value allowed which is 6V. The valid data range is 0 - 140 (6V - 34V).
MCP Series Brushed DC Motor Controllers 58 - Set Logic Battery Voltages Set the Logic Battery Voltages cutoffs, Min and Max. Min and Max voltages are in 10th of a volt increments. Multiply the voltage to set by 10. Send: [Address, 58, Min(2 bytes), Max(2bytes, CRC(2 bytes)] Receive: [0xFF] 59 - Read Main Battery Voltage Settings Read the Main Battery Voltage Settings.
MCP Series Brushed DC Motor Controllers 90 - Read Status Read the current unit status.
MCP Series Brushed DC Motor Controllers 95 - Read Settings from EEPROM Read all settings from non-volatile memory. Send: [Address, 95] Receive: [Enc1Mode, Enc2Mode, CRC(2 bytes)] 128 - Set M1 Inductance and Resistance Set Motor Inductance and Resistance values. Used for torque mode control. Inductance = L * 16777216. Resistance = R * 16777216. L is in henrys and R is in ohms. For example a motor with L of .6 millihenries = .0006henrys = .0006 * 16777216 = 10066. A motor with resistance of 6mohm = .
MCP Series Brushed DC Motor Controllers 135 - Read M1 Max Current Limit Read Motor 1 Maximum Current Limit. Current value is in 10ma units. To calculate divide value by 100. MinCurrent is always 0. Send: [Address, 135] Receive: [MaxCurrent(4 bytes), MinCurrent(4 bytes), CRC(2 bytes)] 136 - Read M2 Max Current Limit Read Motor 2 Maximum Current Limit. Current value is in 10ma units. To calculate divide value by 100. MinCurrent is always 0.
MCP Series Brushed DC Motor Controllers 139 - Set Priority Levels Set Priority Level signal types. Each of three Priority Levels can have a control signal type selected. The higher priority level is used first. If that input is inactive(determine by a timeout value) the Priority Level is changed to the next level down. if the particular Priority level is disabled the next lower level is moved to. if a higher level signal input becomes active the Priority level is changed back to the higher level.
MCP Series Brushed DC Motor Controllers 143 - Set Signal Properties Set Signal Properties. This command will set all the properties for one channel(eg P0,P1, PID1A, PID1B ect). Types: (Note: Not all types are available on all input pins) NONE 0 ANALOG 1 PULSE 2 ENCODER 3 PSERIAL 4 Modes: Position 0 Percent(0 to 65535) 1 Average Speed 2 Speed 3 Target: None 0 Motor1 1 Motor2 2 Both Motors 3 MinAction...
MCP Series Brushed DC Motor Controllers Timeout The timeout in millisecond for the signal to be considered idle. This is used to determine when a lower priority level should be switched to. LoadHome value to set the position to on a LoadHome action. This is usually used to zero a quadrature encoder input. Minimum...Maximum The minimum and maximum position values. Any values higher or lower than these settings will trigger a MinAction or MaxAction if set. Center: The middle point of the control input.
MCP Series Brushed DC Motor Controllers 144 - Get Signal Properties Read all Signal Properties. Command returns the pin count plus the properties for all the pins the controller supports. See command 143 for descriptions of the properties.
MCP Series Brushed DC Motor Controllers 145 - Set Stream Properties Set Stream Properties. Index: USB 0 RS232 UART0 1 TTL UART1 2 TTL UART2 3 TTL UART3 4 Type: MCL PacketSerial Disabled (Note: CAN will 0 1 2 be active if UART0 is disabled, I2C will be active if UART1 is disabled) Rate: The bps setting for the stream Timeout: the timeout in milliseconds before the stream is considered inactive.
MCP Series Brushed DC Motor Controllers 149 - Read PWM Mode Read PWM Drive mode. See Command 148. Send: [Address, 149] Receive: [PWMMode, CRC(2 bytes)] 200 - E-Stop Reset Reset an E-Stop error. This command will do nothing if the E-Stop is not first unlocked. Send: [Address, 200, CRC(2 bytes)] Receive: [0xFF] 201 - Lock/Unlock E-Stop Reset Lock/Unlock the E-Stop reset capaibility. By default teh E-Stop software reset is locked.
MCP Series Brushed DC Motor Controllers 249 - Stop Script Stop the loaded Script. Send: [Address, 249, CRC(2 bytes)] Receive: [0xFF] 252 - Read User EEProm Word Read a value from the User EEProm memory(256 bytes). Send: [Address, 252, EEProm Address(byte)] Receive: [Value(2 bytes), CRC(2 bytes)] 253 - Write User EEProm Word Get Priority Levels.
MCP Series Brushed DC Motor Controllers 2.4 Encoders 2.4.1 Cloosed Loop Modes MCP supports a wide range of encoders in close loop mode. This section of the manual mainly deals with Quadrature and Absolute encoders. However additional types of encoders can be supported. 2.4.2 Quadrature Encoders MCP is capable of reading two quadrature encoders, one for each motor channel. The main MCP interface provides a dual A and B input signals for each encoder as well as acces to regulated 5v.
MCP Series Brushed DC Motor Controllers 2.4.3 Absolute Encoder MCP is capable of reading absolute encoders that output an analog voltage. Like the Analog input modes for controlling the motors, the absolute encoder voltage must be between 0v and 5v. The diagram below shows the main battery as the only power source. The 5VDC shown connected is only required if your MCU needs a power source. This is the BEC feature of the MCP. If the MCU has its own power source do not connect the 5VDC.
MCP Series Brushed DC Motor Controllers 2.4.5 Auto Tuning Ion Studio provides the option to auto tune velocity and position control. To use the auto tune option make sure the encoder and motor are running in the desired direction and the basic PWM control of the motor works as expected. It is recommend to ensure the motor and encoder combination are functioning properly before using the auto tune feature. 1. Go to the PWM Settings screen in Ion Studio. 2.
MCP Series Brushed DC Motor Controllers 3. Once the motor has some semblance of control you can set a moderate speed. Then start increasing the P value until the speed reading is near the set value. If the motor feels like it is vibrating at higher P values you should reduce the P value to about 2/3rds that value. Move on to the I setting. 4. Start increasing the I setting. You will usually want to increase this value by .1 increments. The I value helps the motor reach the exact speed specified.
MCP Series Brushed DC Motor Controllers 2.4.8 Encoder Commands The following commands are used with the encoder(quadrature and absolute) hardware. Command Description 16 Read Encoder Count/Value for M1. 17 Read Encoder Count/Value for M2. 18 Read M1 Speed in Encoder Counts Per Second. 19 Read M2 Speed in Encoder Counts Per Second. 20 Resets Encoder Registers for M1 and M2(Quadrature only). 22 Set Encoder 1 Register(Quadrature only). 23 Set Encoder 2 Register(Quadrature only).
MCP Series Brushed DC Motor Controllers 17 - Read Quadrature Encoder Count/Value M2 Read M2 encoder count/position. Send: [Address, 17] Receive: [EncCnt(4 bytes), Status, CRC(2 bytes)] Quadrature encoders have a range of 0 to 4,294,967,295. Absolute encoder values are converted from an analog voltage into a value from 0 to 4095 for the full 5.1v range. The Status byte tracks counter underflow, direction and overflow.
MCP Series Brushed DC Motor Controllers 22 - Set Quadrature Encoder 1 Value Set the value of the Encoder 1 register. Useful when homing motor 1. This command applies to quadrature encoders only. Send: [Address, 22, Value(4 bytes), CRC(2 bytes)] Receive: [0xFF] 23 - Set Quadrature Encoder 2 Value Set the value of the Encoder 2 register. Useful when homing motor 2. This command applies to quadrature encoders only.
MCP Series Brushed DC Motor Controllers 2.4.9 Advanced Motor Control The following commands are used to control motor speeds, acceleration distance and position using encoders. Command Description 28 Set Velocity PID Constants for M1. 29 Set Velocity PID Constants for M2. 32 Drive M1 With Signed Duty Cycle. (Encoders not required) 33 Drive M2 With Signed Duty Cycle. (Encoders not required) 34 Drive M1 / M2 With Signed Duty Cycle. (Encoders not required) 35 Drive M1 With Signed Speed.
MCP Series Brushed DC Motor Controllers 28 - Set Velocity PID Constants M1 Several motor and quadrature combinations can be used with RoboClaw. In some cases the default PID values will need to be tuned for the systems being driven. This gives greater flexibility in what motor and encoder combinations can be used. The RoboClaw PID system consist of four constants starting with QPPS, P = Proportional, I= Integral and D= Derivative.
MCP Series Brushed DC Motor Controllers 33 - Drive M2 With Signed Duty Cycle Drive M2 using a duty cycle value. The duty cycle is used to control the speed of the motor without a quadrature encoder. The command syntax: Send: [Address, 33, Duty(2 Bytes), CRC(2 bytes)] Receive: [0xFF] The duty value is signed and the range is -32768 to +32767 (eg. +-100% duty). 34 - Drive M1 / M2 With Signed Duty Cycle Drive both M1 and M2 using a duty cycle value.
MCP Series Brushed DC Motor Controllers 38 - Drive M1 With Signed Speed And Acceleration Drive M1 with a signed speed and acceleration value. The sign indicates which direction the motor will run. The acceleration values are not signed. This command is used to drive the motor by quad pulses per second and using an acceleration value for ramping. Different quadrature encoders will have different rates at which they generate the incoming pulses. The values used will differ from one encoder to another.
MCP Series Brushed DC Motor Controllers 41 - Buffered M1 Drive With Signed Speed And Distance Drive M1 with a signed speed and distance value. The sign indicates which direction the motor will run. The distance value is not signed. This command is buffered. This command is used to control the top speed and total distance traveled by the motor. Each motor channel M1 and M2 have separate buffers.
MCP Series Brushed DC Motor Controllers 44 - Buffered M1 Drive With Signed Speed, Accel And Distance Drive M1 with a speed, acceleration and distance value. The sign indicates which direction the motor will run. The acceleration and distance values are not signed. This command is used to control the motors top speed, total distanced traveled and at what incremental acceleration value to use until the top speed is reached. Each motor channel M1 and M2 have separate buffers.
MCP Series Brushed DC Motor Controllers 46 - Buffered Drive M1 / M2 With Signed Speed, Accel And Distance Drive M1 and M2 with a speed, acceleration and distance value. The sign indicates which direction the motor will run. The acceleration and distance values are not signed. This command is used to control both motors top speed, total distanced traveled and at what incremental acceleration value to use until the top speed is reached. Each motor channel M1 and M2 have separate buffers.
MCP Series Brushed DC Motor Controllers 51 - Buffered Drive M1 / M2 With Signed Speed, Individual Accel And Distance Drive M1 and M2 with a speed, acceleration and distance value. The sign indicates which direction the motor will run. The acceleration and distance values are not signed. This command is used to control both motors top speed, total distanced traveled and at what incremental acceleration value to use until the top speed is reached. Each motor channel M1 and M2 have separate buffers.
MCP Series Brushed DC Motor Controllers 54 - Drive M1 / M2 With Signed Duty And Acceleration Drive M1 and M2 in the same command using acceleration and duty values for each motor. The sign indicates which direction the motor will run. The acceleration value is not signed. This command is used to drive the motor by PWM using an acceleration value for ramping.
MCP Series Brushed DC Motor Controllers 63 - Read Motor 1 Position PID Constants Read the Position PID Settings. Send: [Address, 63] Receive: [P(4 bytes), I(4 bytes), D(4 bytes), MaxI(4 byte), Deadzone(4 byte), MinPos(4 byte), MaxPos(4 byte), CRC(2 bytes)] 64 - Read Motor 2 Position PID Constants Read the Position PID Settings.
MCP Series Brushed DC Motor Controllers 69 - Set M2 Default Duty Acceleration Set the default acceleration for M2 when using duty cycle commands(Cmds 32,33 and 34) or when using Standard Serial, RC and Analog PWM modes. Send: [Address, 69, Accel(4 bytes), CRC(2 bytes)] Receive: [0xFF] 81 - Read Default Duty Acceleration Settings Read M1 and M2 Duty Cycle Acceleration Settings.
MCP Series Brushed DC Motor Controllers 3.0 Programming MCP 3.0.1 MCL The MCL programming language is based on a subset of BASIC. The MCL language provides full control over sensors and motor performance characteristics to create robust stand alone applications. MCL is capable of 32 bit integer and floating point math. 3.0.2 MCL Editor Ion Studio incorporates an editor for creating and managing MCL programs. The editor is also used to comppile and downloaded user generated MCL programs to the MCP.
MCP Series Brushed DC Motor Controllers 3.0.3 Device Menu The Ion Studio Device menu is used to check and download a MCL program. After creating a MCL program use the Check MCL to compile and check the program for syntax errors. Once the program is checked, select Download MCL to send the program to the connect MCP. 3.0.4 Start and Stop Program Execution Once a program is downloaded to the MCP and Ion Studio is connected use the Start Script to begin program execution.
MCP Series Brushed DC Motor Controllers 3.1 MCL Language 3.1.1 Variables Variables are used to store values used in your program. The values stored will typically change during program run time. What was stored at the start of your program in a given variable can change by the time your program stops running. To use a variable it must be defined in your program so the MCP knows to set aside the required amount of space in RAM. The MCP can handle up to 32 bit variables.
MCP Series Brushed DC Motor Controllers 3.1.5 Variable Names Variable names must start with a letter but can be any combination of letters and numbers including some symbols that are not in the reserved word list. You can name your variables almost anything. However, its a good idea to name them something useful that you will remember and understand for debugging your program. Variable names can be up to 1,024 characters long. The only names you can not use for your variables are reserved words.
MCP Series Brushed DC Motor Controllers 3.1.8 Variable Modifier Types Modifier Description LowBit Returns the low bit of a variable (least significant bit). HighBit Returns the high bit of a variable (most significant bit). Bitn Returns the Nth bit of a variable. From 0 to 31 depending on variable size. LowNib Returns the low nibble (4 bits) of a variable (least significant nib). HighNib Returns the high nibble (4 bits) of a variable (most significant nib).
MCP Series Brushed DC Motor Controllers 3.1.11 Constants Constants are defined values that will never change. The assigned value is stored in program memory and can not be changed. Constants are set during compile time by MCL. Constants are a convenient way to give a name to a numeric value. They are typically used to make a program more human readable. There are two types of constants. Normal constants defined using CON and an explicit floating point constant defined by FCON.
MCP Series Brushed DC Motor Controllers 3.1.14 System Registers System registers are special variables defined by MCL to access functions of the MCP control unit. System registers can, in most cases be used just like a user defined variable. However some System Registers are read only(see table below) and Variable Modifiers can not be used with system registers. 3.1.
MCP Series Brushed DC Motor Controllers Variable Names Variable Size Array Size MOTORSPEED SLONG 2 R Motor Speed MOTORDEFAULTACCEL LONG 2 R/W Motor Default Acceleration MOTORMAXCURRENT SWORD 2 R/W Motor Maximum Current MOTORMINCURRENT SWORD 2 R/W Motor Minimum Current MOTORL LONG 2 R/W Motor Inductance MOTORR LONG 2 R/W Motor Resistance MOTORENCPOS SLONG 2 R/W Encoder Position MOTORENCSPEED SLONG 2 R Encoder Speed MOTORENCSPEEDS SLONG 2 R Average Encoder Speed(
MCP Series Brushed DC Motor Controllers VERSION The version variable holds the firmware version loaded on the board. This allows a MCL script to determine if the firmware version supports the functions being used by the script. The high byte of the word value stores the major version number and the low byte of the word value stores the minor verison number. main puts 0,[“Version “,hex2 VERSION.byte1\2,”.”, hex2 VERSION.
MCP Series Brushed DC Motor Controllers SYSTEMP2 Variable holds the boards secondary temperature in 10ths of a degree increments. Only MCP21xx support this feature. There is two temperature sensors one for each channel. SYSMBAT variable hols the main battery voltage reading in 10ths of a volt. main puts 0,[real TOFLOAT SYSMBAT/10.0\2,13] pause 100 goto main SYSLBAT Variable to read the logic battery voltage in 10ths of a volt.
MCP Series Brushed DC Motor Controllers SYSMAXLBAT Variable can be use to read or set the maximum logic battery voltage limit. Values are in 10ths of a volt. SYSMAXLBAT = 120 ;tenths of a volt main puts 0,[hex4 SYSSTATUS\4,13] ;watch status for an error pause 100 goto main DOUTACTION(8) Variable array is used to set or read the DOUT pins action setting.
MCP Series Brushed DC Motor Controllers PRIORITYLEVEL Variable holds the control priority level that is currently active. Levels 0,1 or 2. main if PRIORIYLEVEL=0 then puts 0,[“Prioritylevel 1”,13] elseif PRIORITYLEVEL=1 puts 0,[“Prioritylevel 2”,13] elseif PRIORITYLEVEL=2 puts 0,[“Prioritylevel 3”,13] goto main PRIORITYACTIVE Variable holds the trigger mask for priority levels. The mask indicates which control types can become active.
MCP Series Brushed DC Motor Controllers MOTORPWM (2) Variable array holds the current PWM setting for both motor channels. main puts 0,[“Motor 1 PWM:”,dec MOTORPWM(0),13] pause 100 goto main MOTORCURRENT (2) Variable array holds the current reading for both motor channels. Value is in 10ma increments main puts 0,[“Motor1 current:”,real MOTORCURRENT(0)/100.0\2,13] pause 100 goto main MOTORTARGETPWM (2) Variable array holds the target PWM setting for both motor channels.
MCP Series Brushed DC Motor Controllers MOTORVELQPPS (2) Variable array holds the QPPS setting for both motor channels. ;initialize motor QPPS setting in script MOTORVELQPPS(0) = 180000 main goto main MOTORTARGETSPEED (2) Variable array holds the target Speed setting for both motor channels. This is the speed the motor is accelerating/deccelerating to reach.
MCP Series Brushed DC Motor Controllers MOTORPOSKD (2) Variable array holds the position Kd setting for both motor channels. ;initialize motor Kd setting in script MOTORPOSKD(0) = TOINT(40000.0*2048.0) main goto main MOTORPOSMAX (2) Variable array holds the position Max setting for both motor channels. ;initialize motor maximum position MOTORPOSMAX(0) = 10000 main goto main MOTORPOSMIN (2) Variable array holds the position Min setting for both motor channels.
MCP Series Brushed DC Motor Controllers MOTORDECCEL (2) Variable array holds the current decceleration setting for both motor channels. The seperate decceleration value is only used with position commands. Acceleration is used as both acceleration and decceleration in velocity/distance commands. main puts 0,[“Motor1 Decceleration Setting:”,dec MOTORDECCEL(0),13] pause 100 goto main MOTORSPEED (2) Variable array holds the current speed setting for both motor channels.
MCP Series Brushed DC Motor Controllers MOTORL (2) Variable array holds the motor inductance setting for both motor channels. If this value and MOTORR are set then PWM commands are executed using a current control algorithm instead of voltage control. main puts 0,[“Motor1 inductance:”,real TOFLOAT MOTORL(0)/16777216.0\2,13] pause 100 goto main MOTORR (2) Variable array holds the motor resistance setting for both motor channels.
MCP Series Brushed DC Motor Controllers MOTORENCSTATUS (2) Variable array holds the current encoder status for both motor channels. This value is equal to the signal channel assigned as encoder input for the specific motor. main puts 0,[“Motor1 status:”,hex MOTORENCSTATUS,13] pause 100 goto main MOTORENCPIN (2) Variable array holds the signal number used for encoder input. This allows any signal pin(P0,P1,PID1A,PID1B etc) to be used as an encoder input.
MCP Series Brushed DC Motor Controllers STREAMTIMEOUT (4) Variable array holds the activity timeout in milliseconds for each stream. The timeout value is the maximum time between receiving data on the channel before the channel is deactivated and a low priority channel is activated. ;initialize USB stream timeout to 1 second STREAMTIMEOUT(0) = 1000 main goto main STREAMTICK (4) Variable array holds the last activity tick count for each stream.
MCP Series Brushed DC Motor Controllers SIGNALTYPE (32) Variable array holds the signal type for each signal. Signal Types None 0x00 Analog 0x01 RC Pulse/PWM 0x02 Quadrature Encoder 0x03 main puts 0,[“P0 SignalType:”,dec SIGNALTYPE(0),13] pause 100 goto main SIGNALTARGET (32) Variable array holds the target for each signal. The target can be either Motor1(0) or Motor2(1).
MCP Series Brushed DC Motor Controllers SIGNALMINACTION (32) Variable array holds the action that will trigger if the minimum is reached for each signal.
MCP Series Brushed DC Motor Controllers SIGNALMIN (32) Variable array holds the minimum position for each signal. This limits the minimum signal value and can trigger an action(on a DOUT or a motor channel). main puts 0,[“P0 Minimum:”,dec SIGNALMIN(0),13] pause 100 goto main SIGNALMAX (32) Variable array holds the maximum position for each signal. This limits the maximum signal value and can trugger an action(on a DOUT or a motor channel).
MCP Series Brushed DC Motor Controllers SIGNALPOWERMIN (32) Variable array holds the minimum power level for each signal. This sets the absolute minimum control output for a signal controling a motor. main puts 0,[“P0 Power Minimum:”,dec SIGNALPOWERMIN,13] pause 100 goto main SIGNALMODE (32) Variable array holds the mode for each signal.
MCP Series Brushed DC Motor Controllers SIGNALPOSITION (32) Variable array holds the current position for each signal. main puts 0,[“P0 Position:”,dec SIGNALPOSITION(0),13] pause 100 goto main SIGNALPERCENT (32) Variable array holds the current percentage of the signal throw for each signal. main puts 0,[“P0 PERCENT:”,dec SIGNALPERCENT(0),13] pause 100 goto main SIGNALSPEED (32) Variable array holds the current speed for each signal.
MCP Series Brushed DC Motor Controllers 3.2 MCL Math 3.2.1 Math Functions MCL includes a full complement of math and comparison functions. MCL supports 32 bit integer math, both signed and unsigned. It also supports floating point math. A signed value denotes whether the resulting value is positive or negative. 3.2.2 Number Bases Although all calculations are handled internally in binary, users can refer to numbers as decimal, hexadecimal or binary, whichever is most convenient for the programmer.
MCP Series Brushed DC Motor Controllers Operator Description MAX Limits the expression to a maximum value MIN Limits the expression to a minimum value DIG Returns the specified digits value << Shift left by specified amount. >> Shift right by specified amount. & Binary math AND. | Binary math OR. ^ Binary math XOR. &/ Binary math NAND. |/ Binary math NOR. ^/ Binary math NXOR. = Is equal to. <> Is not equal to. < Is less than. > Is greater than. <= Is less than or equal to.
MCP Series Brushed DC Motor Controllers 3.2.5 Operator Precedence All math functions have a precedence order. This simply means each math function in an expression is calculated based on its precedence not necessarily based on the order in which it appears in the expression. This even holds true for math as it was taught in school. However, the precedence of order may differ. To solve the following equation 2+2*5/10 = 3 MCL would start with multiplication first since it has the higher precedence order.
MCP Series Brushed DC Motor Controllers ABS The Absolute Value (ABS) converts a signed number to its absolute value. The absolute value of a number is the value that represents its difference from 0. The absolute value of -4 is 4. If the number is positive the result will always be the same number returned: temp = abs(-1234) temp = abs(1234) In the example above, the result will always be 1234 since the difference of 0 from -1234 is 1234.
MCP Series Brushed DC Motor Controllers This will warn the operator if the arm angle exceeds approximately 8 units (11.25 degrees) and shut down the equipment if the arm angle exceeds approximately 16 units (22.5 degrees). Most control examples don’t need to work in actual degrees or decimal values of sine or cosine. To find the sine of a 60 degree angle, first convert the angle to MBasic units by multiplying by 256 and dividing by 360. For example: angle = 60 * 256 / 360 will result in a value of 42.
MCP Series Brushed DC Motor Controllers BIN2BCD This command let you convert binary to “packed” binary coded decimal (BCD). A BCD number is one in which each decimal digit is represented by a 4 bit binary number (from 0 to 9). Packed BCD packs two 4 bit decimal digits in a single byte of memory.
MCP Series Brushed DC Motor Controllers Subtraction (-) Subtract a value (integer or floating point) from another value. The resulting number is not signed unless a signed variable is used. An example of subtraction: time var byte time = 100 time = time - 1 The variable time will now equal 99 since we subtracted 1 from 100. Addition (+) Add one value (integer or floating point) to another value. The resulting number is not signed unless a signed variable is used.
MCP Series Brushed DC Motor Controllers Alternatively, when using integer variables multiply the dividend by 10, 100, 1000 etc. before dividing. The result will gain extra digits of precision but must be interpreted correctly. Using the previous example we can gain three digits of precision as follows. This is known as fixed point division: temp = dividend * 1000 result = temp/7 ;dividend is now 76000 The example sets “result” to a value of 10857.
MCP Series Brushed DC Motor Controllers Mod (//) The mod function (short for “modulo”) returns the remainder after an integer division. So, for example, 13 modulo 5 is 3 (the remainder after dividing 13 by 5).
MCP Series Brushed DC Motor Controllers Shift Left (<<) The Shift Left operator shifts all the bits of a value to the left by a specified amount. Shifting left is the same as multiplying the value by 2 to the nth power. Bits shifted off the left end are lost. Zeros are added to the right for vacant bits. The example program will display the value of time before and after shifting left by 4.
MCP Series Brushed DC Motor Controllers Value1 0 1 0 1 1 1 0 1 Value2 0 0 0 0 1 1 1 1 Result 0 0 0 0 1 1 0 1 As you can see, the high 4 bits are now all set to 0’s, regardless of their original state, but the low 4 bits retain their original state. OR ( | ) The OR ( | ) function is a binary operator. It sets the bit to 1 if either or both of the matching bits are 1 or to 0 if both bits are 0’s.
MCP Series Brushed DC Motor Controllers NAND (&/) The NOT AND function is a binary operator. It compares the bits of two values. It sets the result bits to 1 if neither bit is set or to a 1 for all other cases. 1 1 0 0 &/ &/ &/ &/ 1 0 1 0 = = = = 1 1 1 0 Value1 0 1 0 1 1 1 0 1 Value2 1 0 0 1 0 0 1 1 Result 1 1 1 0 1 1 1 0 NOR (|/) The NOT OR function is a binary operator.
MCP Series Brushed DC Motor Controllers Equal (=) The Equal (=) is a logic operator and also is used to set a variable to some value. if(temp = 10)then endif or temp = 10 The two examples compares the value of temp to 10 and sets temp to 10 using “=”. NOT Equal To (<>) The NOT Equal (<>) is a logic operator and compares to see if a value is not equal to another value. if temp <> 10 then The conditional statement will check to see if temp is not equal to 10.
MCP Series Brushed DC Motor Controllers Greater Than or Equal To (>=) The Greater Than or Equal To (>=) is a logic operator and compares to see if a value is greater than or equal to another value. if temp >= 10 then The conditional statement will check to see if temp is greater than or equal to 10. If the value of temp is greater than 10 or equal to 10 the comparison is true. Therefore, any value from 0 to 9 is false. AND The AND operator is a logic comparison operator.
MCP Series Brushed DC Motor Controllers OR The OR operator is a logic comparison operator. It compares two conditions to make a single true or false statement. The OR operator will return a true if one or both conditions are true. If both conditions are false then a false is returned.
MCP Series Brushed DC Motor Controllers NOT The NOT operator is a logic operator that inverts a condition. When used, true becomes false and false becomes true. The truth table demonstrates all combinations: Condition Result True False False True The NOT operator is used in decision making commands such as IF..THEN, DO..WHILE and so on. Example of the NOT operator: if hour = 5 then Quit_Time if NOT hour < 5 then Over_Time If hour is not equal to 5 the first conditional statement will skip Quit_Time.
MCP Series Brushed DC Motor Controllers TOINT The TOINT operator explicitly converts a floating point value into an integer value. The decimal point of the floating point number is truncated. myfloat var float myint var long myfloat = 10.0 ;myfloat now equals 10.0 myfloat = myfloat * 123.123 ;myfloat now equals 1231.23 myint = TOINT myfloat ;myint now equals 1231 serout s_out,i9600,[“result = “,sdec myint,13] TOFLOAT The TOFLOAT operator explicitly converts an integer value into a floating point value.
MCP Series Brushed DC Motor Controllers FSIN The FSIN operator calculates the floating point Sine of an angle in radians. FSIN gives the ratio of the length of the side opposite of the angle to the length of the hypotenuse in a right triangle. myangle var float mysin var float myangle = 3.14159/2.0 ;myangle now equals PI/2 degrees in radians mysin = FSIN myangle ;mysin now equals 1.
MCP Series Brushed DC Motor Controllers FACOS The FACOS operator calculates the floating point arc cosine of a value. FACOS returns the angle in radians given the ratio of the length of the side adjacent the angle and the length of the hypotenuse in a right triangle. mycos fcon 0.0 myangle var float myangle = FACOS mycos ;myfloat equals 0 serout s_out,i9600,[“myangle = “,real myangle,13] FATAN The FATAN operator calculates the floating point arc tangent of a value.
MCP Series Brushed DC Motor Controllers FSINH The FSINH operator calculates the floating point hyperbolic Sine of the value. param var float result var float param = FLN 2.0 result = FSINH param serout s_out,i9600,[“The hyperbolic sine of “,real param,” is “,real result,13] FCOSH The FCOSH operator calculates the floating point hyperbolic cosine of the value. param var float result var float param = FLN 2.
MCP Series Brushed DC Motor Controllers 3.3 MCL Modifiers 3.3.1 Output Modifiers Modifiers can be use when outputing data using the PUTS command or when storing data in a variable using the LET(=) command. An example of a command modifier is formatting a decimal value into a printable string. The decimal value 32 would output to a terminal window as a space character(ASCII code 32 is a space).
MCP Series Brushed DC Motor Controllers DEC DEC{#max} expression{\#min} #max: optional maximum number of digits to send #min: optional minimum number of digits to send The DEC modifier when used in an output command will convert a stored values to ASCII characters. The example will format the value of temp so it prints out the number in a terminal window. The output would display 1234.
MCP Series Brushed DC Motor Controllers SDEC SDEC{#max} expression{\#min} #max: optional maximum number of digits to send #min: optional minimum number of digits to send The SDEC modifier when used in an output command will convert a stored values to ASCII characters. The example will format the value of temp so it prints out the number in a terminal window. The output would display 1234.
MCP Series Brushed DC Motor Controllers HEX HEX{#max} expression{\#min} #max: optional maximum number of digits to send #min: optional minimum number of digits to send The HEX modifier, in output commands, converts stored values to ASCII characters. The example will format the value of temp so it prints out the number in a terminal window. The output would display 12ab.
MCP Series Brushed DC Motor Controllers IHEX IHEX{#max} expression{\#min} #max: optional maximum number of digits to send #min: optional minimum number of digits to send The IHEX modifier, in output commands, converts stored values to ASCII characters. The example will format the value of temp so it prints out the number in a terminal window. The output would display $12ab.
MCP Series Brushed DC Motor Controllers REAL REAL{#maxint} expression{\#maxdec} #maxint: optional maximum number of integer digits to send #maxdec: optional maximum number of decimal point digits to send The REAL modifier, in output commands, converts stored values to ASCII characters. The example will format the value of temp so it prints out the number in a terminal window. The output would display 3.14159. temp var float temp = 3.14159 puts 0, [REAL temp] ;prints “3.
MCP Series Brushed DC Motor Controllers 3.4 MCL Commands 3.4.1 Command Reference The syntax and example is provided for each command in the command reference section of this manual. In addition, Ion Studio MCL editor has built in syntax help. As a command is typed, The editor will show the syntax for that command as its being typed.
MCP Series Brushed DC Motor Controllers BRANCH Syntax branch index, [label1, label2, label3, ..., labelN] • Index - is a variable, constant or expression that is used to reference a label in a list. The index is 0 based. • Label - is a list of constant labels that are jump points in a program. Description The BRANCH command will jump to a label defined within the brackets. The label used for the jump is determined by the pointer index.
MCP Series Brushed DC Motor Controllers CLEAR Syntax clear Description The clear command sets all user memory to zero. The CLEAR function is typically used in the beginning of a program to set all memory to a know state. In some situations CLEAR is used in place of several statements like variable = 0.
MCP Series Brushed DC Motor Controllers DIST Syntax dist motor,speed,accel,distance,buffer • Motor - is a variable, constant or expression that specifies which motor to access. • Speed - is a variable, constant or expression that sets the speed to run the motor at. • Accel - is a variable, constant or expression that sets the acceleration/decceleration to use when the motor speeds up or slows down to the specified speed.
MCP Series Brushed DC Motor Controllers DIST2 Syntax dist speed1,accel1,distance1,speed2,accel2,distance2,buffer • Speed1 & Speed2 - is a variable, constant or expression that sets the speed to run the motor at. • Accel1 & Accel2 - is a variable, constant or expression that sets the acceleration/decceleration to use when the motor speeds up or slows down to the specified speed. • Distance1 & Distance2 - is a variable, constant or expression that specifies the distance to move the motor.
MCP Series Brushed DC Motor Controllers DO - WHILE Syntax do program statements while condition • Statements - any group of commands to be run inside the loop. • Condition - can be a variable or expression Description The DO - WHILE loop executes commands nested inside of it while some condition is true. The condition can be any variable or expression that is tested every loop until it is false. Zero (0) is false, not zero (0) is true. By default DO - WHILE will test this condition.
MCP Series Brushed DC Motor Controllers END Syntax end Description END stops program execution until the unit is reset.
MCP Series Brushed DC Motor Controllers FOR...NEXT Syntax for countVal = startVal to finishVal {step increment} ...code... next • CountVal - a variable used to store the current count. • StartVal - the starting value to count from. • FinishVal - a value to count up or down to. • Increment - the value to increment the variable by through each loop. Description Repeats a block of instructions and increments a variable counter with a value specified each time through the loop. The FOR...
MCP Series Brushed DC Motor Controllers GETS Syntax gets stream,[variable1,...,variableN] • Stream - is a variable, constant or expression that specifies which stream to read. • Variabl1...VariablN - is a list of variables to store the read values in. Description The GETS command is used to read bytes from a data stream and store them in user variables.
MCP Series Brushed DC Motor Controllers GOSUB Syntax gosub label{[argument1,...,argumentN]}{,DataResult} • Label - the go to label of the subroutine to be executed. • Argument - is user defined arguments to send to the called subroutine. The only limit to the amount of arguments used is program memory. • DataResult - is an optional variable to store the value returned from called subroutine. Description The GOSUB command will jump to a specified label.
MCP Series Brushed DC Motor Controllers GOTO Syntax goto label • Label - is a label the program will jump to. Description The GOTO command tells the program to jump to some label. Examples The following program is a simple loop using GOTO that will repeat forever.
MCP Series Brushed DC Motor Controllers IF...THEN...ELSEIF...ELSE...ENDIF Simple Syntax if expression then label if expression then goto label if expression then gosub label Extended Syntax if expression then ...code... endif if expression then ...code... else ...code... endif if expression then ...code... elseif expression ...code... endif if expression then ...code... elseif expression ...code... else ...code... endif Description IF..THEN commands are the decision makers of MBasic. IF..
MCP Series Brushed DC Motor Controllers Notes Multiple ELSEIF blocks may be used in a single IF...THEN block. ELSE will only execute following code if no conditions were true. ENDIF is required to close a block of conditionals. Example This first example demonstrates using the IF...THEN argument with a goto label. If something is true jump to the label after the THEN statement. Otherwise, if the condition is false execute the commands on the next line after the THEN statement.
MCP Series Brushed DC Motor Controllers Advanced Arguments Now that we have covered the basics of the IF..THEN commands we can explore optional syntax. The next section will explain each with sample code that will display the result so you can follow along. ENDIF Example In some cases you may want to run a block of code when the condition is true. MCL can execute a command or commands directly after a THEN statement, instead of jumping to a label.
MCP Series Brushed DC Motor Controllers There is no limit to how many ELSEIF statements you can have in any single IF...THEN block. The following program shows an example using multiple ELSEIF statements.
MCP Series Brushed DC Motor Controllers I2COUT..I2COUTNS Syntax i2cout {label,timeout}, [databyte1, ..., databyteN] i2coutns {label,timeout}, [databyte1, ..., databyteN] • Label - is a label to jump to if the timeout triggers. • Timeout - is the time in milliseconds to wait for a byte to transfer. • DataBytes - is a list of byte sized variables or expressions that are the values to be sent to an attached I2C device.
MCP Series Brushed DC Motor Controllers I2CIN Syntax i2cin {label, timeout}, [databyte1,...,databyteN] • Label - is a label to jump to if the timeout triggers. • Timeout - is the time in milliseconds to wait for a byte to transfer. • DataBytes - is a list of byte sized variables that store the values read from an attached I2C device. The only limit to the number of data bytes in one command is determined by the device itself.
MCP Series Brushed DC Motor Controllers MOVE Syntax move motor,speed,accel,deccel,position,buffer • Motor - is a variable, constant or expression that specifies which motor to access. • Speed - is a variable, constant or expression that sets the speed to run the motor at. • Accel - is a variable, constant or expression that sets the acceleration to use when the motor start its movement.
MCP Series Brushed DC Motor Controllers MOVE2 Syntax move2 speed1,accel1,deccel1,position1, speed2,accel2,deccel2,position2, buffer • Motor1...Motor2 - is a variable, constant or expression that specifies which motor to access. • Speed1...Speed2 - is a variable, constant or expression that sets the speed to run the motor at. • Accel1...Accel2 - is a variable, constant or expression that sets the acceleration to use when the motor start its movement. • Deccel1...
MCP Series Brushed DC Motor Controllers PAUSE Syntax pause time • Time - is a variable, constant or expression that specifies the number of milliseconds to wait. Description The PAUSE command is used to create a predetermined delay in a program. The amount of delay is specified in milliseconds. There are 1000 milliseconds in 1 second. If a value of 500 is used for time, it would be a half second. If 1000 is used for time, the program would wait 1 second.
MCP Series Brushed DC Motor Controllers POWER Syntax power motor,duty,accel • Motor - is a variable, constant or expression that specifies which motor to access. • Duty - is a variable, constant or expression that sets the duty to run the motor at. • Accel - is a variable, constant or expression that sets the acceleration/decceleration to use when the motor powers up/down to the specified power. Description The POWER command is used to control a motor using just a PWM duty cycle percentage.
MCP Series Brushed DC Motor Controllers POWER2 Syntax power2 duty1,accel1,duty2,accel2 • Duty1...Duty2 - is a variable, constant or expression that sets the duty to run the motor at. • Accel1...Accel2 - is a variable, constant or expression that sets the acceleration/decceleration to use when the motor powers up/down to the specified power. Description The POWER2 command is used to control both motors using just PWM duty cycle percentages.
MCP Series Brushed DC Motor Controllers PUTS Syntax puts stream,[{modifiers}data1,...,{modifiers}dataN] • Stream - is a variable, constant or expression that specifies the stream to send data to. • Modifiers - see the Modifiers section of the manual for specific syntax and usage. • Data1...DataN - are variables, constants or expressions that specifies the data to be sent to the specified stream.
MCP Series Brushed DC Motor Controllers READ Syntax read address, databyte • Address - is a byte sized variable or constant that specifies what address to read the on-board EEPROM from. • DataByte - is a byte sized variable (0-255) which stores the data returned from the on-board EEPROM. Description All modules except the BasicATOM Pro 24 and BasicATOMPro ONE come with built in EEPROM. The READ / WRITE commands were created to access the built-in memory.
MCP Series Brushed DC Motor Controllers REPEAT...UNTIL Syntax repeat program statements until condition • Statements - any group of commands to be run inside the loop. • Condition - can be a variable or expression Description The REPEAT - UNTIL loop executes commands nested inside of it until some condition is false. This is the opposite of DO - WHILE and WHILE - WEND. The condition can be any variable or expression and is tested every loop until true.
MCP Series Brushed DC Motor Controllers RETURN Syntax return {DataResult} • DataResult - an optional value to return to the gosub statement, that can be an expression, constant or variable. Description GOSUB stores the address of the next command on the stack and jumps to the specified label. After executing the code at the jump label a RETURN command is used to remove, from the stack, the address stored by GOSUB and then jumps to that address.
MCP Series Brushed DC Motor Controllers SPEED Syntax speed motor,speed,accel • Motor - is a variable, constant or expression that specifies which motor to access. • Speed - is a variable, constant or expression that sets the speed to run the motor at. • Accel - is a variable, constant or expression that sets the acceleration/decceleration to use when the motor speeds up or slows down to the specified speed.
MCP Series Brushed DC Motor Controllers SPEED2 Syntax speed2 speed1,accel1, speed2,accel2 • Speed1...Speed2 - is a variable, constant or expression that sets the speed to run the motor at. • Accel1...Accel2 - is a variable, constant or expression that sets the acceleration/decceleration to use when the motor speeds up or slows down to the specified speed.
MCP Series Brushed DC Motor Controllers STOP Syntax stop Description Stops program execution until a reset occurs. This is an alias to END. Example The following example will only run once. The program will only restart if the unit is reset. value var long stop puts 0,[“This program just stops.”,13] puts 0,[“Press reset to see it again.
MCP Series Brushed DC Motor Controllers WHILE - WEND Syntax while condition program statements wend • Condition - can be a variable or expression • Statements - any group of commands to be run inside the loop. Description The WHILE - WEND loop executes commands nested inside of it while some condition is true. The condition is tested before the WHILE - WEND loop is run. This is opposite of DO - WHILE which will test the condition for true after running once.
MCP Series Brushed DC Motor Controllers WRITE Syntax write address, data • Address - address of EEPROM to store data • Data - is a byte value that will be written to the address specified. It can be an expression, constant or variable. Description All modules except the BasicATOM Pro 24 come with built in EEPROM. The READ / WRITE commands were created to access the built-in memory. WRITE will write a signal byte to the built-in EEPROM at the address specified in the command.
MCP Series Brushed DC Motor Controllers 3.4 Compile Time Directives 3.4.1 Compiler Directives MCL supports compile time directives. Compile time directives can be used to selectively include or exclude parts of a program which can be very useful. During compile time you can define parts of the program to compile or not. 3.4.2 Conditional Compiling If you’ve written a program to display temperature from a sensor, you may want versions for Celsius and Fahrenheit.
MCP Series Brushed DC Motor Controllers #IFDEF .. #ENDIF #IFDEF name ..optional code.. #ENDIF ..rest of program.. Example Compiles the code (up to #ENDIF) if the constant or variable (name) is defined, or if the label appears previously in the code. temperature var byte #IFDEF temperature ..optional code.. #ENDIF ..rest of program.. This will compile “optional code” because “temperature” has been defined. #IFNDEF .. #ENDIF #IFNDEF name ..optional code.. #ENDIF ..rest of program..
MCP Series Brushed DC Motor Controllers #ELSE #IF expression ..optional code.. #ELSE ..use this code if the other code wasnt used.. #ENDIF ..rest of program.. Example Allows you to have two code snippets and compile one or the other depending on the result of the #IF, #IFDEF or #IFNDEF directive. temp con 1 #IF temp=1 ..optional code.. #ELSE ..more optional code.. #ENDIF ..rest of program.. Compiles “optional code” if “temp = 1” and “more optional code” if “temp” is equal to any other value.
MCP Series Brushed DC Motor Controllers #ELSIF #IF expression ..optional code.. #ELSEIF ..more optional code.. #ELSEIF ..even more optional code.. #ELSE ..if nothing else was used, then use this code.. #ENDIF ..rest of program.. Example Allows multiple snippets of code to be compiled based on multiple tests. ELSEIF is an extension of #ELSE and allows multiple conditional tests to run during compile time. screentype con 1 #IF screentype=1 ..optional code.. #ELSEIF screentype=2 .. more optional code..
MCP Series Brushed DC Motor Controllers ASCII Table Dec Hex Char 0 0x00 NUL 1 0x01 SOH 2 0x02 STX 3 0x03 4 0x04 5 6 Function Hex Char Dec Hex Char 43 0x2B + 86 0x56 V Start of Heading 44 0x2C , 87 0x57 W Start of Text 45 0x2D - 88 0x58 X ETX End of Text 46 0x2E .
MCP Series Brushed DC Motor Controllers Warranty Ion Motion Control warranties its products against defects in material and workmanship for a period of 1 year. If a defect is discovered, IonMC will, at our discretion, repair, replace, or refund the purchase price of the product in question. Contact us at support@ionmc.com. No returns will be accepted without the proper authorization. Copyrights and Trademarks Copyright© 2014 by Ion Motion Control, Inc. All rights reserved.