Author Topic: CUSTOM GRBL PINOUT FOR CUSTOM GRBL BOARD  (Read 3335 times)

0 Members and 1 Guest are viewing this topic.

Offline SebastianEspendeTopic starter

  • Newbie
  • Posts: 4
  • Country: ar
CUSTOM GRBL PINOUT FOR CUSTOM GRBL BOARD
« on: December 09, 2024, 01:15:08 am »
Hi, im a student from Argentina. Im looking to modify grbl to suit my needs for making my own GRBL Board for Arduino Uno.
Im having a problem with changing the pins on the cpu_map.
Basically i've already made my own board which pins are not setup the way grbl boards are setup normally, this isnt a thing i've done on purpose its just i didnt know enough when making the board.

GRBL Pinout works by using Port groups, which you can see when checking the arduino uno pinout, the problem is my board does not do this. How can i modify the code to make it so that i can set any pin i want?

Before anyone tells me to just buy a standard GRBL Board, i cant, this is part of my final project for my secondary school, which requires me to make my own, and im a bit short on time to make a new one with the correct pin arrangement.

Here is what i would like the pinout to be

X_STEP_BIT to be pin 12
Y_STEP_BIT to be pin 11
Z_STEP_BIT to be pin 3

X_DIR_BIT to be pin 13
Y_DIR_BIT to be pin 10
Z_DIR_BIT to be pin 2

Here is how its currently setup by default on the cpu_map:
Code: [Select]
  // Define step pulse output pins. NOTE: All step bit pins must be on the same port.
  #define STEP_DDR        DDRD
  #define STEP_PORT       PORTD
  #define X_STEP_BIT      2  // Uno Digital Pin 2
  #define Y_STEP_BIT      3  // Uno Digital Pin 3
  #define Z_STEP_BIT      4  // Uno Digital Pin 4
  #define STEP_MASK       ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT)) // All step bits

  // Define step direction output pins. NOTE: All direction pins must be on the same port.
  #define DIRECTION_DDR     DDRD
  #define DIRECTION_PORT    PORTD
  #define X_DIRECTION_BIT   5  // Uno Digital Pin 5
  #define Y_DIRECTION_BIT   6  // Uno Digital Pin 6
  #define Z_DIRECTION_BIT   7  // Uno Digital Pin 7
  #define DIRECTION_MASK    ((1<<X_DIRECTION_BIT)|(1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT)) // All direction bits

Any help is apreciated, thanks.
Please dont be mean  ;D
« Last Edit: December 09, 2024, 01:17:01 am by SebastianEspende »
 

Offline SebastianEspendeTopic starter

  • Newbie
  • Posts: 4
  • Country: ar
Re: CUSTOM GRBL PINOUT FOR CUSTOM GRBL BOARD
« Reply #1 on: December 09, 2024, 01:22:15 am »
im new to this forum, have i posted this on the wrong place?
Should it be on the microcontrollers tab?
 

Online moffy

  • Super Contributor
  • ***
  • Posts: 3053
  • Country: au
Re: CUSTOM GRBL PINOUT FOR CUSTOM GRBL BOARD
« Reply #2 on: December 09, 2024, 02:17:10 am »
I don't think you can do that, because the groups e.g. X,Y,Z Direction; X,Y,Z Step etc. are coded at quite a low level in the standard GRBL, it would require a significant rewrite of the code and be a performance hit. However GRBLHal: https://github.com/grblHAL
is a rewrite of GRBL that can basically do what you ask, but I don't think it would run on the UNO, not enough program space, GRBL barely fits as is in the UNO, also the hardware abstraction has quite a performance hit as it is really meant for faster processors e.g. ARM etc.
 
The following users thanked this post: SebastianEspende

Online abeyer

  • Frequent Contributor
  • **
  • Posts: 953
  • Country: us
Re: CUSTOM GRBL PINOUT FOR CUSTOM GRBL BOARD
« Reply #3 on: December 09, 2024, 02:25:00 am »
Can you just cut some traces and bodge the connections on your board? That seems like the simpler fix here.
 
The following users thanked this post: Ian.M, SebastianEspende

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 14132
Re: CUSTOM GRBL PINOUT FOR CUSTOM GRBL BOARD
« Reply #4 on: December 09, 2024, 02:38:20 am »
GRBL's stepper pin handling is (mostly) in stepper.c.   ATmega328P Port D was chosen because it had six free GPIOs, enough for three axes, the UART on PD0:1 wouldn't conflict,, and it didn't tie up any peripherals needed elsewhere in the GRBL code.  If you wanted to remap those pins as you propose, you'd have to rewrite stepper.c to split the pins across multiple ports which would have knock-on effects on the code size and ISR execution time, and you'd have to be very careful to avoid disrupting other inputs and outputs which would then share a port with a stepper pin.

Chamnit, the lead maintainer of the GRBL project reckons it isn't possible: https://github.com/gnea/grbl/issues/325

If you are a more experienced and skilled AVR developer than Chamnit, you may have a chance, but its weeks or months of work with no guarantee of success. However if you had the skills you wouldn't be asking how to do it here!

For the rest of us, if faced with a MCU pin allocation f.up with a tight deadline without time for a new PCB, we'd start cutting tracks and fitting bodge-wires to rearrange the pins to meet the existing firmware constraints.   Done right, it doesn't even look too bad!

Good luck - you are going to need it . . .
 
The following users thanked this post: SebastianEspende

Offline SebastianEspendeTopic starter

  • Newbie
  • Posts: 4
  • Country: ar
Re: CUSTOM GRBL PINOUT FOR CUSTOM GRBL BOARD
« Reply #5 on: December 09, 2024, 07:48:45 am »
Well im certainly not a better developer than Chamnit so, i guess ill be cutting traces tomorrow, thank you guys for the nice answers!
 :-+
 

Offline phil from seattle

  • Super Contributor
  • ***
  • Posts: 1262
  • Country: us
Re: CUSTOM GRBL PINOUT FOR CUSTOM GRBL BOARD
« Reply #6 on: December 10, 2024, 01:53:12 am »
A suggestion - take a look at grblHAL. It is the 32 bit version of Grbl and runs on all sorts of 32 bit ARM chips. If you are familiar with Grbl, grblHAL will be very easy. There are a number of advantages to this approach: faster chips, more RAM/Flash, more flexibility, currently in active development. The developer is approachable and very helpful. The ARM chips aren't maxed out like the ATMega. In particular, I would look at STM32F4xx or the RasPi RP2040 (Pico).  Both are plentiful and cost less than the ATMega chips do.  If you pick the right pinout, you could use the grblHAL Web Builder to build your firmware binary. The web builder will give you the pin mappings for any board you select. The RasPi RP2040 doesn't require any special hardware or software to load the firmware - just a USB cable.  You could prototype with a Pico which is $4 USD.

FWIW I make and sell a grblHAL breakout board based on the Pico used for a number of different CNC machines including Mills, Router and Lathes. It's a 2 layer board.
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 5370
  • Country: nl
Re: CUSTOM GRBL PINOUT FOR CUSTOM GRBL BOARD
« Reply #7 on: December 14, 2024, 10:53:26 am »
These look like arduino pin numbers. (Yuch).

Here is what i would like the pinout to be

X_STEP_BIT to be pin 12
Y_STEP_BIT to be pin 11
Z_STEP_BIT to be pin 3

X_DIR_BIT to be pin 13
Y_DIR_BIT to be pin 10
Z_DIR_BIT to be pin 2

While these very likely are the real register names and pins of the controller itself, and the comment "// Uno Digital Pin 2" is a lie. "Arduino pin numbers" can not be shifted and added in the way as in #define STEP_MASK while this is the way to do it with the hardware register and pin names.


Here is how its currently setup by default on the cpu_map:
Code: [Select]
  // Define step pulse output pins. NOTE: All step bit pins must be on the same port.
  #define STEP_DDR        DDRD
  #define STEP_PORT       PORTD
  #define X_STEP_BIT      2  // Uno Digital Pin 2
  #define Y_STEP_BIT      3  // Uno Digital Pin 3
  #define Z_STEP_BIT      4  // Uno Digital Pin 4
  #define STEP_MASK       ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT)) // All step bits

  // Define step direction output pins. NOTE: All direction pins must be on the same port.
  #define DIRECTION_DDR     DDRD
  #define DIRECTION_PORT    PORTD
  #define X_DIRECTION_BIT   5  // Uno Digital Pin 5
  #define Y_DIRECTION_BIT   6  // Uno Digital Pin 6
  #define Z_DIRECTION_BIT   7  // Uno Digital Pin 7
  #define DIRECTION_MASK    ((1<<X_DIRECTION_BIT)|(1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT)) // All direction bits

Any help is apreciated, thanks.
Please dont be mean  ;D
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

-->