Skip to content

12. Output devices

All this information is refered to Output Devices class.

Assigment

  • Add an output device to a microcontroller board you’ve designed,
  • Program it to do something

The Objective

As you can see in my Final Project Page I’m working in an intechangeable extruder for viscous material 3D printing. My intention this week is to build a Bricoleur Clay Extruder that complimets the tank I have already built. All the details of how it worked are in the Final project page.

The hole point is to have a continous Auger Print Head that moves continuously the material, to avoid the intermitent flow that the tank gives. So the motor just have to be continuously rotatting in the same direction.

The designs for this weeks extruder are based on Lauhaus Project.

The Board

I designed a board to move a Unipolar Stepper Motor Jameco 238538. I added the capacity to have FTDI comunication to the board, so I can control the motor through serial comunication. All the designes where made using Eagle.

Schematic

As you can see, you have just the TX conection enabled.

The Board

To design the board, I need to break some design rules, as you can see with the cable going through the mosfets. But this allowed me to get a much cleaner board. To fix this, I just cutted out the manually the parts that the machine couldnt mill.

The Fabrication files are:

The Code

The first version of the code is just a mofication of Neil Gershenfeld’s unipolar stepper code, I adjusted it to continuously rotate in one direction, that is whta I need for the extruder to operate correctly. I also had to modify some Pin definition, as we didn’t have the same conections:

#include <avr/io.h>
#include <util/delay.h>

#define output(directions,pin) (directions |= pin) // set port direction for output
#define set(port,pin) (port |= pin) // set port pin
#define clear(port,pin) (port &= (~pin)) // clear port pin
#define pin_test(pins,pin) (pins & pin) // test for port pin
#define bit_test(byte,bit) (byte & (1 << bit)) // test for bit set

#define MOSFET_port PORTA // MOSFET port
#define MOSFET_direction DDRA // MOSFET direction
#define brown (1 << PA1) // MOSFET output pins
#define black (1 << PA0) // "
#define yellow (1 << PA3) // "
#define orange (1 << PA2) // "
#define on_delay() _delay_us(15) // PWM on time
#define off_delay() _delay_us(5) // PWM off time
#define PWM_count 200 // number of PWM cycles

static uint8_t count;

//
// yellow, brown PWM pulse
//
void pulse_yellow_brown() {
   for (count = 0; count < PWM_count; ++count) {
      set(MOSFET_port, yellow);
      set(MOSFET_port, brown);
      on_delay();
      clear(MOSFET_port, yellow);
      clear(MOSFET_port, brown);
      off_delay();
      }
   }
//
// yellow, black PWM pulse
//
void pulse_yellow_black() {
   for (count = 0; count < PWM_count; ++count) {
      set(MOSFET_port, yellow);
      set(MOSFET_port, black);
      on_delay();
      clear(MOSFET_port, yellow);
      clear(MOSFET_port, black);
      off_delay();
      }
   }
//
// orange, brown PWM pulse
//
void pulse_orange_brown() {
   for (count = 0; count < PWM_count; ++count) {
      set(MOSFET_port, orange);
      set(MOSFET_port, brown);
      on_delay();
      clear(MOSFET_port, orange);
      clear(MOSFET_port, brown);
      off_delay();
      }
   }
//
// orange, black PWM pulse
//
void pulse_orange_black() {
   for (count = 0; count < PWM_count; ++count) {
      set(MOSFET_port, orange);
      set(MOSFET_port, black);
      on_delay();
      clear(MOSFET_port, orange);
      clear(MOSFET_port, black);
      off_delay();
      }
   }
//
// clockwise step
//
void step_cw() {
   pulse_yellow_brown();
   pulse_yellow_black();
   pulse_orange_black();
   pulse_orange_brown();
   }
//
// counter-clockwise step
//
void step_ccw() {
   pulse_orange_brown();
   pulse_orange_black();
   pulse_yellow_black();
   pulse_yellow_brown();
   }

int main(void) {
   //
   // main
   //
   static uint8_t i,j;
   //
   // set clock divider to /1
   //
   CLKPR = (1 << CLKPCE);
   CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0);
   //
   // initialize MOSFET pins
   //
   clear(MOSFET_port, brown);
   output(MOSFET_direction, brown);
   clear(MOSFET_port, black);
   output(MOSFET_direction, black);
   clear(MOSFET_port, yellow);
   output(MOSFET_direction, yellow);
   clear(MOSFET_port, orange);
   output(MOSFET_direction, orange);
   //
   // main loop
   //
   while (1) {
      for (i = 0; i < 10; ++i) {
         for (j = 0; j < i; ++j)
            step_cw();
         }
      }
   }

Its important to modify the on and off delay, because those to parameters are defined in the motors datasheet. As you can see this motors datasheet isn’t soo detailed, so I just tried diferent values.

The Results

An important item in the board is the motor conection, the cables don’t go in a random way, because they follow the current flow:

The Motor

José Tomás Domínguez (Joseto) on Vimeo.

The motor was mounted in the Bricoleur extruder:

José Tomás Domínguez (Joseto) on Vimeo.

Then I mounted Everything in the machine:

José Tomás Domínguez (Joseto) on Vimeo.