Automatic Voltage Regulator (AVR) using PIC16f72

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Automatic Voltage Regulator (AVR) using PIC16f72

Postby Enamul » Fri Oct 05, 2012 9:01 am

Hello,
Good morning..
This post is about Automatic Voltage Regulator (AVR)..how to design and develop.
Introduction:
AVR is a very primitive electronic product although very regularly used in our day-to-day life. This is why it is still very demanding product in the countries specially 3rd world where mains voltage fluctuates frequently. AVR can play a significant role in saving your expensive products by adopting the input voltage to the required output voltage (220-240V) while the input voltage can be as low as 100V.
Digital AVR:
Although this AVR is quite popular using analog control circuit with group of relays to switch between auto-transformer tapping to provide required output, the PIC based AVR is even has potential because of minimum setting required using PIC based system. In analog control, manufacturer need to tune all the relay control circuits manually which makes the manufacturing process slow whereas in PIC based user only need to adjust one or two POT to get accurate adc value. Additionally user can interface better user interface by adding LCD and add much more functionality in the system.
I have worked on AVR couple of years back. I have been developing one for one of my student but meanwhile I need to move to UK. I can't finish R&D in that time due to lack of time. Now I feel it's a great scope for me as one of our forum user is designing one for him..So it would be nice if I can help him in designing that and make my code matured.
Description:
The system uses 6 relays to adjust output voltage in proper level which are connected in RB<1> to RB<6>. If the voltage drops very low close to low cut (95V), the circuit driving power become low and which makes tough to drive circuitry..that's why we have two tapping in the transformer with different voltage and we have switched between them depending on input voltage and the is done by power relay (RB<0>). There is one output relay(RC<7>) which is used to control output in the occasion of low-cut, high-cut and delay. There are 4 LED in the system..Delay LED(RB<7>), Low-cut (RC<4>), High-cut (RC<5>) and Normal (RC<6>).
Delay is before any re-connection to output..if AVR goes into low-cut or high-cut, it goes to Delay mode and then to normal mode if input voltage is fine. The programmed delay is 3 minutes but there is a reset switch (RC<0>) which can be used to skip the delay.
I guess I have to add schematic and bit more description later on. I can recall only these looking at the program as I designed that couple of years back.
Attachments
Digital_AVR.fcf
(36.8 KiB) Downloaded 789 times
These users thanked the author Enamul for the post (total 4):
Benj (Fri Oct 05, 2012 9:47 am) • s.k.sahoo (Fri Oct 05, 2012 4:09 pm) • riyadnyn (Mon Dec 17, 2012 2:14 pm) • belayat (Fri Mar 08, 2013 7:46 pm)
Rating: 21.05%
 
Enamul
University of Nottingham
enamul4mm@gmail.com

s.k.sahoo
Posts: 147
Joined: Sun Sep 16, 2012 3:02 am
Has thanked: 144 times
Been thanked: 7 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby s.k.sahoo » Fri Oct 05, 2012 4:08 pm

Dear Mr Enamu,
Many many Thanks for opening this thread.
We will have a good discussion regarding AVR in this thread.
I had a quick look about the topic, its quite good.
Shall i post my Design here for more discussions, or in my thread?

Thanks
With best regards
sks

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby Enamul » Fri Oct 05, 2012 4:35 pm

Shall i post my Design here for more discussions, or in my thread?

It's up-to you. I made this thread mainly for you but may be useful to other users as well. If you look at my program, you will see couple of issues, we (me & my student) considered to make that commercially viable. But need to tune bit more which I guess you can do easily with the up-coming discussions.
These users thanked the author Enamul for the post:
s.k.sahoo (Fri Oct 05, 2012 5:08 pm)
Rating: 5.26%
 
Enamul
University of Nottingham
enamul4mm@gmail.com

s.k.sahoo
Posts: 147
Joined: Sun Sep 16, 2012 3:02 am
Has thanked: 144 times
Been thanked: 7 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby s.k.sahoo » Fri Oct 05, 2012 5:43 pm

Dear Mr Enamul,
Thanks a lot for helping me and opening the thread for betterment of this kind of project.
For me, it is some how little difficult to follow your code right now. I may take some time to understand.
As you had worked in this kind of project before, you must have considered everything before writing the code.
Please upload the schematics and little more description on the code as well as on the Circuit.

I have attached two codes in my old tread. I am attaching here also. If you have answered in old thread, please ignore here.
I want this code with LCD to measure INPUT and OUTPUT voltage by a press button switch, and one with out LCD.
I have tested both the code in my project pcb with transformer. It is working, but having some bugs.
The LCD some times Blank and some times Showing Block like things.
Is in PIC i should use 10k pull up resisters in every port pins?
Can i use two ADC?
In my code, First i am making my Relay drive Port pins to High with some delay to switch ON All 4 Relays and
HI-CUT Relay at OFF state, after the delay time is over it goes to ON state and the OUT PUT is made.
Please check the both code and guide for further improvement.

Thanks
With best regards
sks
Attachments
5RELAY_CTRL_v1.2.fcf
(18 KiB) Downloaded 466 times
5RELAY_CTRL_LCD_v1.2.fcf
(19 KiB) Downloaded 465 times

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby Enamul » Fri Oct 05, 2012 6:58 pm

Hi SKS,
I am right now changing my PIC 16f72 code to fit in your PIC16f88.In transformer tapping environment it's not easy to keep LCD stable. That's why I told earlier to test without transformer. Now the real challenge is! You have put couple of capacitor in couple of places. MCLR capacitor can be increased to 10 uF and can put one capacitor close Vdd of LCD. Please let me know lcd is behaving.
For input and output two ADC is better than to use switch. I will post program for you.
These users thanked the author Enamul for the post:
s.k.sahoo (Fri Oct 05, 2012 7:17 pm)
Rating: 5.26%
 
Enamul
University of Nottingham
enamul4mm@gmail.com

s.k.sahoo
Posts: 147
Joined: Sun Sep 16, 2012 3:02 am
Has thanked: 144 times
Been thanked: 7 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby s.k.sahoo » Fri Oct 05, 2012 7:47 pm

Hello Mr Enamul,
Thanks for the reply.
In MCLR there is a 1uf and a .1uf capacitor. Right now there is no Cap in LCD pcb (it is an add on board)
OK, i will add a capacitor there.
When the power is ON LCD is not showing any Text, it shows square blocks, after a while the text is there with the ADC value.
Here we may need some delay or (Display OFF condition)The LCD should be blank for some time.
When i do change the input voltage firstly by my variac, LCD goes blank. After switching OFF to ON the variac, LCD again functioning.
I think the LCD is not reacting speedily.
Can a single ADC can be used for correcting voltage and HI-CUT purpose?
I are thinking to use two ADC, one for correction another for HI-CUT.
Right now i am using IN PUT voltage as my ADC INPUT source, from that i can show the INPUT voltage in LCD.
If we use another ADC to sense OUT PUT then we can read and show the OUTPUT voltage in LCD and for High cut purpose.
Sorry you didn't answer my pull up resister question.

Thanks
With best regards
sks

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby Enamul » Fri Oct 05, 2012 7:49 pm

Here is the program with input and output both in LCD..
Attachments
5RELAY_CTRL_LCD_v1.3.fcf
(22.32 KiB) Downloaded 418 times
These users thanked the author Enamul for the post:
s.k.sahoo (Fri Oct 05, 2012 8:26 pm)
Rating: 5.26%
 
Enamul
University of Nottingham
enamul4mm@gmail.com

s.k.sahoo
Posts: 147
Joined: Sun Sep 16, 2012 3:02 am
Has thanked: 144 times
Been thanked: 7 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby s.k.sahoo » Fri Oct 05, 2012 8:33 pm

Dear Mr Enamul,
Thanks for the code. I just can't express my feelings.
I will test the code tomorrow and post the result. You are supposed to absent for two days, Ok there is no problem.
We can meet on Monday.
Thanks
With best regards
sks

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby Enamul » Sat Oct 06, 2012 12:56 am

Hi
I will be able see your post but not codes in mobile. Please let me know.
These users thanked the author Enamul for the post:
s.k.sahoo (Mon Oct 08, 2012 4:34 pm)
Rating: 5.26%
 
Enamul
University of Nottingham
enamul4mm@gmail.com

s.k.sahoo
Posts: 147
Joined: Sun Sep 16, 2012 3:02 am
Has thanked: 144 times
Been thanked: 7 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby s.k.sahoo » Sat Oct 06, 2012 7:29 pm

Dear Mr Enamul,
I have tested the code for both input and output LCD display using AN0 and AN1, It is working with little modification in LCD Connection in code.
I found the LCD DATA1 was connected to RA1/AN1 of CPU. i just disconnect from RA1 to RB0 in code and wired accordingly in my pcb.
It is working,but the output display is not showing the exact value what shows in my multimeter.
I have used the same component as used in AN0 except the rectifier, in AN0 i am using a bridge but in AN1 i am using 2 IN4007.
I have adjusted the pot at different voltage to get the exact reading, but it won't work.
As per your advice i have added a 47uf in my LCD pcb power rail, Thanks it works well, solved many problems.
Please tell How to use INTCLK Oscillator (excluding XTAL) to use the osc pins as output pins?
I have a PICKIT-2 to flash my pic chips.

Finally i have decided to UPGRADE my HOME version to PRO version.
I am going to write a PM to Mr David regarding this?
Waiting for your reply.

Thanks
With best regards
sks

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby Enamul » Sun Oct 07, 2012 10:56 pm

I have tested the code for both input and output LCD display using AN0 and AN1, It is working with little modification in LCD Connection in code.

Sorry..I should remember that but I post that program in a hurry as I was going out.
It is working,but the output display is not showing the exact value what shows in my multimeter.
Did you tested the program without transformer tapping connection and still giving wrong value for AN1? If that's the case, you will see I put two delays (100 ms) in code one is before AN1 read and other is after AN1 read..i.e., before AN0 read. You can increase those delays to 500 ms and try again.
Issue might be due to fast ADC sampling..because you know although these PIC have couple of ADC channels but physical A/D converter is just one and that is multiplexed among the channels. So while only one channel is being used, there is no issue but when multiple channels come into play in that timing becomes an issue.
As per your advice i have added a 47uf in my LCD pcb power rail, Thanks it works well, solved many problems.
It's good to know, this issue is sorted.
Please tell How to use INTCLK Oscillator (excluding XTAL) to use the osc pins as output pins?

I have changed the configuration (Build>Projects Option>General Options>Configure Chips). I put the c code in the program for 4MHz internal clock with I/O in oscillator pins.

Code: Select all

osccon = 0x6C;

Finally i have decided to UPGRADE my HOME version to PRO version.

That's great! You will feel comfort more in R&D now..
Attachments
5RELAY_CTRL_LCD_v1.3.fcf
(22.54 KiB) Downloaded 334 times
These users thanked the author Enamul for the post:
s.k.sahoo (Mon Oct 08, 2012 4:33 pm)
Rating: 5.26%
 
Enamul
University of Nottingham
enamul4mm@gmail.com

s.k.sahoo
Posts: 147
Joined: Sun Sep 16, 2012 3:02 am
Has thanked: 144 times
Been thanked: 7 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby s.k.sahoo » Mon Oct 08, 2012 7:10 am

Dear Mr Enamul,
Thanks for your nice reply. Thanks, you already modified the code using C code and 500ms delay.
I am compiling the code now, ( its taking 15 to 20 mnts ) After testing i will post the result.

Thanks
With best regards
sks

s.k.sahoo
Posts: 147
Joined: Sun Sep 16, 2012 3:02 am
Has thanked: 144 times
Been thanked: 7 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby s.k.sahoo » Mon Oct 08, 2012 11:40 am

Dear Mr Enamul,
Sorry for little late. It is working all right. I am going to test the real hardware (AVR) in real condition today.
Thank you very very much for your kind support to develop the 1st version.
Without your help, it was not possible. Thanks again.
THANKS THE REALCODE TEAM.
I am planning to tweak a little bit in Port pins for better allocations for LCD and Relays, its 5Relay model.
I will post every details after everything is completed. We will proceed for a 6Relay model next.
I have to make PCB for my 1st model its a 0.5KV model.
I have wrote a PM to Mr David, not received any reply, awaiting his reply.
I had requested him for some discount, If he gives any, it will be helpful otherwise i have to pay what ever the real amount.

Thanks
With best Regards
sks

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby Enamul » Mon Oct 08, 2012 11:55 am

Thanks for letting me know. You are most welcome :)
I will post after finishing my code in your PIC chip..I also post schematic for you.
These users thanked the author Enamul for the post:
s.k.sahoo (Mon Oct 08, 2012 4:33 pm)
Rating: 5.26%
 
Enamul
University of Nottingham
enamul4mm@gmail.com

s.k.sahoo
Posts: 147
Joined: Sun Sep 16, 2012 3:02 am
Has thanked: 144 times
Been thanked: 7 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby s.k.sahoo » Mon Oct 08, 2012 4:36 pm

Dear Mr Enamul,
Thanks.
No reply from Mr David yet.

sks

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby Enamul » Mon Oct 08, 2012 4:38 pm

I guess David might be in holiday..I am sending PM to Ben to have a look in your issue..But discount is completely MM issue and depends on their will.
These users thanked the author Enamul for the post:
s.k.sahoo (Mon Oct 08, 2012 5:58 pm)
Rating: 5.26%
 
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby Enamul » Mon Oct 08, 2012 6:37 pm

Hi SKS,
I have made the mentioned program for you with 4 relays..you can have a look in the program and let me know..
Attachments
Digital_AVR_SKS.fcf
(29.98 KiB) Downloaded 347 times
These users thanked the author Enamul for the post:
s.k.sahoo (Tue Oct 09, 2012 3:44 pm)
Rating: 5.26%
 
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Benj
Matrix Staff
Posts: 14247
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4370 times
Been thanked: 4104 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby Benj » Tue Oct 09, 2012 9:34 am

Hello,

Finally i have decided to UPGRADE my HOME version to PRO version.
I am going to write a PM to Mr David regarding this?


You can upgrade your Home to Pro version by following the URL here.
http://www.matrixmultimedia.com/product ... d=flowform

If you enter your home key then you will receive a discount which is the difference between the cost of the home and pro versions.
These users thanked the author Benj for the post:
s.k.sahoo (Tue Oct 09, 2012 3:44 pm)
Rating: 5.26%
 

s.k.sahoo
Posts: 147
Joined: Sun Sep 16, 2012 3:02 am
Has thanked: 144 times
Been thanked: 7 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby s.k.sahoo » Tue Oct 09, 2012 7:52 pm

Dear Mr Enamul,
Thanks for writing the code for me, i can learn many tricks from the code.
I have few questions on the code.
1: Will it help, if we assign unsigned int to ReadAsInt ?
2: Is the statement " if INPUT <=115 && INPUT >=110 " same as " if INPUT <=115 AND INPUT >=110 " and " if (INPUT <=115) AND (INPUT >=110) " ?
Please answer.

Thanks
With best regards
sks

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby Enamul » Wed Oct 10, 2012 7:43 am

1: Will it help, if we assign unsigned int to ReadAsInt ?
I would prefer to use INT as we don't need unsigned int.
2: Is the statement " if INPUT <=115 && INPUT >=110 " same as " if INPUT <=115 AND INPUT >=110 " and " if (INPUT <=115) AND (INPUT >=110) " ?
Yes, these are same.
These users thanked the author Enamul for the post:
s.k.sahoo (Wed Oct 10, 2012 7:28 pm)
Rating: 5.26%
 
Enamul
University of Nottingham
enamul4mm@gmail.com

s.k.sahoo
Posts: 147
Joined: Sun Sep 16, 2012 3:02 am
Has thanked: 144 times
Been thanked: 7 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby s.k.sahoo » Wed Oct 10, 2012 7:35 pm

Dear Mr Enamul,
Thanks for answering my questions. I was little busy couldn't reply you.
I am following your sent code, it may take some time to understand.
After testing, i will be in touch with you very soon.
Thanks
With best regards
sks

s.k.sahoo
Posts: 147
Joined: Sun Sep 16, 2012 3:02 am
Has thanked: 144 times
Been thanked: 7 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby s.k.sahoo » Sat Oct 13, 2012 6:46 pm

Dear Mr Enamul,
I was busy testing my 1st Stabilizer design, Thanks a lot to you, It is working fine. It is on a field test, i will test for 15 days.
You know it is based on PIC16F88. I had one 16F88, i couldn't get another piece in our local market. I purchased 2Nos PIC16F72.
I tried to test the LCD using attached code, but no display is there. Will you please check the code?
I am planning to use this chip as it is cheaper and can be procure locally.

Thanks
With best regards
sks
Attachments
2Line_LCDDisplay_1.fcf
(10 KiB) Downloaded 249 times

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby Enamul » Sun Oct 14, 2012 12:20 am

I had one 16F88, i couldn't get another piece in our local market. I purchased 2Nos PIC16F72.
Yes, that's the issue in sub-continent. I always search chip in local market first and then design..In UK, I can order anything for R&D but my employees in Bangladesh can't find that in local market. For AVR, PIC16f72 is ideal as it's cheap and available..
I tried to test the LCD using attached code, but no display is there. Will you please check the code?
I have been through your code..I have come across one issue which might cause the problem in program..P16f72's ADC is 8-bit ADC not 10-bit ADC like PIC16f88. So you can't use INT READ for ADC in PIC16f72. I have changed the code and hope that it will work now.
Attachments
2Line_LCDDisplay_1.fcf
(15 KiB) Downloaded 269 times
These users thanked the author Enamul for the post:
s.k.sahoo (Mon Oct 15, 2012 3:40 pm)
Rating: 5.26%
 
Enamul
University of Nottingham
enamul4mm@gmail.com

s.k.sahoo
Posts: 147
Joined: Sun Sep 16, 2012 3:02 am
Has thanked: 144 times
Been thanked: 7 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby s.k.sahoo » Mon Oct 15, 2012 3:40 pm

Dear Mr Enamul,
Thanks for modifying the 2Line_LCDDisplay code. I have tested and incorporated in my Stabilizer code, its working fine.
You know our costumer's sentiment (in this region), if we pay a little more, we ask something extra without understanding
the new technology. As we are using the LCD Display, To satisfy the local costumers sentiment, i am thinking to add either a
CLOCK or a CALENDER using DS1307 like chip.
What you suggest? Can we add this facility in the current 16F72 stabilizer design? If yes, how to write/add the clock code?
Please guide or suggest.

Thanks
With best regards
sks

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Postby Enamul » Mon Oct 15, 2012 4:45 pm

You know our costumer's sentiment (in this region), if we pay a little more, we ask something extra without understanding
the new technology. As we are using the LCD Display, To satisfy the local costumers sentiment, i am thinking to add either a
CLOCK or a CALENDER using DS1307 like chip.
I understand customer sentiment in sub-continent quite clearly..if you offer something they want more and to lead market you have to be unique.
Yes, DS1307 is a very good chip which is locally available and cheap for clock. It can maintain time upto 9 years with a coin battery. So power interruption will not cause any problem. so you want to add this clock feature in your PIC16f72 AVR version?
I have been always working for clock as I have to very often add this in my different products. I will tell you how to do that after getting your feedback.
These users thanked the author Enamul for the post:
s.k.sahoo (Mon Oct 15, 2012 6:12 pm)
Rating: 5.26%
 
Enamul
University of Nottingham
enamul4mm@gmail.com