[Grbl_Esp32 Issue#84] How to invert select control pins

未分类 bolang 3个月前 (10-14) 42次浏览

Issue #84 | 状态: 已关闭 | 作者: 109JB | 创建时间: 2019-02-02


So I’m about ready to switch out my AVR Grbl for the ESP32 Grbl and put it into use on a CNC converted milling machine I have. I have one thing I would like to do but due to my lack of C programming knowledge I don’t know how to do it. What I want to do is invert the Safety Door input pin but not the other control pins. In the AVR Grbl the Config.h file had the following which would allow this:

// Inverts pin logic of the control command pins based on a mask. This essentially means you can use
// normally-closed switches on the specified pins, rather than the default normally-open switches.
// NOTE: The top option will mask and invert all control pins. The bottom option is an example of
// inverting only two control pins, the safety door and reset. See cpu_map.h for other bit definitions.
// #define INVERTCONTROLPINMASK CONTROLMASK // Default disabled. Uncomment to disable.
// #define INVERTCONTROLPINMASK ((1<SAFETYDOORBIT)|(1<RESETBIT)) // Default disabled.

I see that in the ESP32 Grbl, this has been changed, and I saw the following note in cpu_map.h

Unlike the AVR version certain pins are not forced into the same port.
Therefore, bit masks are not use the same way and typically should not be
changed. They are just preserved right now to make it easy to stay in sync
with AVR grbl

So, is there currently a way to invert only select control pins while not inverting the others?


评论 (5)

#1 – bdring 于 2019-02-02

The control pin inputs can be any IO pin. When they are read, they combined into a status byte. system.h defines the bits…

#define CONTROLPININDEXSAFETYDOOR bit(0)
#define CONTROLPININDEX_RESET bit(1)
#define CONTROLPININDEXFEEDHOLD bit(2)
#define CONTROLPININDEXCYCLESTART bit(3)
`
system.cpp has this in the function that reads the pins
`
#ifdef INVERTCONTROLPIN_MASK
controlstate ^= INVERTCONTROLPINMASK;
#endif
`

in config.h you can define the mask like this...
`
#define INVERTCONTROLPINMASK (1<PININDEXSAFETY_DOOR)

.. or’ing together more pins with “|”

I have not heard feedback from people doing this, so hopefully it all works OK.

BTW: When I have been configuring machines lately, I have been putting a lot of defines in cpu_map.h. That makes it easier to keep as many changes in one spot as possible.


#2 – 109JB 于 2019-02-03

Thanks. I’ll give it a try and let you know how it goes. I tried testing it but I think I have some kind of IDE issue because after changing the one line on config.h, it is telling me that the program excess the esp32’s memory capacity. Once I get that sorted I’ll be able to test the control pin mask.


#3 – 109JB 于 2019-02-03

An update for this:

I tried changing the invert control pin mask in config.h to

#define INVERTCONTROLPINMASK (1<PININDEXSAFETY_DOOR)

but that didn’t work. Near as I could tell it didn’t do anything. So I did some searching around and in cpu_map.h at the bottom I found this line:

#define INVERTCONTROLPIN_MASK B1110 // don’t change

Even though it said “don’t change”, I changed it to

#define INVERTCONTROLPIN_MASK B1111 // don’t change

and it worked for inverting the Safety Door pin. Looks to me like you modified this and maybe forgot about it. After some experimenting I found that the order for this mask is:

Cycle Start | Feed Hold | Reset | Safety Door

It is your project and up to you, but I would recommend moving any setting like this to config.h, more maintain consistency with how the AVR Grbl is set up than anything else. For the control pin mask I would put something like this in config.h:

// Inverts pin logic of the control command pins based on a mask. This essentially means you can use
// normally-closed switches on the specified pins, rather than the default normally-open switches.
// The mask order is Cycle Start | Feed Hold | Reset | Safety Door
// For example B1101 will invert the function of the Reset pin.
#define INVERTCONTROLPIN_MASK B1111

I created a pull request for the above (my first) in the WebUI brach that you can consider rolling in. Since this is my first pull request, I’d appreciate it if you could let me know if I did it right.

If you don’t accept the pull request, at a minimum I would replace the “don’t change” note in cpu_map.h with a description of how the mask works like above.

I also saw the Probe Pin mask in cpu_map.h, but I think this is fine there since the probe pin can be inverted in EEPROM settings.


#4 – 109JB 于 2019-02-03

Well I guess I did something wrong with the pull request because the second file modified didn’t come through. I had also deleted the mask from cpu_map.h and it didn’t show up on the pull request. I had thought the pull request would compare all files in my fork to yours and include all changes to the pull request. Do you know what I did wrong?


#5 – bdring 于 2019-02-03

Thanks for all the work on this.

I think originally I did not support the INVERTCONTROLPIN_MASK and then did not clean up the notes.

I’ll take care of getting the changes in. I don’t know what went wrong for you.


原始Issue: https://github.com/bdring/Grbl_Esp32/issues/84

喜欢 (0)