cncpaw / GRBL-electronics

Uncommitted discussion for issues related to electronics in GRBL.
0 stars 0 forks source link

Arduino mega shield #1

Open adambrum opened 6 years ago

adambrum commented 6 years ago

This is continuing on from the discussion on the GRBL limit switch issiue. https://github.com/gnea/grbl/issues/96

Hers where i got to on the limit switch wiring. input

cncpaw commented 6 years ago

Thanks.

  1. With BR=+ve, BL=0V, BK=Pull-up output normally closed, then P1 numbering is upside down.

  2. Junctions appear to be lacking at the bottoms of R2, C1 and D1. It could be a bug in program rendering, but they are required if you intend to output it as a netlist to the PCB.

Minor: I don't think it'll make any difference to your shield, but you might wish to check the differences between "Earth", "Ground", "Chassis", "Common" and "0V" as well as named nodes such as "0VA" and 0VP" which are both 0V but for different sections. https://electronics.stackexchange.com/questions/108776/common-vs-ground

Just in case anyone else has the same problem: My ISP (Sky) had turned on its family filtering shield and blocked images (jpg, png) from Github (including yours) without me knowing, it just timed-out the images. Took a while to find out it was them. Filter is now off.

gerritv commented 6 years ago

Yes, it is really necessary to filter out schematic porn because we know what it does to our brains!

Thank you for the excellent analysis re: grounding and loops. I fondly remember installing Univac 1100/80 systems in the late 70's with 8" wide copper strips on the sub floor to tie the logic grounds to. Lot of fun isolating logic from frame ground when a system is spread over 3 floors. Not fun to troubleshoot spurious problems when the grounding was wrong.

adambrum commented 6 years ago

That's some bad drawing by me, only my forth day drawing schematics, when i flip the connectors in the drawing it flips the numbers.

your right about the earth,common and 0v, i know what i mean but its not clear on my drawings.

What would be the best way to label P2 connector.

cncpaw commented 6 years ago

My tower PC will not reliably run my CNC controller because 0V is connected to Earth at both ends and hence it has a ground loop via the USB. Noise in that tends to corrupt the USB comms. But my laptop works fine because it's 0V is not connected to ground. My CNC controller is a prototype, the stepper drivers are on stripboard and there is no isolation except for the spindle driver. If/when it needs improving I'd like to consider an ARM or Arduino-Mega with PCBs and isolation.

@gerritv I use GRBL and GRBL-panel. Very much appreciate the work gone into both.

@adambrum I'm not aware of any extra industry standards or good conventions for part labels on schematics. As long as you're consistent, specify a prefix and identifier like "D1", and a model like "1N4001". The model being generic or proprietary or described in documentation elsewhere. However, prefix "P" is usually for plug, "S" is for usually for socket, and "J" is either (sex defined by model). There's nothing stopping you from using letters in the identifier, e.g. "P1a" and "P1b", or base numbers, e.g. add 100 for all off-board components. I personally find it useful to put peripheral circuits with the main circuit, but they must not be part of the final net list and computers/CAD are notoriously pedantic.

What electronic CAD software do you use?

adambrum commented 6 years ago

Tried fritzing, easy but not a huge library of parts now on EasyEDA still to try the PCB part .

I have Bcnc running on a Raspberry pi3 so far so good

gerritv commented 6 years ago

I was using CamBam to generate gCode but will likely switch to the free HSM 2.5. Might try Fusion360 as well. For PCB layout I use DipTrace with Elecrow as board house.

I hope to get my cnc going again soon, which should spark a re-write of GrblPanel as it has become a bit of a rats nest over time :-( It works but it can be challenging to add features, of which there is a growing list of needs.

adambrum commented 6 years ago

Drawn up all the inputs now, all inputs

gerritv commented 6 years ago

@adambrum Are you planning on making this input/output conditioner a separate pcb? That in my view is more useful than one tied to a specific processor. It would be useful now with the Arduino's and later on with the ARM versions. 4 axes worth of limits and step/dir/enables.

adambrum commented 6 years ago

Originally i was planning on a I/O board connected with a 26 way ribbon cable and a separate shield for uno , mega or an ARM board when there out then went back to an arduino mega shield.

Now you've raised the same thought an I/O board would be easier so why not, cost is negligible . i could add another bank of 4 inputs and 4th axis

langwadt commented 6 years ago

I still think the optocouplers are rather pointless if there is no way to actually isolate the two sides. why not skip the 5V supply and just run the output side from the arduino 5V ? and don't connect the grounds

and instead of a 10R resistor (it'll just catch fire if something shorts) use a voltage regulator that is current limited and short circuit protected

gerritv commented 6 years ago

It might help @adambrum to draw an imaginary line down the board through middle of the opto's. No trace or wire should cross the divide.

adambrum commented 6 years ago

Updated now with 0-10v added, think i have managed to isolate the circuit. From looking around google it looks like standard optos work with PWM. ver 2

I have added a six way header for an external relay board, these are optoisolated and are probably cheaper to buy than make. I will add some holes to the Pcb so it can be mounted with standoffs.

relay board

Just the STEP,DIR and Stepper enable to be added, Any thoughts ?

langwadt commented 6 years ago

the 5V in P11 needs to be the arduino 5V or it won't work The pwm/0-10V won't work as drawn, the optocoupler only pulls one way

adambrum commented 6 years ago

Yup i can see what i have done there

cncpaw commented 6 years ago

@langwadt - I was drawing up the same comment...

adambrum 3

You'll need arduino-side power for arduino-side signals. Mod shows 1k pull down and 10k for filter R. But R and C values can be optimised later.

Also... Feedback pot=10k and res=22k gives a gain range of 1 to approx 1.45. Thus 100% duty (about 5V in) would get at most 7.25V out. Should be pot=22k and res=10k for gain range of 1 to approx 3.

As @biasedlogic said, GRBL has an issue with jitter and delay being added to the STEP and DIR signals and he suggested using the Analog Devices (AD) digital isolators instead of Opto-isolators. I've not yet been able to find a spec. for GRBL's tolerance but think that 20Mbit/s opto-isolators should be as fast as the AD digital isolators and much cheaper.

biasedlogic commented 6 years ago

@langwadt

I still think the optocouplers are rather pointless if there is no way to actually isolate the two sides.

I'm not sure what you mean. The digital inputs are fully isolated if you use external/separate power for the switches. If you don't, and tap the 12V from the Arduino, you still get at least better immunity against EMI, but you are not forced to.

@cncpaw: iirc the direction pin is asserted just before toggling the step pin, of that's the case not many optos are up to that.

adambrum commented 6 years ago

altered the drawing again, added a 5v from the arduino to the relay header and looking at some posts for the relay board its needs 5v plus the digits signals and 5v,gnd from an external supply with no gnd from the arduino because of the optos. ver 3

JayPerez1 commented 6 years ago

Hi Everyone,

Trying to follow this thread as I have been experiencing noise related issues with my CNC Lathe build but the detailed electronics are more than a few fathoms over my head ... :-)

@cncpaw:

You made a comment a few days ago that I was hoping you would expand on. "(I'm wary of commenting in this issue because it is no longer a problem in GRBL ...)" I'm using an Arduino UNO and shield from zyltech with GRBL v1.1. Did I understand you correctly that GRBL has somehow found a way to eliminate the noise problem in their code ? If so would you please point me to where I can find more information on this ?

Thanks to everyone for sharing your knowledge so freely and all the hard work.

Jay

biasedlogic commented 6 years ago

Did I understand you correctly that GRBL has somehow found a way to eliminate the noise problem in their code

What I believe @cncpaw meant is, it's nothing to solve in code, it's got to be solved in hardware and so it should not be discussed in a software issue thread...

adambrum commented 6 years ago

For the step/dir is it something like this were looking for ?

http://uk.farnell.com/toshiba/tlp118-e-o/optocoupler-3-75kv-20mps-soic/dp/2075566

biasedlogic commented 6 years ago

That could/would do, but considering you need a couple of these, you may be off cheaper to just go for

http://uk.farnell.com/analog-devices/adum7440arqz/ic-isolator-digital-quad-16qsop/dp/1827342?ost=ADUM7440ARQZ (pulse skew, and that's what counts here, <25ns)

or

http://uk.farnell.com/analog-devices/adum7440crqz/ic-digital-isolator-40ns-16qsop/dp/1858062?ost=adum7440crqz (if you want pulse skew <5ns)

These are 4-channel with matched propagation, so you actually save on parts and get better reliability for the control signals. Just route DIR/STEP through same chip.

For other digital outputs, or for drivers that need 5V supply, (there's also a sister part for inputs) you may find this one interesting: http://uk.farnell.com/analog-devices/adum5402crwz/isolator-4ch-dcdc-conv-16soic/dp/2067769 Not only it's fast and isolated, it also provides up to 100mA at 5V of isolated power to the output side, no separate isolated power supply necessary.

adambrum commented 6 years ago

What about this one, i would like to keep it all in dip packages. Its dual channel so one for each drive. http://uk.farnell.com/nve/il612-2e/2ch-dig-mag-isolator-pdip8-612/dp/1139041?MER=bn_para_1TP_LastViewed_2

i like the last one, could be good for the relay outputs, i think they need 70ma per channel.

I noticed earlier that you went to Karlsruhe, been there myself a few times, my main office was just up the road in Bretten

gerritv commented 6 years ago

GBP7.94 each is a bit steep???

biasedlogic commented 6 years ago

DIP is so yesterday... And, while it is extremely fast, it's also 4x more expensive, per channel, than the simplest ADuM...

adambrum commented 6 years ago

I know, might need to rethink the packages,

I was trying to keep it easy to assemble, might have a go at soldering some surface mount to see how hard it is.

langwadt commented 6 years ago

@adambrum IMO surface mount is in many cases easier than through hole @biasedlogic The iCouplers are nice and all, but they are very expensive, power hungry and internally running at hundreds of MHz can make emissions a problem

And once you have all that stuff on a pcb there is little reason not to put the MCU on there as well

gerritv commented 6 years ago

And once you have all that stuff on a pcb there is little reason not to put the MCU on there as well

I disagree. Implementing MCU agnostic means that you are not re-designing the difficult' stuff every time you need/want to change MCU's. Just like the db25 style breakout boards, you are free to choose the computer, controller and drivers. How would you choose which MCU? Too many choices there.

biasedlogic commented 6 years ago

@langwadt I support @gerritv on this one. I have even an ST board that's mechanically arduino shield compatible, I know there was a discussion to port GRBL to such hardware.

cncpaw commented 6 years ago

@adambrum Re your latest circuit of 24 sep 2017 21:10 GMT You've added the pull-down but the "PWM" output is still taken from the capacitor. It should be taken from the opto's emitter

@JayPerez1 An ATmega328 (The chip in an Arduino uno) could do digital filtering, but best practice is to remove the noise at source with screening, or with a simple/cheap filter before it gets to the ATmega, and GRBL for the Uno is practically near max memory and speed capacity so adding software filtering is unlikely for the Uno and should not be needed. GRBL does have switch debouncing but it is not meant for removing interference.

DIR STEP timing tolerance I've only dabbled in small parts of GRBL, e.g. modifying GRBL and Simon-K software so the Arduino would work with a BLDC motor controller, but most of GRBL is beyond me so I can't be sure I have this next bit right:

Section of code determining DIR-STEP spacing My configuration

#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))

#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))
//STEP_PULSE_DELAY not defined

Extract of C-code from ISR(TIMER1_COMPA_vect)

// Set the direction pins a couple of nanoseconds before we step the steppers
DIRECTION_PORT = (DIRECTION_PORT & ~DIRECTION_MASK) | (st.dir_outbits & DIRECTION_MASK);
// Then pulse the stepping pins
#ifdef STEP_PULSE_DELAY
  //Not used
  st.step_bits = (STEP_PORT & ~STEP_MASK) | st.step_outbits;
#else  // Normal operation
  STEP_PORT = (STEP_PORT & ~STEP_MASK) | st.step_outbits;
#endif

Disassembly of compiled extract

in   r25, DIRECTION_PORT
lds  r24, st.dir_outbits
andi r24, DIRECTION_MASK
andi r25, ~DIRECTION_MASK
or   r24, r25
out  DIRECTION_PORT, r24    ;(1c) DIR edges/transitions
in   r24, STEP_PORT         ;1c
andi r24, ~STEP_MASK        ;1c
lds  r25, st.step_outbits   ;2c
or   r24, r25               ;1c
out  STEP_PORT, r24         ;1c STEP edges/transitions

@biasedlogic - I don't see how pulse skew need be less than 25ns. DIR change to STEP change is 6 instruction cycles = 375ns (at 16MHz) including one but not both of the out instructions. (More than "a couple of nanoseconds".) This should provide a max value for an isolator's propogation delay. GRBL should easily accomodate propogation delays of 100ns and hence 10Mbaud digital-output opto-couplers are a possibility. Having looked up a few isolators on Farnell I note that open-collector type typically quote a pull-up of 375ohm making them a bit power hungry. ( or more accurately jitter and variations in delay.) Typical example: http://uk.farnell.com/broadcom-limited/acsl-6400-00te/optocoupler-smd-quad-high-speed/dp/9130152

langwadt commented 6 years ago

@gerritv you wouldn't have to redesign anything, just copy paste, and a footprint for an mcu is practically free. and it avoids the all too common hair ball of wires that does nothing for reliability. @biasedlogic I run grbl on an ST board with ST drivers, but I'm not to crazy about the skyscraper of boards

it would be easy to move the setting of the direction pin to the end of the interrupt or even to when a new segment is loaded, that would remove the need for silly skew requirements

biasedlogic commented 6 years ago

@cncpaw

I don't see how pulse skew need be less than 25ns.

I'm sorry, if I was misleading. I didn't mean it needs to be less than 25ns, but that the chip I linked to has a skew of under 25ns and that it's the skew that counts and not the absolute transfer delay. This said, the A4988 driver has a setup time of at least 200ns (page 6 of the datasheet, Tc). This means, that the DIR pin needs to be stable 200ns before the STEP pin is toggled. So we have a window of 175ns left. The additional thing with ATMEL µC output driver is, that the high-to-low and low-to-high transitions don't happen at the same step in the clock cycle, so worst case we have not 6, but 5.something cycles, say 320ns -> 120ns window. Skew of 25ns is OK, and we have effective tollerance margin of 100ns.

Many "A4988" boards have actually a HR4988 chip, a chinese clone/development, for which setup times are an unknown parameter altogether, but that's another story

adambrum commented 6 years ago

Your all losing a me a bit here but i found some data on the drives im using.

leadshine drive

cncpaw commented 6 years ago

@adambrum I know the feeling. In short, discussing isolation for STEP & DIR has raised and expanded a known issue, but one that could be easily solved in GRBL with no extra code thus allowing isolation for STEP and DIR and use of cheaper opto-couplers. Don't know how it affects your work yet, maybe it can be a separate board if the concensus is to have it.

@biasedlogic Not misleading, 25ns is the biggest number you quoted here so I used it to compare with 375ns. But my brain must be getting rusty, I forgot about setup time. Now you've said it, the datasheet for the DRV8825 (a common alternative to the A4988) has a minimum setup time of 650ns. I use them in my CNC and have not noticed any issues. Still IMO, at 650ns, the possible desirability of isolation using cheap optocouplers, and the still widespread use of Uno merits a new issue on GRBL. Edit: And leadshine's 5us setup time

My "simple" but limeted solution would be to replace

DIRECTION_PORT = (DIRECTION_PORT & ~DIRECTION_MASK) | (st.dir_outbits & DIRECTION_MASK);
#ifdef STEP_PULSE_DELAY
  st.step_bits = (STEP_PORT & ~STEP_MASK) | st.step_outbits;
#else
  STEP_PORT = (STEP_PORT & ~STEP_MASK) | st.step_outbits;
#endif
TCNT0 = st.step_pulse_time;
TCCR0B = (1<<CS01);
busy = true;
sei();

with

DIRECTION_PORT = (DIRECTION_PORT & ~DIRECTION_MASK) | (st.dir_outbits & DIRECTION_MASK);
TCNT0 = st.step_pulse_time;
TCCR0B = (1<<CS01);
busy = true;
sei();
#ifdef STEP_PULSE_DELAY
   st.step_bits = (STEP_PORT & ~STEP_MASK) | st.step_outbits;
#else
  STEP_PORT = (STEP_PORT & ~STEP_MASK) | st.step_outbits;
#endif

No change in code size and the time between edge transitions becomes 14 cycles = 875ns, excluding both of the out instructions, giving 100ns for isolators and 100ns margin with DRV8825.

adambrum commented 6 years ago

Had an idea and pulled my drive apart as its already optoisolated. m542-schematic

langwadt commented 6 years ago

@cncpaw I think moving sei() before setting the steps is dangerous with an overlap of interrupts you risk using an "old" st.step_bits or jitter.

if you need more setup time on direction use STEP_PULSE_DELAY that's what it is there for

gerritv commented 6 years ago

Just joking but old school method (used in different format on Univac 1100/80's to calibrate clock signals between cabinets) http://www.newark.com/w/c/semiconductors-ics/clock-timing-frequency-management/delay-lines/prl/results?st=delay+line

Gerrit

cncpaw commented 6 years ago

I saw STEP_PULSE_DELAY in config.h, but wasn't completely sure what it was for. Surprised nobody has mentioned it before and hence wonder if it has an unmentioned downside or using it still rules out using slower/cheaper opto-couplers in the STEP/DIR/ENABLE paths, such the 5us setup in leadshine. There doesn't seem to be much on Farnell between the typical 2us of classic cheap opto-couplers and the 100ns of the digital output types.

langwadt commented 6 years ago

@cncpaw the leadshine drivers most likely have optocoupler buildin so there is no reason to yet another layer of isolation. Slow enable shouldn't be an issue, slow dir is taken care off by STEP_PULSE_DELAY at tiny cost of an extra interrupt

adambrum commented 6 years ago

So whats the thoughts on isolating the STEP/DIR, i know with the drives im using theres no point but not all drives are going to have internal protection.

Looking around the leadshine drives are being used on a lot of builds with no problems so im thinking the high speed opto should be more than capable. The ADUM are coming in at around £3 each for dual channel

JayPerez1 commented 6 years ago

Thanks biasedlogic,

I found this thread using a Google search so never really noticed what thread it was in. Perfectly obvious now that you pointed it out.

On Sep 25, 2017 1:27 AM, "biasedlogic" notifications@github.com wrote:

Did I understand you correctly that GRBL has somehow found a way to eliminate the noise problem in their code

What I believe @cncpaw https://github.com/cncpaw meant is, it's nothing to solve in code, it's got to be solved in hardware and so it should not be discussed in a software issue thread...

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cncpaw/GRBL-electronics/issues/1#issuecomment-331780428, or mute the thread https://github.com/notifications/unsubscribe-auth/AdejyGNkydDG69NCPpPf_Kc9PFVSm-joks5slzm7gaJpZM4Pg8Mc .

biasedlogic commented 6 years ago

@Adambrum

So whats the thoughts on isolating the STEP/DIR, i know with the drives im using theres no point but not all drives are going to have internal protection.

I consider this interface as secondary priority for isolation. Usually, at least for what grbl is good for, the drivers are physically close to the grbl controller, and the wiring between them is short and does not have to run long stretches parallel to motor power wiring. It's rather easy to get good ground across.

cncpaw commented 6 years ago

I'm drawing up isolation schematics for EN/STEP/DIR and will upload those and the schematics for my CNC in a day or so, to use as you wish. I'm assuming STEP_PULSE_DELAY will allow use of cheaper transistor-output isolators (~2us delay). My CNC controller has no isolation except for PWM to the spindle, which was necessary because of ground currents. Limit and stepper signals are not isolated, but they are protected with series resistances up to a point. Considering how much current it takes to drive an opto-coupler LED compared to ATmega input, I think it is possible to protect the limit inputs just as well without the opto-coupler, provided the switches are commoned at the Arduino end. Hence why I think isolation should be for both limits and stepper, or neither. Isolation would be useful both as better protection, e.g. fault from output to input side of stepper driver, and prevent ground loop via USB. Would it be cheaper and reliable to do the isolation in the USB? In the rare event of a damaging fault, replacing an arduino is not so expensive.

biasedlogic commented 6 years ago

Would it be cheaper and reliable to do the isolation in the USB?

No, but don't forget, that the actual microprocessor uses plain serial port, and isolating ttl-level RS 232 is rather easy. This would mean using external usb to ttl serial board, omitting the usb on the Arduino board completely and putting isolation between the usb-serial and the Arduino.

adambrum commented 6 years ago

Been tinkering around changing the schematic to use smd parts just need to find a replacment for the input optos and the diode. Im using 1206 sizes as it looks like a good compromise between size and ease of soldering. Would this be ok for the diode.http://uk.farnell.com/bourns/cd1206-s01575/diode-switching-100v-150ma-1206/dp/2211947

Also looking back at the shield Luben111 made would there be any advantages to adding a 74hct245p buffer to the step/dir ?

Thanks Adam

biasedlogic commented 6 years ago

@adambrum the diode you linked will be more than enough. In general, just check you have a footprint that can accomodate SOD-323F, 1206 and mini-melf. Usually a 1206 footprint can be hand-populated with all these, as long as there's no track between the pads (SOD-323F may have some exposed leads beyond the pad boundaries and could lead to a short if the board has no solder resist)

I'm not that great fan of the buffer in this application, we are talking about a shield to a cheap µC board. This buffer does not offer real protection for the connected PC in case of a surge, it might protect the Arduino. But it's harder to replace a fried SMD buffer than to swap out a $10 arduino board, and the Arduino board is sold on any each street corner.

If you are into expanding the board, I'd rather invest the effort into putting an USB-to-TTL-serial chip on the board, with a galvanic separation (opto/adum) on the serial side, to offer some real protection and ground separation for the control PC.

adambrum commented 6 years ago

Looks fairly easy to convert usb to serial than add an opto.

I will try and knock up a quick schematic

langwadt commented 6 years ago

by far the easiest and cheapest would be to add a 6 pin header for one of the numerous ftdi etc. usb-serial cables

adambrum commented 6 years ago

what about this https://www.aliexpress.com/item-img/1500V-2Mbps-USB-to-TTL-CH340-STC-RS232-high-speed-serial-isolation-module-5V-3-3V/32712574529.html?spm=2114.10010108.1000017.2.416dc638RvihT8#

Just a thought if we go this way the arduino is going to have to be powered separately so another power supply needed, I dont think we can use the same 12v supply from the I/O board as we have just isolated it from the arduino.

or could add an isolated dc-dc converter

cncpaw commented 6 years ago

FYI I uploaded the schematic of my CNC controller into a new issue for use as you see fit.

This isolation issue is becoming ironic. The USB/RS232 module on the arduino has problems meaning that control programs need to use schemes like character-counting to achieve high speed. Isolation is best placed in the RS232 path. So it seems well worth doing, yet do that and the arduino becomes an ATmega328 with a resonator and connectors. Might as well make a bespoke ATmega328 board?

Avoid the CH340 type USB/RS232 modules. Problems with them have been mentioned before in GRBL. FTDI-chips are recommended.

If isolation is moved from the Arduino's IO to its RS232, then the arduino's power comes from the stepper drivers, suitably regulated but it need not be isolated. Just be careful with grounds and supply noise.

adambrum commented 6 years ago

It would be quite easy to make a 328 board now but im still intending to use the mega and i have a feeling that as soon i get this finished a 32 bit grbl will be released.

Good to know about the CH340 chip that was the one i was looking at.