1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

How to Detect Exceed AC Voltage

Discussion in 'Microcontrollers' started by Suraj143, Oct 28, 2008.

  1. mdorian

    mdorian Member

    Joined:
    Oct 17, 2008
    Messages:
    64
    Likes:
    0
    Location:
    Romania
    Last edited: Oct 30, 2008
  2. Suraj143

    Suraj143 Active Member

    Joined:
    Jan 11, 2007
    Messages:
    1,586
    Likes:
    2
    Location:
    South Mald Isld
    Hi mdorian my program is like this.

    This is an example

    For 230V AC, the AD input voltage is let say 4.0V
    For 220V AC, the AD input voltage is let say 3.8V
    For 240V AC, the AD input voltage is let say 4.2V

    I just sample AD (but not repeatedly) & compare the result.So I can sample AD at any time like half a second etc.....

    In this method there is no any peak stuff there.Just sample the DC..........
     
    Last edited: Oct 30, 2008
  3. mdorian

    mdorian Member

    Joined:
    Oct 17, 2008
    Messages:
    64
    Likes:
    0
    Location:
    Romania
    The time for ADC conversion is ~ 150us, for an accurate result (without a bridge and a smothener) you need to take a least 20 samples in a semiperiod (10ms) -> a sample in 500us. You just start AD conversion and do something else for 500us or use ad interrupt and do something else in the main program. If not , use a bridge and a smoothener for the second transformer. The load (a resistor , can be the divider) for a response time can be calculated (approx) like that : time = 0,025ζ, where ζ= RC
    for time = 0.5s and C = 220uf -> R = ζ/C = 40*0.5/(220*10^-6) ~ 90Kohm
    (including the ADC-in divider)
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. mdorian

    mdorian Member

    Joined:
    Oct 17, 2008
    Messages:
    64
    Likes:
    0
    Location:
    Romania

    An improved schematic for smoothener will look like that:
    withbridge.JPG
    D4 and D5 must be identical with the bridge diodes to compensate the temperature coefficient of the bridge
    C3 = 220uF
    R1+R2= 50..100 Kohm
     
    Last edited: Oct 30, 2008
  6. Suraj143

    Suraj143 Active Member

    Joined:
    Jan 11, 2007
    Messages:
    1,586
    Likes:
    2
    Location:
    South Mald Isld
    Hi mdorian that will be fine thats a good way I believe.I'll workout right now.Thanks for your precious time.

    One more thing mdorian

    what happens when the adc input goes negative?
     
  7. mdorian

    mdorian Member

    Joined:
    Oct 17, 2008
    Messages:
    64
    Likes:
    0
    Location:
    Romania
    It doesn't matter , the ADc input have clamp diodes. As long as you don't exceed the max input current it's ok. Use a pot > =1kohm (at 5v this means 5mA) and you're safe. The ADC input will be 0
    pin.JPG
     
    Last edited: Oct 30, 2008
  8. Suraj143

    Suraj143 Active Member

    Joined:
    Jan 11, 2007
    Messages:
    1,586
    Likes:
    2
    Location:
    South Mald Isld
    Hi mdorian

    Thanks for your diagrams.

    The circuit must be isolated.First I'm going to check the attached diagram, I changed the voltage dividers resister values please tell are they correct or not?

    After I'm going to add the 2nd transformer like your one.

    Also tell your edited final circuits resister values.Is that two diodes still there?
     

    Attached Files:

  9. kchriste

    kchriste New Member Forum Supporter

    Joined:
    Jul 23, 2006
    Messages:
    3,677
    Likes:
    47
    Location:
    Victoria BC, Canada
    You need to flip the pot and the resistor around like this:
     

    Attached Files:

  10. Suraj143

    Suraj143 Active Member

    Joined:
    Jan 11, 2007
    Messages:
    1,586
    Likes:
    2
    Location:
    South Mald Isld
    Hi kchriste thanks for showing that mistake.Whats that cap thing near the pot?
     
    Last edited: Oct 30, 2008
  11. mdorian

    mdorian Member

    Joined:
    Oct 17, 2008
    Messages:
    64
    Likes:
    0
    Location:
    Romania
    The cap in for noise suppression and better filtering the dc voltage use 1uF ..10 uF polarized cap. How big is your transformer?
     
  12. Suraj143

    Suraj143 Active Member

    Joined:
    Jan 11, 2007
    Messages:
    1,586
    Likes:
    2
    Location:
    South Mald Isld
    Hi mdorian my tramsformer is 230V/9V-500mA.

    Another point to take into account.The project going to work all 365 days so the transformer may get heat.Will it cause to sample voltage?

    Also if the AC input from the mains if exceed let say 260V will it burn the transformer?

    Whats your comments on longer life run on this project?
     
  13. kjennejohn

    kjennejohn New Member

    Joined:
    Mar 19, 2006
    Messages:
    338
    Likes:
    8
    Location:
    Bay Area, California
    Yes, the last two schematics are what I had in mind. are what I had in mind.

    Sorry it took me so long to get back.
    Forget about a second transformer and all that. Your existing DC supply will do nicely.
    I'm thinking mdorian's cap at the pot is unnecessary, but it can't hurt.
    A simple experiment might clear a lot up here. The windings in the AC adapter's transformer are fixed. The windings ratio is something like 25.55:1. So, put 230 in, get approx. 9V out. Put in 220, get 8.61V. Put in 240, get out 9.39V. So, the voltage at the regulator's input, even after rectification and filtering (smoothing) will go up and down with the mains voltage. The regulator's 5V output remains constant, and the divider's output is much lower than the 5V reference, so don't sweat it. The ADC's input is high impedance, and the divider's resistance to the PIC is a couple of K, so don't sweat THAT. If you could get a Variac and run your board off it, you could literally discover what the actual DC voltages will be at your regulator input. Better yet, if you have the divider built and working, you could find the output voltages for THAT compared to the two mains extremes.

    If you can't, then you can figure there is a close relationship between the mains voltages and the DC in (and the divider's output) and experiment to come up with the approximate divider voltages for the AC voltage ranges you want to monitor. For now, install one of the dividers as provided by mdorian or kchristie. (thanks, guys, saves me the trouble of cranking up the OrCAD). Set the divider pot for 2.5V. This is the middle of the ADC's input range, which internally is 512 or 513 (200 HEX). Remember, being a 10 bit device means the internal values are 0 to 1023 (3FF HEX). If the mains happen to measure 230V at this time, BINGO, you're right on. The divider's output will be higher then 512 when the mains are 240; it will be less then 512 when the mains are 220. Each of these 1024 steps is 4.88mV each. As can be seen above, the AC adapter's output is 390MV difference between the adapter's 9V at 230V AC and the two outermost mains voltages. So, 390/4.88 is 79, or 4F HEX, which means the outer readings are 79 greater or less than the 512 in the middle (i.e., 1B1 HEX for 220V, 24F for 240). I can't swear this is true after rectification and filtering, though. This is where a Variac would be a real help. Otherwise, you have to just sit there and constantly measure the mains versus the divider's output to get the exact values. No doubt someone here will give us a mathematical way to figure this.

    Hope that helped!
    kenjj
     
    Last edited: Oct 31, 2008
  14. Suraj143

    Suraj143 Active Member

    Joined:
    Jan 11, 2007
    Messages:
    1,586
    Likes:
    2
    Location:
    South Mald Isld
    Hi kenjj thanks for your clever explanation that settles lots of problems.I was also waiting for your reply bcuz you also in the same boat with me "Let the PIC do all the work" :D

    I think you referred to kchriste's diagram.

    After seen your examples I decided to go for 10bit AD rather than 8bit to get a wider gap.
     
    Last edited: Oct 31, 2008
  15. mdorian

    mdorian Member

    Joined:
    Oct 17, 2008
    Messages:
    64
    Likes:
    0
    Location:
    Romania
    1) the transformer will not burn in 260V
    2) As kjennejohn said you have a 700mV margin , the diodes have 2mV/C coefficient. 2diodes with worst case 40C temperature lowest/ highest means 80mV error
    3) Try this : measure the voltage after the bridge with a precise multimeter having all LEDs off. Put the LEDs on and measure the voltage again. If there is a difference higher than 50..100 mv you need more powerful transformer.
     
  16. kchriste

    kchriste New Member Forum Supporter

    Joined:
    Jul 23, 2006
    Messages:
    3,677
    Likes:
    47
    Location:
    Victoria BC, Canada
    Yes, as mentioned by mdorian, the cap is for noise suppression.
    To keep the current consumption constant you could add extra resistors so that the circuit always draws the same amount of current whether the LEDs are on or off:
     

    Attached Files:

  17. kjennejohn

    kjennejohn New Member

    Joined:
    Mar 19, 2006
    Messages:
    338
    Likes:
    8
    Location:
    Bay Area, California
    The study of consequences asks...

    if you find yourself standing in a pool of vomit up to your lip
    and someone throws a turd at your head
    do you duck?

    You're worried about damage at 260Vac when you have a system designed to warn you when the mains reach 240Vac?! Use that PIC to sound a Piezo buzzer to warn you instead of lighting an LED! Install a fuse in there somewhere! Your AC adapter will put out 10.2vac, which your supply will probably crank up to 18 to 20Vdc. This will lead to your regulator getting warm enough to brand the manufacturer's logo on your finger if you touch it, and make you wish you'd installed a heat sink. I rather doubt much else will happen. The divider may put out 5V at that point. If this thought worries you, install a 1K resistor for limiting between the divider's output and the PIC's ADC pin and go back to sleep.

    Mmm, yes, having said that, we need to consider how to handle inconsistencies at your regulator's input voltage. You already have ripple on top of the DC, and the changing current draw in your circuit when turning LEDs on and off (or anything else you may add later) will create small, but worrying, changes in voltage at the regulator's input, which means also at the divider's output. You can always make the filtering (smoothing) capacitor in the power supply larger so it "fills in" the sudden draws in current better. To a point. So, you need to introduce hysteresis into your code when monitoring voltages.

    Hysteresis is where you redefine what a set point is to deal with noise and "jitter". In our previous discussion, the ADC value for 230V was 200 HEX, 220 was 1B1 HEX, and 240 was 24F HEX. However, these values will change rapidly because of noise in the wiring, the ripple in the supply voltage, and the natural jitter in the ADC itself. This jitter in values when you reach a set point will cause rapid changes in the PIC's evaluation of "good/bad" levels.

    Let's say you reach 240V on the mains, which is the 24F in the ADC. This reading may go up and down around this value several hundred times a second. That LED is going to get a real work out! Hysteresis solves this problem. When you reach 240V, 24F HEX, you subtract 10 (0A in HEX) from the 24F. This means the jitter or other noise no longer has an effect unless the mains actually drop a few volts below 240. When it finally drops, and you reach the new lower trip point, you add 10 to the set point and you're back where you started. I picked 10 because I noticed in measurements of ADC jitter, readings can swing 3 to 4 counts from the center point.
    As for reaching 220, you ADD 10 and wait for the mains to rise.

    As for voltage differences caused by current draw changes, with 390mV between 230 and the other extremes, this only a factor if you are REALLY close to the extremes. If supplying 20mA to an LED causes enough drop to defeat the hysteresis value of 10, then make it 15 and change this value BEFORE you turn the LED on or off.

    And if all this really, really worries you, then go with the separate transformer/power supply suggested earlier for your mains reference. This only has the steady state divider on it, no sudden drops/rises from sudden current draws. You'll still have to use hysteresis to get past problems with ripple, noise and ADC jitter.

    Hope this helps. Did you duck?
    kenjj
     
  18. Suraj143

    Suraj143 Active Member

    Joined:
    Jan 11, 2007
    Messages:
    1,586
    Likes:
    2
    Location:
    South Mald Isld
    What to Measure AC Differece or DC output Difference?

    Hi guys I thank you again for the extreme support.

    I made the circuit & wrote the software & checked & measured voltages all the time.

    According to kenjj method you are measuring the transformers output AC voltages.

    230V=9V AC
    240V=9.39V AC
    220V=8.61V AC

    So the different is 390mV. That is 390/4.88 = 79.

    But When I measured the AD inputs DC voltages I got these values.

    Code (text):

    Supply    AD Input Voltage

    220V    =   2.39 DC
    230V    =   2.50 DC
    240V    =   2.61 DC
    So the different is 110mV after resister dividers to AD input.That is 110/4.88 = 22

    I wrote the software for this 22 value.Am I correct or not?Do I need to take the 390mV difference or this 110mV difference ?
     
    Last edited: Nov 2, 2008
  19. Suraj143

    Suraj143 Active Member

    Joined:
    Jan 11, 2007
    Messages:
    1,586
    Likes:
    2
    Location:
    South Mald Isld
    How to ADD Hysteresis ??

    You are totally correct.Thats what I need to know.Please help me on that.

    I have only one relay for 230V & Two LEDs for 220V & 240V.The relay is always on when AC is 230V & off when the AC voltages go below or above 220 & 240.

    I wrote the software without Hysteresis oh my god that relay toggles so much fast when its closing the set point.That is very bad.So I need to add Hysteresis as you said.

    I'm in doubt of some things please help me to add Hysteresis :)

    When AD Reading reach setpoint (24F) I'll subtract 10 from the setpoint.So I get a new set point.
    After again read the AD value & wait until the new AD reading reached the new set point.
    When AD value reached the new set point add 10 to the set point.So now the set point is still same as earlier that is (24F).

    Now what to do?So when I turn on the 240V LED?
     
  20. kjennejohn

    kjennejohn New Member

    Joined:
    Mar 19, 2006
    Messages:
    338
    Likes:
    8
    Location:
    Bay Area, California
    Cool! So you have the actual divider voltages for the mains voltages to work with! I said this would work best if we could measure the actual ADC input voltages.

    So, we have a difference of 110mV both ways. And you calculated that is 22 in the ADC. So, your limits are 512-22 (using decimal here), i.e., 490 (1EA HEX), for 220, and 512+22, i.e., 534 (216 HEX), for 240. Let's remember the ADC's center point is 512 (200 H).

    For 240V, when you get up to 534 (216 H), reset your set point for 524 (20C H) and wait for the mains to come back down to that. When you're back down to 524, reset the high set point to 534.

    For 220V, when you get down to 490 (1EA H), ADD 10. Your new set point is 500 (1F4 H). You wait for the ADC to rise back to 500, at which point you reset the low set point to 490.

    Thus, for 220V: hit 490, set->500 (turn on LED, relay off), rise to 500, set back to 490 (LED and relay back to normal).
    For 240V: hit 534, set->524 (LED on, relay off), fall to 524, set back to 534 (LED and relay back to normal).

    The total effect is: You have 10V leeway at the mains from 230V either way before an LED comes on and the relay drops out. But, once you hit a limit, you have to get back to within five volts or so of 230V to recover. Make the set point differences smaller (say, 5 instead of 10) if you want to turn back on closer to 230V. But, you run the risk of noise and ripple undoing your set points.
    BUT you have to leave power on at the PIC. I hope your're not insulted by that warning. People do miss that *oopsy!* once in a while!

    And that should do it!
    kenjj
     
  21. Suraj143

    Suraj143 Active Member

    Joined:
    Jan 11, 2007
    Messages:
    1,586
    Likes:
    2
    Location:
    South Mald Isld
    Making a 5V difference will give us a stable operation.But needs to wait until the AC voltage rises upto that 5V.

    For the time being I sampled AD 500mS time.By using your hysteresis method I hope I can sample AD continuously or any time without getting the relay to be toggled.

    Also I placed a 10uF polarized cap near the AD pin.

    I think I got all the solutions to my problems.

    Thank you very much kenjj for the support.You all helped me to make that project smoothly.

    Thanks again
     
    Last edited: Nov 2, 2008

Share This Page