"A low cost USB-CAN Distributed Motion Control System"

Mad Dash for Flash Cash Design Contest

Project #M250

Abstract

An extremely low cost, but high performance distributed motion control system is presented. During the development of automation equipment, rapid prototyping of multi-axis designs is often required. One can use centralized controls with PC motion control cards, external amplifiers, and a tangle of wires, or utilize existing high cost distributed motion control system with RS485, Ethernet, or one of the fieldbuses (DeviceNet, CANOpen, Profibus, etc.). With the use of highly integrated microcontrollers, such as the PIC18FXX8, and power devices like the Allegro A3977/A3959, a very small and inexpensive system was developed.

The main goals of the system were as follows:

The system consists of two units (I/O expansion in the future); a USB-CAN converter and a dual axis controller. The USB-CAN converter uses the PIC18F258 and a FTDI FT245BM USB interface chip to translate messages between the USB and CAN buses.

The PIC18F458 is kept busy implementing the following servo/stepper trajectory and PID calculations. A new calculation is made every 500 usec:

V(k) = V(k-1) + A - current commanded velocity

P(k) = P(k-1) + V(k) + A/2 - current commanded position (maintained as 48 bit integer 32.16)

E(k) = P(m) – P(k) - error = measured position – calculated position

Output(k) = min ( KpE(k) + KdV(k) + Ki£ Ej + Kvff * V(k) /4+ Kaff * A * 8 + Bias, max_output) – Output DAC value

The stepper step rate is calculated as follows:

V(k) = V(k-1) + A

Timer3Reload = 65535 – 40960000 / V(k) – Timer 3 setup as 800nsec per tick (Fosc/8).

Most of the on chip resources are utilized including all four timer/counters, hardware SPI, CAN, UART, ADC, EE, program updates of flash, digital I/O, interrupts, ICD, RAM, and watchdog timer.

Photo of the "PIC2UP" Dual Axis Motion Controller with on board Motor Drivers.

Photo of the "USB-CANtastic" A Bus powered USB to CAN convertor board.

Overall System Block Diagram

PIC2UP Rev 1.0 Block Diagram

Clearer versions of the schematics are avaiable in the full entry. (Download full entry)

 

 

Clearer versions of the schematics are avaiable in the full entry. (Download full entry)

The following code snippet implements a S48 = S48 +S32 (signed 48 bit + signed 32 bit) addition algorithm. The "C" compiler does not support 48 bit data types. The servo position is maintained as a 48 bit number in order to have a full 32 bit position and have a 16.16 fractional commanded velocity.


#asm
// start with a standard S32 + S32 addition
MOVF &servo_commanded_velocity,W
ADDWF &position48,F
MOVF &servo_commanded_velocity
+1,W
ADDWFC &position48
+1,F
MOVF &servo_commanded_velocity
+2,W
ADDWFC &position48
+2,F
MOVF &servo_commanded_velocity
+3,W
ADDWFC &position48
+3,F

// sign extend to 48 bits just by adding 0 or 0xff to the upper two bytes

// just need to look at bit 31 of servo_commanded_velocity or bit 7 of byte 3.

// The CCS compiler stores data low to high byte
MOVLW
0
BTFSS &servo_commanded_velocity
+3.7 // test bit7 of byte3 see if negative
GOTO VEL_NO_NEG
MOVLW
0xff
VEL_NO_NEG
:
ADDWFC &position48
+4,F
ADDWFC &position48
+5,F
#endasm