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

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

Post by s.k.sahoo »

Dear Mr Enamul,

Thanks for the reply. It is my mistake, i couldn't make you understand properly.

"It seems to me now that you want output voltage to be sensed fast (like within 10ms) and react HICUT relay fast to disconnect output if goes high. But when it returns normal only then you want to make delay of 5sec to re-connect. Is that what you mean?"

YES Now you are correct.

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

Post by Enamul »

No problem. Here is I guess what you are looking for.
Attachments
6_Relay_96_255_NB_CTRL_v1.3.fcf
(32.9 KiB) Downloaded 345 times
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

Post by s.k.sahoo »

dear Mr Enamul,

Thanks for the code. I think this will solve my problem.We can see the LCD issue later on.
I will post the result tomorrow morning.

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

Post by Enamul »

Hi SKS,
2. The LCD used to see the INPUT and OUTPUT Voltage is not stable, it hangs at the time of Relay ON/OFF. I have tried to rectify the fault by using a series resistor and filter Cap, but could not rectify.
First of all, please don't put any series resistor in LCD lines; this will worsen the result. And don't put any capacitor in data, rs or En line of LCD. You can put capacitor of 10uF in Vdd of LCD. But that might not solve your issue.
Although it seems to me that you don't want to put capacitor across Relay coil but there is no other way to avoid LCD issue without that capacitor. At least your PIC are not resetting with Relay switching in transformer tapping that's good.
Another important issue is PIC and LCD power supply..I think relays are driven by 12V and the power supply of relay and PIC & LCD completely isolate. May be separate bridge rectifier, filtering ckt and regulator for relay drive and separate for PIC&LCD.
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

Post by s.k.sahoo »

Dear Mr Enamul,

Thanks for the reply.
I am not using any series resistors or any Caps in Dataline, Rs and Emable pins. Only one 10uf/63v is at VDD to gnd with a 10ohms series resistor from 5v supply line.

I am using 10uf/63v Elcos across relay coils.

" At least your PIC are not resetting with Relay switching in transformer tapping that's good. "
YES, PIC don't resets normally.

If a high voltage spike comes from veriac (when i increase the input votage by rotating the knob little fastly)
OUTPUT Relays acts OFF with NO OUTPUT, Why?

" Another important issue is PIC and LCD power supply..I think relays are driven by 12V and the power supply of relay and PIC & LCD completely isolate. May be separate bridge rectifier, filtering ckt and regulator for relay drive and separate for PIC&LCD."

Regarding the Power Supply, this could be wrong. I am using same bridge for 12v for Relay drives, 5V supply line for VDD of PIC and 5v for LCD with a 10 Ohm series resistor.
I will change to different Bridge supply line.

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

Post by Enamul »

Hi Mr SKS,
I am not using any series resistors or any Caps in Dataline, Rs and Emable pins. Only one 10uf/63v is at VDD to gnd with a 10ohms series resistor from 5v supply line.
That's fine then..
I am using 10uf/63v Elcos across relay coils.
You can try again by increasing up to 47uF to see whether it improves or not.
If a high voltage spike comes from veriac (when i increase the input voltage by rotating the knob little fastly)
OUTPUT Relays acts OFF with NO OUTPUT, Why?
You mean, changing input voltage suddenly causing output voltage to drop in transformer or in ADC input or both. If ADC voltage doesn't change with input's sudden change, in that case ADC output reading is causing problem.This is because high speed reading..
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

Post by s.k.sahoo »

Dear Mr Enamul,

I have changed a little in power supply rail. From a auxiliary winding of main transformer, i connected 2 full wave rectifier unit,
one for Relay drives with filter cap and another for 5v regulator to supply CPU and LCD. A lot of improvement is there in LCD.

Can we use Analog Interrupt in our code?
Instead of sensing a DC Voltage, can we sense Pulsating DC without any Eclcos as filter in ADC input? (just a 01 or 0.1uf filter can be used)

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

Post by Enamul »

A lot of improvement is there in LCD.
That's a very good news.
Can we use Analog Interrupt in our code?
You can use interrupt only for detecting presence or absence of power..but you can't use that to get voltage level..so I'm not quite clear why u need that.
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

Post by s.k.sahoo »

Dear Mr Enamul,

Thanks for the reply with answering my questions.

"Instead of sensing a DC Voltage, can we sense Pulsating DC without any Eclcos as filter in ADC input? (just a 01 or 0.1uf filter can be used)"

Why i want a pulsating DC as my source to ADC.
I want to avoid Elcos in ADC input for faster reaction of ADC, I can go upto 0.1uf as filter cap.
The charging time makes the ADC slow, as i am thinking. Am i right or wrong?
I want in every 10ms the cpu should read the ADC input and compare the if else fxn and decide the output.
It will be another code.

Can i use Brown-Voltage bit in CONFIG2L register in my current code, if yes, how ?
You must be thinking why i want this.
Because, at Low voltage condition the CPU may malfunction, to avoid this, i want it, is it possible ?

I will change the Relay coil caps and tell you the result.

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

Post by Enamul »

Why i want a pulsating DC as my source to ADC.
I want to avoid Elcos in ADC input for faster reaction of ADC, I can go upto 0.1uf as filter cap.
The charging time makes the ADC slow, as i am thinking. Am i right or wrong?
I don't think small capacitor causing any issue rather you filter normally to better DC. We can speed up ADC sense in PIC program always. I just tell you to check whether changing input fast causes change in Output as well or not..If changes in output but not in ADC input for output sense..in that case you have to decrease capacitor to make the response faster. But as long as the ADC input is changing fast it's program and PIC hardware issue not capacitor issue.
Can i use Brown-Voltage bit in CONFIG2L register in my current code, if yes, how ?
You must be thinking why i want this.
Because, at Low voltage condition the CPU may malfunction, to avoid this, i want it, is it possible ?
I can enable this in code and also guide you how to enable that in PICKIT-2. I will post that.
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

Post by Enamul »

Hi,
I have look through the PICKIT-2 software and it's user guide and I can't find any option to set Brown-out there. So I think you should be fine by just setting that in Flowcode (as according to Ben), the configuration is embedded in Hex that Flowcode generates even though you right the code using third-party programmer like PICKIT-2. So I am guiding you how to config Brown-out and Code Protection in Flowcode...
Click Build>Project Options>General Options tab>Config chip..
The following window will pop-up..set like the following..
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

Post by Enamul »

Hi,
I have look through the PICKIT-2 software and it's user guide and I can't find any option to set Brown-out there. So I think you should be fine by just setting that in Flowcode (as according to Ben), the configuration is embedded in Hex that Flowcode generates even though you right the code using third-party programmer like PICKIT-2. So I am guiding you how to config Brown-out and Code Protection in Flowcode...
Click Build>Project Options>General Options tab>Config chip..
The following window will pop-up..set like the following..
Attachments
config.PNG
(21.92 KiB) Downloaded 6098 times
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

Post by s.k.sahoo »

Dear Mr Enamul,
Thanks for your effort to help me.
I am sending 3 images of my 0.6KVA model, it is almost complete, it is a demo model. One problem is in LCD Display.
The 3rd digit/number flickers (frequently changing the value) and some times at power on the LCD don't shows the value.

Thanks for sending the configuration image and description. I will try and post the result.

Thanks
With best regards
sks
Attachments
Image028.jpg
(110 KiB) Downloaded 1572 times
Image027.jpg
(100.75 KiB) Downloaded 1572 times
Image026.jpg
(65.72 KiB) Downloaded 1572 times

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

Post by s.k.sahoo »

Dear Mr Enamul,

I have Config the chip as per the image posted by you and burn the chip. i don't find any major difference, but there is a slow power on at start up, what i see.
In Mazidi book " PIC Microcontroller and Embedded System"
CONFIG2L Register
bit-0 is PWRTEN bit, which is Power-up Timer Enable/Disable bit, Active Low
bit-1 is BOREN bit, which is Brown-out Reset Enable/Disable bit, Active High
bit-2-3 is BORV0-BORV1 are Brown-out Reset Voltage bits
11= set to 2.0v
10= set to 2.7v
01= set to 4.2v
00= set to 4.5v
I am little confused, shall i use just bit-0 and bit-1 or bit-0 to bit-3?

I am attaching the image of my PICKIT-2 Config window, please look at it and suggest.

Thanks
With best regards
sks
Attachments
Config_01.jpg
Config_01.jpg (103.17 KiB) Viewed 11944 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

Post by Enamul »

bit-0 is PWRTEN bit, which is Power-up Timer Enable/Disable bit, Active Low
bit-1 is BOREN bit, which is Brown-out Reset Enable/Disable bit, Active High
bit-2-3 is BORV0-BORV1 are Brown-out Reset Voltage bits
11= set to 2.0v
10= set to 2.7v
01= set to 4.2v
00= set to 4.5v
I am little confused, shall i use just bit-0 and bit-1 or bit-0 to bit-3?
I don't know which chip you are looking through in the book you mentioned..But PIC16f72 will not allow you those..as the datasheet says the following:
conf.png
(33.85 KiB) Downloaded 6082 times
But what you have mentioned available in other lots of chip. But not available in PIC16f72..Can you please confirm which PIC is have that config2L..as PIC16f72 don't seems to have that. Address is 2007h as you have shown rightly for PIC16f72 and config register is fine and matches ok with flowcode config.
Edit: I have checked your config in PICKIT-2..that's right and perfect..so please tell your problem.
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

Post by Enamul »

i don't find any major difference, but there is a slow power on at start up, what i see.
I guess you actually mean that there is no such difference..that's right..slow start up caused by PWRUPTMR..that's good. Brownout is not visible but it makes circuit reliable.
The 3rd digit/number flickers (frequently changing the value) and some times at power on the LCD don't shows the value.
I will post program to sort this LCD flicker issue..But what it shows somethime at powerup? Black blocks?
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

Post by s.k.sahoo »

Dear Mr Enamul,

Thanks a lot for your replies.
"I don't know which chip you are looking through in the book you mentioned.."

Yes, it is not 16F72, its a different chip mentioned on book.
If i should stick to Flowcode config parameters, i will, i will not see the config option of my Programmer, what do you say ?
I just want to know, there is absolutely no problem. I have told you the result and you have described

"slow start up caused by PWRUPTMR..that's good. Brownout is not visible but it makes circuit reliable. "
Thanks.

"what it shows somethime at powerup? Black blocks?"

Yes, showing Black blocks.

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

Post by Enamul »

If i should stick to Flowcode config parameters, i will, i will not see the config option of my Programmer, what do you say ?
As I can see the PICKIT-2 is just showing what you set in Flowcode so I would suggest you to just stick to Flowcode.
Yes, showing Black blocks.
This is probably due to transformer hamming noise spike at the beginning which might be avoided by delay in the beginning to start LCD. You can try adding 1 sec delay in code before LCD start to see how it behaves.
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

Post by s.k.sahoo »

Dear Mr Enamul,

Thanks for the reply. OK, i will follow the Flowcode config. I will take care the LCD issue and post the result.

Now i am posting a code with the Relay logic Table, please see, this code is not working properly.
This time please tell me what is wrong in the program.

Thanks
With best regards
sks
Attachments
RelayLogicTable.jpg
RelayLogicTable.jpg (87.43 KiB) Viewed 11922 times
6-RELAY_CROSS_LOGIC_V1.01.fcf
(25.23 KiB) Downloaded 216 times

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

Post by s.k.sahoo »

Dear Mr Enamul,

Good Morning, I think you must be very busy.
Please answer my previous mail. This is little urgent, as i am going out for 15days. I need your help.

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

Post by Enamul »

Hi
I guess this is somewhat you want to get...
Attachments
6-RELAY_CROSS_LOGIC_V1.01.fcf
(19.16 KiB) Downloaded 247 times
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

Post by s.k.sahoo »

Dear Mr Enamul,

Thank you very much. Please describe my mistake in details, by which i can proceed on my learning.
I will test and post the result.

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

Post by Enamul »

Ok..I have changed two things among that one is minor but other is major..Minor is:
I have used masking in PORTB and sent data in all masked bit not individual bits as that save flowchart space and some clock cycles of pic.

Major is: Your decision branches were executed one after another like...if USE_AN0>=200 do one thing but if USE_AN0<=185 do another..that's fine but if you have similar if else in the same tree they will be executed one after another and Relay will be chattering according to each command. I have arranged the decision in such a way that only one decision will be executed depending on voltage and will be in that branch until voltage changes.
Hope it make sense.
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

Post by s.k.sahoo »

Dear Mr Enamul,

Thanks for pointing my errors on the code, and elaborating corrections you have made in details.
Now i understood.
Yes the Relays were chattering. Now it is alright.
Some errors are there, i have to check in details, whether its a hardware error or a software error, then i will post the result.

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

Post by Enamul »

Some errors are there, i have to check in details, whether its a hardware error or a software error, then i will post the result.
Yes you are right. There are some hysteresis issue in relay switching. In some voltages relays remain off I guess..This is sorted now.
Attachments
6-RELAY_CROSS_LOGIC_V1.01.fcf
(28.45 KiB) Downloaded 237 times
Enamul
University of Nottingham
enamul4mm@gmail.com

Post Reply