AC input on 28X1 - OK with protection diodes?

nekomatic

Member
I'm building a project where I want to use the mains frequency for timing - my Picaxe 28X1 is running off 5 V and I have 9 V AC from the transformer. Space is tight so I want to limit component count if possible.

If I just connect 9V AC to an input pin via a suitable resistor - 100K say - am I right that the Picaxe's input protection diodes will happily protect the chip from damage, or do I need to add external diodes as well?
 

Goeytex

Senior Member
I'm building a project where I want to use the mains frequency for timing - my Picaxe 28X1 is running off 5 V and I have 9 V AC from the transformer. Space is tight so I want to limit component count if possible.

If I just connect 9V AC to an input pin via a suitable resistor - 100K say - am I right that the Picaxe's input protection diodes will happily protect the chip from damage, or do I need to add external diodes as well?
That should be OK

However, if it were me I would not depend upon the internal ESD diodes and would use external clamp diodes (BAT85), that take the internal diodes out of play.
If you have trouble using the 100K series resistor. Try reducing it to 47K or even 22K. ( 9V / 100K = 90 microamps) May be a bit low ...
 

Attachments

Last edited:

geoff07

Senior Member
It is always difficult when space is limited, but I found that using input from a transformer (in my case rectified dc, zener limited to 4.7v) to be problematic. I was using this to detect the presence of 240v ac in the system I was controlling. The issue was that the additional incoming energy in the signals, when on, was enough to keep the picaxe and the attached oled display energised even when the +5v VCC power was off. My solution was to use optocouplers, fed from the transformers to avoid resistive loss, which transmitted the signal but not the energy.
 

nekomatic

Member
That should be OK

However, if it were me I would not depend upon the internal ESD diodes and would use external clamp diodes (BAT85), that take the internal diodes out of play.
So that's one vote for and one vote against? Er... thanks ;)

Geoff, what you describe won't be a problem in my case because if the AC is present then the Picaxe's supply will also be present. I'm inclined to let the internal diodes do the job...
 

Dippy

Moderator
Things are often not quite as black&white.
When used appropriately with the proper design that method is perfectly OK - I can't comment on detail as no schematic is provided.

They key is your last sentence where, it appears, you won't be vulnerable to the parasitic powering that geoff07 mentioned.

Microchip engineers recommend calculating resistor values such that only a few microamps can flow in the section of circuit. Maybe this is where Geoff had his little problem. Studying the values and current flow should highlight the cause. The stiff/limp -ness of the PSU (if separate) can also play a part.

I've used a similar method for zero-cross detection with PIC in transformer and transformerless supplies for phase switching of AC motors and heaters.
Microchip have several App Notes which can provide guidance.
There are also suggestions on how to make the circuit a little more bullet-proof against noise and transients.

As Goeytex has mentioned the external diode is the safest method especially as a) some PIC I/O doesn't have clamps, and b) the internal diodes are quite slow.

Post an example circuit so people can have a look-see.
 

geoff07

Senior Member
Microchip engineers recommend calculating resistor values such that only a few microamps can flow in the section of circuit. Maybe this is where Geoff had his little problem. Studying the values and current flow should highlight the cause. The stiff/limp -ness of the PSU (if separate) can also play a part.
It was certainly a low impedance signal input, though it was zener clamped to 4.7v. I don't recall any advice on using high impedance signals for digital inputs but I will take a look at the data sheet. I assumed the problem was clamp diodes in the Picaxe conducting when the input voltage was above the (absent) Vcc, and which I didn't anticipate, though should have done of course. I think the general point is that if there is energy incoming from another source then you do really need complete isolation at the input to avoid side effects. Which is not too surprising given the minute amount of energy needed to run a Picaxe.
 

Goeytex

Senior Member
geoff07 Posted:
I think the general point is that if there is energy incoming from another source then you do really need complete isolation at the input to avoid side effects. Which is not too surprising given the minute amount of energy needed to run a Picaxe.
There are other options besides complete isolation. One might be to use the MCLR Pin as the input with a Zener Clamp to ground as in the case of your example. (No internal or external coupling to the +V rail). Another is to use diode coupling with a pullup. Another is to put a load resistor on the +V rail. There are others.

I will agree though that sometimes an OPTO is a best choice.
 

Dippy

Moderator
" I assumed the problem was clamp diodes in the Picaxe conducting when the input voltage was above the (absent) Vcc" - an example of parasitic power.
In nekomatic's circuit he appears to have the 'sense' and power together so he shouldn't get that problem.

The advice from a Microchip engineer was email advice when I asked about Z/V detection and referred to the old AN521 and various Triac circuits using a K22 PIC.

You need to design around your requirements and your circuit spec. including the supply. And whether, or not, you need complete isolation depends on what you are trying to do and the requirements. Optos are one excellent solution where appropriate.
Like I said before; it's not completely black&white without information.
 

Skiwi

New Member
My vote is also for optos.
My philosophy is that it is cheaper to buffer inputs than to replace a chip if something goes wrong!

OR
A simple transistor buffer.
Without doing a drawing, use a BC459,
emitter to 0V
Input the AC to base, through 10K resistor
4k7 resistor +5V to collector
collector to Picaxe input.

ULN2803 chip is also great for buffering multiple inputs
 

nekomatic

Member
Thanks for the further responses - here's a schematic showing what I'm talking about. It's 6 V AC, not 9 V, fwiw. The power supply (everything apart from R1 and the PICAXE) is already constructed in one box, and the PICAXE circuit I'm now building on individual-pad board (what's the proper name for that?) so while I could fit in a diode or two, it's making additional connections to 0V that's a little bit of a pain.

The PICAXE pins I have available for this are a0 - a3 (legs 2 - 5). The PIC16F886 datasheet gives a maximum 'input clamp current' of 20 mA, unless this doesn't apply to those pins? So with a 10 K resistor I'd have to have a 200 V spike on the transformer output to exceed this - if that ever happened it'd probably be enough to take out the regulator and the PICAXE anyway, no?

picaxe with ac timing signal_schem.png
 

geoff07

Senior Member
Your 6v (rms, on load) transformer is likely to produce 6 x square_root(2) (8.5v) peak voltage if on full load and likely in excess of perhaps 10v when very lightly loaded, as in your circuit. I would feed the input pin via a potential divider (e.g. 47k/47k) to create a highish impedance signal that would not exceed the Picaxe ratings. If all this supply is doing is feeding one Picaxe then if space is an issue you could do away with one of the rectifiers and one of the transformer connections and use half-wave rectification. You will probably need a pretty decent electrolytic on the input to the rectifier (say 1000u if you have a small one). I wouldn't push the ratings even if the datasheet suggests it is ok.
 

Goeytex

Senior Member
All I would do to the proposed circuit is to add a 5.2 V Zener from the Picaxe input pin to Ground. ( EXTRA PROTECTION). If space is an issue then this could be soldered directly across the Picaxe input & ground pins. (IMO, board size should follow design, not vice versa)

However, the circuit should work OK as is, but possibly increase the resistor to 22K. Even though the specs may the clamps can handle x milliamps, the input only needs a few microamps. Even if the transformer puts out 15v with a limited/no load there is adequate ( but not ideal) protection as long as the voltage regulator can handle it.

Sometimes it is not possible or prudent to make a circuit "ideal" and then "adequate" is good enough. The posted circuit is adequate IMO.
 

hippy

Technical Support
Staff member
@ nekomatic : For a number of reasons you probably do not want to connect your PICAXE 0V to mains earth.
 

nekomatic

Member
Goeytex, thanks; the application dictates the board size in this case - it's a projection clock I'm building in to an old SLR camera body. I'll try and write it up to share here if I find time!

hippy, my understanding is that if I can't guarantee my mains power supply meets the requirements for SELV (a.k.a. Class II or 'double insulated') then it's safer to have the 0V tied to mains earth making it PELV or class I ( http://en.wikipedia.org/wiki/Extra-low_voltage ). What reasons did you have in mind?
 

geoff07

Senior Member
You might want a metallic camera body to be earthed, but there is no reason why the electronics should be as long as they are not exposed to the user. There are good reasons why you wouldn't - i.e. the amount of ac and noise likely to be on the earth connection that could interfere with the logic. Alternatively, use an old phone charger SMPS and that will already be class II, as well as saving a lot of energy over the life of the project, though you might need to add an rtc chip if you are planning to take the timing from the 50Hz. Not having a magnetic transformer in the case would give you a lot more space.
 

hippy

Technical Support
Staff member
I had been led to believe there can be issues with connecting 0V to earth particularly if connected to other systems ( ground loops etc ), but I am no expert on the subject.

If you can use a plug-in wallwart power supply that usually will be certified as doubly insulated.
 

nekomatic

Member
Thanks both. The transformer etc - everything in my previous circuit diagram except the PICAXE and 10k resistor - are in a wall wart style case which I've already built, so I'm reluctant to open that up and start modifying it. Earth loops are definitely a consideration if connecting different pieces of equipment together but that doesn't need to happen in this case. I've never experienced problems with noise in digital circuits when earthing the 0V rail in the past - it'd have to be pretty bad to get past a smoothed, regulated PSU with the usual decouplinc caps I'd have thought?

I should say that this project has been on the go for some time and has evolved as it's gone along - I might well do things differently if starting from scratch but time to tinker with things is always short so I've been focusing on the quickest way to get from where I am to a working project. Thanks again for the detailed consideration of what was only meant to be a quick question!
 

geoff07

Senior Member
it'd have to be pretty bad to get past a smoothed, regulated PSU with the usual decouplinc caps
But the thing about the ground connection is that it doesn't have to get past anything - it is directly connected. However, it depends entirely on the quality of your earth, how your local power is distributed, and what is going on in the neighbourhood. If you want a quiet, clean ground connection you generally have to make your own and just use the power earth for protection.
 

nekomatic

Member
The positive supply is referenced to the ground though, so any noise will be common mode.

I've built hi-fi amps with phono inputs, so a few millivolts input sensitivity for full output, and always tied the case and 0V rail to mains earth - as recommended in the designs I've followed - and never had trouble with noise anywhere I've used them, so I'm not convinced this is likely to be a problem for a digital circuit in a UK domestic environment. Maybe I've just been lucky?
 

geoff07

Senior Member
I'm sure that most of the time there wouldn't be a problem. But these issues are about fault conditions, not everyday usage necessarily. If next door drops a knife in the toaster and trips the mains with an earth short when you are asleep having set a critical alarm so you can get up early and catch a plane, and the system resets and cancels the alarm because it got a pulse up the earth wire, then what? As with programming, it is the rare error conditions that bite you because they don't get tested, so defensive design is always worth thinking about.
 
Top