Shahariar
Published © CC BY

IFX007T Brushed DC Motor Speed and Direction Controller Demo

IFX007T based PN MOSFETs Half Bridge IC's Motor Control Shield for controlling the speed and direction of a Brushed DC motor

BeginnerProtip2 hours271
IFX007T Brushed DC Motor Speed and Direction Controller Demo

Things used in this project

Hardware components

BLDC Shield IFX007T
Infineon BLDC Shield IFX007T
×1
DC Motor, Brush
DC Motor, Brush
×1
Xenon
Particle Xenon
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

IFX007T Motor Control Shield User Guide

IFX007T Datasheet

Schematics

Schematic

MCU pinout

Code

Brushed DC Drill Motor Speed Controller

C/C++
/*
  Project: Brushed DC Motor Control using IFX007T
  Hardware Setup:
    - Motor Driver: 2x Infineon IFX007T ICs (each configured as a half-bridge).
      Together they form a full H-bridge for driving a 775 brushed DC motor.
    - Microcontroller: Adafruit Feather nRF52840 Express (Arduino-compatible).
    - Power Source: 12V drill machine battery pack.
    - Inputs: 
        * MOTOR_MODE_BUTTON (mode select: stop/forward/reverse)
        * MOTOR_SPD_UP_BUTTON (increase speed)
        * MOTOR_SPD_DOWN_BUTTON (decrease speed)
    - Outputs:
        * LEDs for feedback (mode, speed up/down, forward, reverse, stop).
        * PWM signals to IFX007T ICs for motor control.

  Operation:
    - Speed control is achieved by varying PWM duty cycle.
    - Direction control is achieved by enabling one half-bridge path at a time:
        * Forward: IC1 P-MOS ON (motor terminal A = +12V), IC2 N-MOS ON (motor terminal B = GND).
        * Reverse: IC2 P-MOS ON (motor terminal B = +12V), IC1 N-MOS ON (motor terminal A = GND).
    - Dead-time and built-in protection in IFX007T prevent shoot-through.
    - Offset duty cycle ensures motor startup torque and avoids stall.


*/

#include <Arduino.h>   // Core Arduino library

// ---------------- Button pin definitions ----------------
#define MOTOR_MODE_BUTTON 11     // Button to change motor mode (stop/forward/reverse)
#define MOTOR_SPD_UP_BUTTON 12   // Button to increase motor speed
#define MOTOR_SPD_DOWN_BUTTON 3  // Button to decrease motor speed

// ---------------- LED pin definitions ----------------
#define MOTOR_MODE_LED A7        // LED lights up when mode button is pressed
#define MOTOR_SPD_UP_LED A2      // LED lights up when speed-up button is pressed
#define MOTOR_SPD_DOWN_LED A6    // LED lights up when speed-down button is pressed
#define MOTOR_FWD_RUN_LED 26     // LED indicates forward rotation
#define MOTOR_STOP_LED 25        // LED indicates stop mode
#define MOTOR_RWD_RUN_LED 24     // LED indicates reverse rotation

// ---------------- Motor driver pins ----------------
// Two IFX007T ICs are used, each as a half-bridge.
// Together they form a full H-bridge for the brushed DC motor.
#define MOTOR_DRIVE_INHIBITOR 7  // Enable/disable motor driver ICs
#define MOTOR_PWM_DRIVER_CW 4    // PWM output for clockwise rotation (controls IC1)
#define MOTOR_PWM_DRIVER_CCW 5   // PWM output for counter-clockwise rotation (controls IC2)

// ---------------- Variables for speed and mode ----------------
uint8_t speed_U = 0;             // Speed value for forward rotation (IC1 active)
uint8_t speed_V = 0;             // Speed value for reverse rotation (IC2 active)
uint8_t offset = 75;             // Minimum duty cycle offset (~28%) to prevent motor stall
uint8_t MODE = 0;                // Current operating mode (0=stop, 1/2=forward, 4/5=reverse)

// ---------------- Setup function ----------------
void setup() {
  // Configure buttons as inputs with pull-up resistors
  pinMode(MOTOR_MODE_BUTTON, INPUT_PULLUP);
  pinMode(MOTOR_SPD_UP_BUTTON, INPUT_PULLUP);
  pinMode(MOTOR_SPD_DOWN_BUTTON, INPUT_PULLUP);

  // Configure LEDs as outputs
  pinMode(MOTOR_MODE_LED, OUTPUT);
  pinMode(MOTOR_SPD_UP_LED, OUTPUT);
  pinMode(MOTOR_SPD_DOWN_LED, OUTPUT);
  pinMode(MOTOR_FWD_RUN_LED, OUTPUT);
  pinMode(MOTOR_STOP_LED, OUTPUT);
  pinMode(MOTOR_RWD_RUN_LED, OUTPUT);

  // Configure motor driver enable pin
  pinMode(MOTOR_DRIVE_INHIBITOR, OUTPUT);
  digitalWrite(MOTOR_DRIVE_INHIBITOR, LOW); // Start with driver disabled
}

// ---------------- Main loop ----------------
void loop() {
  // ----------- Speed Up Button pressed -----------
  if (digitalRead(MOTOR_SPD_UP_BUTTON) == LOW) { 
    digitalWrite(MOTOR_SPD_UP_LED, HIGH);   // LED feedback
    delay(100);
    digitalWrite(MOTOR_SPD_UP_LED, LOW);

    // Forward mode (MODE 1 or 2)
    if (MODE == 1 || MODE == 2) {
      speed_V = 0; // Disable reverse path

      // Driving forward:
      // - IC1 high-side P-MOS ON → Motor terminal A = +12V
      // - IC2 low-side N-MOS ON → Motor terminal B = GND
      // → Motor sees positive polarity, spins forward
      if (speed_U < 180) speed_U += 5;
      analogWrite(MOTOR_PWM_DRIVER_CCW, speed_V); // Ensure reverse path is off
      analogWrite(MOTOR_PWM_DRIVER_CW, speed_U + offset); // Apply PWM to forward path
    }

    // Reverse mode (MODE 4 or 5)
    if (MODE == 4 || MODE == 5) {
      speed_U = 0; // Disable forward path

      // Driving reverse:
      // - IC2 high-side P-MOS ON → Motor terminal B = +12V
      // - IC1 low-side N-MOS ON → Motor terminal A = GND
      // → Motor sees flipped polarity, spins backward
      if (speed_V < 180) speed_V += 5;
      analogWrite(MOTOR_PWM_DRIVER_CW, speed_U); // Ensure forward path is off
      analogWrite(MOTOR_PWM_DRIVER_CCW, speed_V + offset); // Apply PWM to reverse path
    }
  }

  // ----------- Speed Down Button pressed -----------
  if (digitalRead(MOTOR_SPD_DOWN_BUTTON) == LOW) {
    digitalWrite(MOTOR_SPD_DOWN_LED, HIGH);      // LED feedback
    delay(100);
    digitalWrite(MOTOR_SPD_DOWN_LED, LOW);

    // Forward mode
    if (MODE == 1 || MODE == 2) {
      speed_V = 0; // Disable reverse path
      if (speed_U >= 5) speed_U -= 5;            // Decrease forward speed
      analogWrite(MOTOR_PWM_DRIVER_CCW, speed_V);// Ensure CCW PWM is off
      analogWrite(MOTOR_PWM_DRIVER_CW, speed_U + offset); // Apply reduced forward PWM
    }

    // Reverse mode
    if (MODE == 4 || MODE == 5) {
      speed_U = 0; // Disable forward path
      if (speed_V >= 5) speed_V -= 5;            // Decrease reverse speed
      analogWrite(MOTOR_PWM_DRIVER_CW, speed_U); // Ensure CW PWM is off
      analogWrite(MOTOR_PWM_DRIVER_CCW, speed_V + offset); // Apply reduced reverse PWM
    }
  }

  // ----------- Mode Button pressed -----------
  if (digitalRead(MOTOR_MODE_BUTTON) == LOW) {
    digitalWrite(MOTOR_MODE_LED, HIGH);          // LED feedback
    delay(100);
    digitalWrite(MOTOR_MODE_LED, LOW);

    MODE++;                                      // Cycle to next mode
    if (MODE >= 6) MODE = 0;                     // Wrap around after mode 5

    // Stop mode
    if (MODE == 0 || MODE == 3) {
      digitalWrite(MOTOR_DRIVE_INHIBITOR, LOW);  // Disable motor driver
      analogWrite(MOTOR_PWM_DRIVER_CW, 0);       // Stop CW PWM
      analogWrite(MOTOR_PWM_DRIVER_CCW, 0);      // Stop CCW PWM
      speed_U = 0; speed_V = 0;                  // Reset speeds
    } else {
      digitalWrite(MOTOR_DRIVE_INHIBITOR, HIGH); // Enable motor driver
    }
  }

  // ----------- LED feedback for modes -----------
  if (MODE == 0 || MODE == 3) {                  // Stop mode
    digitalToggle(MOTOR_STOP_LED);               // Blink stop LED
    delay(100);
    digitalToggle(MOTOR_STOP_LED);
  }
  if (MODE == 1 || MODE == 2) {                  // Forward mode
    digitalToggle(MOTOR_FWD_RUN_LED);            // Blink forward LED
    delay(100);
    digitalToggle(MOTOR_FWD_RUN_LED);
  }
  if (MODE == 4 || MODE == 5) {                  // Reverse mode
    digitalToggle(MOTOR_RWD_RUN_LED);            // Blink reverse LED
    delay(100);
    digitalToggle(MOTOR_RWD_RUN_LED);
  }
}

Credits

Shahariar
76 projects • 273 followers
"What Kills a 'Great life' is a 'Good Life', which is Living a Life Inside While Loop"

Comments