Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Designing Automatic Voltage Stabilizers

Status
Not open for further replies.
Hi irfan ahmad,

It is desirable to actuate electromagnetic relay near current zero crossing. If a voltage zero crossing detector is included and interfaced to any port, how you will manage it in code. To be more clear - how much delay would be required to send a drive for relay after detecting voltage zero crossing.

swapan
 
  • Like
Reactions: sahu

    sahu

    Points: 2
    Helpful Answer Positive Rating
You are right MR swapan .
i have worked for 5 years in stabilizer field.
there are 2 major reasons to ignore your great idea.
1:> stabilizer is very cheep item, it should be as cheep as possible.
2:> stabilizer is mostly used in rural areas . there are not available trained engineers.
So design should be as simple as possible.
 

You are right MR swapan .
i have worked for 5 years in stabilizer field.
there are 2 major reasons to ignore your great idea.
1:> stabilizer is very cheep item, it should be as cheep as possible.
2:> stabilizer is mostly used in rural areas . there are not available trained engineers.
So design should be as simple as possible.

Please sir irfan ahmad please write a programming the transformer with pic16f676. pic16f676 is used so it is reprogramming? upload.jpg
 

Hi, Mr. irfan ahmad,

Please clear me the meaning of this line under your programme given below
Code:
 void adc_read  (void)

{
   delay_ms(20);

      main_v =read_adc();

         main_v=main_v*5000/1023;
}
 
Last edited:

This section read output voltage of stabilizer.

Hi, Mr. irfan ahmad,

I know this section is read the output voltage. i just want to understand this calculation. (main_v=main_v*5000/1023)
 

Hi irfan ahmad,

It is desirable to actuate electromagnetic relay near current zero crossing. If a voltage zero crossing detector is included and interfaced to any port, how you will manage it in code. To be more clear - how much delay would be required to send a drive for relay after detecting voltage zero crossing.

swapan

A problem here is that you don't know for sure how long it takes for the relay to "switch completely" after you engergized/deenergized the coil. So,even though you need to do this, the behavior isn't necessarily very predictable. While you may know approximate values (by measurement or from datasheet if available), you can expect significant variation from part to part for the cheap regular relays available in the market.

Hi, Mr. irfan ahmad,

I know this section is read the output voltage. i just want to understand this calculation. (main_v=main_v*5000/1023)

That is for scaling the measured voltage. Since the maximum reading of the ADC is 1023 and that corresponds to the max voltage of 5000, the main_v is scaled to a range of 0 to 5000 (I believe 5000 corresponds to 5.0V but I could be wrong).

However, I do think that it should be /1024 not /1023.
 

@ irfan

What are the voltages that appear at each tapping of the transformer ?
 

DEAR milan.rajik
as i have mentioned in post#9 (circuit diagram)
voltages are
0
135
175
220
260
and isolated 12volts for circuit excitation.
 

Dear Irfan

Where can I buy such a transformer online for testing purpose. I want to build a stabilizer using 5 relays.


Irfan please test this code. I have converted your CCS C code to mikroC code. Maybe ADCON1 setting has to be done. I think other things are ok. Hex file attached compiled for 4 MHz INTROSC.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#define relay1   RA1_bit      //main   change
#define relay2   RA2_bit      //main   change
#define relay3   RC0_bit      //outputchange
#define relay4   RC1_bit      //output on off
#define led      RC4_bit      //
#define sw       RA3_bit      //active low
   
#define low_limit  1550  // limit for low  voltage
#define high_limit 2450  // limit for high voltage
#define low_ok     2100  // value for main low  function compleate
#define high_ok    2440  // value for main high function compleate
 
#define on output_high
#define off output_low
 
unsigned long main_v = 1000, count;
unsigned char step = 1, time = 0, x;
unsigned char fault = 0;
unsigned char delay = 30;
 
void read_adc();
void relay_Set ();
void main_high ();
void main_low  ();
void initialize();
void start_up ();
 
//Timer1
//Prescaler 1:8; TMR1 Preload = 3036; Actual Interrupt Time : 500 ms
 
//Place/Copy this part in declaration section
void InitTimer1(){
  T1CON = 0x31;
  TMR1IF_bit = 0;
  TMR1H = 0x0B;
  TMR1L = 0xDC;
  TMR1IE_bit = 1;
  INTCON = 0xC0;
}
 
void Interrupt(){
      //Enter your code here
      if (TMR1IF_bit) {
      
            led = ~led;
 
            if (((++time > delay) || (sw == 0)) && (fault == 0)) {
            
                      time=0;
                      led = 1;
                      relay4 = 1;
                      TMR1IE_bit = 0;
                      GIE_bit = 0;
                      PEIE_bit = 0;
            }
 
            TMR1H = 0x0B;
            TMR1L = 0xDC;
            TMR1IF_bit = 0;
      }
}
 
void initialize() {
      TRISA = 0b11110001;
      TRISC = 0b11111000;
      ANSEL = 0x01;
      relay4 = 0;
      relay1 = 1;
      relay2 = 1;
      relay3 = 1;
      //output_float(pin_a0);
}
 
void read_adc  (void) {
      Delay_ms(20);
      main_v = ADC_Read(0) * 5000 / 1023;
}
 
void start_up() {
      Delay_ms(100);
      read_adc();
      InitTimer1();
}
 
void main_low() {
 
      TMR1IE_bit = 1;;            // reset timer and interrupt
      GIE_bit = 1;
      PEIE_bit = 1;
 
      relay4 = 0;
      relay3 = 0;
      relay2 = 0;
      relay1 = 0;
 
      Delay_ms(500);
 
      while(main_v < low_ok) {
              time = 0;
              read_adc();
      }
}
 
void main_high() {
 
      TMR1IE_bit = 1;;            // reset timer and interrupt
      GIE_bit = 1;
      PEIE_bit = 1;
 
      relay4 = 0;
      relay1 = 1;
      relay2 = 1;
      relay3 = 1;
 
      Delay_ms(500);
 
      while(main_v >= high_ok) {
            time = 0;
            read_adc();
      }
}
 
void relay_set() {
 
      switch(step) {
          case 1:
              relay1 = 1;
              relay2 = 1;
              relay3 = 1;
              break;
          case 2:
              relay1 = 1;
              relay2 = 1;
              relay3 = 0;
              break;
          case 3:
              relay1 = 1;
              relay2 = 0;
              relay3 = 1;
              break;
          case 4:
              relay1 = 1;
              relay2 = 0;
              relay3 = 0;
              break;
          case 5:
              relay1 = 0;
              relay2 = 0;
              relay3 = 1;
              break;
          case 6:
              relay1 = 0;
              relay2 = 0;
              relay3 = 0;
              break;
      };
}
 
void  main() {
   
      initialize();
 
      while(1) {
 
            start_up();
 
            do
            {
                for(x = 0; x < 20; x++) { //loop to perform voltage stabalization function
                                      // if gap is larg then  only one step can not stabal voltage
                    read_adc();
 
                    if(main_v > 2410) {
                           --step;
                           
                           if(step < 1)step = 1;
                    }
                    else if(main_v < 1630) {                      //200V
                           ++step;
                           
                           if(step > 6)step = 6;
                    }
                    
                    relay_set();
 
                }     //239V
 
 
            } while((main_v < high_limit) && (main_v > low_limit));  // check  the limits
 
            fault = 1;
            time = 0;                                 // reset timer if it was running
 
            if(main_v >= high_limit)main_high();      // call  relevent function
            else if(main_v <= low_limit)main_low();    // call  relevent function
 
            TMR1IE_bit = 0;;            // reset timer and interrupt
            GIE_bit = 0;
            PEIE_bit = 0;
 
            fault=0;
      }
}

 

Attachments

  • stabilizer.rar
    1.3 KB · Views: 394
Last edited:
DEAR sir Tahmid.
as maximum value of adc is 1023 .
so if we want to obtain 5000 value at 5 volt
we should use this formula.
AdcValue= AdcValue*5000/1023;

here is a link your personal artical https://www.edaboard.com/blog/1569/

dear milan.rajik .
you can order any transformer maker to make transformer of these specifications (i will upload any picture of of transformer soon )
second thing i dont use mikroc so i will not be able to guide you regarding mikroc sorry for that.
 

Irfan has used 5000 instead of 5.0 to avoid floating point calc.
 

DEAR sir Tahmid.
as maximum value of adc is 1023 .
so if we want to obtain 5000 value at 5 volt
we should use this formula.
AdcValue= AdcValue*5000/1023;

here is a link your personal artical https://www.edaboard.com/blog/1569/

Since the maximum voltage is 5V and you have 1024 steps, each step is: (5/1024) V = 4.8828125mV. So an ADC reading gives (4.8828125 * 1023)mV = 4.99511718175V: [not 5V]. One "step" more would be: 4.99511718175V + 4.8828125mV = 4.99999..... V = 5.0V. So that one more step would correspond to 1024 if available. However you can't have 1024 since it's a 10-bit ADC.

Instead of dividing by 1024, you can ">> 10" - that'll be faster.

However, /1023 and /1024 are both fine - they just 'set maximum ranges'. If in your example you're going for 1023 representing 5.00V then what you've done is correct.

The reason I mentioned the /1024 is because if you're using VDD as +VREF, you'll actually not get 1023 representing 5.0V but instead 4.9V assuming VDD = 5.0V.

However, /1023 is fine as long as that little bit of calibration is done externally.

I'll update the article to reflect this.

Hope this helps.
Tahmid.
 
Last edited:

    V

    Points: 2
    Helpful Answer Positive Rating
Hi Tahmid,

Thanks for your comment on applying relay operation at voltage zero crossing (post #87). Based on your project I have assembled one Voltage Stabiliser with PIC16F676. The code is given as under. I want to operate the relays with a delay of 5ms after detecting zero cross pulse. The zero cross pulse is polled at port RA0. Please see the addition I have made in the code for this purpose. The piece of code I have come across in this forum. But sorry to say, the circuit does not work with the additional piece of code.

Please suggest any way out.


swapan

Code:
 sbit RLY_1 at RC4_bit;
 sbit RLY_2 at RC5_bit;
 sbit RLY_3 at RA4_bit;
 sbit RLY_4 at RA5_bit;
 sbit null at RA0_bit;
 volatile unsigned char testflag;
 sbit normal at testflag.B1;
 # define INTAP_LOW 0
 # define INTAP_MED 1
 # define INTAP_HIGH 2
 
 #define OUTTAP_LOW 0
 # define OUTTAP_HIGH 1
 unsigned char INPUT_TAPPING;
 unsigned char OUTPUT_TAPPING;
 
 void Init(void){
PORTA = 0x0;
TRISA = 0x1;
PORTC = 0x0;
TRISC = 0x2;
ANSEL = 0x20;
CMCON = 0x7;
}

 void StabilizeVoltage(void) {
unsigned int adv, new_adv,adv_old, hysteriasis,  count;
adv = ADC_Read (5);

if (adv < 300) {
normal = 0;
INPUT_TAPPING = INTAP_LOW;
OUTPUT_TAPPING = OUTTAP_LOW;
adv_old = adv;              
               }

else if (adv > 1020) {
normal = 0;
INPUT_TAPPING = INTAP_HIGH;
OUTPUT_TAPPING = OUTTAP_HIGH;
adv_old = adv;                       
                     }

else    {
normal  =1;


if  (adv < adv_old) {
hysteriasis = adv_old - adv;
                    }
else
hysteriasis = adv - adv_old;

if (hysteriasis >= 25){
if (adv < 360) {
INPUT_TAPPING = INTAP_LOW;
OUTPUT_TAPPING = OUTTAP_LOW;
adv_old = adv;
               }
else if (adv<490 ) {
INPUT_TAPPING = INTAP_LOW;
OUTPUT_TAPPING = OUTTAP_HIGH;
adv_old = adv;
              }
else if (adv<649 ) {
INPUT_TAPPING = INTAP_MED;
OUTPUT_TAPPING = OUTTAP_LOW;
adv_old = adv;
                    }
 else  if (adv<969 ) {
INPUT_TAPPING = INTAP_MED;
OUTPUT_TAPPING = OUTTAP_HIGH;
adv_old = adv;
                      }
else if (adv<1020 )  {
INPUT_TAPPING = INTAP_HIGH;
OUTPUT_TAPPING = OUTTAP_LOW;
adv_old = adv;
                     }
else   {
INPUT_TAPPING = INTAP_HIGH;
OUTPUT_TAPPING = OUTTAP_HIGH;
adv_old = adv;
       }
               }

         }
[COLOR="#FF0000"]while (null);
while (!null);
delay_us(5000);[/COLOR]
 if (INPUT_TAPPING == INTAP_LOW ){

 RLY_1 =0;
 RLY_2 =0;
                               }
 else if ( INPUT_TAPPING == INTAP_MED)  {
 RLY_1 =0;
 RLY_2 =1;
                                      }
 else    {
 RLY_1 =1;
 RLY_2 =1;
         }

if (OUTPUT_TAPPING == OUTTAP_HIGH) {
RLY_3  = 1;
                                  }
else     {
RLY_3  = 0;
         }

if (normal == 1) {
RLY_4 = 1;
                }
else      {

RLY_4 = 0;

          }

  }

void main() {
 Init();
 while(1){
 StabilizeVoltage();
         }

}
 

Please help me to simulate this programme in the proteus..
 

Please help me to simulate this programme in the proteus..
Dpwnload Proteus file at #69 post and get hex file #63 post.
Keep both files in same folder and press play button in Proteus simulation window.
 
Hi, Mr. pnjbtr ,

I want to add a buzzer at low line voltage & high line voltage, what to do in programme?
 

I think we can simply use buzzer with some changes in code.
Add buzzer according to given schematic at any extra (empty pin) of pic mcu.
Code:
  [COLOR="#FF0000"]#define     buzzer   pin_c3[/COLOR]      //buzzer for mains low and high
   #define     relay1   pin_a1      //main   change
   #define     relay2   pin_a2      //main   change
   #define     relay3   pin_c0      //outputchange
   #define     relay4   pin_c1      //output on off
   #define     led      pin_c2      //led for indication of timer 
   #define     sw       pin_a3      //active low
   #define     low_limit      1550  // limit for low  voltage
   #define     high_limit     2450  // limit for high voltage
   #define     low_ok         2100  // value for main low  function compleate
   #define     high_ok        2440  // value for main high function compleate
   
   #define  on       output_high
   #define  off      output_low
   
[CODE]
  
[CODE] void main_low  (void)
{
   enable_interrupts(int_timer1);
       enable_interrupts(global);
              
      [COLOR="#FF0000"]   on(buzzer);[/COLOR]
         off(relay4);

And at mains high,
Code:
 void main_high (void)
{
   enable_interrupts(int_timer1);

      enable_interrupts(global);
      
        [COLOR="#FF0000"] on(buzzer);[/COLOR]
         off(relay4);

            on(relay1);
 

Attachments

  • stab.pdf
    9.1 KB · Views: 354
Last edited:
Hi, Mr. pnjbtr

Many many Thnaks..................

but how it off now & i want it's sound with delay (on, off, on, off)
 
Last edited:

but how it off now & i want it's sound with delay (on, off, on, off)
In previous post i forget to mention that,we also need a port pin(RC3) as output.
Code:
set_tris_c(0b1111[COLOR="#FF0000"]0[/COLOR]000);//RC3 now output
And here we can keep buzzer off,when output volts low/high become ok.
Code:
 if (((time>delay)||(input(sw)==0))  &&  (fault==0)) 
   {
   
                  time=0;                          // for next round

                     on(led);
                         [COLOR="#00FF00"]off(buzzer);[/COLOR]
                        on(relay4);
   
                        disable_interrupts(int_timer1);

                            disable_interrupts(global);}
}[CODE]
Regarding buzzer flash need some time to understand the code.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top