Output Devices


Objectives for Week 9

  1. Add an output device to the microcontroller board we have designed and program it to do something
  2. Group Assignment: Measure the power consumption of an output device

This week I thought of starting with the basics for my Final Project. The project consists of a board on which the game pieces or the tokens are controlled using CNC XY table whose primary output device is Stepper Motor. So for this week I am designing and creating a new PCB that can help run a stepper motor.

NEMA 17 Stepper Motor

In our FabLab, we have two kinds of stepper motor: 28BYJ-48 and NEMA 17. After a brief discussion with my instructor, Saheen, I planned to use NEMA 17 because I got to know that the other motor is quite slow compared to NEMA 17.

NEMA 17

Features of NEMA 17 Stepper Motor

Biploar and Unipolar

      NEMA 17 stepper motors can be designed as either bipolar or unipolar:
      • Bipolar motors have two coils (or two groups of coils) and require a change in the direction of current flow to change the magnetic field polarity, typically requiring more complex driving circuits like H-bridges.
      • Unipolar motors have an additional tap in the middle of each winding, allowing simpler driving circuits but often resulting in lower torque for the same size motor. 
    
      The motor I am using is having bipolar configuration with 4 leads.
    Wiring
    

DRV8825

DRV8825
DRV8825

The motor driver can provide higher output power, more accurate output current voltage, frequency control, more precise position control, and higher efficiency.

DRV8825 is a propular choice for controlling NEMA 17 because of the following reasons:

Microstepping

Microstepping is a method used in stepper motor control that allows a motor to make finer steps than its basic step size, leading to smoother motion, reduced resonance, and increased positional accuracy. The DRV8825 stepper motor driver supports microstepping up to 1/32 steps.

The DRV8825 achieves microstepping by proportionally controlling the current in the two coils of the stepper motor. The microstepping resolution of the DRV8825 is configured by setting the logic levels of three pins: M0, M1, and M2. The combination of these pins' states (high or low) determines the microstepping mode.

Microstepping

Refer Last Minute Engineers to know more about the driver module.

ATtiny1614

ATtiny-1614-pinout

At first thought, I wanted to create a separate PCB with the driver module that can be compatible with the SAMD11C14A board I have created last week. But my instructor suggested I try using a different microcontroller. During the past weeks, I have tried using XIAO RP2040 and SAMD11C14A, and for this week I used ATtiny1614.

Features of ATtiny1614

PCB Design

During 'Electronics Design' week, I was introduced to KiCad to design PCBs. So I used the same tool this week. The first task is to identify the required components apart from the driver and the microcontroller. Once that was done, I started with the schematic diagram.

I started off with designing a board just for the driver module thinking that I could use the microcontroller board I have created last week for the purpose. Here's the PCB I had designed.

First_PCB

I converted the gerber files to png files using Gerber Viewer. Refer the documentation of Week 8 to know how I did it. Once I got the files, I milled the PCB. But soon enough I realized my mistake.

First_PCB

The footprint for the driver module I used was through-hole. So, in order to solder the pins, the module has to be inserted from the bottom side, thereby, the footprint had to be flipped during the design process and I had forgotten to do so. Hence, I had to edit the design again.

And this is when my instructor suggested I create an entirely new board with an ATtiny1614 microcontroller. And I did so. I was hesitant at first as this meant the number of components will be larger and the thought of routing all these components made me weak at the knees😣. But then I thought I'll give it a chance as anyway I have to create new boards for my upcoming weeks and final project and this would be an added experience.

I made the schematic diagram with all the required components.

Schematic

Once I completed the schematic, since the driver was through-hole, I designed a new footprint for the driver making it SMD so that I can connect them using headers.

Footprint

But while programming I realized a major mistake in my footprint created. I gave the pin numbers in wrong order, and it was too late so I had to modify the board I had milled with cuts and jumpers. The corrected footprint is available to download at the end of this documentation.

Footprint

It took me more than 5 hours this time to route all the traces. I wanted it to be single side so no to jumpers. Instead, Midhun, my fellow mate at FabAcademy suggested I use 0 ohm resistors to cross at those places where I find it really difficult to connect the power lines. Here's how it looked after routing.

Main_PCB

I used Gerber Viewer to convert the gerber files to png files and I proceeded to milling.

PCB Milling

The next step is milling the PCB. I am using Roland Modela MDX20 along with MODs for the purpose. I already have some experience in using both during Electronics Production and Electronics Design weeks.

Modela

Refer documentation of Week 4 to know about the working processes of Roland Modela MDX20 and MODs.

Modela

The next step is to request for the required components from Fab Inventory. The component list is as below:

Request Log

Then I started soldering the components to the board and this is how it finally turned out.

After Soldering
After Soldering

In case of microstepping, later I soldered all the three jumpers and therefore achieving full step.

Programming

I used Arduino IDE for the code. I took a sample code to run the stepper motor in both clockwise and counter-clockwise direction from Last Minute Engineers and modified it to my requirements. Here's the modified code:

   
// defines pins
#define stepPin 10 //referred from ATtiny1614 Pinout Diagram
#define dirPin 0 //referred from ATtiny1614 Pinout Diagram
#define faultPin 8 //referred from ATtiny1614 Pinout Diagram
#define enablePin 9 //referred from ATtiny1614 Pinout Diagram
 
void setup() {
  // Sets the pins as Outputs
  pinMode(stepPin,OUTPUT); 
  pinMode(dirPin,OUTPUT);
  pinMode(faultPin,OUTPUT); 
  pinMode(enablePin,OUTPUT);
}
void loop() {
  digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
  digitalWrite(enablePin,LOW); // DRV8825 driver is enabled when the pin is LOW
   digitalWrite(faultPin,HIGH); // If FAULT pin is LOW, chip is disabled
  // Makes 200 pulses for making one full cycle rotation
  for(int x = 0; x < 800; x++) {
    digitalWrite(stepPin,HIGH); 
    delayMicroseconds(700);    // by changing this time delay between the steps we can change the rotation speed
    digitalWrite(stepPin,LOW); 
    delayMicroseconds(700); 
  }
  delay(1000); // One second delay
  
  digitalWrite(dirPin,LOW); //Changes the rotations direction 
  // Makes 400 pulses for making two full cycle rotation
  for(int x = 0; x < 1600; x++) {
    digitalWrite(stepPin,HIGH);
    delayMicroseconds(500);
    digitalWrite(stepPin,LOW);
    delayMicroseconds(500);
  }
  delay(1000);
}
  

Once the code was ready, the next step is to add the code to the board. Since, the ATtiny board cannot be directly connected to the system, I used the Quentorres board as a programmer. I followed the link below to set up everything in Arduino.

https://wolles-elektronikkiste.de/en/using-megatinycore

I took the URL:"http://drazzy.com/package_drazzy.com_index.json" provided in the site and pasted it on "Additional Boards Manager URLs" from File > Preferences

Then I downloaded a package from Boards Manager.

Board Library

Once the package is downloaded, click on Tools > Board Manager > megaTinyCore > ATtiny3224/1624/1614/1604/824/814...

Board

Next select the chip, Tools > Chip > ATtiny1614

Chip

Select the programmer as SerialUPDI - SLOW: 57600 baud

Programmer

The next step is to connect the new board to the Quentorres then to the system. Quentorres doesn't have UPDI pin so we are using a FTD to UPDI convertor we have here at FabLab in between.

FTD to UPDI
Connected

Then I connected it to the system, selected the port and click on Burn Bootloader.

Burn Bootloader

Once completed, I uploaded the code to the board.


Running the Stepper Motor

I screwed in two wires at the terminal and connected it to DC Power Supply.

  Parameter values set on DC Power Supply
  Voltage: 12V
  Current: 0.5A (To check if it's shot)

Current Limiting Potentiometer

Before running the motor, we must limit the maximum current flowing through the stepper coils so that it does not exceed the motor’s rated current. This is done by tightenening or loosening the screw which actually is a current limiting potentiometer. Here, I have set its voltage at around 0.6V.

Refer Last Minute Engineers to know about the two methods in which the adjustment can be done.

Power Supply


Mistakes and Problems faced this week

  1. I had to design the PCB again as I forgot to flip the driver module so as to solder. (in through-hole case)
  2. Solution: Made a new footprint making the DRV8825 as SMD instead of through-hole.

  3. It is while soldering the components that I noticed the position of the FTDI. It was supposed to be at the edge but while providing the edge cut without realizing, I gave space in between.
  4. Space

    Solution: Used a connector pin.

    connector pin
  5. The distance between the solder jumper was too small that the machine wasn't able to cut it.
  6. Solder Jumper

    Solution: Manually made the cuts in between solder jumper.

    Solder Jumper Cut
  7. I forgot to change the name under one of the label connecting to the 12V power line.
  8. Different Label

    Solution: Used a 0 ohm resistor to connect the lines.

    0 ohm
  9. While connecting to the system once soldered, the voltage regulator was heating up.
  10. Solution: Manually cut the voltage regulator 5V output and added a Schottky diode of 150mA 100v in between. Diode

  11. I gave the wrong pin number order for the footprint I had created for DRV8825.
  12. error

    Solution: Cuts and jumpers were given in order to correct the path.

    Final path

    Group Assignment

    This week's group assingment was to measure the power consumption of an output device. We chose Stepper Motor as the output device. Graph

    For further details, click on the link below.

    Group Assignment-Week 9



    Download Files

    Design FilesTop Traces (Main PCB) png fileTop Drills (Main PCB) png fileEdge Cut (Main PCB) png file
    
    Footprint DRV8825 SMD Footprint
    
    Program CodeStepper Motor (Arduino Code)