Naive Transistor Question

chigley

Senior Member
Hey all,

I've currently got a toggle in the middle of a USB cable which allows me to stop the flow of data through the green wire inside the cable. When the switch is closed, data flow is normal. When the switch is open, the data is interrupted. My circuit (if you can call it that, it's so simple) currently looks like this:



I'm now trying to make this more intelligent, hopefully using a PICAXE. The PICAXE will read an input via a push-to-make switch, and should then allow the USB data to flow through the green wire for 5 seconds, after which data flow is restored. I've had a think about this and the only simple method which springs into my mind is an NPN transistor on an output leg of the chip.. I'm really not sure if what I'm suggesting will work though, and I don't have time to research it fully as I'm right in the middle of the exams. The picture is below - the data in the green wire is flowing from top to bottom.



Would the above work? If not, is there a simple change to make (i.e. resistors to prevent damage to the transistors?) Or am I on the completely wrong track and need guiding in the right direction?

Thanks a lot!

Charlie
 

BeanieBots

Moderator
and I don't have time to research it fully as I'm right in the middle of the exams
And there lies the problem.
We cannot answer your question without a lot more information from yourself.
Things such as voltage levels, data rates, bi-directional or uni etc. etc.

However, to be safe, use a device designed for the job.
It's known as an analogue switch. Simply wire it in-line just like your switch but it can be controlled by a PICAXE output pin.
The CD4066 is an example of such a switch. (it actually has four switches).
 

chigley

Senior Member
And there lies the problem.
We cannot answer your question without a lot more information from yourself.
Things such as voltage levels, data rates, bi-directional or uni etc. etc.

However, to be safe, use a device designed for the job.
It's known as an analogue switch. Simply wire it in-line just like your switch but it can be controlled by a PICAXE output pin.
The CD4066 is an example of such a switch. (it actually has four switches).
Yeah I probably shouldn't be experimenting with hobby projects like this during exams, but I enjoy it so I am doing anyway.

Thanks for the advice on the switch, will look into it tonight.
 

hippy

Ex-Staff (retired)
USB is a bi-directional protocol so there is no 'data flows this way down the wire'. The voltage is nominally 3V3 but is as low as 0V4 for high speed USB. Timing accuracy of the two signal lines is essential, especially as speeds go up. Transmission speeds will be 1.5Mbps, 12Mbps or 480Mbps.

I'm quite surprised that 'cutting a wire' works without bringing whatever is on both ends of the USB cable crashing down. It's effectively introducing a fault condition and the results would largely be unpredictable, especially if the switching occurred mid data or control packet.
 

chigley

Senior Member
Thanks for all the advice :) I promise I'm not normally this keen to rush things!!

Any ideas where I can get a CD4066 (or equivalent, as I don't need 14 pins) in the UK without having to buy a tube of 25?
 

slimplynth

Senior Member
Ta

And there lies the problem.
We cannot answer your question without a lot more information from yourself.
Things such as voltage levels, data rates, bi-directional or uni etc. etc.

However, to be safe, use a device designed for the job.
It's known as an analogue switch. Simply wire it in-line just like your switch but it can be controlled by a PICAXE output pin.
The CD4066 is an example of such a switch. (it actually has four switches).
Cheers BB & Ec. the CD4066 was exactly what I needed for the switching on this keyboard encoder. I bought 10 of them and some other things from Bitsbox, delivered within two days :) can throw away the makeshift mechanical (electromagnetic) switch and say good bye to 60 emails in one minute.
 

chigley

Senior Member
Just thought some people would be interested to know that my 4066 arrived this evening - just got a dummy circuit working on a breadboard with an LED very easily!

Will implement with the USB data as initially intended tomorrow.

Thanks to all that helped :)

EDIT: Another question, sorry! Does the 4066 have any internal capacitors or anything which need to fill up before operation is normal? I've had a quick scan through the datasheet and can't find anything to suggest so. Basically; after applying power the 4066 behaves as if the control pin is high for up to 30 seconds, before it then begins to function as it should.

This isn't the end of the world but it'd be nice if there was an obvious fix to this problem. After 30 seconds of being powered everything then works perfectly. If this is strange behaviour and can't be explained, I'll post a circuit diagram tomorrow. Cheers!
 
Last edited:

jglenn

Senior Member
No, something is wrong. It is just a switch, the gate inputs must be either 0 or 5V. All 4 should be strapped, don't leave them open. Make a divider network with 2 1K resistors, to get 2.5V, and feed this to all the ANALOG inputs. When you turn each gate high, you will see the 2.5V at the outputs. I've used these chips all the time.

The one thing they don't like is analog inputs outside the rails. Instant destruction. :(

There are faster analog switches, some work to video freq.
 

chigley

Senior Member
No, something is wrong. It is just a switch, the gate inputs must be either 0 or 5V. All 4 should be strapped, don't leave them open. Make a divider network with 2 1K resistors, to get 2.5V, and feed this to all the ANALOG inputs. When you turn each gate high, you will see the 2.5V at the outputs. I've used these chips all the time.

The one thing they don't like is analog inputs outside the rails. Instant destruction. :(

There are faster analog switches, some work to video freq.
Thanks for the advice.

I've now tied the other three input legs to 0V, rather then floating, and the one I'm using is now going straight to 5V (originally I put it through a 10k resistor as it seemed more stable with it in).

Not got any 1k resistors at home unfortunately so I can't try a voltage divider for the analog inputs. The datasheet says that the input can go up to VDD though, so I'm not "breaking any rules".

I can see why 2.5V would be preferable, but could that still be the cause for the 30 second delay when I power up the circuit?

EDIT: Just thought; it could be the 08M causing the problems too. I'm going out now, but I'll get the multimeter on it all when I get home.
 
Last edited:

jglenn

Senior Member
Chig: there are no timers in the 4066, nothing that will cause a 30 sec delay.
You have a problem with the chip or hookup. It could have blown out. Try another one, and make sure the ground and 5V are connected correctly.

The gate input of the fet switch you can put a pullup resistor on to 5V, maybe a 1K or 10K. Then use a switch to pull it down to shut off. Apply any voltage from 0-5V to the analog switch input. When the gate is high, the analog voltage will appear at the output. That's all there is to this chip.
 

chigley

Senior Member
Hey,

I did a load of testing last night and discovered that it was the 08M which was misbehaving, not the 4066. Tried reprogramming it but it didn't work.

This is most likely because my 3xAA (4.5v) battery box is in college with my project, so I've been forced to try both 2xAA (3v) and I even tried a PP3 (9v) with a voltage divider bringing it down to 4.5v. I'm aware that the PP3 doesn't have the capacity to run the 08M, however.

I've ordered another battery box - so I'm hoping that everything will work perfectly upon its arrival. 4066 seems to be working brilliantly on its own though :)

Thanks a lot,

Charlie
 

chigley

Senior Member
All working now :)

EDIT: Oops, feel free to merge. The only other forum I use has a 5 minute edit limit so I'm not used to there being no limit!!
 

chigley

Senior Member
Hmm.... after getting the circuit fully working with the LED, I've just tried it out on the USB data wire as originally intended, but I'm having some difficulties.

I have cut the green data + wire of my USB extension cable, and each end is on a matching input/output leg of the 4066. The control pin for this input/output set is high. In this situation I would have expected for the data flow through the USB to be constant.

The data light on the USB device is actually behaving as if the data flow is rapidly going on/off/on/off. I don't have an ossciloscope to test this, but is it possible that the 4066 simply isn't quick enough for USB data? If this is the case, is there a quicker version of the 4066 which would be better suited for my needs?

If the frequency of the 4066's operations definitely isn't the problem, any ideas what is?

Cheers
 

hippy

Ex-Staff (retired)
USB speeds ranges from 11Mbps to 480Mbps and ( as best I can tell ) the 4066 has a rating of 40MHz. It's also not a perfect switch, it has an on-resistance plus the pass-through signal may be delayed and slewed. As USB is timing sensitive then this may be a problem.

Worth taking the 4066 out of circuit and relacing it with a physical switch to test if it is the 4066 causing a problem.

If the 4066 doesn't work a solution may be a relay which will hopefully perform just as a physical switch does.
 

chigley

Senior Member
Worth taking the 4066 out of circuit and relacing it with a physical switch to test if it is the 4066 causing a problem.

If the 4066 doesn't work a solution may be a relay which will hopefully perform just as a physical switch does.
I originally started this "project" with a physical switch, which worked perfectly. Adding the 4066 is definitely what's caused the data flow to be intermittent.

Bit of a pain as I've never been a fan of relays at all... but might have to give it a go.
 

jglenn

Senior Member
You probably have inserted a lumped RLC circuit into the USB link that is disrupting the signal. You need a scope to see the signal before and after
the mod. It is probably that not having a tight RF layout and cabling is causing trouble. Even impedance mismatch. It's a tough world. ;)
 

chigley

Senior Member
You probably have inserted a lumped RLC circuit into the USB link that is disrupting the signal. You need a scope to see the signal before and after
the mod. It is probably that not having a tight RF layout and cabling is causing trouble. Even impedance mismatch. It's a tough world. ;)
If only I actually understood you! RLC? RF? Impedance!?
 

chigley

Senior Member
Can't help but think that a simple micro project has turned into something a lot more complex! Ah well... I tried my best. :(
 

jglenn

Senior Member
Don't give up, an analog switch should be able to do it, you may need
a faster one. You can try paralleling all the 4066 switches, that will
reduce the insertion R to 1/4 of one switch. I have used Harris switches
for video, so it should be possible, check their parts and view the specs.
 

MartinM57

Moderator
JG's idea of parallel'ing the switches is a good one - reading the data sheet (you have read and understood the 4066 data sheet haven't you?) shows a typical "on" resistance of 270 ohms with a 5V supply.

So it's like putting a 270R resistor in the line of the USB data signal - which as it is such a high frequency signal, it may not tolerate. In fact, try just putting a 270R resistor in place of the 4066 switch and see if the USB link still works...

Paralleling up all the switches will reduce this to 270/4 ohms which might help.

Also you are taking a high speed digital (up to 40mbps if it's USB 2.0) line out of its comfortable 'piece of wire inside a shielded cable' to your own wiring and:
- made it pass through a silicon switch (ie the inside of the 4066 chip) rather than through a mechanical switch (which was your prototype)
- maybe you haven't taken any particular care to keep the cable lengths absolutely minimal, screened etc.

If the signal you were cutting was just a simple low frequency 5v logic level then you have the correct circuit - but you have chosen something that isn't that.

Also take heed of post #4 - switching at inappropriate times during USB data transfer can lead to Bad Things Happening on the link.

What is the actual application for this device - why are you trying to switch the data line on a USB link?
 

moxhamj

New Member
If you are not a fan of relays (post 20) but you like the 4066, how about something that falls half way between the two, like a 5V reed relay? There are ones available with coil resistances of 500 ohms, and at 5V that is only 10mA so a picaxe could drive one directly. (I'd add a 914 diode for back emf)
 
Last edited:

chigley

Senior Member
JG's idea of parallel'ing the switches is a good one - reading the data sheet (you have read and understood the 4066 data sheet haven't you?) shows a typical "on" resistance of 270 ohms with a 5V supply.

So it's like putting a 270R resistor in the line of the USB data signal - which as it is such a high frequency signal, it may not tolerate. In fact, try just putting a 270R resistor in place of the 4066 switch and see if the USB link still works...

Paralleling up all the switches will reduce this to 270/4 ohms which might help.
Yes I have read the datasheet, and think I understand most of it.

I haven't got a 270R but I just tried putting a 220R across the wire and the signal doesn't work. This could be the main problem. EDIT: I just measured the resistance across the two input/output pins - 297 Ohms. This would mean that, once wired in parallel, this value would fall to 74 Ohms. What are the chances of the data being able to flow at this resistance?

Also you are taking a high speed digital (up to 40mbps if it's USB 2.0) line out of its comfortable 'piece of wire inside a shielded cable' to your own wiring and:
- made it pass through a silicon switch (ie the inside of the 4066 chip) rather than through a mechanical switch (which was your prototype)
- maybe you haven't taken any particular care to keep the cable lengths absolutely minimal, screened etc.
I've got the circuit currently set up on a breadboard and the wires are very neat and short. Each wire has one piece of rubber insulation on it, but that is all.

If you are not a fan of relays (post 20) but you like the 4066, how about something that falls half way between the two, like a 5V reed relay? There are ones available with coil resistances of 500 ohms, and at 5V that is only 10mA so a picaxe could drive one directly. (I'd add a 914 diode for back emf)
If I can get it working with the 4066, that'd be preferable, but as a last resort I will look into this.

Thanks to all :)

EDIT2: Just wired all of the switches in parallel. Resistance measured at a rough average of 72 Ohms, but data flow remains intermittent.
 
Last edited:

chigley

Senior Member
OK I'm now going to take a completely different approach - cutting the power from the USB device. Data was getting too complicated so I'll see if I can get this to work instead. Here's what I've tried:

The red +V wire inside the USB cable is tied to the +5V rail. The black 0V wire inside the USB cable is attached to an 08M output pin set as low. I would have expected for the p.d. from the 0V output pin to the +5V rail to be 5V. I would then be able to set the 08M output to high to cut power to the device. Unfortunately the p.d. when the output is low only about 4.7V, which isn't enough.

Nothing's easy! Any easy way around this? I've also tried bringing the 4066 into the equation, but still getting a p.d. similar to 4.7V.

Looking forward to hearing suggestions :) I promise I'll give up on this soon if I don't get results soon!
 

chigley

Senior Member
Look at the 12F683 datasheet, and you'll see that a low pin isn't 0V. It can be up to 0.3V greater than this.

A
OK thanks for that. Is there any way around this?

I tried it the other way round - with the output pin high and the 0Vs tied together. Before I add any connections to the output pin, it reads at 5V. As soon as I connect the red power wire to this pin the p.d. drops to 4.6V - not enough to power the device.
 

hippy

Ex-Staff (retired)
The red +V wire inside the USB cable is tied to the +5V rail. The black 0V wire inside the USB cable is attached to an 08M output pin set as low ... I would then be able to set the 08M output to high to cut power to the device
You are treading on very dangerous ground and quite likely to destroy your PICAXE, USB device and PC's USB port and possibly worse.

By pulling the USB 0V up to the USB +V level you are effectively shorting out the USB port power supply. With all the other circuit paths formed between the active signal lines of the USB port and slave device and PICAXE who knows what else you are doing or what damage you are causing.
 

chigley

Senior Member
You are treading on very dangerous ground and quite likely to destroy your PICAXE, USB device and PC's USB port and possibly worse.

By pulling the USB 0V up to the USB +V level you are effectively shorting out the USB port power supply. With all the other circuit paths formed between the active signal lines of the USB port and slave device and PICAXE who knows what else you are doing or what damage you are causing.
Okie dokie I guess I'll give up for now then :p Cheers for the advice, think I'm in a bit too deep now though.
 

MartinM57

Moderator
You still haven't said why you are trying to do all this - offering up the "why" will undoubtedly get the PICaxe-massive offering all sorts of advice (probably including the right answer somewhere) on different ways of achieving the same end result...;)
 

chigley

Senior Member
You still haven't said why you are trying to do all this - offering up the "why" will undoubtedly get the PICaxe-massive offering all sorts of advice (probably including the right answer somewhere) on different ways of achieving the same end result...;)
Hmm maybe I'll be back in a number of days and I'll explain all.

Until then, I'm going to concentrate on exam revision. It's amazing how many hours I've spent on this simple little circuit in the last few days - I've learnt a hell of a lot but I think it's time to give it a rest and get my priorities straight.
 
Top