# Week 09: Output Devices¶

Week 9 at the Fab Academy presented an intriguing challenge for the cohort: to measure the power consumption of an output device, specifically a stepper motor, utilizing a programmable single output DC power supply and a stepper motor. This task not only aimed to deepen the students’ understanding of electronics and power management but also to foster teamwork and collaborative problem-solving skills. Here’s a look at how we approached the project, step by step.

## Objective:¶

The primary goal was to measure and analyze the power consumption of a stepper motor under different conditions, including varying speeds, loads, and step modes (full step, half step, microstepping). The programmable single output DC power supply was instrumental in providing a controlled and adjustable power source for the motor.

## Equipment and Materials:¶

1. Stepper Motor: The output device in question, chosen for its widespread use in various applications from printers to CNC machines.
2. Programmable Single Output DC Power Supply: Allowed for precise control over the voltage and current supplied to the motor.
3. Microcontroller: To control the stepper motor’s operation modes and to send commands for different speeds and steps.
4. Multimeter: Used to measure the voltage and current directly if needed for verification.
5. Computer with Software: To program the microcontroller and possibly to log and analyze data from the power supply if it had data connectivity. We used Arduino IDE as the programming interface.

## 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, we planned to use NEMA 17 because we got to know that the other motor is quite slow compared to NEMA 17.

## Features of NEMA 17 Stepper Motor¶

1. 2 phase motor with bipolar configuration
2. Requires a driver that can reverse the current direction to achieve motion.
3. It has a step angle of 1.8 degrees, which translates to 200 steps per full revolution contributing to precise control of movements
4. The holding torque varies from 12 N.cm to over 50 N.cm. Holding torque is a critical factor since it determines the maximum load the motor can handle without losing position when stationary.

## 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 we are using is having bipolar configuration with 4 leads.

## 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:

It can handle motor supply voltages up to 45V and can deliver up to approximately 2.5A per phase (1.5A without overheating). This range is suitable for NEMA 17. It supports adjustable current limiting and offers up to 1/32-step microstepping. Microstepping allows for smoother motor motion, higher step resolution, and reduced mechanical resonance, which are crucial for applications that demand precise motion control and low vibration. Includes features like thermal shutdown, under-voltage lockout, and crossover-current protection. It offers improved performance compared to some other drivers, such as the A4988, in terms of driving capability and heat dissipation. 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¶

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.

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

## Features of ATtiny1614:¶

Utilizes the high-performance, low-power AVR RISC architecture. 16 KB of flash memory. Supports up to 20 MHz clock speed, providing a good balance between processing power and power consumption. Provides support for I2C, SPI, and UART communication, enabling the microcontroller to connect with a wide range of sensors, actuators, and other microcontrollers or microcomputers. Includes high-resolution timers and multiple PWM channels for precise control over timing and output modulation, suitable for tasks ranging from simple time-keeping to complex motor control. ATtiny1614 can be programmed via UPDI (Unified Program and Debug Interface), simplifying the development process with only a single wire for programming and debugging.

## PCB Design¶

During ‘Electronics Design’ week, we were introduced to KiCad to design PCBs. So we 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, we started with the schematic diagram.

we started off with designing a board just for the driver module thinking that we could use the microcontroller board we have created last week for the purpose. Here’s the PCB our fellowmate Laxmi had designed.

And this is when my instructor suggested we create an entirely new board with an ATtiny1614 microcontroller. And we did so. we 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 we thought I’ll give it a chance as anyway we have to create new boards for my upcoming weeks and final project and this would be an added experience.

We made the schematic diagram with all the required components.

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

## PCB Milling¶

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

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

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

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

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

## Programming:¶

We used Arduino IDE for the code. We 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:

Programming code for the experiment

## Stepper Motor Control 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, we used the Quentorres board as a programmer. We followed the link below to set up everything in Arduino.

https://wolles-elektronikkiste.de/en/using-megatinycore We 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

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

Next select the chip, Tools > Chip > ATtiny1614

Select the programmer as SerialUPDI - SLOW: 57600 baud

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.

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

Running the Stepper Motor We 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, we have set its voltage at around 0.6V.

Measurement and Data Collection: With the setup complete, the group began running their tests. They adjusted the settings on the DC power supply to vary the voltage and current supplied to the motor and recorded the power consumption under different conditions. This phase required careful observation and documentation.

## Analysis:¶

The collected data was then analyzed to determine the power consumption patterns of the stepper motor. The team looked for trends based on the operational modes, speeds, and loads, using the data to calculate efficiency and identify any unexpected results.

## Challenges and Learnings:¶

Understanding Power Supply Features: One challenge was fully utilizing the programmable DC power supply’s features, such as setting limits for voltage and current to protect the motor.

Programming for Precise Control: Developing the code to precisely control the stepper motor’s various operational modes required a deep dive into its mechanics and electronics.

Team Coordination: Coordinating roles and responsibilities within the team was crucial, especially when parallel tasks like programming and circuit setup needed to happen simultaneously.

Last update: May 8, 2024