Advice needed : PCB for home switch

PsyKo
Posts: 430
Joined: Thu Aug 30, 2012 8:42 pm
Location: France

Advice needed : PCB for home switch

Post by PsyKo » Thu Sep 17, 2015 6:48 am

Hello,

I've been using home switch on my Shapeoko for a long time now, but always had some noise, triggering wrong home location. I'm using TinyG v7.
I'd like to add capacitor/resistor to reduce the noise and also add a state led for each limit switch on my main control enclosure.
That's where I need your help, especially for the electronic skilled people (which I'm not :) )

Below is the diagram for the PCB I plan to make.
Few explanations :
- XHOMEIN is connected to my home switch (simple mechanical homeswitch. NO or NC can be configured),
- XHOMEOUT will be connected to the homing/limit pins on the TinyG board,
- LED1 is a green led to indicate that the homing switch is not triggered (the LED already has built in resistor),
- LED2 is a red led to indicate that the homing switch is triggered (the LED already has built in resistor),
- Therre will be one for each home switch.

The CX capacitor will probably be something like a 22µF (0.22 µF ???) ceramic capacitor.

Does this look good to you ?

Thanks
Attachments
HomeSwitchPlate.jpg
HomeSwitchPlate.jpg (36.53 KiB) Viewed 1747 times
Shapeoko #736
Kress 800, Z Axis upgrade, dual Y, 600mm X&Y rails, metal spacers and V Wheels, home switches, 4th axis
Goko - Free CNC Control Software - http://www.shapeoko.com/forum/viewtopic ... 380#p44380

cvoinescu
Posts: 4442
Joined: Thu Jul 19, 2012 6:50 pm
Location: Camberley, UK
Contact:

Re: Advice needed : PCB for home switch

Post by cvoinescu » Thu Sep 24, 2015 1:10 pm

The transistor and LED connections won't work the way the schematic is drawn. Maybe some lines ended up on top of each other, but what I see does not make any sense. It should look something like this (sorry for the two R4s, that's a "typo"):
limit-switch-leds-transistors.jpg
limit-switch-leds-transistors.jpg (52.85 KiB) Viewed 1661 times
Also, as far as I know, the TinyG already has capacitors and pull-up resistors on the limit switch inputs, and I'm pretty sure their limit switch inputs are 3.3 V logic, so keep the 5 V away from them.

Since you're already using two transistors and some resistors per limit switch, you can substitute ICs and get a more useful circuit, for the same amount of work. Something like this does exactly what you need, and has even better signal conditioning than what's already on the TinyG.
limit-switch-leds-ICs.jpg
limit-switch-leds-ICs.jpg (73.35 KiB) Viewed 1661 times
Values are (acceptable range in parantheses):
R1 = 680 ohm (470 ohm to 1.2 kohm),
R2 = 2.2 kohm (1 k to 10 k),
C1 = 47 nF (10 nF to 100 nF),
R3 and R4 chosen for no more than 10 mA through the LEDs at VDD = 3.3 V (say, 180 ohm to 270 ohm).

If you have three limit switch circuits, you can use a single 74HC14, which has six inverters, so it's enough for all three axes. If you have six limit switches, you use a 74HC14 for the first inverter (because it has the Schmitt trigger input), and either another 74HC14 or a 74HC04 as the second inverter (a total of two ICs for all six limit switches). (Note that the 74HCT versions don't work at 3.3 V; they need to be 74HC, or, even better, 74LV.)

You don't have to wire the switches in the changeover configuration I've shown -- a NC or NO switch to ground will do -- but my configuration is likely to have better noise immunity, and wire is cheap.
Proud owner of ShapeOko #709, eShapeOko #0, and of store.amberspyglass.co.uk

PsyKo
Posts: 430
Joined: Thu Aug 30, 2012 8:42 pm
Location: France

Re: Advice needed : PCB for home switch

Post by PsyKo » Thu Sep 24, 2015 1:39 pm

Hello,

Thank you for taking the time to look at it.

TinyG includes a capacitor from v8. I own a v7 which only includes a pullup resistor.
TinyG switch input is limited to 3.3v but the 5v is required for my LEDs (constructor data). I though my schematics kept both 3.3 and 5v away from each other. I was wrong :)

I'll have to look carefully at your schematic when I get back home. At first glance, I imagine I can remove R2 and R4 (first diagram) or R3 and R4 (second diagram) because my LEDs already have builtin resistor, right ?

Thanks
Shapeoko #736
Kress 800, Z Axis upgrade, dual Y, 600mm X&Y rails, metal spacers and V Wheels, home switches, 4th axis
Goko - Free CNC Control Software - http://www.shapeoko.com/forum/viewtopic ... 380#p44380

veng1
Posts: 250
Joined: Fri Nov 30, 2012 12:09 pm

Re: Advice needed : PCB for home switch

Post by veng1 » Thu Sep 24, 2015 2:06 pm

Cat,

If you use just '04s and add a large value resistor from the output of last inverter to the input of the first inverter, it will give some hysteresis and tend to act like a Schmitt. The ratio of the added resistor to R2 sets the amount of hysteresis. Don't make it too small or you end up with an oscillator as it is positive feedback. Start about 10 X R2.

cvoinescu
Posts: 4442
Joined: Thu Jul 19, 2012 6:50 pm
Location: Camberley, UK
Contact:

Re: Advice needed : PCB for home switch

Post by cvoinescu » Thu Sep 24, 2015 3:36 pm

PsyKo wrote:TinyG switch input is limited to 3.3v but the 5v is required for my LEDs (constructor data). I though my schematics kept both 3.3 and 5v away from each other. I was wrong
No, you were right, you kept them separate. Check whether your LEDs work at 3.3 V -- I bet they do, only not as brightly.
PsyKo wrote:At first glance, I imagine I can remove R2 and R4 (first diagram) or R3 and R4 (second diagram) because my LEDs already have builtin resistor, right ?
Yes, that's correct.
veng1 wrote:Cat,

If you use just '04s and add a large value resistor from the output of last inverter to the input of the first inverter, it will give some hysteresis and tend to act like a Schmitt. The ratio of the added resistor to R2 sets the amount of hysteresis. Don't make it too small or you end up with an oscillator as it is positive feedback. Start about 10 X R2.
Yes, that's a technique I have used before, but it seems easier (fewer components) to use the '14, and I'm pretty sure C1 gets in the way of the hysteresis, unless I add yet another series resistor...
Proud owner of ShapeOko #709, eShapeOko #0, and of store.amberspyglass.co.uk

PsyKo
Posts: 430
Joined: Thu Aug 30, 2012 8:42 pm
Location: France

Re: Advice needed : PCB for home switch

Post by PsyKo » Thu Sep 24, 2015 4:57 pm

cvoinescu wrote: No, you were right, you kept them separate. Check whether your LEDs work at 3.3 V -- I bet they do, only not as brightly.
They do work, but so low that given the workshop environment I almosst can't distinguish if it's on or off.
Shapeoko #736
Kress 800, Z Axis upgrade, dual Y, 600mm X&Y rails, metal spacers and V Wheels, home switches, 4th axis
Goko - Free CNC Control Software - http://www.shapeoko.com/forum/viewtopic ... 380#p44380

cvoinescu
Posts: 4442
Joined: Thu Jul 19, 2012 6:50 pm
Location: Camberley, UK
Contact:

Re: Advice needed : PCB for home switch

Post by cvoinescu » Thu Sep 24, 2015 5:24 pm

Then you can't use them with the IC solution, only with the transistors. That one should be safe with 5 V for the LED circuit.
Proud owner of ShapeOko #709, eShapeOko #0, and of store.amberspyglass.co.uk

PsyKo
Posts: 430
Joined: Thu Aug 30, 2012 8:42 pm
Location: France

Re: Advice needed : PCB for home switch

Post by PsyKo » Thu Sep 24, 2015 6:20 pm

Ok then no IC :)

I actually open my eagle file to clean up my diagram (the wire are the same) and I have this, which is more easy to read :
diagram.png
diagram.png (5.32 KiB) Viewed 1619 times
I think it's almost the same as the first one you posted (and should work better than the first one I posted). The only thing I don't understand is : what is the R4 resistor for (between the 2 leds) ?
Shapeoko #736
Kress 800, Z Axis upgrade, dual Y, 600mm X&Y rails, metal spacers and V Wheels, home switches, 4th axis
Goko - Free CNC Control Software - http://www.shapeoko.com/forum/viewtopic ... 380#p44380

cvoinescu
Posts: 4442
Joined: Thu Jul 19, 2012 6:50 pm
Location: Camberley, UK
Contact:

Re: Advice needed : PCB for home switch

Post by cvoinescu » Thu Sep 24, 2015 7:20 pm

That looks like it will work. It is quite different from what I did, and not the usual approach with bipolar transistors.

In my schematic, both transistors work as inverters. R4 is there to ensure that the base current of Q2 does not go through D1 and light it up slightly; you can leave it out if you don't care.

In your schematic, T7 is an emitter follower, so the voltage on LED1 depends on the input voltage. It works, but it's not ideal. In my schematic, once the input voltage is above a certain threshold and the transistor gets enough base-to-emitter current, the transistor is as "on" as it gets (said to be "saturated"), and the LED is supplied with a pretty constant voltage. The only downside is that I need an extra part, the base resistor.

Your T8 shunts LED2, so the current through R7 increases when LED2 is off. R7 needs to be fairly low to keep LED2 near full brightness, which means the current when LED2 is off and T8 conducts is significant. This wastes power -- which may not matter, but why do it? My Q1 acts as an inverter, so I can use its output to drive a second, identical stage, which will turn D2 on when D1 is off, using power only when the LED is on.

If unnecessary current consumption and a dimmer LED2 are not a problem, you can save a transistor by connecting LED1 in parallel with R7, and getting rid of T7. (If there wasn't the 5 V vs 3.3 V issue, you could have used the limit switch itself instead of T8, to shunt LED2 and power LED1, for the absolute minimum part count.)
Proud owner of ShapeOko #709, eShapeOko #0, and of store.amberspyglass.co.uk

PsyKo
Posts: 430
Joined: Thu Aug 30, 2012 8:42 pm
Location: France

Re: Advice needed : PCB for home switch

Post by PsyKo » Thu Sep 24, 2015 7:55 pm

Thanks for the explanation. I'll go with your schematic then ;)
Shapeoko #736
Kress 800, Z Axis upgrade, dual Y, 600mm X&Y rails, metal spacers and V Wheels, home switches, 4th axis
Goko - Free CNC Control Software - http://www.shapeoko.com/forum/viewtopic ... 380#p44380

Post Reply