## GPIO.input voltage levels vs edge detection

tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

### Re: GPIO.input voltage levels vs edge detection

Brandon92 wrote:
Thu Aug 30, 2018 7:12 am
I did not read it all, because of time.
But what is the working voltage of C2.

10uF minimum.

Don't ask me the details. I skipped all the equations, and dared not to even look the equation with power to the mysteriously scary Euler's number e !
Attachments
eNMjqdw[1].jpg (57.41 KiB) Viewed 2581 times
Last edited by tlfong01 on Fri Aug 31, 2018 1:19 am, edited 2 times in total.
I am an electronics and smart home hobbyist.

Brandon92
Posts: 794
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

### Re: GPIO.input voltage levels vs edge detection

tlfong01 wrote:
Thu Aug 30, 2018 8:58 am
Brandon92 wrote:
Thu Aug 30, 2018 7:12 am
I did not read it all, because of time.
But what is the working voltage of C2.

10uF minimum.
That is the required capacity. And that's not the same as the maximum working voltage of the capacitor itself.

Edit
It the maximum voltage is to low. The capacitor can fly (literly) away or it will produce a lot of smoke.

tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

### Re: GPIO.input voltage levels vs edge detection

Brandon92 wrote:
Thu Aug 30, 2018 9:24 am
tlfong01 wrote:
Thu Aug 30, 2018 8:58 am
Brandon92 wrote:
Thu Aug 30, 2018 7:12 am
I did not read it all, because of time.
But what is the working voltage of C2.
10uF minimum.
That is the required capacity. And that's not the same as the maximum working voltage of the capacitor itself.

Edit
It the maximum voltage is to low. The capacitor can fly (literly) away or it will produce a lot of smoke.

Capacitor's working voltage

You confused me. I vaguely remember that when I started playing capacitors ages ago, I learnt that there are many types of capacitors, including the following:

• 1. High class electrolyte, looking elite, which has polarity and maximum voltage,
• 2. Creamic, which is made of mud, looks ugly, cheap and easy to break, not for elite hobbyists like me
• 3. Tantanum, which looks like a bead, very expensive, usually at least one yuan each.
I am using the Tanranum one, which I remember is at least 50V.

But I better wiki, just to make sure.

Appendix

Tantalum capacitor - Wikipedia

Tantalum capacitors in different styles: axial, radial and SMD-chip versions (size comparison with a match)

A tantalum electrolytic capacitor is an electrolytic capacitor, a passive component of electronic circuits. It consists of a pellet of tantalum metal as an anode, covered by an insulating oxide layer that forms the dielectric, surrounded by liquid or solid electrolyte as a cathode. Because of its very thin and relatively high permittivity dielectric layer, the tantalum capacitor distinguishes itself from other conventional and electrolytic capacitors in having high capacitance per volume (high volumetric efficiency) and lower weight.

Tantalum is a conflict mineral. Tantalum electrolytic capacitors are considerably more expensive than comparable aluminum electrolytic capacitors.

Tantalum capacitors are inherently polarized components. Reverse voltage can destroy the capacitor. Non-polar or bipolar tantalum capacitors are made by effectively connecting two polarized capacitors in series, with the anodes oriented in opposite directions.

e - BBC In Our Time - Available now 43 minutes
https://www.bbc.co.uk/programmes/b04hz49f

Melvyn Bragg and his guests discuss Euler's number, also known as e. First discovered in the seventeenth century by the Swiss mathematician Jacob Bernoulli when he was studying compound interest, e is now recognised as one of the most important and interesting numbers in mathematics. Roughly equal to 2.718, e is useful in studying many everyday situations, from personal savings to epidemics. It also features in Euler's Identity, sometimes described as the most beautiful equation ever written.

With:

Colva Roney-Dougal
Reader in Pure Mathematics at the University of St Andrews

June Barrow-Green
Senior Lecturer in the History of Maths at the Open University

Vicky Neale
Whitehead Lecturer at the Mathematical Institute and Balliol College at the University of Oxford

Producer: Thomas Morris.
I am an electronics and smart home hobbyist.

petermeigs
Posts: 97
Joined: Thu Mar 23, 2017 1:34 pm
Location: Los Altos, California

### Re: GPIO.input voltage levels vs edge detection

IMPORTANT update to schematic!

To my horror, In the previous schematic I have left off two very important resistors. There should be a 4.7k resistor between V3700 pin 6 Vo and rpi GPIO-25 and a 10.0k resistor between the same V3700 pin 6 and MCP3008 pin 1 CH0.

petermeigs
Posts: 97
Joined: Thu Mar 23, 2017 1:34 pm
Location: Los Altos, California

### Re: GPIO.input voltage levels vs edge detection

Here is the updated schematic with the two resistors inserted in the right place.
correctedrpiA3700testCircuit.PNG (57.43 KiB) Viewed 2536 times
This schematic still has some errors in it. Check the +3v and the ground.

I also corrected the value of C2 which should have been 10uF.

I hope no-one built the previous version! Without the resistor to the MCP3008, I burned the insulation off a wire.
I'll see if I can delete the erroneous schematic from the earlier post.

By the way, the values of C-min were calculated for us for 50Hz and 60Hz so I just used those. I found the discussion about the C-min calculation in the App note 1004 helpful. I might try to apply that to my beginning work to see what capacitor value I SHOULD have used instead of the trial and error I did.

Update: Oh Rats! In my haste to get the resistors in, I show the resistor at rpi GPIO pin 25 as 10k. I used 4.7 in my circuit where I got good results.
Update again: Sorry about the flurry of updates. This last schematic should be correct.
Last edited by petermeigs on Sat Sep 01, 2018 6:31 am, edited 1 time in total.

Brandon92
Posts: 794
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

### Re: GPIO.input voltage levels vs edge detection

tlfong01 wrote:
Thu Aug 30, 2018 12:25 pm
• 1. High class electrolyte, looking elite, which has polarity and maximum voltage,
• 2. Creamic, which is made of mud, looks ugly, cheap and easy to break, not for elite hobbyists like me
• 3. Tantanum, which looks like a bead, very expensive, usually at least one yuan each.
Well, this is not true.
1, They look maybe elite, but they can't provide large amount of current. Because of the large ESR.
2, is used all the time as decouple capacitor, and can provide a decent amount of current.
3, most of the time you stay away from them. And only required in a certain application.

Long story short, I think you should watch this. This is I think a well explained. And I also agree that the capacitor is 10uF. But this is not my point! For example. You are using 24VAC, so that is 34Vdc. And if you capacitor is rated at 20Vdc. It will / could do this or this.
And when I chose one, I often use the maximum voltage of the circuit times 2 (at least). And I use only well know brands. So I would chose a capacitor from >70Vdc

So, again what is the voltage that you are using. And this is also the reason why I like the place the capacitor on the output of the device. Because of the low voltage.

petermeigs
Posts: 97
Joined: Thu Mar 23, 2017 1:34 pm
Location: Los Altos, California

### Re: GPIO.input voltage levels vs edge detection

Brandon92 wrote:
Thu Aug 30, 2018 7:12 am
I did not read it all, because of time.
But what is the working voltage of C2.
Thanks for catching that I typo'd the wrong capacitance for C2. It should be 10uF as noted from the App Note 1004. I used a 35v electrolytic capacitor that I had in my box of stuff. The way I read the datasheet is that the voltage across pins 2 &3 clamps at a max of 7.3 volts by the zener diode bridge in the case where AC is across pins 1 & 4. Therefore, 35v capacitor is more than enough. I learned the hard way that over-voltage in electrolytic capacitors cause them to pop as does getting them in backwards. Here is where I also learned that 24vac will pop a 25v capacitor because RMS of 24vac is 1.414 * 2.4 shows a max of 35v, way too much for a 25v electrolytic capacitor. It was an impressive display though.

Brandon92
Posts: 794
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

### Re: GPIO.input voltage levels vs edge detection

petermeigs wrote:
Thu Aug 30, 2018 4:42 pm
Brandon92 wrote:
Thu Aug 30, 2018 7:12 am
I did not read it all, because of time.
But what is the working voltage of C2.
Thanks for catching that I typo'd the wrong capacitance for C2. It should be 10uF as noted from the App Note 1004. I used a 35v electrolytic capacitor that I had in my box of stuff. The way I read the datasheet is that the voltage across pins 2 &3 clamps at a max of 7.3 volts by the zener diode bridge in the case where AC is across pins 1 & 4. Therefore, 35v capacitor is more than enough. I learned the hard way that over-voltage in electrolytic capacitors cause them to pop as does getting them in backwards. Here is where I also learned that 24vac will pop a 25v capacitor because RMS of 24vac is 1.414 * 2.4 shows a max of 35v, way too much for a 25v electrolytic capacitor. It was an impressive display though.
Ehm, maybe you have a point here. You can also measure the voltage across the capacitor. If you apply a the 24vac to the ac input. Than you now it for sure

edit
Yup, my mistake here haha. But my advice is still true, only in another scenario

tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

### Re: GPIO.input voltage levels vs edge detection

tlfong01 wrote:
Thu Aug 30, 2018 8:58 am
Brandon92 wrote:
Thu Aug 30, 2018 7:12 am
I did not read it all, because of time.
But what is the working voltage of C2.
10uF minimum.

Input filtering using 4u7 and 4u7 x 2

Guess which is which?
Attachments
DDWwaia[1].jpg (128.24 KiB) Viewed 2492 times
I am an electronics and smart home hobbyist.

Brandon92
Posts: 794
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

### Re: GPIO.input voltage levels vs edge detection

The one to the left is 2x4.7uF.

tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

### Re: GPIO.input voltage levels vs edge detection

Brandon92 wrote:
Thu Aug 30, 2018 4:25 pm
Well, this is not true.
1, They look maybe elite, but they can't provide large amount of current. Because of the large ESR.
2, is used all the time as decouple capacitor, and can provide a decent amount of current.
3, most of the time you stay away from them. And only required in a certain application.
Long story short, I think you should watch this. This is I think a well explained. And I also agree that the capacitor is 10uF. But this is not my point! For example. You are using 24VAC, so that is 34Vdc.

Really? I though 24VAC rms means 34V pp, one 17V cycle up and one 17V cycle down. After rectifying, becomes 17V pp, both cycles up. In other words, it is OK to use 17V (or for double safety, 34V) rated cap.

Thanks for the David Jones videos. Usually this funny guy teaches me in 10 minutes many more things than I can learn from reading books for an hour. In other words David Jones show is very professionally educational but also very entertaining.

I am glad I learnt many things from him, including the following:

• The metal can capacitors has a pressure vent on the top. No wonder from time to time I carelessly insert capacitors with the wrong polarity, there is no burning smell, but only white smoke coming out from the vent. And only smoke, never explosion for me, perhaps because I am an alertful kung fu fighting guy and react lightning fast to pull the plug before something explodes.
• Why tantalum one are expensive.
• Why it is a good way to use two capacitors in parallel.
I have never heard of the term ESR before. I am not sure what this electronics ignorance implies, perhaps:

• I am a efficient, speed reading guy and automatically skip irrelevant sentences and paragraphs when reading,
• I am a careless and forgetful guy and never remember things that a professional engineer should be cautious and remember.
Anyway, I found the life of a sloppy hobbyist is more enjoyable than a boring, strictly disciplined engineer.
I am an electronics and smart home hobbyist.

tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

### Re: GPIO.input voltage levels vs edge detection

12V DC Solenoid Testing Notes

https://youtu.be/agcqxM9_tt4

Configuration

1. 555 timer generates 4Hz square signal

2. 4Hz signal inputs Ky019 relay control signal terminal In

3. DC12V power connected to Ky019 COM

4. Ky019 NO connected to solenoid (DC12V, 10mm, 0.8N, Model ZYE1-0837ZP).

Appendix

DC 12V Push Type Open Frame Solenoid Electromagnet (ZYE1-0837ZP) by NDRTJM
https://www.amazon.com/Frame-Solenoid-E ... B008ORSXSC

Features:
Open frame solenoid;
Long service life and reliable;
Applications: Vending machines, transport equipment, office facility household appliance, mechanical, etc
Stroke: 10mm
Input Voltage: 12V DC
Attachments
solenoid_2018sep0101.jpg (72.16 KiB) Viewed 2399 times
Last edited by tlfong01 on Sat Sep 01, 2018 2:04 am, edited 1 time in total.
I am an electronics and smart home hobbyist.

tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

### Re: GPIO.input voltage levels vs edge detection

petermeigs wrote:
Thu Aug 30, 2018 6:59 am
The videos explaining various components are helpful and entertaining. later post.[/b]
How to calculate Rx

Yes, the student need to understand basic things like bridge rectifier, zener dioe, Schmitt inverter, optocoupler, pull down resistor etc. But the most two important thing to understand is the following:

• 1. Characteristic of the Schmitt inverter for input voltage in the range of 0 ~ 5V

• 2. How to use Rx to expand the Schmitt inverter's input range to 0 ~ 200V.
To calculate Rx, what you need to know is the Ohm's Law which can be stated as:

If there is a current flowing in Rx, there will be a voltage drop across Rx.

/ to continue, ...
Attachments
asTF0sN[1].jpg (54.26 KiB) Viewed 2456 times
I am an electronics and smart home hobbyist.

Brandon92
Posts: 794
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

### Re: GPIO.input voltage levels vs edge detection

tlfong01 wrote:
Fri Aug 31, 2018 8:14 am
Really? I though 24VAC rms means 34V pp, one 17V cycle up and one 17V cycle down. After rectifying, becomes 17V pp, both cycles up. In other words, it is OK to use 17V (or for double safety, 34V) rated cap.
Yes, see my explanation below.
tlfong01 wrote:
Fri Aug 31, 2018 2:25 pm
Yes, the student need to understand basic things like bridge rectifier, zener dioe, Schmitt inverter, optocoupler, pull down resistor etc. But the most two important thing to understand is the following:
Well let me explain, in fact if you have 24Vac rms it is 34Vac piek. And to get Vpp (piek-piek) you need to multiply the Vp by a factor 2, so you will get 64Vac.
When you use a bridge rectifier you get 34Vdc ( minus the diode drop voltage).

Let me show it by the use of a simulation, the green line is the input voltage (24Vrms) and the red line is what you will get if you use a full bridge rectifier:
In the simulation (SPICE error) I measured the Input voltage his RMS, Piek-piek (PP), Vmax, Vmin.
Simulation full bridge.png (61.52 KiB) Viewed 2451 times
edit
tlfong01 wrote:
Fri Aug 31, 2018 8:14 am
• The metal can capacitors has a pressure vent on the top. No wonder from time to time I carelessly insert capacitors with the wrong polarity, there is no burning smell, but only white smoke coming out from the vent. And only smoke, never explosion for me, perhaps because I am an alertful kung fu fighting guy and react lightning fast to pull the plug before something explodes.
Well the vent is designed so that the capacitor will not explode (safety feature). If you use a capacitor without that vent it will explode and you are not fast enough.

petermeigs
Posts: 97
Joined: Thu Mar 23, 2017 1:34 pm
Location: Los Altos, California

### Re: GPIO.input voltage levels vs edge detection

Are we talking about a 10uF capacitor across the internal bridge in the A3700 when connected to 24vac or are we talking about a plain ol'4 diode rectifier we would want to smooth out?

If we are talking about smoothing 24vac through a 4 diode rectifier, then the RMS calculation (x 1.414 = 34v) would apply and we would want at least a 50v capacitor (or to be safe, use the factor of 2 suggested earlier for a 68v capacitor) . The current is rectified but not smooth so an electrolytic capacitor would be ok assuming you get the polarity right when you install it.

However, if we are talking about the pins 2 & 3 of the A3700, it is a different stroy. On pins 2 & 3, the diode bridge is made of zener diodes that clamp at a typical value (V-ihc2) of 6.7 vdc. I measured 4.9vdc with my ohmmeter across the 10uF capacitor (pins 2 & 3). Since the dc voltage is rectified AC, the RMS factor would be a good approximation giving us 4.9 x 1.414 or 6.93. This matches well with the HCPL-3700 datasheet value for Min= 6.1 and Max=7.3 for V-ihc2.

I think I am missing why the concern for 24vac across the 10uF capacitor. Perhaps there is something I missed in the discussion.

Brandon92
Posts: 794
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

### Re: GPIO.input voltage levels vs edge detection

petermeigs wrote:
Fri Aug 31, 2018 7:22 pm
Are we talking about a 10uF capacitor across the internal bridge in the A3700 when connected to 24vac or are we talking about a plain ol'4 diode rectifier we would want to smooth out?

If we are talking about smoothing 24vac through a 4 diode rectifier, then the RMS calculation (x 1.414 = 34v) would apply and we would want at least a 50v capacitor. The current is rectified but not smooth so an electrolytic capacitor would be ok assuming you get the polarity right when you install it.

However, if we are talking about the pins 2 & 3 of the A3700, it is a different stroy. On pins 2 & 3, the diode bridge is made of zener diodes that clamp at a typical value (V-ihc2) of 6.7 vdc. I measured 4.9vdc with my ohmmeter across the 10uF capacitor (pins 2 & 3). Since the dc voltage is rectified AC, the RMS factor would be a good approximation giving us 4.9 x 1.414 or 6.93. This matches well with the HCPL-3700 datasheet value for Min= 6.1 and Max=7.3 for V-ihc2.

I think I am missing why the concern for 24vac across the 10uF capacitor. Perhaps there is something I missed in the discussion.
What is explained in my last post has nothing to do with the A3700. I explained to tlfong01 how the signals will look like if you use a 4 diode rectifier.
Well, the 1.414 factor has "not much influence" because of the use of the zener clamp and you are limiting the current through the zeners. And if you provide a higher current the voltage will rise at the capacitor. I hope I don't confuse you right now

petermeigs
Posts: 97
Joined: Thu Mar 23, 2017 1:34 pm
Location: Los Altos, California

### Re: GPIO.input voltage levels vs edge detection

No confusion. I was pretty much guessing why voltage across pins 2 & 3 with 10uF capacitor in parallel was the voltage I measured. Then I realized that multiplying by sqrt(2) made the voltage come out right. So I made the leap ---.

To really know, I'll have to dig out some textbooks on RC circuits.

tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

### Re: GPIO.input voltage levels vs edge detection

petermeigs wrote:
Sat Sep 01, 2018 1:44 am
To really know, I'll have to dig out some textbooks on RC circuits.

AC Waveform and AC Circuit Theory - Electronics Tutorials
https://www.electronics-tutorials.ws/ac ... eform.html

Me too. So I read the following tutorials.

1. AC Waveform and AC Circuit Theory
2. Sinusoidal Waveforms
3. Phase Difference and Phase Shift
4. Phasor Diagrams and Phasor Algebra
5. Complex Numbers j , and Phasors

I always found the number π (not to mention e and j), and the functions sine and cosine mysterious (though I am OK in geometry or algebra). So I only read the first two chapters. I skimmed through to Chapter 5, then I recollect why I never understood things like impedance etc, because they use imaginary numbers which are even more mysterious. I can never imagine those unimaginable things.

Sam Cooke - Don't know much trigonometry, Don't know what a slide rule is for - 7,908,540 views
Attachments
ac_conversion_2018sep0101.jpg (65.52 KiB) Viewed 2399 times
Last edited by tlfong01 on Sat Sep 01, 2018 6:37 am, edited 2 times in total.
I am an electronics and smart home hobbyist.

tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

### Re: GPIO.input voltage levels vs edge detection

tlfong01 wrote:
Fri Aug 31, 2018 2:25 pm
But the most two important thing to understand is the following:
• 1. Characteristic of the Schmitt inverter for input voltage in the range of 0 ~ 5V
• 2. How to use Rx to expand the Schmitt inverter's input range to 0 ~ 200V.
To calculate Rx, what you need to know is the Ohm's Law which can be stated as:
If there is a current flowing in Rx, there will be a voltage drop across Rx.

How to calculate Rx

This was the part I got stuck. I read the paragraphs again and again. I concluded the following:

• 1. If you want to set the upper threshold at 5V, say, then you cannot set the lower threshold. In other words, you can set either upper or lower threshold, but not both. Errata 2018sep01hkt2148 - App Note 1004 Example 3 describes how to use Rp to set two thresholds.
• 2. It is easy to calculate the Rx. If you want upper threshold 5V, then there must be a voltage drop at Rx to 3.8V (Schmitt inverter characteristic), and the current must be 2.5mA (Schmitt inverter characteristic) .
• 3. After you calculated Rx, then you can calculate the lower threshold 3.21V using the fixed magic numbers 1.3mA, 2.6V.
• 4. If you want to set the lower threshold say, 4V, then calculate the Rx for 4V, and if you like, you can also calculate the upper threshold.
5. If you set the upper (lower) threshold, calculate Rx, and find the low (upper) threshold does not meet your requirement, then you can use two A3700s, one for upper threshold, the other lower threshold.

Next post, I will try to use A3700 to detect overloading/short circuit of a 12V 5A switching power supply in my home automation project.
Attachments
rx_calculation_2018sep0101.jpg (103.06 KiB) Viewed 2385 times
Last edited by tlfong01 on Sat Sep 01, 2018 1:52 pm, edited 1 time in total.
I am an electronics and smart home hobbyist.

tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

### Re: GPIO.input voltage levels vs edge detection

tlfong01 wrote:
Sat Sep 01, 2018 4:46 am
How to calculate Rx
Next post, I will try to use A3700 to detect overloading/short circuit of a 12V 5A switching power supply in my home automation project.

For my home automation and control project, I am using a switching power supply with the following spec:

• Input = AC220V
• Output = 12VDC 5A
I know if the power supply is overloaded, over 5A (or short circuit), the output voltage will drop below 10V. So I set the lower threshold voltage a little bit below to

V-
= 9V

Then I can calculate
Rx
= (V- - Vth-) / Ith-
= (9V - 2.6V) / 1.3mA
= 4.92K

I don't need any uppper threshold V+, but just for completeness's sake, I can calculate

V+
= (Ith+ * Rx) + Vth+
= (2.5mA * 4.92k) + 3.8V
= 16.1V

I found that my chosen V- of 9V and calculated Rx = 4.92k, V+ of 16.1V matches the values in my experiment results of

V- = 8.6V, Rx = 4.7K , V+ = 15.6V

RE: GPIO.INPUT VOLTAGE LEVELS VS EDGE DETECTION Post by tlfong01 » 2018-Aug-27 Mon 4:06 pm
https://www.raspberrypi.org/forums/view ... 5#p1358137

Update 1 - 2018sep01hkt1701

I went back to compare petermeigs' calculation and explanation of Rx, V-, V+, and surprisingly found that his methods seem different from me. I need to check carefully why.

Update 2 - 2018sep01hkt2126

I read petermeigs' post and found him using Example 2 of App Note 1004. I found his calculations following Example 2. I understand all the steps and found everything OK. There is a possibility that I made a big mistake in interpreting the meaning of V+ and V-.

Another thing is that I only studied Example 1 which is for a different application to Example 2. So of course I did not have the big picture and might have misunderstood something somewhere.

Furthermore, I used Rx recommended by petermeig in my AC24V experiment, with and without input filtering and found everything OK. So if my understanding is fundamentally different from him, it is very likely that my understanding is wrong.

I also read Example 3 and found that in an earlier post I was wrong in saying that two A3700s must be used to set two thresholds precisely. Actually Example 3 describes how to use Rp to set two threshold precisely.

My conclusion is that I have not gained enough knowledge to understand the problem, and I need to read the app notes again and think harder.

Appendix - Petermeigs' Calculation

RE: GPIO.INPUT VOLTAGE LEVELS VS EDGE DETECTION Post by petermeigs » 2018-Aug-28 Tue 9:05 am
https://www.raspberrypi.org/forums/view ... &start=100

I'll do the calculation for resistors for the AC 24 vac case along with the power dissipated.
I will use Electrical characteristics taken from the Feb 2106 Fairchild HCPL3700M Rev 1.1 datasheet and calculate the case for "Example 2. AC operation with no filtering" shown Application Note 1004

Using the Typical (Typ.) values from the HCPL3700 Data Sheet Rev 1.1 for AC on pins 1,4 with pins 2&3 Open we see:
V-th+ 5.00v
V-th- 3.70v
I-th+ 2.40mA
I-th- 1.20 mA

Let's assume the voltage we want to detect is 2/3 of 24vac or 16vac. This makes sure we detect it is on even if the solenoid we expect the circuit is driving cause a voltage drop.

For a resistor R1 in series with pins 1 and 4 of the device, we know that the voltage drop across the HCPL3700 is 5.00 V because that is V-th+.

Since the sum of the voltages around a cirucit must equal 0, we can say that the voltage across R1 is 16vac - 5vac or 11vac. We also know that the current is 2.40mA because that is the current for I-th+. Therefore the resistor R1 would be 11v / 2.4mA or 4.58k ohms.

If we use 2 x 2.2k ohm resistors then 2.4mA * 4.4k would be 10.56 + 5vac or 15.56vac. This is close enough and at any voltage between 15.56vac and 24vac we would detect ac on.

Now that we have picked value for the resistor, the voltage at which we stop detecting the circuit can be calculated. We know the current I-th- to be 1.20mA. The resistor R1 has been chosen to be 4.4k ohms. When the voltage is at the lower threshold, the voltage drop across R1 is 1.20mA * 4.4k ohms or 5.28 vac. V-th- is 3.7v so summing the voltages around the circuit we get 5.28vac + 3.7vac or 8.98 vac
.
I am an electronics and smart home hobbyist.

petermeigs
Posts: 97
Joined: Thu Mar 23, 2017 1:34 pm
Location: Los Altos, California

### Re: GPIO.input voltage levels vs edge detection

The problem I see in what you are doing is that the power supply can never reach V+. And if you set V+ to say 90% of the output rating of the power supply, V- will be too low.

I assume that you are connecting your 12vdc power supply across pins 1 & 4. Since you are using a 12v DC power supply it is already filtered it for you so no capacitor is needed across pins 2 & 3.

It occurs to me that what you really want is to know is when the current is too high. This is one of the applications of the HCPL-3700 but I don't see that this application is discussed in App Note 1004. Take a look at https://www.allaboutcircuits.com/textbo ... er-design/ By putting a very low value (milli Ohm range) and accurate resistance in series with the 12vdc/max 5A circuit we can detect voltage drops across the resistance. We can then calculate the max voltage we will tolerate across resistor and a voltage where we consider the current ok. Here voltages above V+ are bad news and voltages below V- are good news.

We know that I-th+ is 2.5mA and I-th- is 1.3 mA so the resistance can be chosen to fall in this range. We will probably need to follow the notes on how to set both the upper and lower limit.

With any luck we can find an app note where someone worked this all out for us.
Update a couple of days later:
After thinking about this for a while, I realized putting a resistor in series will not be practical, at least not directly with a A3700 dealing with 12vdc and 5amps. The reason is that we would need a resistor capable of causing a voltage drop of at least 6v, the lowest voltage needed for V-th+ (the V-ihc1 case). That would only leave 6v for the rest of the circuit. I suppose we could get transistors involved to use a lower resistance. That would mean a lower voltage drop and then amplify it with a transistor to so the 6v threshold falls in a suitable range suitable range. Perhaps there is a better way. --
Last edited by petermeigs on Sun Sep 02, 2018 8:08 pm, edited 1 time in total.

Brandon92
Posts: 794
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

### Re: GPIO.input voltage levels vs edge detection

What do you mean by "when the current is to high". That should be stated in the datasheet. For the maximum current that is allowed.

I read also some were that you burn our some wire. But that is technical not possible! Because the A3700 is your source. And only vcc (via the pull up) or gnd (via a open collector) and the Rpi and also the mcp have a high impedance. (They are inputs). So the can never burn down a wire. This means that you made a mistake somewhere

petermeigs
Posts: 97
Joined: Thu Mar 23, 2017 1:34 pm
Location: Los Altos, California

### Re: GPIO.input voltage levels vs edge detection

Brandon92 wrote:
Sat Sep 01, 2018 6:09 pm
What do you mean by "when the current is to high". That should be stated in the datasheet. For the maximum current that is allowed.

I read also some were that you burn our some wire. But that is technical not possible! Because the A3700 is your source. And only vcc (via the pull up) or gnd (via a open collector) and the Rpi and also the mcp have a high impedance. (They are inputs). So the can never burn down a wire. This means that you made a mistake somewhere
For "current too high", I meant the current draw on the 12vdc-5A power supply. It has a voltage regulator and it will try to keep voltage at 12vdc as long as it can, until its current limits are reached. I suppose then the voltage will drop.. But really we want to know when, for example, we reach 4.75 Amps. That lets us know we are working properly but are reaching a limit. The circuit would be analogous to implementing an ammeter. I think that if we wait for the voltage output from the 12vdc-5A power supply to drop, we are very late in the process. Anyway, its just an idea. I was going to do the calculations myself but I got bogged down and I have an appointment in 45 mins.

For wire burning: yes, I made a mistake. My kung fu fighter speed is quite slow. I believe the connection was to my ADC channel 1 (MCP3008) from my 5v power supply. I was testing it before connecting it to the rpi. Without a resistor, it was pretty much a short circuit. Anyway, while I agree with your comments, I now add a resistor when unsure and then measure current/voltage drop to make sure there are no more surprises

tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

### Re: GPIO.input voltage levels vs edge detection

petermeigs wrote:
Sat Sep 01, 2018 5:57 pm
1. The problem I see in what you are doing is that the power supply can never reach V+. And if you set V+ to say 90% of the output rating of the power supply, V- will be too low.

2. I assume that you are connecting your 12vdc power supply across pins 1 & 4. Since you are using a 12v DC power supply it is already filtered it for you so no capacitor is needed across pins 2 & 3.

3. It occurs to me that what you really want is to know is when the current is too high. This is one of the applications of the HCPL-3700 but I don't see that this application is discussed in App Note 1004. Take a look at https://www.allaboutcircuits.com/textbo ... er-design/ By putting a very low value (milli Ohm range) and accurate resistance in series with the 12vdc/max 5A circuit we can detect voltage drops across the resistance. We can then calculate the max voltage we will tolerate across resistor and a voltage where we consider the current ok. Here voltages above V+ are bad news and voltages below V- are good news.

We know that I-th+ is 2.5mA and I-th- is 1.3 mA so the resistance can be chosen to fall in this range. We will probably need to follow the notes on how to set both the upper and lower limit.

4. With any luck we can find an app note where someone worked this all out for us.

1. Yes, what you are saying:

• " if you set V+ to say 90% of the output rating of the power supply, V- will be too low."
is one of my headaches. I need to think harder to cure my headache.

2. I also agree youe saying that:

• 12v DC power supply it is already filtered it for you so no capacitor is needed across pins 2 & 3.
Actually I only used the variable power supply to test the V+, V- values for a range of Rx resistor values. If I am going to detect DC12V only, of course I will not use a cap. But if I connect the DC AC inputs together (pins 1 to 2, 3 to 4), then perhaps there is no harm leaving the cap there. But I have not thought about that deeply. Just a brainstorming comments.

3. Using a current meter to detect power supply overload is one solution. I also found App Note 1004 saying that A3700 can detect not only voltage V+, V- but also current. I either found the detecting current thing in the App Note 1004.

4. I might randomly google and find another app note to help us.
I am an electronics and smart home hobbyist.

tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

### Re: GPIO.input voltage levels vs edge detection

Brandon92 wrote:
Fri Aug 31, 2018 5:38 pm
1. if you have 24Vac rms it is 34Vac piek.
2. to get Vpp (piek-piek) you need to multiply the Vp by a factor 2, so you will get 64Vac.
3. when you use a bridge rectifier you get 34Vdc ( minus the diode drop voltage).
4. let me show it by the use of a simulation,
5 Well the vent is designed so that the capacitor will not explode (safety feature). If you use a capacitor without that vent it will explode and you are not fast enough.

AC 24V values - rms, peak, peak to peak, bridge rectified DC

1, 2, 3 - Many thank for your detailed explanation and Spice simulation. Now let me summarize:

AC24V means the following:

• Peak (Max) = +24 * 1.414 = + 3.39V = +34V
• Min = -34V
• Peak to Peak = 34 * 2 = 68V
• DC after bridge rectificaion = +34V (minus diode drop)
4. Spice simulation is very good. I heard of Spice but never used before.

5. Your are right. Very likely all my metal can capactiors are cheapies and should not have any safety smoke vent. I guess they don't explode because I only place them with the wrong polarity. If I apply over voltage, say, 30V to capacitors rated at 10V, they should explode faster than lightning.

PS - I once thought "piek" was a typo error, but Wiktonary tells me it is "peak" in Dutch.
I am an electronics and smart home hobbyist.