CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Protection for Analog Inputs?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dmurray



Joined: 29 Dec 2005
Posts: 5
Location: Edmonton, AB

View user's profile Send private message Send e-mail

Protection for Analog Inputs?
PostPosted: Thu Dec 29, 2005 8:31 pm     Reply with quote

I'm working on a project which uses a 16f877 as the controller for a security system. Security systems typically use an end-of-line resistor at the end of each sensor loop. This way, three different loop states can be monitored (normal, open, shorted).

To implement this, I was considering using one 8 bit analog input for each sensor loop. Each state would therefore corresond to a digital value of 0, 128, or 255. But because the loops can sometimes be fairly long (up to 500 ft.), I'm a bit concerned about noise and transients being picked up and either damaging the analog inputs, messing with the conversions, or causing other problems for the PIC.

First of all, are the analog inputs on the PIC fairly robust, or is some sort of external input protection generally recommended? If so, what would be the best protection method? I don't want to add any capacitance, so I was think of using zeners or transorbs. Does anyone have other suggestions? Perhaps opto-isolation?

Thanks for any ideas you can offer.
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Re: Protection for Analog Inputs?
PostPosted: Thu Dec 29, 2005 8:56 pm     Reply with quote

dmurray wrote:
First of all, are the analog inputs on the PIC fairly robust, or is some sort of external input protection generally recommended?

I would recommend clamping diodes to ground and to +5V. Transorbs could also be useful for ESD protection.

Use shielded cable to reduce EMI, or best of all - use shielded differential pair and instrumentation amp.
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Dec 29, 2005 9:11 pm     Reply with quote

Quote:
Use shielded cable to reduce EMI, or best of all - use shielded differential pair and instrumentation amp.


I would not do this for a commercial product because the cost would be too high.

I would use a the clamping diodes as suggested plus a pullup resistor to VDD (obviously) and a series resistor to the loop. I would also add a capacitor - the reason being they are a cheap for of protection and will help filter the transients plus the scan rate for these types of inputs is so low (10s of milliseconds to 100s of milliseconds) that the effect of the capacitor is insignificant.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!


Last edited by asmallri on Thu Dec 29, 2005 9:23 pm; edited 1 time in total
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Thu Dec 29, 2005 9:21 pm     Reply with quote

asmallri wrote:
Quote:
Use shielded cable to reduce EMI, or best of all - use shielded differential pair and instrumentation amp.


I would not do this for a commercial product because the cost would be too high.


OK, then 4-20mA current signalling on a simple twisted pair without shield. If the cuurent goes below 4mA - the circuit is broken. 500ft of a single-ended analog voltage signal without shield just doesn't sound right.
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Dec 29, 2005 9:24 pm     Reply with quote

Quote:
OK, then 4-20mA current signalling on a simple twisted pair without shield. If the cuurent goes below 4mA - the circuit is broken. 500ft of a single-ended analog voltage signal without shield just doesn't sound right.


We have concensus on the technique. However, my own house alarm has 30 plus zones, each zone having its own loop. Even at 4mA, the loop drain would be too high considering the system must be capable of running from battery in the event of power failure. Ideally the loop currents would want to be 100 times lower.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Fri Dec 30, 2005 2:31 am     Reply with quote

Quote:
However, my own house alarm has 30 plus zones, each zone having its own loop. Even at 4mA, the loop drain would be too high considering the system must be capable of running from battery in the event of power failure.


4mA * 30 = 120mA. I wonder, what kind of battery does you alarm system have? Even the alcaline AA cells have one the order of 1Ah, don't they? How long does the system have to work without the line power?
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Dec 30, 2005 8:54 am     Reply with quote

Quote:
4mA * 30 = 120mA. I wonder, what kind of battery does you alarm system have? Even the alcaline AA cells have one the order of 1Ah, don't they? How long does the system have to work without the line power?


Just becayse you asked - my alarm system is an Ademco unit which is configured with 4 x 12 Volt 3AH batteries. I have 32 loops, plus two alarm extensions, 3 panels panels, alarm relay, auto dialer etc and I expect the alarm system to survive for at least a long weekend (3 days) without power. Why waste 120mA on idle loops when exacty the same supervision could be accomplished with 1 mA?
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
dmurray



Joined: 29 Dec 2005
Posts: 5
Location: Edmonton, AB

View user's profile Send private message Send e-mail

Re: Protection for Analog Inputs?
PostPosted: Fri Dec 30, 2005 4:14 pm     Reply with quote

Thanks for the suggestions guys. I really like the idea of using a current loop. The only problem I see with this is that the 4-20mA (or whatever) current transmitter obviously has to be co-located with the alarm sensor at the "far" end of the loop so that the transmitter can adjust the loop current based on the sensor state.

That means that I have to provide power for the current transmitter either from the panel over a second twisted pair, or from a battery located with the transmitter/sensor.

I'll have to do some research into constant current sources and see what might be involved in doing this. 500 ft of 24 ga. twisted pair has about 25 ohms of DC resistance. At 5mA, that only works out to a voltage drop of 0.125 volts which is certainly workable.

Now, assuming all of the above works, once I have an analog voltage to feed into the PIC, I assume I would just read the values for each analog port in an endless loop. Do I need to wait for the ADIF interrupt before using the value, or can I just insert a delay between each measurement like in the EX_ADMM.C sample program?

Thanks again.
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: Protection for Analog Inputs?
PostPosted: Fri Dec 30, 2005 8:50 pm     Reply with quote

dmurray wrote:
Thanks for the suggestions guys. I really like the idea of using a current loop. The only problem I see with this is that the 4-20mA (or whatever) current transmitter obviously has to be co-located with the alarm sensor at the "far" end of the loop so that the transmitter can adjust the loop current based on the sensor state.



No. It does not mean this. Lets assume for argument sake we use a 22K termination resistor at the end of the loop (used to detect open circuit). This connects to the A/D input of the PIC via a 22k series resistor (input protection) and a 22K pull up resistor to VDD. And assume VDD = 5 V.

When the loop is idle the voltage at the PIC with be VDD * (22 + 22)/(22 + 22 + 22) = 3.33 volts. If the loop fails open the voltage at the A/D input will be VDD = 5 volts. If the loop is shorted the voltage at the A/D input = VDD * 22 / (22+22) = 2.5 volts

The resistance of the cable is low low, wrt to series resistance and the loop terminating resistor that it can be ignored.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
dmurray



Joined: 29 Dec 2005
Posts: 5
Location: Edmonton, AB

View user's profile Send private message Send e-mail

Re: Protection for Analog Inputs?
PostPosted: Sat Dec 31, 2005 9:43 pm     Reply with quote

asmallri wrote:

No. It does not mean this. Lets assume for argument sake we use a 22K termination resistor at the end of the loop (used to detect open circuit). This connects to the A/D input of the PIC via a 22k series resistor (input protection) and a 22K pull up resistor to VDD. And assume VDD = 5 V.

When the loop is idle the voltage at the PIC with be VDD * (22 + 22)/(22 + 22 + 22) = 3.33 volts. If the loop fails open the voltage at the A/D input will be VDD = 5 volts. If the loop is shorted the voltage at the A/D input = VDD * 22 / (22+22) = 2.5 volts


But this is just a voltage divider circuit, which means we're back to where we started. It will certainly work, but it will be susceptible to various sorts of noise, RF, and other common mode signals with long runs of UTP.

When "Kender" suggested the current loop concept as an alternative to using single-ended voltage signalling, I thought it was a great idea. Maybe we're talking about two different things, but my understanding of 4-20mA current signalling (as used for instrumentation applications) is that the transmitter is a constant current source which sets the loop current based on the sensor state. By doing it this way, the loop can be miles long without signal loss or noise becoming a problem. Telephone subscriber loops work in much the same way. By modulating the loop current at an audio rate, voice can be carried on unshielded copper for many miles.

I've been looking at some current regulating diodes which might work in this application. Failing that, Texas Instruments also has some nice current loop transmitter ICs.

Thanks again to both of you for your comments and suggestions.
Storic



Joined: 03 Dec 2005
Posts: 182
Location: Australia SA

View user's profile Send private message Send e-mail

PostPosted: Sat Dec 31, 2005 11:13 pm     Reply with quote

Hi

Why not when reading the input, allow a +/-10% error of the required value. this will allow for any drift due to cable lenght, heat etc; Also write your code to respond say 3 to 5 reads (to allow for power spike induced onto the cable). if all reads are within the same value a required responce will then be activated

ANdrew
_________________
What has been learnt if you make the same mistake? Wink
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: Protection for Analog Inputs?
PostPosted: Sun Jan 01, 2006 12:14 am     Reply with quote

dmurray wrote:
But this is just a voltage divider circuit, which means we're back to where we started. It will certainly work, but it will be susceptible to various sorts of noise, RF, and other common mode signals with long runs of UTP.


Yes it is a voltage divider. Hence the capacitor as a filter - more than enough to meet the original requirement for a security system.

Quote:
Telephone subscriber loops work in much the same way. By modulating the loop current at an audio rate, voice can be carried on unshielded copper for many miles.


I spent several years as an equipment designer in the network design group for a large Telephone company designing such equipment. The voice signal is differentially superimposed as an ac voltage on the loop.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
dmurray



Joined: 29 Dec 2005
Posts: 5
Location: Edmonton, AB

View user's profile Send private message Send e-mail

PostPosted: Sun Jan 01, 2006 12:17 am     Reply with quote

Storic wrote:


Why not when reading the input, allow a +/-10% error of the required value. this will allow for any drift due to cable lenght, heat etc; Also write your code to respond say 3 to 5 reads (to allow for power spike induced onto the cable). if all reads are within the same value a required responce will then be activated

ANdrew


Yes that's a good idea. Basically the analog equivalent of debouncing a switch. I was thinking of using ReadADC() in an endless loop in my main() function to poll the connected analog inputs. In the ADIF interrupt handler, I'll start a timer (perhaps 200ms). When it overflows, I'll check the value again. If it's within 5-10% of the first reading then it should be a valid sensor state change. I haven't worked with analog inputs on the PIC before so my theories may not work at all, but you have to start somewhere. Thanks for your suggestions.
dmurray



Joined: 29 Dec 2005
Posts: 5
Location: Edmonton, AB

View user's profile Send private message Send e-mail

Re: Protection for Analog Inputs?
PostPosted: Sun Jan 01, 2006 12:45 pm     Reply with quote

asmallri wrote:

I spent several years as an equipment designer in the network design group for a large Telephone company designing such equipment. The voice signal is differentially superimposed as an ac voltage on the loop.


Er.. no, although that is a common misconception. Only the ringing signal which consists of a 90-120VAC 20Hz sinewave is superimposed on the DC talk battery. The original phone design actually used a carbon granule microphone wired in series with the subscriber loop. When the user spoke into it, the resistance of the microphone changed at an audio rate which served to modulate the loop current at the same rate. At the CO end, the audio was recovered using an ingenious split winding transformer arrangement.

While phones haven't used carbon microphones since the seventies, the electret mic/transistor arrangement that replaced it does exactly the same thing. What is truly amazing is how little modern phone designs have changed over the last hundred years. While semiconductors and computer technology have improved performance and reliability at both ends, the basic design of the 2 wire copper subscriber loop remains functionally the same. A testament to the genius of the original designers.

Happy New Year.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group