Digital Fever! That sounds cool, right? Same here.  And "we're sending out PSoC4200 for your ideas"!!! That's exciting and it is how was able to try stepper control using PSoC4200. Thanks to E14!


Project14 Motor Drive

Starting off, I had heard about PSoC quite a bit and knew that it's highly configurable and can be designed application-specific. I started thinking about what could be done using digital logics and incidentally came across this article on the Johnson Ring counter and its application in stepper control. Ok, I had learnt a bit about that while on the Trinamic Stepper Driver RT and waveforms of the johnson counter looked familiar to coil firing sequence in a stepper. So, it's fully digital and relating with PSoC, woot! it had a UDB(universal digital block) consisting of all basic digital gates and units. So I put up an idea to design it without really knowing how to implement it!


  • Block Diagram and Features of PSoC 4200

PSoC 4200 BlockPSoC4 Features


Now, why to design another fully digital stepper driver? There are tonnes of trending chips by TI, ST, ROHM, Infineon and not to forget, the Trinamic etc like L298N, TMC2209, A4988, DRV8825 etc. But, these are mostly H-Bridge based, power-hungry and heat-bleeding. Yet are suitable and needed for high torque and control applications.


  • Typical stepper driver configuration with MOSFETs

Typical driver


Here, I am looking specifically for 28BYJ-48 unipolar stepper motor and usage of the digital logic counter method to generate coil pulse sequence. Doing this would make the driver handy and easy to implement with a couple of flip-flops and logic gates. Putting it inside PSoC would be like a highly configurable driver and multiple ones can be designed inside one PSoC chip. No high heat dissipation, no exclusive driver chips like L298N is required and several driver logic can be implemented in a single PSoC chip(limited by GPIOs and UDB count though).

This was a sort of a cool thing and I decided to go hardcore with PSoC and try to get it running. Also, I loved doing stepper driver the other way and thought it would be a good learning thing for my motor stuff addiction.


  • Overall Plan - Block Diagram



I found two ways to implement a unipolar stepper motor coil sequence generator. The first one is "Design02" which is a plain 2-bit quadrature generator and the second one, "Design01" is with two multiplexers(MUX) which facilitate in reversing the pulse sequence and thereby allow to change forward/reverse the direction of the motor. I now have to see how to implement both the designs in PSoC4200. The 28BYJ-48 unipolar motor has 5 wires one being Vcc from centre-tap of both the coils and others are A/A1 and B/B1 ends of each coil respectively. Some features:

  • Rated Voltage: 5V DC
  • Number of Phases: 4
  • Stride Angle: 5.625°/64
  • Pull in torque: 300


stepper pinout


I made the first one first, Design02 on a PSoC. For the clock signal, I put a configurable clock block(48MHz default) and set it to a minimum of 1kHz. The GPIO of PSOC4200 won't be able to handle more than a couple of tens of mA and had to use some kind of high side driver for supplying the 420mA rated current of the motor. So, I used a ULN2003A darlington array IC for whose input A/A1, B/B1 are given and output is given to the motor pins.

darlington arrayULN2003A internal

After assigning the pins and downloading the design to the PSoC, nothing seemed to work. The motor was buzzing slightly and heating up a lot. I waited, went to my university lab to get an oscilloscope and checked for the waveforms from pins A/A1/B/B1 pins of the PSoC. They looked fine and were complementary to each other as required by the motor. I checked the frequency and was close to 1kHz as assigned in the design. Later after tinkering a lot, I found it was overclocked or infact, the frequency of 1kHz was too high for the coils and didn't slip out and rotate. So,....with PSoC I dodn't know how to go below 1kHz as lower ranges aren't possible directly as the maximum possible divider is 65536 for a 48MH onboard one(clock dividing is a choice? let me know, I wanna try)


Time being, I pulled out the clock pin through one of the GPIOs of PSoC P0[4]  and used Arduino UNO as a clock source giving 500Hz.


{gallery} Design02 - Stepper Driver


design 2 pinout


This code generates a 500Hz clock signal through pin13 of Arduino. I tried lower and higher frequencies too(10Hz, 100Hz, 1kHz etc) but 500Hz seems to be a good tradeoff and there isn't overheating of coils. The speed of the motor can be controlled by the frequency of the clock signal. Too slow at 100Hz and running well at 500Hz.


  • Clock Generator Code

/* Program to generate clock signal; delay() = 1ms; T = 1+1=2ms; frequency = 1/T = 1/2ms = 500Hz */

//setup the pinout and LED
void setup() 
  pinMode(LED_BUILTIN, OUTPUT);      //builtin LED pin 13

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1);                          // wait for a millisecond
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1);                          // wait for a millisecond


Well, this works fine!

PSoC4 Motor ctrl


Now, I thought of having the direction control too for the motor! So, I added two MUX with one being fed in a reverse coil firing sequence so that when I toggle it, the complementary waveform goes to the motor which inturn changes the motor direction.

I actually wanted to have the clock within the PSoC itself. After reading this Prototyping with FPGAs - Part 3 - Sequential Logic with Quartus Prime on Cyclone-IV FPGA insightful blog by yesha98 I thought of using clock divider method for the internal 48MHz one to get 500Hz. Eventually, I found that PSoC has a Frequency Divider block FreqDiv_1 and plugged it in with a division factor of 2 for a 1kHz signal (that's the minimum I could get).


{gallery} Design01 - Stepper Driver


design 1 schematic

design 1 pinout


Grrrrrrrrrrr........goes the motor and rrrrrrrrrrrrG....... when the direction is reversed! The gear ratio is high in this 28BYJ-48 unipolar stepper and hence it always runs slowly but with higher torque.


{gallery} Project Gallery

PSoC Device


Full Setup

Motor Specs

Motor Attached


This method of designing a stepper driver and efficiently using it suits the 28BYJ-48 unipolar stepper motor and maybe just lame for others if some hi-end motors having precise micro-stepping and step-delay are considered. This particular motor suits the printer, robotic arms, high torque traction applications etc. So, drivers for these can be easily designed with logical blocks and multiple ones can be implemented.

I enjoyed building this stuff with an idea that came from nowhere and now having a configurable driver in hand. The PSoC creator is a well designed software and enables easy configuration and flashing of designs. It feels like making something Sci-Fi while dragging and connecting blocks and see it running on hardware right away. Further, I want to look into the waveforms and try to reduce distortions/gerks in the motor to improve the efficiency of this design. I am also thinking of designing drivers in a similar way for BLDCs too which I have used in one of the earlier RoadTest. Excited about this and looking forward!


Feel free to provide suggestions/improvements or an upgrade plan for this project. Thanks


Quick update! Finally, I got a chance to look through the scope at my univ!

Stepper Driver Scopy Test

Looking through pin 0[1] which is A1 and 0[3] which is B in final design.

For clockwise rotation:

Clockwise rotation


For anti-clockwise rotation:

Anticlockwise rotation

A 90-degrees of phase shift is seen in the anti-clockwise control signal compared to the clockwise control signal. This shift in pin B of the stepper and signal A1 is intact.



Links and References

Stepper Motor Basics TI Precision Labs:
How to Drive a Stepper Motor:
Selecting Stepper Motor Drivers:
Designing of Johnson Ring Counter:


All design files are attached below(ZIP)