Embedded Systems and Power Electronics

Total Pageviews

About Me

My photo
I am currently a PhD student at UC Berkeley, following a 6-year journey working at Apple after my undergrad years at Cornell University. I grew up in Dhaka, Bangladesh where my interest in electronics was cultivated, resulting in the creation of this blog.

BTemplates.com

Powered by Blogger.

Feb 16, 2014

Automatic voltage stabilizer (AC-AC) with PIC16F873A - circuit, explanation, PCB, source code, videos and loads of pictures!




Download links for the article: 

Google docs (go to the link, click File in the PDF window, then click Download):
https://docs.google.com/file/d/0B4SoPFPRNziHb3VrX3JhWko3d1E/edit

Scribd link: http://www.scribd.com/doc/207498741/Automatic-Voltage-Stabilizer-with-PIC16F873A

4shared download link: http://www.4shared.com/office/ktU0k9dqba/Voltage_Stabilizer.html



You can download all the files related to the voltage stabilizer:

Google docs (go to the link, click File in the PDF window, then click Download):

PCB images:
 

 


110 comments:

  1. nice post sir plz do a project on z source ac to ac boost voltage regulator (transformer less stabilizer)

    ReplyDelete
  2. Great effort as usual thanks for the knowledge shared. please can you give a circuit of the input Voltage sensing especially the resistors. I guess u finally used the 47k resistors in series which gives 282k (47kx6) and in parallel with 3k3 resistor. Am i rite?

    Doing a little calculation:

    230v Ac = 325v Dc (after rectification and filtering.)

    using voltage divider rule

    vout = vin x r2/(r1+r2)

    r1 = 282k, r2 = 3k3, vin = 325vDC

    then vout will be ~ 3 to 3.5v Dc.

    1. is this how you come about the input voltage conversion and sensing? and please what re the power rating of the resistors.

    2. the filtering cap after the rectifier, is it polarised or non-polarised

    3. what is voltage rating of the capacitor after the rectifier.

    thanks

    ReplyDelete
    Replies
    1. Yes, that's how I got there. Except, for the AC to DC, I didn't use 1.4142 but 1.3836.

      The bulk filtering capacitor is polarised. The one on the voltage sense section (high voltage section) - C1 - is to be rated for at least 450V.

      Regards,
      Tahmid.

      Delete
    2. Hello Tahmid,
      The code is not working. First I compile with MikroC Pro, it compile with errors. I've corrected the errors it compile but no reactions at all. No display, no blinking or even a spark.
      please what can I do

      Delete
  3. Hi again, I was going through the code and i must say you ve really done a very good job in creating a good algorithm within a short time.
    But i just want to be clear about the something in the code.

    You said 6 X 47k ohms resistor in series and 3k3 ohm were your final selection for the voltage divider. but this portion of the code says otherwise.

    //Voltage_FLOAT = Voltage_FLOAT + 1.5;
    /* Use 100k and 1k resistors for voltage division
    * Divide by 1.3836 to convert from DC voltage to AC
    */

    2. please can you throw more light on this (Voltage_FLOAT = (float)((float)ADC_Get_Sample(Vin_CHANNEL) * 5.0 * 101.0 * Kc) / (1.3836 * 1023.0);)

    3. how did you get the value of 1.3836

    thanks

    ReplyDelete
    Replies
    1. 1) Sorry for the confusion. The code should be updated. I initially used 100k and 1k for the voltage divider. That is almost the same as using 6x 47k resistors and a 3.3k resistor (in series). Using 6x 47k and a 3.3k resistor instead helps reduce the power consumption. You'll get more information about this in the article I wrote.

      2) and 3) ADC_Get_Sample gets the ADC digital output (10-bit: 0 to 1023). The *5.0 and / 1023.0 scale the ADC result to a 0.0 to a 5.0 (a little less actually) level that represents the actual voltage present at the ADC input pin. 101 is the multiplication factor to get to the actual DC voltage level. Kc is the scaling factor (as saved previously in the EEPROM as the calibration value). 1.3836 is my measured AC to DC conversion ratio. I noticed (upon measurement) that my DC voltage was 1.3836 times the AC RMS value and not 1.414. So I just used that.

      Hope that helps.
      Tahmid.

      Delete
    2. thanks for your candid explanation, i am very grateful.

      but please can you explain this too.

      //Voltage_FLOAT = Voltage_FLOAT + 1.5;

      thanks

      Delete
    3. That was just for my testing - to test for an "offset". You can ignore that - that's why I commented it out.

      Regards,
      Tahmid.

      Delete
    4. Have you built the circuit and tested it?

      Delete
    5. To be candid i might not really make this circuit, but i am going to use a lot from the code and part of the circuit in making my next inverter. Particularly the calibration part of the code, the AC measuremaent for feedback (i ve been having issues with these for a long time). Now i know how to measure the AC voltage and display a correct value using your code and following your explanation. Well maybe i cud include tapping on the xformer and make the inverter also behave like a regulator. But truly i m going to copy a lot from the code.

      I am a very huge fan of proton basic. I have to convert all your code to basic so it takes a while due to syntax differences. But I am learning Mikro C already so i might migrate fully to using C to develop my code.

      thanks for your help everytime.

      ABM

      Delete
  4. Thanks for sharing the knowledge.
    1) Kindly tell where the calibration pot is located ? Is it a part of voltage sense section ? or it is separately connected to the micro-controller.
    2) whats the value of calibration pot?
    3) whats the value of capacitor connected at the output of voltage sense section (that was referred in the article as being parallel to the adc input capacitance)

    ReplyDelete
    Replies
    1. 1. According to the article and the code writeup, the calibration pot is on one of the ADC pin of the micro
      (const unsigned char CalibratePot_CHANNEL = 1;) which means AN1 of the micro check the datasheet of the micro search for the pin that has AN1 then u wil get the pin number

      2. He mentioned 5k if i am correct

      3. he said between 10uf to 33uf but he said he chose 22uf.

      hope it helps

      Delete
    2. According to the article "To ensure that the ADC measured the low-voltage DC level properly, a capacitor was placed at the output of the voltage divider section such that this would act as a parallel capacitance to the internal one (of the ADC)." I am referring to this capacitor value. I think the 22uf capacitor is used as a high voltage (450dc) filter capacitor (to convert AC to DC) in the voltage sense section. Moreover, the article does not mention the value of calibration pot. I am confused whether this 5k pot is part of sense resistors or it is separate. The schematics can clearly show this.
      hope u understand my point
      Thanks

      Delete
    3. The parallel capacitance is 0.1uF (100nF).

      The calibration pot is a 5k pot.

      Regards,
      Tahmid.

      Delete
  5. i my possible we can show input voltage value , output voltage value , output current in amp & output power in watt or kwatt ?

    ReplyDelete
    Replies
    1. Yes it is, but then modifications need to be made since the PIC does not have enough pins left.

      Additionally, it may be better to switch to an LCD screen if all those parameters are to be shown.

      Regards,
      Tahmid.

      Delete
    2. its PIC16F873A Pin Configuration


      *
      * O = Output
      * I = Input
      *
      * ________
      * MCLR | 1 28 | RB7 --> (O) == DIGIT1 CC H CA
      * ADC1(I) --> AN0 | 2 27 | RB6 --> (O) == G CA
      * ADC2(I) --> AN1 | 3 26 | RB5 --> (O) == F CA
      * DIGIT2 CC == (O) <-- RA2 | 4 25 | RB4 --> (O) == E CA
      * ADC3(I) --> AN3 | 5 24 | RB3 --> (O) == D CA
      * Delay_SW (I) --> RA4 | 6 23 | RB2 --> (O) == C CA
      * DIGIT3 CC == (O) <-- RA5 | 7 22 | RB1 --> (O) == B CA
      * Vss | 8 21 | RB0 --> (O) == A CA
      * OSC1 | 9 20 | Vdd
      * OSC2 |10 19 | Vss
      * RL4 == (O) <-- RC0 |11 18 | RC7 --> (O) == LED_HILO
      * RL3 == (O) <-- RC1 |12 17 | RC6 --> (O) == LED_NORMAL
      * RL2 == (O) <-- RC2 |13 16 | RC5 --> (0) == LED_DELAY
      * RL1 == (O) <-- RC3 |14 15 | RC4 --> (0) ==
      * ---------

      I'm right ?
      why u 3 ADC ?

      Delete
  6. Replies
    1. I haven't yet completed drawing the schematic on the computer. I have it drawn by hand. I'll upload it soon when I finish drawing it.

      Regards,
      Tahmid.

      Delete
  7. u can use ExpressSCH for draw Schematic diagram .it is very easy for Schematic diagram

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. pl tell me
    how can open PCB_v9.LYT ?
    or give the link its PDF ver.

    ReplyDelete
  10. pl up load drawn by hand Schematic diagram .

    ReplyDelete
    Replies
    1. hi Mr.. Tahmid.pl post or mail me its sch diagram .
      shivendrakumarsahu@gmail.com

      Delete
    2. Schematic has been uploaded.

      Delete
  11. Hello Thamid. I have a question about a PWM Full Bridge Primary Current waveform. I read a lot about it. Nobody could give me an answer. Please, where can I find you? Thks! ALU

    ReplyDelete
  12. hi tahmid

    i've been reading your blog and i got interested in your projects concerning sinewave inverters
    for commercial affairs.

    if you wish, please don't hesitate to contact me

    rafaelholguin@yahoo.com

    ReplyDelete
  13. hi tahmid

    i've been reading your blog and i got interested in your projects concerning sinewave inverters
    for commercial affairs.

    if you wish, please don't hesitate to contact me

    rafaelholguin0288@yahoo.com

    ReplyDelete
  14. Tahmid Sir, thanks for creativity, I love Technology, Your post & video is most useful & helpful for Bangladeshi electronics hobbyist, now you will publish circuit diagram for complete lesson

    ReplyDelete
  15. Mr Tahmid, please make tutorial dc-dc converter.

    ReplyDelete
  16. Hi,TAHMID
    I compile your given .c file and got hex.
    And check with proteus all is fine except,adc module become inactive during start up delay.
    Either delay is 2000ms or 3 minutes.
    Adc module did not work and relays are off during delay time.
    I hope you will think about it

    ReplyDelete
  17. Hi sir I will need your help in the same product which you had made...Automatic Voltage Stabilizer...
    Previously I have one of the kit..Please see
    http://www.solarindianproducts.com/automatic-voltage-stabilizer-kit.html#automatic-voltage-stabilizer-kit
    I want to make prototype of this kit but not able to program the IC because I am not able to get correct algorithm..I will send you more Visible pictures..can you help me regarding this means programming the IC...yours...Lucky

    ReplyDelete
  18. WHERE IS PART LIST AND SCHEMATIC?

    ReplyDelete
    Replies
    1. Will be available within the next week.

      Delete
    2. Thank you soo much for the fast answer !!! :)

      Delete
  19. how we design automatic voltage stabilizer for any range of input and tell us formula for calculation, please help me,

    ReplyDelete
  20. Thank you very much, greetings from Serbia

    ReplyDelete
  21. Replies
    1. Oscillator = HS
      Watchdog timer = Off
      Power up timer = On
      Brown out detect = On
      Low voltage program = Disabled
      Background debug = Disabled

      Code protect is up to you.

      Delete
  22. Hi boss, Which software can I use to open lyt file?

    ReplyDelete
    Replies
    1. Proteus ARES. I've added image versions of the file so if you don't have Proteus you can use the image version.

      Delete
  23. dear tahmid sir
    i am aneesh, i like your tutorial, i gained too much knowledge from you

    i have 1 doubt sir,i am making 700va high frequency inverter using sg3525, in that circuit (CT-3.3nf,,,RT-6.8k and RD-47E)are used, then what will be the frequency,,if 66khz HF transformer frequency will be half of that, please help me sir,
    which core better ETD 55 or EE55 please replay me

    thanks@regards

    ReplyDelete
  24. Hi bhai, ami apnar c file dia hex compile korar chesta korsi kintu ekhane error dekhasse. Ami mikroc pro use korsi. Apni ki kindly hex kore dite paren. hex file ti dite parle upokar hoto. Thanks

    ReplyDelete
  25. Hi boss, can you post pcb and parts list without led display?

    ReplyDelete
    Replies
    1. The 7 segment display is used to calibrate the unit. So, it should be added. However, if you feel like skipping it, you can just omit it once calibration is done.

      Delete
  26. Hi bhai, ami 16f873a id ta dhaka er market a passi na. Ami akhon ai ic er alternate kon ic use korte pari kindly janaben.

    ReplyDelete
    Replies
    1. You should be able to find the 16F873A easily. Did you look for it at Patuatoly?

      Delete
  27. Hi boss, Make another voltage stabilizer using pic without display. I think this is very hard to make it for me.

    ReplyDelete
  28. hi, sir i am rajeev from patna, i am making 90v-280v ,16f676 based,relay voltage stabiliser kit,with lo,hi,cut,&timer,with 7 segment voltage display,extra facility- lo cut on off switch,quick start switch with LT supply.

    thanks

    ReplyDelete
  29. hi, dear brother that u done is great,,,but i need some help about programing that ic i also need its programing data ( Hex ) & how can i program in ic,,,& thanks a lot....

    ReplyDelete
  30. do u have a skype to talk my skype marcony641

    ReplyDelete
  31. Hi Mr. Tahmid can I have ur email

    ReplyDelete
  32. Both files CODE and hex gives the same .c file for download. Is a hex file available anywhere for download?

    ReplyDelete
  33. Ok..the link doesnt work for hex file. Copying the text and pasting in a new browser window gives the hex fle. Correct it if possible.

    ReplyDelete
  34. hello sir, i am a new student of microcontroller.... i want to use PIC16F877A & proton Ide coading. will u help me?? and i want your ready-mate pcb board.....please sent me your instruction....this is my email: arifmishba@gmail.com & contuct number is: 01824294744

    ReplyDelete
    Replies
    1. I have not used Proton and will likely not be able to help you in that.

      If you have any general PIC questions, feel free to email me at inferno (hyphen) rage (at) hotmail (dot) com

      Delete
  35. dear Tahmid , its work very nice .have some problem in code .
    when mcu intered in delay mode adc not work , its then , when mcu exit form delay mode .
    pl guide us .
    it possible Automatic voltage stabilizer (AC-AC) with with out relay ,we can use IGBT for AC-AC regulation ?
    if yes pl do something .i konw u complet this task before telling me .
    if u cont post here due to commersicail rigion ,pl mail me those source cost.

    ReplyDelete
  36. Hello Tahmid I need 10 volt step not 25 volt and also 12 and 24 volt battery charging feature in it if possible then plz help me thanks

    ReplyDelete
    Replies
    1. If you want to reduce the voltage step, you will have to increase the number of tappings on the transformer.

      I am no longer developing voltage stabilizers and so will not further implement battery charging.

      Delete
  37. Always test your health with better ways ,contact us :- The Pcb test San Diego will try to gauge just what quantity of the contaminant has gotten into the soil. PCB soil contamination can be stalled if enough effort is given in the identification of the sources. It goes without saying that the pcb lawsuit California can be initiated if some company or business or enterprise is found to be responsible. Free pcb test will allow the people to know which are the problematic zones.

    ReplyDelete
  38. Hello sir,
    Tell me about load rating which is already you connect in this project...
    Thank u

    ReplyDelete
  39. Give me current rating of the transformer.
    thank you

    ReplyDelete
    Replies
    1. That depends on how much load you want to drive. What type of load are you driving?

      Delete
  40. have you tested it the generator? I had made one servo controlled stabilizer, it worked well with line voltage but when generator is on it does not work well. Output voltage increases 10V. I think there is some problem with the sensing circuit. Do let me know if you face this problem

    ReplyDelete
    Replies
    1. Interesting.

      I have not. If the generator generates 220V (standard rated) 50Hz sinusoidal AC, I don't see why there should be an issue. What type of generator was it? Do you have a model no.?

      Delete
  41. Hi Tahmid it's me Derrick from Uganda am trying to build your automatic stabiliser based on the PIC 16F873A.I have finished the PCB but I have one question and it's on the 3 digit 7 segment display.1-i want to know what is its inches? 2-Is it a common Anode or a common cathode 3 digit 7 segment display? Thanks for your help and work you do to help us learn electronics you are a teacher to many.

    ReplyDelete
  42. Hi Tahmid am trying to build your automatic stabiliser based on the PIC 16F873A.I have finished the PCB but I have one question and it's on the 3 digit 7 segment display.1-i want to know what is its inches? 2-Is it a common Anode or a common cathode 3 digit 7 segment display? Thanks for your help and work you do to help us learn electronics you are a teacher to many.

    ReplyDelete
  43. Hi Tahmid, Can u through some light on the following lines of code. I am unable to understand the logic behind the calculation of Kc

    CPot = ADC_Get_Sample(CalibratePOT_CHANNEL)/2 + 128;
    Kc = (float)(CPot * 2.0)/1023.0;
    Thanks

    ReplyDelete
  44. Hi i designed the same circuit with atmega8 the mcu checks the input for every 22ms.......i'm using lcd instead of 7 seg..the delay bet enable pin of lcd is 600us i cant reduce it as it's not displaying properly if i reduced it............. is this normal to measure 20ms (50Hz) sine wave at every 22ms and change o/p depending on it.......will it cause damage to load within this time period.......i increased the crystal frequency but i noticed that only time consuming element is lcd..and got 16ms sampling rate

    ReplyDelete
  45. I built this circuit but when i switch on the power, transistor Q8 (2N2222) immediately burns up and smoke is seen coming out of it even if i replace with a brand new one same thing happens please help.

    ReplyDelete
    Replies
    1. Is the 7 segment display used is common anode or common cathode type?

      Delete
    2. Is the 7 segment display used is common anode or common cathode type?

      Delete
  46. I have done this project and burnt the HEX code you provided but the circuit does not do anything at-all and when i short the calibration switch then the delay led goes on but without doing that the circuit just sits there doing nothing.Pliz help what do you think is the problem i have checked the circuit many times and i dont see any problem i think its in the code which i cant check.

    ReplyDelete
  47. my mail refatct@hotmail.com.... pls send ur cell no. it's 911

    ReplyDelete
  48. This comment has been removed by the author.

    ReplyDelete
  49. AsalaamOAliakum
    Tahmid plz tell me wht is the pcb size in inch Y and X .
    Thankyou.Mine email yasiralikhi2@gmail.com

    ReplyDelete
  50. hi tahmid brother can give me proteous simulation files or any other software filw that you used for simulation i saw you use proteous please share these file. i have on objection in your schematic part a in microcontroller circuit vrelay that is connected to diodes and vdd are act as input but on relay circuit in part b vrelat is a power source

    ReplyDelete
  51. AsalaamOAliakum
    Tahmid plz send me display actual size pcb.Thankyou
    Email yasiralikhi2@gmail.com

    ReplyDelete
  52. great job, but still don't understand about auto transfmormator make me confuse. it's the common transformator step down type (0,110,220 for primary winding, and 0, 12.5,25,....,165,195,etc),or anything type, i'm waited for the answer, tx

    ReplyDelete
  53. This is fantastic brother .... speechless ... m hobbyist and i'll make this as my 2nd semester project m using jwm programmer ... u didnt shared proteus isis file , if u do i'll be too much thankful... may God give u more success in serving people , www.creativeeagle.blogspot.com

    ReplyDelete
  54. sir
    i am new student in microcontroller.i want to make a voltage stabilizer.how to sense input voltage in micro c.to switch output relay.
    please help me.

    ReplyDelete
  55. would you tell me about the primary voltage range and turn ratio and amperes. because i want to run 2000 watt load.. please tell me as soon as possible.. and you designed a nice circuit. My email is "allahhooooo@gmail.com".

    ReplyDelete
    Replies
    1. please tell me whole specification about transformer. from primary to secondary...

      Delete
  56. is it necessary to use an auto transformer with a particular tap voltage ratio or any kind of auto transformer of 120v-270v will work?

    ReplyDelete
  57. good job. i have used the code and as well redesigned it to suit my needs. welcome

    ReplyDelete
    Replies
    1. good job, Did you made the proteus schematic to work?

      Delete
  58. Dear Tahmid, thank you very much for a well designed circuit ! I am beginning to learn little bit of electronics from you blog.
    Here we have power supply problems, anything between 100v to 290v ! Would you be kind enough to modify your Stablizer circuit and program to address this issue? I plan to use a 2KvA Transformer to feed my house wiring as per output voltage(s)designed from your end(if possible). Thank you very much in advance.
    With kind regards
    Imsa Naga
    imsayuba@gmail.com

    ReplyDelete
  59. Can I further request you to modify your code/circuit to use 16x2 LCD in place of 7 segment display ? I am new to PIC programming but can transfer codes to PIC!
    Thanks again.
    Imsa Naga

    ReplyDelete
  60. hi sir,
    Please give your mail id and contact no. my mail id vasuvit@gmail.com 8838899551.

    ReplyDelete
  61. http://acecct.blogspot.com.ng/2015/11/microcontroller-based-avr.html?m=1

    ReplyDelete
  62. can u upload c code for avr chip?

    ReplyDelete
  63. Thanks for this interesting project. Please I want to know the type of 7segment display you used. Is it common anode or common cathode.

    ReplyDelete
  64. Please I did the circuit pcb and all works but when I power after calibration it shows the High/low led and nothing happens. The calibration seems working well and have been set properly. I need help urgently.

    ReplyDelete
  65. Very nice and informative blog. I like reading your blog regularly. Keep sharing such amazing information.

    ReplyDelete
  66. hello bro,

    I open the source code in MPlab IDE. but it show compile error. can you tel me the IDE you used please....

    Regards
    Partho

    ReplyDelete
  67. Hello Syed Tahmid Mahbub.
    I open the source code in MPlab IDE or PICC, and it shows compile error. In which compiler you have compiled your source code.

    Hugs,

    ReplyDelete
  68. Hi sir I'm intrusting in programming pic can you help me sir.

    ReplyDelete
  69. I really enjoyed reading your post. We at Enertech also brings Voltage Stabilizers for the clients that are widely accepted for providing constant voltage even under unbalanced electric conditions. Our stabilizers are appreciated for their salient attributes like reasonable prices, stable output and free warranty. We make sure that our clients are provided with the stabilizers that are stringently tested on various parameters.
    For more information - Visit today.

    ReplyDelete
  70. Hello Tahmid,
    Please, I just assembled your PCB as it is and load the Hex file onto the ship as it is but there's no response at all. Power to the chip is ok at 5.0V and any other points received supply.
    Please, is there any issue with the Hex for I've troubleshoot a lot even the code could not compile on MikroC pro.

    a certain portion of the code ""while (ADC_Get_Sample(CalibrateSW_CHANNEL) < 512){ // While Calibrate switch is PRESSED""

    Please kindly help.
    Thanks.

    ReplyDelete
  71. what this code does
    CPot = ADC_Get_Sample(CalibratePOT_CHANNEL)/2 + 128;

    why u mtlply kc by 10000 if it btwn 0.00 to 2.00 why not mltbly by 100

    ReplyDelete
  72. Dear sir,
    I want to make the same automatic voltage stabilizer for my project but i don't know how to make the pcb. So could you help me out. What is circuit diagram and pcb layout for this project.

    ReplyDelete
  73. Dear sir,
    I want to make the same automatic voltage stabilizer for my project but i don't know how to make the pcb. So could you help me out. What is circuit diagram and pcb layout for this project.

    9870128641 my no.

    ReplyDelete