Skip to content

9. Output devices

Assignments in this week

Group Assignment:
- [x]Measure the power consumption of an output device. - [x]Document your work on the group work page and reflect on your individual page what you learned.

Individual assignment:
- [x]Add an output device to a microcontroller board you’ve designed, and program it to do something

Group Assignment

Measure the power consumption of output devices

Confirm the measurement methods

1. Use multimeter to messure current and working voltage.

Using a multimeter to measure the voltage of a circuit is a relatively simple and routine operation, but I rarely use a multimeter to measure current, so the focus this time is on measuring the current, so as to properly calculate the power consumption.
Step1: Measure the voltage and select the appropriate voltage range and options.
Since I am using the laptop’s type C interface for power supply, the output voltage is 5V DC. I chose to insert the red test lead into the voltage/resistance range and the black test lead into the COM interface for measurement.

Step2: Measure the current and select the appropriate current range and options.
Since the power supply of the notebook is 5V/3A, I chose the 10A current measurement gear and connected the red test pen. The position of the black test pen remained unchanged. When measuring the current, I only need to connect the measuring pen in series to the circuit.

Step3: Select the appropriate measurement point to measure the desired voltage and current values.
When I want to measure the power consumption of the entire circuit, I need to place the measurement point close to the input end of the circuit, so I connect the black test lead to the GND of the board, and the red test lead to the VCC of the board, and then measure and get the following data.


Step4: Calculate power consumption. P = U*I formula calculation.
The working voltage is 5.21V. The working current is 26.11mA.
P = U*I = 5.21 V * 0.02611 A
The output power consumption is only for DVR8833 and motor parts.
The power consumption will be 0.1360331 W.

2. Use the current sensor and voltage sensor to cutin the working progress.

I saw on the Internet that it was also recommended to use the ACS712 current sensor for real-time measurement of current. The experimental principle is similar, that is, a current sensor is connected in series in the drive circuit, and the corresponding current and voltage data can be read through the Arduino program. This measurement method seems to be more applicable only when the circuit has a separate output, and it is also more challenging. The measurement accuracy of the sensor itself. Because I don’t have the corresponding sensor around me, I didn’t measure it through this method, but I did refer to the relevant information and did some basic learning.

https://forum.arduino.cc/t/measuring-power-consumption-with-arduino-uno-acs712-current-sensor/971129/7

Programing on output devices.

In my final project, since I need to make a mechanical automatic opening and closing mechanism, I must choose to drive a DC motor. In this section, I will record the process and results of my selection and use of DC motor drive.

1.Chosse appropriate motor driver: L293D/L298N or DRV8833

When an Arduino beginner, L293D and L298N are the most preferred motor drivers for Arduino projects. They are inexpensive, reliable and have been used in hundreds if not thousands of projects. However, they have one major drawback - they use bipolar junction transistors (BJTs), which makes them extremely inefficient, bulky and consume relatively large amounts of power when used.After checking the datasheet, I got the following parameter comparison.

Feature L293D L298N DRV8833
Motor Channels 2 (H-Bridge) 2 (H-Bridge) 2 (H-Bridge)
Operating Voltage 4.5V - 36V 4.5V - 46V 2.7V - 10.8V
Output Current 600mA per channel, 1.2A peak 2A per channel, 3A peak 1.2A per channel, 2A peak
Peak Output Current 1.2A per channel 3A per channel 2A per channel
Power Dissipation Moderate, requires heatsink High, requires large heatsink Low
Control Interface TTL Logic (5V) TTL Logic (5V) TTL Logic (3.3V/5V)
PWM Frequency Up to 5kHz Up to 25kHz Up to 100kHz
Internal Diodes Yes No Yes
Cost Low Moderate Low
Package DIP16, SOIC16 Multiwatt15, PowerSO20 HTSSOP16, WQFN12
Protection Features Thermal Shutdown Thermal Shutdown Overcurrent, Overtemperature, Undervoltage Lockout
Efficiency Moderate Low High
Applications Small robotics, basic DC motor control Larger robotics, stepper motors Battery-powered projects, portable devices

Summary:
L293D: Good for basic, low-power applications with simple motor control needs.
L298N: Suitable for higher power applications but requires a heatsink due to higher power dissipation.
DRV8833: Ideal for battery-powered or portable projects with higher efficiency and integrated protection features.

2. Principle of DVR8833

Intruction of DVR8833 At the heart of the DRV8833 module is Texas Instruments’ integrated H-bridge driver IC, which is optimized for motor drive applications.
The DRV8833 features two NMOS H-bridge drivers, allowing it to control two DC brush motors, a bipolar stepper motor, solenoids and other inductive loads.
It operates from 2.7 V to 10.8 V and can continuously deliver up to 1.2 A per channel. Additionally, it can withstand peak currents of up to 2 A per channel for several seconds.
The DRV8833 also includes multiple protection features such as undervoltage lockout, overcurrent and overtemperature protection, providing a high level of reliability. Each of these events disables the H-bridge MOSFET. After the fault condition is eliminated, the equipment will resume operation.
It also includes a low-power sleep mode that allows you to save power, especially when the motor is not in use.These features make it an excellent choice for powering small, low-voltage motors.

Pinout of DRV8833
Power pin:
Unlike most motor drivers, the DRV8833 has only one power connection (because the motor voltage is the same as the logic voltage).
VCC and GND are where the power to drive the motor is connected, ranging from 2.7V to 10.8V.
Note that the DRV8833 can operate at voltages as low as 2.7V. This means it is ideal for low voltage projects, such as those running on a single lithium polymer battery and a low voltage motor.

Output pin:
The output pins of the DRV8825 motor driver, namely OUT1, OUT2, OUT3, and OUT4, are located on one side of the module for easy connection.
Motor A should be connected to OUT1 and OUT2, while motor B should be connected to OUT3 and OUT4. You can connect any brushed DC motor in the 2.7 V to 10.8 V range to these pins.
Keep in mind that the DRV8833 can continuously supply 1.2 A per channel (2 A peak) to a pair of DC motors.

Control input pins:
Each motor has two control inputs; IN1 and IN2 are for motor A, while IN3 and IN4 are for motor B. These control inputs allow you to control the speed and direction of rotation of the motor.

  • Directional control:
    The direction of rotation of the motor can be controlled by applying a logic high (5V) or a logic low (ground) to these inputs. The truth table below shows how the input affects the driver output. speed control:
    If you want to control the speed, you can use pulse width modulation (PWM) on a pin that is normally high. If speed controls are not required, simply set them to “High” or “Low”.
    PS:control input is pulled low internally, effectively disabling the motor driver output by default.

Sleep mode pin:
This sleep pin (labeled EEP on the silkscreen on the board) controls the sleep mode of the DRV8833. Setting this pin low puts the DRV8833 into a low-power sleep mode, while setting it high makes it active again.
In this mode, the H-bridge is disabled, the gate drive charge pump is stopped, all internal logic is reset, all internal clocks are stopped, and all inputs are ignored. It is important to note that when returning from sleep mode, the motor driver takes a moment (up to 1 millisecond) to become fully operational again.
The SLEEP pin on the board is pulled high by default, so you can leave it disconnected if you don’t plan to use low-power sleep mode.There is a solder jumper J1 on the back of the DRV8833 module.

Fault detection pin:
The FAULT pin (labeled ULT on the silkscreen on the board) is an open-drain output that is driven low by the chip whenever an overcurrent, overtemperature, or undervoltage condition occurs.
By default, this pin remains floating. Therefore, if you want to monitor a fault condition on the drive, you need to connect an external pull-up resistor (or use a microcontroller input with a built-in pull-up enabled).

Limiting:
The DRV8833 can actively limit the current through the motor. This is typically accomplished by connecting a resistor between the AISEN pin and ground to set the limit for motor A, and another resistor between the BISEN pin and ground to set the limit for motor B.
However, this particular DRV8833 breakout board connects these current sense pins directly to ground, effectively disabling the current limit feature.

3. Design & Manufacturing the baord

  1. Hardware Connection & PCB Design Image
    In the PCB design part, because I use the makerspace CNC machine for processing, all traces must be drawn on the same layer, which makes it very difficult for me to place components. At the same time, I have to take care of how to leave enough There is enough space to place XIAO and other components.
    Download my PCB Design

 2. Manufacutring the boards. The final circuit board produced is as follows.

4.Coding and Tesing

When the motor accelerates or decelerates, I hear a buzzing sound. At this time, the motor’s speed is relatively low, and the PWM value output by the circuit board is also relatively low. This happens because DC motors require a minimum voltage to operate.

The Arduino code is fairly simple. It doesn’t require any libraries to work. Start by declaring the Seeed XIAO ESP32 pins connected to the DRV8833 control pins.

// Define the control inputs
#define MOT_A1_PIN D0
#define MOT_A2_PIN D1

The setup portion of the code initializes the hardware. It configures all motor control pins as digital outputs and sets them low to initially disable both motors. Then, serial communication is initialized at a baud rate of 9600.

void setup(void)
{
  // Set all the motor control inputs to OUTPUT
  pinMode(MOT_A1_PIN, OUTPUT);
  pinMode(MOT_A2_PIN, OUTPUT);

  // Turn off motors - Initial state
  digitalWrite(MOT_A1_PIN, LOW);
  digitalWrite(MOT_A2_PIN, LOW);

  // Initialize the serial UART at 9600 baud
  Serial.begin(9600);
}

The loop part of the main program generates a fixed motion sequence to express the motion pattern of the motor. The motor first gradually increases the speed of the motor, then reaches full speed, slows down again and reverses direction to full speed, and finally stops.

void loop(void)
{
  // Generate a fixed motion sequence to demonstrate the motor modes.

  // Ramp speed up.
  for (int i = 0; i < 11; i++) {
    spin_and_wait(25*i, 500);
  }
  // Full speed forward.
  spin_and_wait(255, 2000);

  // Ramp speed into full reverse.
  for (int i = 0; i < 21 ; i++) {
    spin_and_wait(255 - 25*i, 500);
  }

  // Full speed reverse.
  spin_and_wait(-255, 2000);

  // Stop.
  spin_and_wait(0, 2000);

  // Full speed, forward, turn, reverse, and turn for a two-wheeled base.
  spin_and_wait(255, 2000);
  spin_and_wait(0, 1000);
  spin_and_wait(-255, 2000);
  spin_and_wait(0, 1000);
}

Three user-defined functions are used in the program: set_motor_pwm(), set_motor_currents() and spin_and_wait().
The set_motor_pwm() function uses PWM and direction logic to set the current on the motor channel. If this pwm value is negative, the motor rotates in one direction. If this pwm value is 0 or positive, the motor stops or rotates in the other direction.
The set_motor_currents() function uses the previous function to set the current on both motors. It prints the current PWM value of each motor to the serial monitor.
The spin_and_wait() function sets the speed and waits for the specified time before moving on to the next command. It sets the PWM values ​​of both motors using the set_motor_currents() function and then waits for the specified value in duration milliseconds.

/// Set the current on a motor channel using PWM and directional logic.
///
/// \param pwm    PWM duty cycle ranging from -255 full reverse to 255 full forward
/// \param IN1_PIN  pin number xIN1 for the given channel
/// \param IN2_PIN  pin number xIN2 for the given channel
void set_motor_pwm(int pwm, int IN1_PIN, int IN2_PIN)
{
  if (pwm < 0) {  // reverse speeds
    analogWrite(IN1_PIN, -pwm);
    digitalWrite(IN2_PIN, LOW);

  } else { // stop or forward
    digitalWrite(IN1_PIN, LOW);
    analogWrite(IN2_PIN, pwm);
  }
}

/// Set the current on the motor.
///
/// \param pwm_A  motor A PWM, -255 to 255
void set_motor_current(int pwm_A)
{
  set_motor_pwm(pwm_A, MOT_A1_PIN, MOT_A2_PIN);

  // Print a status message to the console.
  Serial.print("Set motor A PWM = ");
  Serial.println(pwm_A);
}

/// Simple primitive for the motion sequence to set a speed and wait for an interval.
///
/// \param pwm_A  motor A PWM, -255 to 255
/// \param duration delay in milliseconds
void spin_and_wait(int pwm_A, int duration)
{
  set_motor_current(pwm_A);
  delay(duration);
}

Final usage and end application of this motor

Because I designed an electric rotary opening and closing mechanism in my final project, an output motor is needed to control the opening and closing process of the entire mechanism, so this motor driver will be used in detailed programming in the final project later. Electric opening and closing can meet the needs of remote control opening and closing, and can also meet the automatic opening and closing structure.

Experience & Summary

The problem with BJT transistors is that they have an on-state voltage drop. Most of the voltage needs to be dissipated in the form of heat. When the drive motor is connected for a long time, it will cause a lot of heat loss, and the driver will overheat and affect its performance. This is a very fatal shortcoming.

So this time as the output device, I chose the DRV8833 motor driver, which has excellent driving efficiency. The DRV8833 uses MOSFETs instead of BJTs. MOSFETs have an almost negligible voltage drop, which means that almost all of the voltage from the power supply is passed to the motor. That’s why the DRV8833 is not only more energy efficient than BJT-based motor drivers, but it also generates much less heat, making it safer for long-term use. As an expansion board, it can also be considered as an output device of a microprocessor main control board. Its main function is to bring out some interfaces of the main control board and come with some peripheral functions, such as OLED displays and other peripherals.