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:

Re: Automatic Voltage Regulator (AVR) using PIC16f72

Post by Enamul »

Hi,
I have been looking through the Google for few references to design VFD...
I have come across few nice docs..
http://digitalcommons.calpoly.edu/cgi/v ... ntext=eesp
and also..
http://blog.hardcore.lt/mic/archives/011040.html
You can have a look at those..
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 Links.
Ok Lets talk about the Power Guard code a little.
I have tested in a real hardware, its working, but a little modification has to be done.
Suppose the Supply is (DIM) like 150VAC. (i made my LOW Cutoff Limit t0 155VAC, because our Refrigerator starts at 160V).
At this condition the Output Relay is OFF and the LED Blinks, the power is there with a low voltage, a sudden correction on supply line
come up with a 210VAC, in this condition the Relay become active (ON) and Blinker LED goes OFF now. Ok
But i want a Delay of 45-Sec at this condition. It is to Protect the Compressor of the Fridge.
In either condition whether the Condition is NO Power or LOW Power or HIGH Power the Relay should be OFF and the Blinker should be ON (of course not in No Power),
When the Power is Normal, the Blink LED should go OFF and the Relay should be ON.

One more question, I can write delay in a separate tree, it effects on whole. Please guide.

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 put default delay of 60 sec in the beginning of the code like AVR and put a reset switch to reset delay if user wants..and also if changes from normal to low or high state and then use delay to return to normal..will you like that? Please let me know..
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.
1. You mean to say, you will add a 60Sec Delay at start with a optional switch to reset or skip the delay time by the user if he/she wants.
Or it will be normal operating mode after 60Sec automatically. Right?

2. After a DIM condition, you will tell the CPU to assume it is LOW Voltage or HIGH Voltage condition and stay there for a set Time like 60Sec,
After the time is over, it will be in Normal mode ?

i think there is no problem, if i understand correctly.

You did not answer my Delay question. Please answer. Please be my GURU.
How to protect code using password in PIC Chips? Is it possible?

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 »

1. You mean to say, you will add a 60Sec Delay at start with a optional switch to reset or skip the delay time by the user if he/she wants.
Or it will be normal operating mode after 60Sec automatically. Right?
Yes, you are absolutely right.
2. After a DIM condition, you will tell the CPU to assume it is LOW Voltage or HIGH Voltage condition and stay there for a set Time like 60Sec, After the time is over, it will be in Normal mode ?
Yes, you understand correctly.
You did not answer my Delay question.
Is this the question..
One more question, I can write delay in a separate tree, it effects on whole. Please guide.
or
But i want a Delay of 45-Sec at this condition. It is to Protect the Compressor of the Fridge.
the 60 sec delay I am talking about is that delay I guess you are looking for..but you are thinking anything else please let me know..
How to protect code using password in PIC Chips? Is it possible?
Yes, you can protect PIC program while you writing your program to PIC using "Code Protection" feature in configuration..I can enable that for you in the config option and you can enable that during PIC writing as well. Can you please tell me which PIC programmer you are using to write PIC so that I can tell you how to do 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 SKS,
I made a program which is smarter than last one and with delay and LCD functions of mode..Hope that you will like it..If you want PIC protection please let me know as I have mentioned in my last post..
Attachments
PowerGuard_Model_02.fcf
(25.78 KiB) Downloaded 365 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 replies. Sorry, from last evening my Net connection is OFF due to some technical problem of the service provider.
You know the promptness of our people. I have to wait till Wednesday evening. I can't use cyber cafe as because i communicate
with you at night time. Right now i am using my younger brothers system. Please bear with me, we can talk day after tomorrow.

BTW, Thanks for the code. I will test and tell you the result on Wednesday.

My question regarding Delay was, Suppose i have 3 decision trees in a code and if i write a delay in one of the tree, why it effects all ?

I am using a PICKIT-2 for programming my PIC Chips. Is it OK? Yes i want to protect my codes.

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 »

Suppose i have 3 decision trees in a code and if i write a delay in one of the tree, why it effects all ?
No, should only effect the the tree in which delay is..
I am using a PICKIT-2 for programming my PIC Chips. Is it OK? Yes i want to protect my codes.
I have checked the PICKIT-2 user guide and you can do that in the following way..
cp.PNG
(55.75 KiB) Downloaded 6684 times
I can config the CP(Code Protection) enable but you can do that easily in your PICKIT-2 software as shown in figure..I was looking through the following user-guide. Is that the one you are using?
http://ww1.microchip.com/downloads/en/d ... 51553e.pdf
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.
" No, should only effect the the tree in which delay is.."
Please write a Single LED Blinker Program using different Delay for different LED, by which i can understand correctly and will check whats wrong with my code.

Regarding Code protection, Yes mine is same PICKIT-2. Please let me know how to configure?

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 »

Here is a program in which different delay in different branch..
LED_TREE.fcf
(15 KiB) Downloaded 318 times
Regarding Code protection, Yes mine is same PICKIT-2. Please let me know how to configure?
You can try to write one chip as you write normally..then try to read that chip using read option of your programming software of PICKIT-2. If you can read that fine..then you can simply go to Tool>Enable Code Protect of the PICKIT-2 software. Tick that Enable Code Protect and write your chip as you write normally..After completion of writing now you can try to read again..if you can read as before your code protection is not done..but if you can't read the original hex rather only 000s are read in PICKIT-2 soft..then it's done.
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,

Good Morning. Thanks god.
Today morning i got my NET connection. Thanks for the LED Tree code, you have used switch case, can it be done using if else loop?
Again thanks for elaborating about code protection in PICKIT-2. Suppose i protected my code in a chip by code protection enabled, i want to rewrite
again in the same chip, can i rewrite ?

The sent " PowerGuard_Model_02.fcf " is working but i want, when ever a Delay is processed, the Blinker LED should be in Action.
(Start),((Blink the Blinker LED) (LED_1)), (45SecDelay) , (Check the Input), (if the Input is 160v to 255v ON the Relay, Stop the Blinker,On LED2),
If the Input goes High or Low, Off the Relay, Off the LED2, Start Blinker. This should be the program.

Right now its working without some functions stated above as per my knowledge. Please don't mind if i am wrong some where.
Please help.

I will describe the problem we are facing on the AVR in my next post.

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 »

Thanks for the LED Tree code, you have used switch case, can it be done using if else loop?
Here is the code using if else..
LED_TREE.fcf
(10.5 KiB) Downloaded 247 times
Again thanks for elaborating about code protection in PICKIT-2. Suppose i protected my code in a chip by code protection enabled, i want to rewrite again in the same chip, can i rewrite ?
Yes you can re-write the chip..you might get some error msg if you enable verify after write as you can't read the chip any more...But you should be able to re-write as many times as you want..mentioned in data sheet which is more than we can do!
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 manged to modify the code as you said. Hope this will meet your requirements.
Attachments
PowerGuard_Model_03.fcf
(30.6 KiB) Downloaded 275 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 a lot.
The Power Guard Model_03 worked well in the hardware.
I have not tested the LED Tree code yet.
BTW, i am attaching the Stabilizer code, which is in my Testing model.
The Input sensing is quite good and fast in real hardware without the Delay function.

1. When i add a Delay of 5Sec for OUTPUT Relay ON or HI-CUT Delay, Everything goes slow. I am using the Relay_6 for HI-CUT/POWER ON.
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.
I have thought a logic to rectify the Power ON/HI-CUT Relay problem, Pl see.
TIME = 5
If OUTPUT = 0
TIME - TIME - 1
If TIME = 0
If yes
Check OUTPUT (AN1), If AN1 >= 255
OUTPUT = 1
else OUTPUT = 0
If you have any other Idea you can do that. I am not using the Low-Cut Relay right now but it is there in my code.
Please help.

Thanks
With best regards
sks
Attachments
6_Relay_96_255_NB_CTRL_v1.1.fcf
(25.66 KiB) Downloaded 280 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 »

Hi SKS,
Sorry for taking time in response..I was busy with some other stuffs.
The Power Guard Model_03 worked well in the hardware.
That's good to know.
The Input sensing is quite good and fast in real hardware without the Delay function.
I guess with the program you have posted don't have that delay and you mean without that delay input sensing is fine and you need that.
1. When i add a Delay of 5Sec for OUTPUT Relay ON or HI-CUT Delay, Everything goes slow. I am using the Relay_6 for HI-CUT/POWER ON.
I think you have placed in the main program tree which causing the code to slow down.
I guess you trying to say in the idea that you want to have delay in output voltage sense and OUTPUT Relay ON or HI-CUT..you want that to be 5 sec. Is it? but you don't want to slow down the input sensing and other input relay switching. If so, I will make a work around for that. The idea will be close to yours one..We will discuss LCD issue later on.
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 changed the code according to the above post. Input is faster than earlier as it is now sensing every 250ms and output is sensed every 5 sec and output relay control is done after output sensing so also every 5 sec.
If you have any other Idea you can do that. I am not using the Low-Cut Relay right now but it is there in my code
I can't get it why you will waste one relay for Low-cut. You can use low cut in output like high cut. I have implemented that in output code..Like if output goes below 165V output will be disconnected and re-connect again in 170V to 247V but will disconnect again at 251V.
One more thing I will suggest you to use double of input sense. As you are now getting maximum 255 when ADC input is 5V which will never happen in reality..so if ADC value and voltages are linked by factor of 2..you can measure as high as 512 V which will never occur in real life. But you will be allowed to measure at least 280 or 300V which might occur in power line and will make ADC input greater than 5V and PIC's ADC pin will be destroyed.

Hope that I can make you understand what I am trying to say.
Attachments
6_Relay_CTRL_v1.1.fcf
(27.2 KiB) Downloaded 245 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,

I am really Sorry for sending the wrong old code.
Here is the code i am using now. Please forgive me for my wrong doings.

Thanks
With Best Regards
sks
Attachments
6_Relay_96_255_NB_CTRL_v1.1.fcf
(25.63 KiB) Downloaded 247 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 »

Hi SKS,
I can't see significant difference between the code except delays are very small (1ms). Why you are using so small delay? You should increase that to at least 100ms otherwise ADC read will be erroneous. Is there any difference you found in the if else condition?
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 tested the code " 6_Relay_CTRL_v1.1.fcf" sent by you, the AVR correction is getting slow. but on my sent
code " 6_Relay_96_255_NB_CTRL_v1.1.fcf " the AVR Correction is very fast.

There was a confusion, so i wrote the last mail, i thought i sent an wrong code by seeing your sent code name.

Please describe a little " I will suggest you to use double of input sense. As you are now getting maximum 255 when ADC input is 5V which will never happen in reality..so if ADC value and voltages are linked by factor of 2..you can measure as high as 512 V which will never occur in real life. But you will be allowed to measure at least 280 or 300V which might occur in power line and will make ADC input greater than 5V and PIC's ADC pin will be destroyed. "
I do understand some part of it. Like ADC will damage if the ADC voltage will be 5V.

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

Post by s.k.sahoo »

Dear Mr Enamul,

"You should increase that to at least 100ms otherwise ADC read will be erroneous."
I had corrected 1ms to 100ms now.
" Is there any difference you found in the if else condition?"
Yes

Thanks
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 »

the AVR correction is getting slow
If you change the delay to 100ms from 250 ms in my last code and time to 50 from 20 please. 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 an early reply. I have changed 100ms from 250ms and Time to 20.
I will send you the result tomorrow.

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 wasn't confirm that you managed to do that correctly or not. That's why added here corrected one.
I will suggest you to use double of input sense. As you are now getting maximum 255 when ADC input is 5V which will never happen in reality..so if ADC value and voltages are linked by factor of 2..you can measure as high as 512 V which will never occur in real life. But you will be allowed to measure at least 280 or 300V which might occur in power line and will make ADC input greater than 5V and PIC's ADC pin will be destroyed.
I guess you have adjusted your ADC input of PIC in such a way that for 200Vac, adc pin voltage is such that ADC value in display is 200; which means for 255Vac, the adc pin voltage will be 5V and in display you will get 255. I am asking what if the input become 270Vac; ADC input will be higher than 5 v which will destroy PIC adc.
Attachments
6_Relay_96_255_NB_CTRL_v1.2.fcf
(31.67 KiB) Downloaded 243 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,

Good Morning. I had tested the code, by changing to 100ms delay in main tree improves a little.
But there are problems in HI-CUT, it reacts with a delay

Let me ask you some thing about this delay and HI-CUT Relay first,
can we set the delay time less than 100ms?
can it be possible the input correction will occur within 10msec or less than that? (within 1 cycle of the mains freq)

The HI-CUT should be very fast within 10ms ( Relay should react and OFF) and the Relay should ON after a Delay of 5sec
when the power is within the set range. Are we doing this in our code?

You wrote " if ADC value and voltages are linked by factor of 2.."
I have not linked in my code. do you want me to link? that means,
i should write USE_ADC1 = READ_ADC * 2 ? by this i can display more than 255V.

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 »

I had tested the code, by changing to 100ms delay in main tree improves a little.
But there are problems in HI-CUT, it reacts with a delay
I bit confused now. I can modify that 100 ms delay to as low as 10 ms but not less than that I would recommend. But for HICUT, you said earlier to add 5sec delay and that's why I add delay of 5sec for output sensing and HICUT decision. It seems I understood something wrong.
The HI-CUT should be very fast within 10ms ( Relay should react and OFF) and the Relay should ON after a Delay of 5sec
when the power is within the set range.
From this post, I became certain that I understood wrong. Code is not doing that. Code is actually checking output ADC every 5sec and takes decision about HICUT in every 5 Sec. 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?
Enamul
University of Nottingham
enamul4mm@gmail.com

Post Reply