Industrial PLC on atmel atmega 328

Hello!

I am working on my university project to develop industrial PLC on atmel atmega 328 microcontroller.

I have a 2 questions?!

1.How to measure 0 - 10 V input to analog pin as a 0 - 5 V. Half year a go I done my university engineer project "Elaboration of the Multi-functional PLC on Base of the Arduino Mega Platform". Then I used voltage divider (attached picture). But now my lecture said so I can't use this, because I can't protect microcontroller from higher input as 5 V if input is more then 10 V. I should use amplifier or what to manage max 5V output?

2.PWM output from 0 - 5V to 0 - 10V (see attachment) is not clearly straight. I should use capacitor at end?

Thanks for your help!

  1. with a simple voltage divider

What sort of course are you doing?

What attachment ?
Do you know to attach a file to a forum post ?

It sounds like your analog input criteria is unknown. If it is greater than 10V, what is it ?
If this is unknown, then you have to pick some arbitrary maximum dc input to your signal conditioner
circuit (black box). (15V?, 24V ?) Then you have to design a circuit capable of converting said voltage to
the desired 0- 5V dc range for the ATmega328. You might start with a current limited 5V zener diode.
The only caveat is that anything greater than 6V will be read as the maximum 5V input. Is that a problem ?
(that you will not be able to distinguish between 5V and >5V)

AWOL (he said his professor won't let him use a voltage divider) I think a combination of voltage divider with a 5V zener between the divider and the analog input should satisfy his professor's requirement to
protect the uprocessor.

As I wrote I can’t use simple voltage divider. Zener diode maybe is great idea.

Input is 0 - 10 V, but as You wrote my professor asked to protected processor.

Computer application in electrical equipment design.

heninsh:
But now my lecture said so I can't use this, because I can't protect microcontroller from higher input as 5 V if input is more then 10 V.

Seems your lecturer knows very little about electronics.

MCU input pins have internal protection 'diodes' to VCC and ground.
Total resistance of your voltage divider and R3,R4 will limit the current into those diodes.
The posted diagram won't damage your pin with e.g. 24volt on the divider.

If you don't want to rely on those (unspecified) input protection diodes, use two external schottky diodes.
One from pin to ground, cathode to pin, to protect for negative voltages.
And one from pin to VCC, cathode to VCC (5volt), to protect for positive voltages.
Now you can have hundreds of volts on the divider.
The resistors will go up in smoke before the pin gets damaged.

A zener diode is a poor protector.
It does nothing when the Arduino is accidently off, and adds temp and voltage non-linearity to your measurements.
Leo..

"If you don't want to rely on those (unspecified) input protection diodes,"
But we do know Atmel (nowMicrochip) recommends that they conduct no more than 1mA, and they will attempt to hold inputs to Vcc + 0.5V and Gnd -0.5V.

You could also buffer the input with a device like 74HC4050, to accept higher voltage inputs and output at Vcc of say 5V.

Or just a simple transistor as an inverting buffer.

CrossRoads:
But we do know Atmel (nowMicrochip) recommends that they conduct no more than 1mA...

They have released an application note for a zero crossing detector where those 'diodes' are actually used.

24volt (expamle in post#4) is keeping pin current well under 1mA (447uA).

40volt is needed to reach that theoretical 1mA limit.
Leo..

heninsh:
As I wrote I can't use simple voltage divider. Zener diode maybe is great idea.

Input is 0 - 10 V, but as You wrote my professor asked to protected processor.

Computer application in electrical equipment design.

You could use a Zener to cut top input V and then have the voltage-divide circuit. Suppose you could /3 and get values 0 to 15V data, be able to show over-voltages? Only reason not is to give more resolution to the 0 to 10V range. Can you make a circuit with selective range limit?

Also if you have alarm conditions based on measured specs, you might take several measures over a bit of time before sounding alarms, Zeners aren't perfect and AVR's are fast enough to notice even circuit bumps with some degree of detail.

PLCs normally have a analog voltage range of 0 to 10 V, or 0 to 20 mA. Switch inputs are normally 24 V. Many of these PLCs use optical couplers to isolate the input voltage so that an external source can be safely used. Floating grounds can kill your PLC.

Hi,
You can use an a/d converter that can read 8 channel 12bits like the mcp3208 or the LTC1296. It will isolate the micro input from the sensors.

There are some op-amps with built-in overvoltage protection on their inputs. Some are described here: http://www.analog.com/en/analog-dialogue/articles/robust-amplifiers-provide-integrated-overvoltage-protection.html along with some external protection circuits. The op-amp can of course scale your input to 0-5V as well as buffer it and (perhaps) provide input protection.

Be prepared for "sticker shock" - there's a reason that PLC run 10x the price of an Arduino! One of those Analog Devices Protected Op-amps costs more than an ATmega328.

There are lots of articles on protecting op-amp inputs from overvoltage. Here's one from TI: www.ti.com/lit/an/slaa593/slaa593.pdf

Personally, I don't see much difference between providing a voltage divider plus extra protection for the AVR, and using a separate protected op-amp (although, it depends on the A2D - some microcontrollers have a relatively low input impedance that will interfere with most voltage dividers.

A modern trend is to to do the A2D conversion on "the other side" of an isolated digital connection, since isolation wont affect accuracy of digital info. See the SI890x series, for example (pretty cheap, too.) (they probably still need input protection.)

Thanks a lot for your posts! I will check all information.

But what about my 2nd question?

See about a transistor based amplifier circuit.

Hi,
To your second question to convert from pulse train to analog input it is yes you need a capacitor at the end. That will convert pulses train to analog signal.

Another suggestion to protect the micro input from external high voltage it is to use the CD4067. It is a 16 input multiplexer to one. The output it is selected by 4 address signal. That will give you 16 inputs versus 6 using the 328 analog inputs from A0 to A5. You can use A0 to A3 for the address selection and A4 for the input from the multiplexer analog output signal.

Question 2, drive the base of an NPN transistor with the 5V PWM. Pullup up the collector to 10V with a 1K resistor. Emitter to Gnd.
The collector will then have ~0V the base has 5V, and 10V when the base has 0V.
Add a 2nd transistor set up the same way if you don’t want the signal inverted.