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. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,174
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi,
    You could use the method described by 'mdorian' and sample the rectified, unsmoothed waveform.
    [use a low voltage transformer for the ac detection circuit]

    Are you able to program the PIC's adc OK.?
     
    Last edited: Oct 29, 2008
  2. Suraj143

    Suraj143 Active Member

    Joined:
    Jan 11, 2007
    Messages:
    1,564
    Likes:
    2
    Location:
    South Mald Isld
    Thats what I had in my mind.That "mdorians" method.But I got hurt when I heard that ripple problem.

    Is it ok If I sample a unsmoothed waveform?

    Because for the whole project I'm using a 9V transformer.To power the V reg & to give the AD input.
     
  3. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,174
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi,
    The transformer for the sample waveform should not be used to power other devices.
    As the load of the other devices change, so will the sampled waveform.!

    Calculate the maximum sampling/testing loop rate for your program and lets know that value.:)
     
  4. dave

    Dave New Member

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


     
  5. Suraj143

    Suraj143 Active Member

    Joined:
    Jan 11, 2007
    Messages:
    1,564
    Likes:
    2
    Location:
    South Mald Isld

    I mean like this.What about that?
     

    Attached Files:

  6. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,174
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi Suraj,
    I would not recommend using the PIC/7805 transformer for the low voltage 'ac' that you are going to sample.
    Use a small say 2.5VA 4.5V/6V transformer and a low power rectifier to drive the adc input [ resistor scaling]

    I have just written a quickie program for your application, using the 12F675 and its running in my simulator.
     
  7. Suraj143

    Suraj143 Active Member

    Joined:
    Jan 11, 2007
    Messages:
    1,564
    Likes:
    2
    Location:
    South Mald Isld
    Hi Eric thanks for spending time on this.

    So that means do I have to use two transformers?One for PIC power supply & other for AD input?

    I'm still in a doubt about the hardware.How to connect the AD input & the Power for PIC.
     
  8. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,174
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    Let me know the details of the transformer you are using for the sampling waveform and we can work out the details.
     
  9. Suraj143

    Suraj143 Active Member

    Joined:
    Jan 11, 2007
    Messages:
    1,564
    Likes:
    2
    Location:
    South Mald Isld
    I have only one transformer that is 230V/9V (500mA) to power the PIC & to give input to AD.
     
  10. Hero999

    Hero999 Banned

    Joined:
    Apr 6, 2006
    Messages:
    14,902
    Likes:
    79
    Location:
    England
    Why do you want to do this?
     
  11. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,174
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi Suraj,
    Take a look at these two attachments.
    Its a simple demo program, works in the Simulator.

    I have included the *.asm and *.bas [txt] [both same program]
     

    Attached Files:

    Last edited: Oct 29, 2008
  12. Hero999

    Hero999 Banned

    Joined:
    Apr 6, 2006
    Messages:
    14,902
    Likes:
    79
    Location:
    England
    Why are you using a PIC, a comparator with in-built referance will just just as much hardware, cost less and won't require any programming.
     
  13. Suraj143

    Suraj143 Active Member

    Joined:
    Jan 11, 2007
    Messages:
    1,564
    Likes:
    2
    Location:
    South Mald Isld
    Hello eric gibbs thanks for your help.

    PIC has only max 5V input ADC.Can you tell what reference to use?
    I think in this case reference means the output voltage to analog input.:) ex:230V -->2.5V

    I think this for 2.5V am I right?

    If I can scale the 230V AC to 5V ADC I can write the software.Still I'm struggling about what hardware to use.

    I have again attached my earlier drawing please tell me is that the one do I have to use?

    Your earlier method LM393 output polling with PIC is very nice.The problem is I need your help how to calculate the 230V AC inputs to comparator.

    Help me to calculate the inputs in that method.
     

    Attached Files:

    Last edited: Oct 29, 2008
  14. Suraj143

    Suraj143 Active Member

    Joined:
    Jan 11, 2007
    Messages:
    1,564
    Likes:
    2
    Location:
    South Mald Isld
    Hi Hero999.

    As earlier eric suggested a comparator LM393.The thing is I don't know how to give input to the comparator from 230V AC.

    If you have idea on that method please tell.
     
  15. kjennejohn

    kjennejohn New Member

    Joined:
    Mar 19, 2006
    Messages:
    338
    Likes:
    8
    Location:
    Bay Area, California
    Let the PIC do all the work.

    Hi. All you need is a 10K to 20K pot, a resistor from 2.2K to 4.7K and one ADC input on your PIC. The idea is to use the INPUT voltage to your 5V regulator to track the mains INDIRECTLY. That is, you can establish a relationship between the mains voltage and the DC volts at your regulator. As the mains go up and down then that DC voltage follows IF your AC adapter is unregulated and you need a 5V regulator to get the 5v for the PIC. The voltage at your regulator input has already been rectified and smoothed, so just go with it. If you're using a 9V AC adapter and you have 10.1V at the regulator's input when the mains are 230V (these things hardly EVER put out 9V), then it follows that that voltage will fall when the mains go lower and go higher as the mains voltage rise. A simple voltage divider using the pot and resistor will let you set an output voltage range that will include values from 220 to 240 volts, plus probably more either way. Just poll the ADC readings constantly and track the highest readings obtained and use known ADC values to compare against and you'll do just fine.

    So, some questions:
    1. Do you have an ADC input available? If you don't have one, we're done here.
    2. What do you measure at the mains (DMM set for AC) and the regulator's input (DC)?
    3. What value of pot and resistor can you come up with?

    Get back to us with these answers and we'll see if we can't figure ADC values to monitor and supply a simple schematic. I can't help with the code, someone else will have to help you with that.

    Later!
    kenjj
     
  16. Suraj143

    Suraj143 Active Member

    Joined:
    Jan 11, 2007
    Messages:
    1,564
    Likes:
    2
    Location:
    South Mald Isld
    Hi kenjj thanks for your valuable idea.

    1.Yes I have ADC input.
    2.After the bridge rectifier (input to the VREG) I set DC range in DMM.(230AC,12.1DC)
    3.I cant come up with it because I have to concern about ADC input impedance also :)
    4.No need software I can write it. The hardware is my main problem.

    This is the circuit I'm having now.What changes do I have to do?

    Note that input to the VREG voltage is smoothed the earlier guy told that there is a problem with that smoother cap.
     

    Attached Files:

    Last edited: Oct 30, 2008
  17. mdorian

    mdorian Member

    Joined:
    Oct 17, 2008
    Messages:
    64
    Likes:
    0
    Location:
    Romania
    We are assuming that you want the main 220/240 voltage to be insulated from your board , if not, you can skip the second transformer.
    Thwe ADC impedance is too high to be a concern.
    The schematic can be used only with an oversized bridge and transformer. If this is a school project don't use-it. This is not a proffesional way to do a measurement.
     
    Last edited: Oct 30, 2008
  18. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,174
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    Morning Suraj,
    The Vref is the internal Vdd =+5V.

    Go over the calculations:

    You want to to measure/detect a change of 10Vac on the mains input.

    The transformer has a 9Vac secondary, so thats a step down of 25:1,
    so the change of volts on the secondary for a 10V change on the primary is 10V/25 = 0.4Vac.

    If you rectify and smooth the 9Vac you will get approx 1.4*9 = 12.6Vdc less the diode drop, say 12Vdc.

    This 12Vdc is connected via a voltage divider to the PIC's adc input, say down to 4Vdc.
    Thats a further division of 3:1, so for a 0.4Vac change is now 0.4/3 = 130mVolts. [referred as an ac signal].

    My concern is is that if you use the same voltage source to power the PIC and LED's etc,
    everytime the load of the PIC etc is changed the voltage to the divider to the adc is going to change.

    There isnt a great enough voltage margin, in my opinion.

    I suppose the way to prove this, is to build and test it.
    If it dosnt work reliabily, then just get second low voltage transformer/rectifier and use that as the sampled voltage.


    EDIT:
    Suraj, saw this link while doing another thread, as you using the 12F, I thought it would be useful, one day.
    12F675 tutorial 6: Driving a servo motor using a PIC Micro.
     
    Last edited: Oct 30, 2008
  19. mdorian

    mdorian Member

    Joined:
    Oct 17, 2008
    Messages:
    64
    Likes:
    0
    Location:
    Romania
    The input Leakage current for adc input is 1uA , If you use the noninsulated schematic:
    For ADC divider
    Assuming that you use 0.25W resistors
    P = U^2/R so R >= U^2/P = 193,6Kohm
    for R divider = 220 Kohm
    I divider = 220v/220Kohm = 1mA
    The error from the leakage current is 1mA/1uA = 1/1000
    You can use R divider = 220K , pot = 2,2K
    I don't understand why to use a rectifier and a smothener , this can be done in software as Eric did.
    Insulated.JPG
    notinsulated.JPG
     
  20. Suraj143

    Suraj143 Active Member

    Joined:
    Jan 11, 2007
    Messages:
    1,564
    Likes:
    2
    Location:
    South Mald Isld
    Hi mdorian thanks for your diagrams.Thank you very much.

    The reason I use a rectifier and a smothener is because I need an extra transformer.So no place to get sample voltages in my diagram thats the only place I have.

    But in your 2nd transformer can I drive directly the resister divider without using another bridge rectifier to make it DC.?

    Because this formula is getting confused there.1.414 X 9V = 12.726V
    Without a bridge can I use the same formula for that?
     
    Last edited: Oct 30, 2008
  21. mdorian

    mdorian Member

    Joined:
    Oct 17, 2008
    Messages:
    64
    Likes:
    0
    Location:
    Romania
    NO!!
    You sample the AC voltage until you find the peak value, this wil be ACvoltage*√2

    Wait for ADCin >0
    Take samples and keep the highest value until adc sample = 0
    Compare max value with values for 220v and 240v and set LEDs
    Repeat
    Your program must do somethig else to?
     
    Last edited: Oct 30, 2008

Share This Page