PSoC 5 Port Of the Grbl 1.1 CNC Controller

Image from Cypress

Image from Cypress


Grbl Logo 250px


Grbl is a high performance CNC controller.  It is used on a lot of small scale CNC machines and is the motion control code behind a lot of 3D printers.  It was originally targeted at the Arduino 328p hardware (UNO). It is developed  by Sungeun “Sonny” Jeon. He is a good friend.  He is always very helpful and this port would not have been possible without the quality of his code and his advice.

PSoC Mixed Signal Controller

I love working with the PSoC (Programmable System on Chip) family of micro controllers.  You can configure them on the fly with many analog and digital components.  The analog components are not basic ADCs and DACs, you have OpAmps, PGAs,  filters, MUXs and more.  The digital blocks includes basic logic gates, all the way up to FPGA like components you program yourself in Verilog..  There are over 200 ready to use components you can wire together on the chip.

I have always used them for small prototype projects, but wanted to test my skills by porting a major project like Grbl.  At the same time I wanted to take advantage of the features of the PSoC. The dev board I used was the CY8CKIT-059.  This has ARM Cortex M3 processor a lot of I/O and costs less than $10! It has a built in programmer and debugger.


PSoC Advantages

Here is a comparison between the the ATMega 328p (Arduino UNO) and the PSOC5

PSoc 5

ATMega328p (UNO)


32 bit

(ARM Cortex M3)

8 bit


Up to 80MHz

16MHz Typ.

Flash (program size)










up to 62



Grbl’s flexibility allows you to tailor it to your hardware.  With a few limitations, you can move the pins around and change things like whether switches are active low or high.  This is all done using #define values in configuration files.  That is great, but the code gets a little messy every time you access hardware. It has to do a little logic gymnastics each time.

With PSoC you can do all of that in a visual schematic and pin wiring feature.  Here is a PDF of my schematic.  Have you ever swapped transmit and receive on a UART? In PSoC you can just swap the pins on the schematic.

Here is an example of the difference in firmware code.

Grbl on 328p

uint8_t limits_get_state()
 uint8_t limit_state = 0;
 uint8_t pin = (LIMIT_PIN & LIMIT_MASK);

 if (bit_isfalse(settings.flags,BITFLAG_INVERT_LIMIT_PINS)) { pin ^= LIMIT_MASK; }

 if (pin) {  
   uint8_t idx;
   for (idx=0; idx<N_AXIS; idx++) {
     if (pin & get_limit_pin_mask(idx)) { limit_state |= (1 << idx); }

Grbl on PSoC

uint8_t limits_get_state(){  
 return Status_Limit_Read();


Special Hardware Usage

I used some special features to move functions out of code and onto the hardware.  One of them was the step pulse.  Stepper drivers typically require a pulse of a minimum length to take a step.  In normal hardware you have to raise the pin, then figure out a way to turn it off after a given period of time.  This is typically done via an interrupt.  It works fine, but the code is messy and interrupts can cause timing issues.  PSoC  control registers have a pulse feature that automates this. You attach a clock and the clock determines the length of the pulse.  The code sets it and the hardware clears it.  It looks like this on the schematic.



Another feature I used was hardware switch debouncing.  This can be done completely in hardware.  See the image below.  The clock sets the debounce time.  The debouncers are all fed into a status register where they are read  as a single value.  There are digital “nots” after the debouncers because my switches close to ground.  The firmware could invert the logic, but it is so much easier to read on the schematic. It then feeds an interrupt.



If you would rather do this with an analog filter, you can design custom filters in the hardware.  You could fine tune the filter right from your keyboard.



PSoC has a built in character LCD Component that makes using and LCD  very easy.  The code for the LCD is in the main loop and not an interrupt.  This allows the time critical  stuff to have higher priority.  I used an interrupt to just set a flag so the LCD does not update every time through the main loop.  I found the LCD to be an awesome debugging tool.  I could display stuff while the code is running.



I also used a hardware Quadrature Decoder for the LCD rotary knob. This works great to monitor the encoder in hardware.  I just need to read the value in the LCD update routine.  The clock feature on the QuadDec is a debouncer, which helped debounce my mechanical encoder.


Next Steps

I have been testing for a while and so far it is working great. I also have some plans to use the extra power on some cool projects.

Here is the code on GitHub

Here is a picture of my test setup.


Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks

19 Responses to “PSoC 5 Port Of the Grbl 1.1 CNC Controller”

  1. Stephen

    nice post.

    I haven’t played with the PSoC devices before but has been on my TODO list. This article has just prompted me to order the dev board. Done!

    Thanks for sharing the great article and will be following keenly

  2. bdring

    Stephen, good luck with your project. I plan on posting a few tips and enhancements soon.

  3. Line-us Clone Controlled by Easel and Grbl at Buildlog.Net Blog

    […] recently port Grbl to PSoC. I used (3) 16bit PWM components to control the hobby servos.  See this blog post on how I did […]

  4. Andrew

    GREAT WORK!!!!!
    Have you worked out the maximum step rate you can get out of the PSoC board? I know GRBL was limited to approx. 35,000sps, I’d be very interested to see what you can get.

    Keep up the great work – I would love to see your project once you have finished your testing.

  5. bdring

    Thanks Andrew,

    I have not fully tested the speed limits yet. I have spent more time adding features like the LCD and trying some encoders on the motors.

    I have tried making the motion planner much deeper. The standard buffer size is about 16 and I have tried over 100 with no issues.

    I can look into the stepper speed when I get a chance, but typically the current speed in not an issue for me. I think bigger bottlenecks occur in the communications and other areas. I might look into using DMA and other hardware features to speed up the slower areas of Grbl.

    Sonny says the real speed tests are with Laser Engraving, so I might setup a machine for that.

  6. Sourabh

    HI bdring,

    can i get the Psoc project files , i have the hardware but havent implemented Grbl on that . i want to implement G68 and G69 commands for angular movement. which is not available with Arduino. also to implement this in arduino we dont have enough memory left.

  7. bdring

    I put this code on GitHub.

  8. fjr

    Thank you for this!
    I’ve been waiting for someone to port GRBL (or for that matter smoothie).

    Is it just me, or does this barely even touch the speed/features of this chip?

  9. bdring


    The chip has a lot of untapped speed and features with this port of Grbl. I am already running 6 axis. I have at actively controlling the motor current and implemented an idle current reduction.

    The PSoC 6 is coming soon and will significantly boost the performance with a 150MHz clock, FPU, dual core and Bluetooth.

  10. Carlos

    Just find out your project today, it’s very interesting use of PSoC unique capabilities.

    As far as i know PSoC6 have less programmable logic (~12 UDBs) so maybe it will be not very easy to port the project to it :/.

    Anyway really interesting videos and posts 🙂

  11. flipflop

    Nice and very promissing!
    But is there any tutorial for newbies on programming the PSoC? A step-by-step guide?
    I can get the devboard locally for ~$15
    I have step-dir drivers capable of 512 microstepping
    How long would it take me to build the whole setup? Can I do that from a Mac? Do I upload my g-code the usual way via usb?

  12. bdring

    `There are many tutorials for PSoC. Go to to find them. It is easy if you are comfortable with other microcontrollers.

    You can use USB, just like Arduino with most senders including Universal GCode sender and Easel.

    You must use the PSoc Creator software to program or load firmware. It is free but only runs on Windows operating system.

  13. Rob


    I would very much like to own a PSoc grbl controller. I have bought the dev board and was wondering if you had a pin out diagram for hooking it up to stepper motor drivers. I’ll be using TB6600 drivers. Also, I love the LCD feature and neat 3D printed case, is the LCD this one:

    Can you supply some details for hooking it up to the PSoc dev board?

    Many thanks,


  14. Carlos


    Do you have any kind of TODO list? i would like to contribute to the project, maybe you can add some issues on the github repo and let the people or yourself solve that issues to make this project better.

    I read about you are thinking in use DMA in the “slower” parts of grbl, maybe you can extend a little on this?


  15. DAMIGO

    Hello bdring and hello together,

    1.) for bdring: a super big thank you for this highly interesting idea to use this PSOC as controller. This project leads for me to grab nearly immediately such one and starting to work with it :-). You are right it simplyfied many things which belongs to the HW implemented. I am just wondering why this PSOC is so unfamiliar. There is also a very good documentation and very friendly developement suite.

    2.) for Rob: download the PSOC development suite and load this project into. then you can see in the Pin overview page which pins are where to connect and to hook up. pay attention if you have an optoisolation for the limit switches you need to choose either pull up or pull down as input. It depends from you interface. For the display it self, it just a HD47xx based 4×20 or 4×16 lines. Just a simple one. The datapins are described in the schemata, and example for the resistor look in the datasheet of the lcd inside the PSOC developement suit.

    At the moment I branched this very interesting idea and working on it to shift more configuration to the HW,
    to avoid that the source needs to be modified
    (its always an error source). For example, the limit switches are supplied now with XOR logic gates plus a inverter control register. Same game I do it for the stepper output. Inside the source I will remove the software parts where its done inside there. Additional the limit switches are now single one for each axis (one neg pos and one pos position). Also I want to simplify the GRBL Source and removing some define configs. Because there is a useable AMASS implemented and should be always on for example.

    Regarding DMA, well somebody could try to work out a solution to switch between USB and USB UART(over the debug interface). This would allow to snap away the programmer for example.

    If am a little more fullfilled the work, will supply the github for the branched one. And I would like to see that this amazing project get grown more. There is too less easy to use and programmable systems for controlling the CNC. (Try tinyG2 with arduino Due – Its for me a horror to work with it, I gave simply up to spend there more time into because this is just far to much complicated designed – just feature blown including a frontend in java)

    For the record for sure the GRBL is a masterpiece and I say also a big thank you to Sungeon. I have always a high respect for software developers which can do some magic with limited ressources.

    Cheers Folks

  16. bdring

    Great comments DDAMIGO,

    I am currently looking into directly using the USB without a UART and optionally loading code via bootloader over USB.

  17. DAMIGO

    Hi bdring,

    do you have an email address, so I could send you the first adapted and extended schemata for the PSOC.


  18. Craig Hollabaugh


    Absolutely no issues on compiling and downloading to my 059 kit using Creator 4.2, this is a killer application. Thanks.


  19. bdring

    BTW: I have the native USB port working now as a CDC Serial Port. That means super high speed (2Mbs) or any lower speed and is compatible with all existing com port grbl software