gnea / grbl

An open source, embedded, high performance g-code-parser and CNC milling controller written in optimized C that will run on a straight Arduino
https://github.com/gnea/grbl/wiki
Other
4.04k stars 1.61k forks source link

Limit Switch Wiring #96

Open tklus opened 7 years ago

tklus commented 7 years ago

Good Morning all, Would it be possible for someone to add a page to the Wiki that explains the correct way to wire NC limit switches. maybe with a schematic drawn up. I have been confused about this for some time and there is limited info out there that I have seen that shows how to properly connect NC limit switches to GRBL. also it would be nice to know what resistors are required as well. and what GRBL settings need to change.

I had limit switches set up NO and had nothing but problems with false triggers. I would like to get limit switches working in the NC setup.

Thanks! Tim

Radiu commented 7 years ago

interesting discution for what i understand @vMeph schematic looks good for the exeption that the 47mf is a litle to mutch and a 100nf would be ideal. @luben111 option of using optocouplers woud be more ideal then vMeph schematic from what im reading, im having hard time to understand the luben111 shematic in what end the switch is plug in and where the arduino pin is conected? whould it be possible to show a clear schematic of using only um axis with there right names in how is conect, like arduino limit pin and where is conect the switch pin, is that schematic for NC or NO switches possible to have a schematic for both possibilities NO and NC? sorry for my english and for my questions, my experience in reading shematics is a litle poor so if would be possible to have a more simple shematic more clear would be great

thanks

luben111 commented 7 years ago

See how to connect the opto couplers to switches in the existing schematic - the idea is not new and is used practically in all professional CNC boards. When the switch (NO) is closed current will start to flow through the emitting diode (LED) which in turn will saturate the output transistor. The LED can withstand large currents for short time and suppresses any ESD and noises. There is galvanic isolation of 5KV between LED and output transistor. no connection nc connection

schematic nc schematic no

luben111 commented 7 years ago

It will take me a little more time to draw the names and make the picture as you requested. At the moment the schematic can support both NO and NC switches (see the wiring diagram on previous post). When using NC switches the settings in GRBL for limit pins invert ($6) should be set to 1.

luben111 commented 7 years ago

@tklus - Sure, I could quickly design one board with optocouplers for limit switches only with support for NO and NC types. It's "piece of cake" and will not take more than a day.

Do we have some target size of the board? Some mechanical limitations, requirement for input connectors? The resistors and optocouplers on the board - shall we use SMD (more difficult for soldering) or through hole type? For sure the SMD version will be more compact and elegant.

I can generate the Gerbers for production - do you have some PCB factory in mind?

tklus commented 7 years ago

If optocouplers are available with pins, through mounted would be easier for diy. I have my cnc router running and have some board material on hand and could whip some up real quick. As far as no or nc, we should settle on what is going to be best for the machines. I also have a laser set up and can etch the pcb'

As far as connections, I prefer to solder the wires to the board but we could also do pin headers. I have those on hand too.

tklus commented 7 years ago

Was thinking about this company, http://www.basicpcb.com/?gclid=CjwKEAiAqozEBRDJrPem0fPKtX0SJAD5sAyH2ECf87bvqaWrspJlZbW2YKXJ-O3Rru6jC-jvPDqgNhoCIxjw_wcB

But I haven't used them before. Does anyone else know of a reputable company?

vMeph commented 7 years ago

I would say NC switches is always the best option for safety, lets say a broken wire, a wire lose, etc..it will always stop machine, if NO switch you will not know until you hit with machine

tklus commented 7 years ago

This is the opto to order correct? http://www.digikey.com/product-detail/en/toshiba-semiconductor-and-storage/TLP185(GR-TPR,E)/TLP185(GR-TPRE)CT-ND/3025457

Can we bend the legs a bit to mount it through hole?

I do have solder paste and can do surface mount if that would be better.

luben111 commented 7 years ago

@tklus - OK, through holes components. Notice that if we populate the components on the boards the SMD mounting is much better and cheaper compared to through holes. But if sell the kits - maybe through holes is better.

@vMeph - we'll supply the board with two wiring diagrams and recommend the NC as better and more reliable wiring (with the corresponding changes in GRBL settings $6).

I personally try to avoid soldering the wires - using connectors with screws is the professional approach and is not that difficult to crimp the wire ends. But let's make it simple and start with version with standard 100 mils headers. Some idea what kind text to add on the PCB, some labels, trademark, etc.). If somehow we mention that this is "certified" or approved version from GRBL team it will make better impression. I can add the GRBL logo for example or something similar.

luben111 commented 7 years ago

Here is the schematic of the board - let me know what could be added or changed limit switches buffer

vMeph commented 7 years ago

Correction limit pins invert ($5)?

langwadt commented 7 years ago

opto isolated is nice and all, but it is somewhat pointless when you bypass the isolation by connecting everything to the same gnd and supply

tklus commented 7 years ago

@luben111, What if we use screw terminals like you use on your shield?

Grbl logo would be cool! Labels with inputs and outputs would be great! Also labels for component locations and values would be good if we kit it.

Nice work and thank you for taking time to get this going!

chamnit commented 7 years ago

First, thanks everyone for working out this wiring issue. Dealing with EM noise is voodoo to me. :)

Just an FYI. The Grbl logo itself isn't open-domain. It's reserved for official sponsors only. I'm basically following the Arduino model to try to protect the project.

luben111 commented 7 years ago

@langwadt - It's not pointless to add optocouplers even if the GND is not galvanically isolated. GND wire can withstand more noises than any controller pins. So optocouplers will have good effect on whole reliability.

luben111 commented 7 years ago

Here is the simple version of the board. Tomorrow will send the proper versions with screws and labels. simple grbl pcb_page_2 simple grbl pcb_page_3 simple grbl pcb_page_5 simple grbl v1_page_1 simple grbl v1_page_3 simple grbl pcb_page_1

luben111 commented 7 years ago

I'm going offline now. Let me know what could be added or changed. Next version will have screws and labels and use through holes components (maybe single layer PCB).

tklus commented 7 years ago

Looks great! Thank you so much!!! This will be a great addition for the community

tklus commented 7 years ago

Single layer would be nice for diy. Once you get the through hole one designed I will machine one up for testing. Can you also supply a .dxf file?

It might be nice to have a couple 3mm through mounting holes as well.

luben111 commented 7 years ago

Hi, This is the single layer version of the PCB - the whole project, including the gerbers for production (In Gerbers subdir). Simple V1 project.zip And some snapshots: grbl buffer schematic v1_page_1 grbl buffer schematic v1_page_2 grbl buffer schematic v1_page_3 grbl buffer schematic v1_page_4 grbl buffer schematic v1_page_5 pcb v1_page_1 pcb v1_page_2 pcb v1_page_3 pcb v1_page_4 pcb v1_page_5

tklus commented 7 years ago

This looks fantastic! I will get some components on order. If it is easy, can we do a version with screw terminals? If not, that is totally fine!

I will also get a quote on getting some boards made up.

Thanks again!!! Tim

luben111 commented 7 years ago

I use CopperCam software (really excellent, highly recommend it) for converting the Gerbers to GCode (for milling on CNC machine) - here are the GCode for milling a single layer PCB. I use often CopperCam and if you have vacuum table and flat surface you can achieve 5mil track/clearance

milled GCode.zip

luben111 commented 7 years ago

And the DXF file of the board plus the GCode (the files were tested and uploaded again on 23 Jan 2017 - previous files had problems)

Gerbers V1.zip GRBL DXF V1.zip

tklus commented 7 years ago

Great! Thanks!

vMeph commented 7 years ago

off topic what program u used to draw schematics and also i never have actualy milled pcbs with my machine could you explain progress step by step and softwares used in that

thanks

jahnj0584 commented 7 years ago

Wow. Those look cool. Do you just etch the tracks with a small mill then solder on the parts? If you did a screw terminal one I'd order the parts tonight. Any way to have a power pin for us who use hall sensors? I send 24V and will use a resistor to send 5V back to the arduino.

On Jan 22, 2017 6:41 AM, "Meph1" notifications@github.com wrote:

off topic i never have actualy milled pcbs with my machine could you explain progress step by step and softwares used in that

thanks

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/gnea/grbl/issues/96#issuecomment-274323063, or mute the thread https://github.com/notifications/unsubscribe-auth/AQlzDN4Qd0oGcG_gHt_jiaGbFCUgt_jxks5rUzJpgaJpZM4LnDGT .

vMeph commented 7 years ago

if pcb is with screw terminal defenetly better wasnt able to open the DWG file, not valid

electrokean commented 7 years ago

Nice work @luben111

I will mention though that this doesn't provide any real noise filtering, and only limited isolation - limited because of the shared power supply. The response speed (bandwidth) of the optoisolator also probably provides some filtering of noise. The newer TLP185s are several times faster so provide marginally less benefit.

I'm hopeful that people who build this do see an improvement, and watching with interest.

If noise is still causing issues on a particular machine, it wouldn't be difficult to solder some 100nF 50V 0805 SMD capacitors across the limit input pin pairs, and see if that improves things.

lucky62 commented 7 years ago

Just one trick - how to connect two cheap endstops (for exaple from here ebay ) in serial and connect to one arduino pin.

The problem is that Signal pin is normally connected to the +5V. When switched it is connected to Ground. So it is not possible to simply connect two endstops together because switching one or other will cause short cirqiut (+5V connected to the ground).

The trick is to connect output (signal) of first endstop to +5V of the second endstop. Output (signal) of second endstop is connected to the Arduino Limit pin. See picture. Everything works fine including LED signalizing.

serial_endstops

luben111 commented 7 years ago

Here is the version with proper terminals with screws and through hole resistors and opto couplers. This version could be sent as a kit and the soldering will not require special skills like with SMD. Attached are the gerbers and the whole project as ZIP. pcb v2_page_1 pcb v2_page_2 pcb v2_page_3 grbl buffer schematic v2_page_1 grbl buffer schematic v2_page_2 grbl buffer schematic v2_page_3 grbl buffer schematic v2_page_4

Simple V2.zip

Gerbers.zip

I'll generate now the DXF and the GCode for milling (from CopperCam software)

chamnit commented 7 years ago

@luben111 : Is this 3.3V compatible?

luben111 commented 7 years ago

Here is the DXF (it looks like DWG is less compatible format) and the GCode

Simple GRBL V2 DXF.zip

Simple V2 GCode.zip milled

luben111 commented 7 years ago

@chamnit Sure, the board is 3.3V compatible - just connect the 5V pin to 3.3V power supply.

luben111 commented 7 years ago

In the BOM file are listed the Suppliers of the parts and the Supplier numbers, some estimated price is also calculated for small volume. Let me know if you find something to be added or changed

tklus commented 7 years ago

This looks good, would it make sense to do screw terminals on the arduino side as well?

vMeph commented 7 years ago

for some reason i cant open the dxf its blank, also used the g code on simulation and isnt complete only does holes and cutes de board, not doing the circuit part

luben111 commented 7 years ago

@electrokean

I will mention though that this doesn't provide any real noise filtering, and only limited isolation - limited because of the shared power supply.

I would disagree with you - when we speak about "noises" it's important to understand what kind of noises we have and what kind of impact they have on the microcontroller. While working in Atmel I spent a lot of time making the the firmware robust against noises and we investigate what is causing the program malfunction.

One of the worst noises are the ESD discharges (somebody is walking around the CNC and can discharge 10-20KV into the wire). If the affected wire is directly connected to the microcontroller pin weird and nasty effects occur (I saw with my eyes how the program counter jumps to random locations and memory bits change). So on first place as nasty noises I put ESD discharges - optocouplers simply can't pass such noises.

Another noises are caused when switching on/off inductive loads (stepper motors) - they are characterized with huge amplitude of currents and voltages. If the limit switch wires pass near such inductive loads you can see induced voltages and currents. Again optocouplers don't pass such noises - LED are inert elements and require a lot of energy, the photo transistor also needs some minimum amount of photons.

I just don't have time to explain in all details all benefits of the optocouplers (even if there is no galvanic isolation as you noticed).

My own experience is that optocouplers significantly improve the reliability, the design is inspired by professional CNC controllers like Galil and NI . I made designs with and without optocouplers and the difference is huge.

luben111 commented 7 years ago

@vMeph I'll check the DXF and code. At least I can open the DXF in CorelDraw, but I know that there are many versions. What version of DXF you can support?

luben111 commented 7 years ago

@vMeph About the GCode - in the hurry I set wrong parameters in CopperCam and the result was skipped tracks. See the correct GCode - I loaded it in Mach3 and it shows correctly the milling.

Simple V2 GCode.zip

vMeph commented 7 years ago

@luben111 looking more complete but for some reason is still missing parts on tracks, i have loaded on UGS Platform are you using mach 3 with arduino or you using paralel port? what bit you using for PCBs? PCB Engraving Bits CNC Router Tool 20 Degree 0.1mm?

i open the dxf on corel also but for some reason not clear design at moment i dont have the optocouplers you using, i have a bunch of 4n35 laying arround with 6 legs might first test it out on a breadboard

electrokean commented 7 years ago

@luben111 I apologise though as I may have worded my original comment poorly. This circuit is not a filter in the sense being discussed earlier, but the response time of the optoisolator does provide a low pass filter. Mind you, at a significantly higher cost that just adding a capacitor.

I know quite well how optoisolators/optocouplers work, and have studied the topic of ESD substantially. EMI is generally the issue in a CNC environment, not ESD (although ESD issues can increase depending on the materials being machined). In fact the optoisolator device will be ESD sensitive. The datasheet for the TLP185 doesn't provide any ESD rating, but the LTV-817 seems to be rated for 8kV HBM. Ideally there should be an anti-parallel diode (zener/TVS) at the opto input rather than relying on that built in protection. Remember that the shortest path to ground may not be via the GND wire due to the thin wire people tend to use and the other connections that will exist. Also a CNC machined PCB will reduce effective electrical isolation due to the remaining copper between traces.

I totally agree that optoisolators should be used in any professional/industrial control equipment, or any hobby machine that aspires to be reliable. I use them myself, and even all the low cost Chinese CNC boards I have seen include them. It is a miracle how well the ATmega can perform in hobby machines when people put them together with non-isolated stepper drivers.

luben111 commented 7 years ago

@vMeph I use 0.8mm drill for all component holes, 3.1mm for the four corner holes, engraving cutter with sharp end 30 deg, and 3mm for cutting the board contour. You can put different engraving tool and it will still work, you can change the cutting depth by replacing the Zxxx level in GCode file.

This is the latest version of CopperCam so I would not be surprised if there is some bug.

coppercam active tools

Can you send me some feedback which tracks were not milled? Best regards, Luben

vMeph commented 7 years ago

2017-01-22_193358

luben111 commented 7 years ago

@vMeph You're right - 1/3 of the tracks are missing. I'll regenerate the GCode.

luben111 commented 7 years ago

@vMeph I found the problem - after upgrading the CopperCam I forgot to apply the license file they sent me from the company, like result the program was in demo version and was skipping randomly segments/holes.

Simple GRBL.zip

luben111 commented 7 years ago

@vMeph >>off topic what program u used to draw schematics and also i never have actually milled pcbs with my machine could you explain progress step by step and softwares used in that

The whole cycle looks like:

Milling PCB is actually easier than it sounds or you can imagine, there is only one important point - to get the proper Gerber file / DXF to GCode converter. If you want to mill 5mil tracks you need extremely flat surface, proper engraving bits, vacuum table and precise CNC. But if you target 10-15mils tracks things become simpler.

vMeph commented 7 years ago

thanks for info is there Convert Gerber files to GCode for free programs out there that are good?i was looking into this, do you know it? http://flatcam.org/

would be great to have more clear videos in how to mill pcbs from design circuit, convet to gerber, convert to g-code to use on grbl

tklus commented 7 years ago

I couldn't seem to get the .dxf file to work either. I am using fusion 360 and autodesk inventor 2017

I did get flat cam to open the gerber files and I will try and get it to work through that

luben111 commented 7 years ago

@tklus Try this DXF file generated from CopperCam GRBL V2.zip

I also uploaded again the DXF and GCode for the small board (see the posts above)

tklus commented 7 years ago

that seemed to work, thanks for uploading again