element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products & Partners
    Products & Partners
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Blog EZ-MCXN: NXP MCXN326 simple stepper motor controller
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 18 Nov 2026 3:47 PM Date Created
  • Views 22 views
  • Likes 3 likes
  • Comments 0 comments
  • EZ-MCXN
  • MCXN
  • nxp
  • MCXN236
Related
Recommended

EZ-MCXN: NXP MCXN326 simple stepper motor controller

Jan Cumps
Jan Cumps
18 Nov 2026

This post shows a very simple stepper motor design, using NXP's Configurator and driver APIs. It can control the direction and the number of steps to take.
It's a fixed speed design. I'm testing it on shabaz' EZ-MCXN dev board.

This can be helpful to work with the stepper(s) of the Rise Of The Robots - Robotics Design Challenge.

image

What can this code do:

  • control a STEP/DIR motor driver (e.g. A4988 )
  • generate a number of steps
  • fixed speeds, that you can set at config time, or in code before launching a step command
  • set the motor direction

How does it do that:

  • DIR is a simple GPIO pin
  • STEP is controlled by a timer, in PWM mode.
  • an interrupt counts the number of steps and stops the timer when all steps are taken.

Resources:

  • PWM timer CTIMER3
  • STEP pin 39 set by CTIMER3 PWM output
  • DIR pin 38 controlled by GPIO port 4 pin 16.

image

Configuration

Configure CLOCK

image

Configure CTIMER

image

Configure PINs

image

Code

This example will take 100 steps, change motor direction, and take 100 steps again. Repeat.

#include "fsl_common.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "peripherals.h"

#include "fsl_gpio.h"
#include "fsl_ctimer.h"
#include <stdbool.h>
#include <stdint.h>

volatile uint32_t steps_remaining = 0;

void CTIMER3_PwmCallback(uint32_t flags) {
    if (flags & kCTIMER_Match3Flag) {
        if (steps_remaining > 0) {
            steps_remaining--;
            if (steps_remaining == 0) {
                CTIMER_StopTimer(CTIMER3_PERIPHERAL);
            }
        }
    }
}

void Stepper_MoveSteps(uint32_t steps) {
    if (steps == 0) return;

    steps_remaining = steps;
    CTIMER_Reset(CTIMER3_PERIPHERAL);
    CTIMER_StartTimer(CTIMER3_PERIPHERAL);
}

int main(void) {
    BOARD_InitPins();
    BOARD_BootClockRUN();
    BOARD_InitBootPeripherals();
    while (1) {
        GPIO_PortToggle(BOARD_INITPINS_DIR_PIN_GPIO, 1U << BOARD_INITPINS_DIR_PIN_GPIO_PIN);
        Stepper_MoveSteps(100);
        while (steps_remaining > 0) {
            __NOP();
        }
        for (uint32_t i = 0; i < 1000000U; i++) {
            __NOP();
        }
    }
}

If you use an NXP dev board - like in the Rise Of The Robots Design Challenge - you may not have to call the individual init functions. If you enable initialisation in the configurator, the individual setup functions will be called in your board init code.

Thank you for reading

Related posts.

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube