Extruder Controller 2.2
Contents
Overview
This board is a combination of the PWM Driver Board, DC Motor Driver Board, Temperature Sensor Board, RS485 comms, and an Arduino! All on one board. It has screw terminals for easy hookup, as well as a power jack for power and an IDC header for the rotary encoder. Its an all-in-one solution for controlling an extruder. The RepRap configuration is shown at the top, the MakerBot one underneath.
Some highlights:
1. Onboard atmega168 - program it just like an Arduino because it is an Arduino.
2. 3 x MOSFET drivers for controlling up to 14A @ 12V. Perfect for heaters, fans, solenoids, etc.
3. 2 x H-Bridges capable of up to 2A each. Control 2 motors, or control one stepper motor.
4. A temperature sensor circuit for reading the standard 100K thermistor.
5. RS485 connection for noise-free communications with the motherboard.
6. IDC header for connecting a Magnetic Rotary Encoder.
7. Polarized ICSP header for simple, easy programming.
8. It mounts directly to the Pinch Wheel Extruder!
9. It is plug and play with the RepRap Motherboard.
WARNING!! This board produces an awfull whine in the extruder motor if you use a stepper-motor due to the fact that it has been designed for DC motors and a hack is applied to use it as a stepper controller 。First off, running the extruder stepper of the extruder board is a horrible hack. It works if tuned right, but you'll get a lot less grief if you get a pololu stepper controller and use that to drive the extruder stepper instead. The "extruder board" is actually designed to control a DC motor, and though you CAN use that to control a stepper motor instead, it doesn't work all that well (among other things there's the audible whine you've noticed, that'll go away if you use a proper stepper driver instead) Anyhow, there is on the atmel a agnd that is separate from dgrnd. (though the datasheet does specify that it cannot be more than Hrm.. Something.. from the dgnd) Do you have a link to the schematic for the extruder board that you're using? I'd expect that the schematic shows that they're already linked. Suggestions:
Check the datasheet for your processor (atmel168 on the extruder board, I believe) This'll give you the pin numbers. Check the silkscreen (white numbers printed on the board itself) The pins might be labeled or even broken out. Check the schematic for the board (possibly they are already connected, probably have to refer to the datasheet to be sure of what all those pin numbers mean) This'll show if these pins are connected already, and give you a hint as to what they're connected to if not eachother, make it easier to do something about it.
Burn the Bootloader
The atmega168 chips come totally blank, so you'll need to upload the special program called a bootloader to the chip so that you can then easily program it with the Arduino software. In order to do this, you'll need an AVR programmer. I highly recommend the USBtinyISP from LadyAda. Its cheap, simple, and easy to assemble. It is also rock-solid. I've used it to program almost a thousand chips and it works great. Before you start, make sure your extruder controller board is not hooked up to anything. In order to program the chip: Plug the USBtinyISP into your computers USB port Plug the USBtinyISP into the Extruder Controller. Open the Arduino software, make sure the 'Arduino Diecimilia' option is selected in 'Boards'. Choose the menu option of "Tools -> Burn Bootloader -> w/ USBTinyISP". Once you do that, a bunch of lights should start blinking and flashing (in particular, the MOSFET indicator LEDs) If everything is successful, then the debug pin will start flashing on and off every second. This is the 'blink' sketch which also gets uploaded to test the Arduino.
Program It! Now that the bootloader is burned, you can burn any program you want to the board using a serial link through arduino. Programming the Extruder Controller is very easy. You'll need a USB -> Serial Cable to talk to it. In order to program it, follow these steps: Plug your USB -> Serial cable into your computer. Plug the other end of your USB -> Serial cable into the serial header. The silkscreen lists the colors of the wires that should match up with the cable. Make sure you have selected Boards -> Arduino Diecimila in the Arduino software. Load your program, and hit upload. On Windows and Linux it sometimes does not auto-reset. Simply hit the reset button as you click upload if it is not uploading properly. [edit] Test Program The program below will test all the MOSFETs and H-bridges, as well as the servo headers. What it does is ramps up the speed/power on all pins, then ramps it back down. For servos, it should rotate them back and forth smoothly. You should hook up motors or other devices like DC fans, etc. to the various outputs of the board. When you run it, the motors will speed up and then slow down. Yay!
// // Extruder Controller v2.2 Test Program. //
- define MOTOR_1_SPEED_PIN 5
- define MOTOR_1_DIR_PIN 7
- define MOTOR_2_SPEED_PIN 6
- define MOTOR_2_DIR_PIN 8
- define SERVO1_PIN 9
- define SERVO2_PIN 10
- define HEATER_PIN 11
- define FAN_PIN 12
- define VALVE_PIN 15
- define THERMISTOR_PIN 3
- include <Servo.h>
Servo servo1; Servo servo2;
void setup() {
pinMode(MOTOR_1_SPEED_PIN, OUTPUT); pinMode(MOTOR_1_DIR_PIN, OUTPUT); pinMode(MOTOR_2_SPEED_PIN, OUTPUT); pinMode(MOTOR_2_DIR_PIN, OUTPUT);
pinMode(HEATER_PIN, OUTPUT); pinMode(FAN_PIN, OUTPUT); pinMode(VALVE_PIN, OUTPUT);
servo1.attach(SERVO1_PIN); servo2.attach(SERVO2_PIN);
}
bool direction = true;
void loop() {
digitalWrite(MOTOR_1_DIR_PIN, direction); digitalWrite(MOTOR_2_DIR_PIN, direction);
for (int i=0; i<256; i++) { set_i(i); delay(50); }
delay(1000);
for (int i=255; i>=0; i--) { set_i(i); delay(50); }
direction = !direction;
}
void set_i(byte i) {
analogWrite(MOTOR_1_SPEED_PIN, i); analogWrite(MOTOR_2_SPEED_PIN, i);
analogWrite(HEATER_PIN, i);
//these are not analog/PWM, but arduino just turns them on or off appropriately. analogWrite(FAN_PIN, i); analogWrite(VALVE_PIN, i);
servo1.write(map(i, 0, 255, 0, 180)); servo2.write(map(180-i, 0, 255, 0, 180));
}
Hacks
File:Extruder Controller 2.21.jpg
Firmware
how to drive stepper motors with this board
his short Arduino program shows how to use the two H-bridge chips in the Extruder Controller V2.2 to drive a stepper. Note that it deliberately messes up on-board Timer 0 in order to drive the PWM (i.e. analogWrite(...) ) at very high frequency. This means that calls to delay(N) will no longer wait N milliseconds, but will come back 64 times faster. The program uses the potentiometer on the board to turn the current to the motor up and down. If you want full stepping, just use the even-numbered cases in the switch statement. /*
* How to drive a stepper with the RepRap Extruder controller v2.2 * * Adrian Bowyer 1 July 2009 * */
// Control pins for the A3949 chips
- define H1D 7
- define H1E 5
- define H2D 8
- define H2E 6
- define POT 0
// We will half-step; coilPosition will take values between 0 and 7 inclusive
byte coilPosition;
// This variable stores the value (0..255) of the on-board potentiometer. This is used // to vary the PWM mark-space values in analogWrites() to the enable pins, hence // controlling the effective motor current.
byte potValue; bool h1Enable; bool h2Enable;
void setup()
{
pinMode(H1D, OUTPUT); pinMode(H1E, OUTPUT); pinMode(H2D, OUTPUT); pinMode(H2E, OUTPUT); pinMode(POT, INPUT); // Change the frequency of Timer 0 so that PWM on pins H1E and H2E goes at // a very high frequency (64kHz see: // http://tzechienchu.typepad.com/tc_chus_point/2009/05/changing-pwm-frequency-on-the-arduino-diecimila.html) // ****NOTE This will mess up timings in the delay() and similar functions; they will no longer work in // milliseconds, but 64 times faster. //First clear all three prescaler bits: TCCR0B &= ~(0x07); //AND the value in TCCR0B with binary number "11111000" TCCR0B |= 1; //OR the value in TCCR0B with binary number "00000001" coilPosition = 0;
}
// Demo program just spins the motor.
void loop() // run over and over again {
motor_click(); coilPosition++; coilPosition &= 7; // Remember the value fed to delay is not 1000 milliseconds, but about // 15.6 ms (= 1000/64). delay(1000);
}
// This writes the appropriate pattern to the output pins for // the value of coilPosition.
void motor_click() {
// Disable the coils digitalWrite(H1E, 0); digitalWrite(H2E, 0); // Which of the 8 possible patterns do we want? // The commented out setPower(...) lines could // be used to run the coils at constant power (with // half-stepping not each step is equal). Just // use the value of the argument to setPower(...) to // scale the PWM values. switch(coilPosition) { case 7: //setPower((stepPower >> 1) + (stepPower >> 3)); digitalWrite(H1D, 1); digitalWrite(H2D, 1); h1Enable = true; h2Enable = true; break; case 6: //setPower(stepPower); digitalWrite(H1D, 1); digitalWrite(H2D, 1); h1Enable = true; h2Enable = false; break; case 5: //setPower((stepPower >> 1) + (stepPower >> 3)); digitalWrite(H1D, 1); digitalWrite(H2D, 0); h1Enable = true; h2Enable = true; break; case 4: //setPower(stepPower); digitalWrite(H1D, 1); digitalWrite(H2D, 0); h1Enable = false; h2Enable = true; break; case 3: //setPower((stepPower >> 1) + (stepPower >> 3)); digitalWrite(H1D, 0); digitalWrite(H2D, 0); h1Enable = true; h2Enable = true; break; case 2: //setPower(stepPower); digitalWrite(H1D, 0); digitalWrite(H2D, 0); h1Enable = true; h2Enable = false; break; case 1: //setPower((stepPower >> 1) + (stepPower >> 3)); digitalWrite(H1D, 0); digitalWrite(H2D, 1); h1Enable = true; h2Enable = true; break; case 0: //setPower(stepPower); digitalWrite(H1D, 0); digitalWrite(H2D, 1); h1Enable = false; h2Enable = true; break; } // How much is the pot turned up? // Divide it by 4 to spread the valid readings out a bit. // This is about right for a 1A 3-ohm/coil stepper. potValue = analogRead(POT)>>2; // Send the appropriate PWM values if(h1Enable) analogWrite(H1E, potValue); else analogWrite(H1E, 0); if(h2Enable) analogWrite(H2E, potValue); else analogWrite(H2E, 0);
}
Hardware
File:Extruder Controller 2.22.jpg
how to use a K-type thermocouple rather than a thermistor with this board.
This allows you to use a K-type thermocouple for temperature sensing as opposed to the standard thermistor. It uses the MAX6675 chip, and is easily put together on a small piece of stripboard that plugs into the I2C connector on the extruder controller board.
The first thing you'll need to do is to remove the 10uF capacitor C8 from the board at B in the picture. You can also remove the thermistor connector (at A) and replace it with a pin. Alternatively, just screw the connection from the new board into the thermistor connector. Getting the capacitor off can be a bit tricky: I levered too hard as I melted the solder and so removed the pad underneath. That's why there is the short white wire connected to the top of R6 is in the picture. If you are more careful, you won't need this... The I2C connector that you will plug the device into is the 4-pin connector just below R6 in the picture.
The MAX6675 is only available as an SMT device. Start by soldering fine wires onto its pins (hold it in a blob of Blu Tack). Cut the tracks on the stripboard, then solder the wires to that. Finally add the connectors, the smoothing capacitor, and the flying lead. You can probably think of a neater wire layout than mine - this evolved as I experimented with the device. Finally, here's the code to drive it. Thanks to [Ryan Mclaughlin for this]. This will give you back the temperature in oC.
- define SO 18 // MISO
- define SCK 19 // Serial Clock
- define TC_0 17 // CS Pin
// Put this next bit in your startup function:
pinMode(SO, INPUT); pinMode(SCK, OUTPUT); pinMode(TC_0, OUTPUT);
// End of startup
// This returns an integer which is the temperature in deg C from the MAX6675
int getTemperature() {
int value = 0; byte error_tc; digitalWrite(TC_0, 0); // Enable device
/* Cycle the clock for dummy bit 15 */ digitalWrite(SCK,HIGH); digitalWrite(SCK,LOW);
/* Read bits 14-3 from MAX6675 for the Temp
Loop for each bit reading the value
*/ for (int i=11; i>=0; i--) {
digitalWrite(SCK,HIGH); // Set Clock to HIGH value += digitalRead(SO) << i; // Read data and add it to our variable digitalWrite(SCK,LOW); // Set Clock to LOW
} /* Read the TC Input inp to check for TC Errors */ digitalWrite(SCK,HIGH); error_tc = digitalRead(SO); // Read data digitalWrite(SCK,LOW); digitalWrite(TC_0, HIGH); //Disable Device
if(error_tc) return 2000; else return value/4;
}
If it detects an error, this code returns a silly high temperature rather than, say, -300. The latter obviously doesn't exist as a temperature and so might make a better error flag. But returning a big positive value is safe if the device is being used in a thermostat loop: it'll turn off the heater if there's an error, rather than locking it on. Note that the final division by four dumps a couple of bits of precision to get an integer value in oC. The MAX6675 can measure to 0.25 oC, and so you may want to preserve those bits if you need the precision.
If you want to swap easily between using a thermocouple and a thermistor, just wire a 10 uF capacitor across the thermistor's connector to replace the one you removed from the PCB. Take care to get the polarity right: the negative capacitor connection goes to the ground pin on the PCB. Upload the original firmware without the function above, and you're good to go. If you want to use thermocouples with the AD595 board then reprapper pjr writes: I checked the Extruder controller 2.2 and there are two extra analogue pins A6 and A7 brought out to 3 pin headers with 5v and ground (next to the trimpot). I tweaked the configuration.h to use pin 6 instead of pin 3 and wired in the thermocouple board 1.0 and it works fine. Notes: - The pinouts are not the same: TC 1.0 and 2.1 have <Ground-Signal-+5v-> but the extruder controller has <Ground-+5v-Signal> so wires needs swapping. - The silkscreen on the controller is reversed (when facing the board with the crystal on the bottom side: ground is top, +5v is centre, A6/7 are at bottom) - The A6 may be already used in firmware as temperature pin for heated bed, but A7 may be free. Better double check this on the current firmware release. No need for any board mods this way.
Interface
File:Extruder Controller 2.24.jpg
Pinout
Here is a handy reference that tells you what pins are hooked up to what features of the board.
H-Bridges
Name | Function | Common Usage |
1A | H-bridge Positive #1 | Motor 1 |
1B | H-bridge Negative #1 | Motor 1 |
2A | H-bridge Positive #2 | Motor 2 |
2B | H-bridge Negative #2 | Motor 2 |
The extruder controller has two separate H-bridge chips onboard. The chips are the Allegro A3949 which is a pretty sweet and modern full H-bridge chip with a simplified interface. This makes it really easy to control DC motors. Since there are two h-bridges onboard, you can control 2 DC motors either forwards or backwards. You could also control a single stepper motor if you like. The interface for controlling these motors is very easy. There are two pins: PHASE and ENABLE. I like to call these pins DIRECTION and SPEED. The DIRECTION/PHASE pin controls the polarity of the output, aka which direction the motor turns. The ENABLE/SPEED pin controls if the output is on or not. By using PWM on the ENABLE/SPEED pin we can control the speed of the motor. Yay! The outputs are labeled Motor 1 and Motor 2. Each motor has an A and B output. There are also LEDs associated with each chip nearby. There is a direction LED which lights up when the direction pin is HIGH, and a speed LED which lights up when the enable pin is high. Blinking LEDs FTW.
MOSFETS
Name | Has PWM? | Common Usage |
A | No | Valve |
B | Yes | Heater |
C | No | Fan |
The extruder controller has three separate power MOSFET chips onboard. The chips are the NIF5003 which are protected 42V 14A N-Channel MOSFET chips. These bad boys can handle a lot of current, which is good for us and good for you. Basically, these chips act just like little switches that can run a lot of juice. Two of the chips are wired up to normal Digital pins and can only be turned on or off. One of the chips is wired up to a PWM pin and can be controlled in full PWM mode. All of the chips are wired directly to the main power supply voltage which is usually 12v. The table below lists which pins have what functionality and their common usage.
Thermistor
Name | Function |
1 | One end of the thermistor |
2 | The other end of a thermistor |
The extruder controller has the onboard circuitry required to measure the temperature of a standard 100K RepRap thermistor. If you wish to measure a thermistor with a different value, all you have to do is change the resistor value. There are screw terminals for you to hook up your thermistor which makes doing temperature measurement very simple. Just wire it up, use the proper thermistor table in your code, and you're good to go. The circuit is identical the the circuit in the previous Temperature Sensor Boards so you can easily re-use the old code.
RS485 Comms + Power
Name | Function |
1 | RS485 A |
2 | RS485 B |
3 | +12V |
4 | +12V |
5 | +12V |
6 | GND |
7 | GND |
8 | GND |
This is one of the major new features of the Generation 3 electronics. RS485 is a robust serial communications channel. It uses differential signaling to provide very noise tolerant communications over relatively long distances, such as in a RepRap machine. RS485 is how the RepRap motherboard communicates with all the tool controllers. It is a very mature technology and is also pretty cheap. Definitely rad. RS485 is a half-duplex channel, which means data can either be transmitted OR received at one time. This makes things a little bit tricky, but don't worry... we have it under control. What you need to know is that there are two wires that need to be hooked up: A and B. These are arbitrary names for the wires due to the differential signaling. Basically, you just have to make sure that all the A's and all the B's are wired up together. To give a bit more insight into the way RS485 is implemented on the Extruder controller, we have given full control over the RS485 chip to the controller. It can independently enable or disable transmitting and receiving. One of the cool things about RS485 is that you can listen in to your own transmissions. This is a critical feature we exploit to ensure that we keep the transmit functionality enabled until all of our data has had a chance to be sent out. Since RS485 only takes up 1 of the 4 pairs of wires in a Cat5e cable, we decided to use the rest of the pairs as power. This allows us to send something like 10 amps over the wire which is more than enough for most extruder needs. The extruder controller has an onboard voltage regulator to produce the 5v required for powering all the logic chips, as well as the optional servo motors. The H-bridges and MOSFETs are powered directly from this input voltage. The maximum allowable voltage is 18v to avoid overheating the 5v regulator.
Quadrature Input
Name | Function | Arduino Pin |
1 | No Connection | N/A |
2 | No Connection | N/A |
3 | No Connection | N/A |
4 | No Connection | N/A |
5 | No Connection | N/A |
6 | No Connection | N/A |
7 | Quadrature B | 3 |
8 | Quadrature A | 2 |
9 | GND | N/A |
10 | +5V | N/A |
This is a handy little feature of the extruder controller board. It has a built-in header to accept the quadrature encoder input from the Magnetic Rotary Encoder board. Since it uses and IDC cable, its very easy to hook up. Just plug and play! Alternatively, if you'd like to use your own rotary encoder that outputs quadrature signals you can easily hack an IDC cable and plug it directly into the board.
Serial Header
Name | Color | Function |
1 | Black | GND |
2 | Brown | CTS# |
3 | Red | VCC |
4 | Orange | TXD |
5 | Yellow | RXD |
6 | Green | RTS# |
This is the serial communications header for programming the board. It uses the same USB<->TTL header format as the Sanguino, Boarduino, or any of the other minimal Arduino clones. You can find out more information about the cable and where to get it on the Sanguino website. Its very easy to use.
I2C Headers
PIN | FUNCTION |
1 | VCC (5v) |
2 | GND (0v) |
3 | SDA |
4 | SCL |
The SDA and SCL pins even have built-in 4.7K pullup resistors to make configuration of the I2C bus hassle-free and automatic. The table below lists the pin-out of the header. The labeling in the v2.0 board is not too good, so pin 1 is towards the top of the board and in to the top and the right in the picture.
Servo Headers
PIN | FUNCTION |
1 | Signal |
2 | VCC (5V) |
3 | GND (0V |
This may be my favorite feature of the extruder controller: servo headers! We had a few extra pins left on the Arduino after implementing the required functionality, so we decided to have some fun. Thats why the extruder controller has the capacity to control two servo motors in addition to everything else! Its really, really, really easy too, thanks to the Arduino Servo library. Simply plug your servo in and its ready to go. We use Arduino pins 9 and 10 for the servos because they are connected to the timer output pins. If you want to use pins 9 or 10 for something, you can just hook up to the headers directly. We supply the pin, 5v, and a ground pin which means you can easily hook them up to whatever you want. The pinout is the standard servo pinout, which is displayed below. The pins should be labeled, but it may be hard to see. Pin 1 is closest to the D9/D10 silkscreen.
Extra Headers
PIN | FUNCTION |
1 | Signal |
2 | VCC (5V) |
3 | GND (0V |
We had a few pins left over, so we decided to break them out for you to use however you like. The pins are A0, A6, and A7. The SMT version of the atmega168 has 2 extra analog pins, which means you get even more awesomeness. The pins are broken out exactly like the servo pins with the exception that they do not have Servo control built-in to the hardware. It is possible to use software to control extra servos, but it might be a bit tricky. However, it is easy to use the extra pins to measure analog signals. The pinout is below. They should be marked on the silkscreen, but like with the servos, the signal pin is closest to the pin name (A0, A6, A7, etc.)
Arduino Slave Extruder Firmware
Once you've verified that the board itself is working, its time to put a firmware on it. There is a generic slave firmware which allows the motherboard to control your extruder controller board. This firmware is part of the RepRap 3rd Generation protocol, which is described in greater deal on the [1]page. Go there for detailed instructions on how to install that software.
file
File:Extruder Controller 2.25.jpg
File:Extruder-controllersilk.pdf