Author Topic: Automatic Transfer Switch Design with Schematics and Code  (Read 17869 times)

0 Members and 2 Guests are viewing this topic.

Offline VEGETATopic starter

  • Super Contributor
  • ***
  • Posts: 2289
  • Country: jo
  • I am the cult of personality
    • Thundertronics
Automatic Transfer Switch Design with Schematics and Code
« on: March 04, 2013, 09:35:06 pm »
Hi... I am working at an ATS project (automatic transfer switch) and this program and schematic I used in protesu ISIS kinda gives me some error.

the ATS have 2 input sources (350v peak each) and 1 output which is gonna be one of them.

now the main problem is that it shorts out the 2 sources!

the control program seems fine as I put some indication LEDs and tested it.

Also, it have a AD736 True RMS-to-DC converter which have 1v peak input and outputs a 1v max dc voltage that equals to the rms of the signal.

I tested this IC in proteus and seemed fine.

I will post the schematic and attach the isis project file and MikroC program.

the program is made to activate the source if the ADC value above 117 as I remember.. I used voltage division to achieve needed signals.

this is the schematic:

http://s10.postimage.org/wr19npjmf/pic_jpeg.jpg

____

I hope that you try it and point out what's causing the short circuit (btw, my laptop is old and so simulation sometimes fail).

one important thing: in real-life should i connect a ground to an AC voltage source? I don't think so but simulation can't be done without it.

looking forward to your help.

FILES:    (45 kb)
« Last Edit: March 05, 2013, 06:27:09 am by VEGETA »
 

Offline NiHaoMike

  • Super Contributor
  • ***
  • Posts: 9782
  • Country: us
  • "Don't turn it on - Take it apart!"
    • Facebook Page
Re: Automatic Transfer Switch Design with Schematics and Code
« Reply #1 on: March 05, 2013, 02:21:03 am »
The contactors should be mechanically interlocked so they cannot turn on at the same time.
Cryptocurrency has taught me to love math and at the same time be baffled by it.
Cryptocurrency lesson 0: Altcoins and Bitcoin are not the same thing.
BTC: 18813fu8LQEdDwH9YLM1ABed3XwCfeSeFi
 

Offline VEGETATopic starter

  • Super Contributor
  • ***
  • Posts: 2289
  • Country: jo
  • I am the cult of personality
    • Thundertronics
Re: Automatic Transfer Switch Design with Schematics and Code
« Reply #2 on: March 05, 2013, 05:10:17 am »
well, I didn't use any contacts yet. I prefer that you point that out in the schematics.

all I did till now is just simulation so no contacts... PLUS, the PIC16F877A will never activate the 2 of them at the same time if you run the file you will see that.. it's in the code too.

plus, no one answered about the neutral/ground in AC sources like here.

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2957
  • Country: au
Re: Automatic Transfer Switch Design with Schematics and Code
« Reply #3 on: March 05, 2013, 05:57:47 am »
Hard to help when you can't even download the file (hosted on another site that requires a login).   :-//
 

Offline VEGETATopic starter

  • Super Contributor
  • ***
  • Posts: 2289
  • Country: jo
  • I am the cult of personality
    • Thundertronics
Re: Automatic Transfer Switch Design with Schematics and Code
« Reply #4 on: March 05, 2013, 06:25:31 am »
Hard to help when you can't even download the file (hosted on another site that requires a login).   :-//

Sorry, I thought it can be downloaded.

HERE is the link on a great host: http://www.gulfup.com/?5XxfM5

for schematic, here is the picture (and it's in attachments too):

http://s10.postimage.org/wr19npjmf/pic_jpeg.jpg

Offline Alana

  • Frequent Contributor
  • **
  • Posts: 297
  • Country: pl
Re: Automatic Transfer Switch Design with Schematics and Code
« Reply #5 on: March 05, 2013, 06:59:26 am »
I'm not an expert but...
Try to imagine that you turn on triac 2 at the exact moment when ADC detect undervoltage on line 1.

You turn on line 2 but because triac 1 will shutdown only on zero crossing you may have line 1 still connected and BUM short circut!

Simplest way to deal with it is IMO to time out 1 period of mains frequency between detection of undervoltage and starting up the other triac. This gives time for triac 1 to shut down before you enable triac2.
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2957
  • Country: au
Re: Automatic Transfer Switch Design with Schematics and Code
« Reply #6 on: March 05, 2013, 07:03:24 am »
Relying on software to keep power sequencing correct is a recipe for disaster.  Better to interlock it in hardware.
 

Offline VEGETATopic starter

  • Super Contributor
  • ***
  • Posts: 2289
  • Country: jo
  • I am the cult of personality
    • Thundertronics
Re: Automatic Transfer Switch Design with Schematics and Code
« Reply #7 on: March 05, 2013, 07:07:19 am »
I'm not an expert but...
Try to imagine that you turn on triac 2 at the exact moment when ADC detect undervoltage on line 1.

You turn on line 2 but because triac 1 will shutdown only on zero crossing you may have line 1 still connected and BUM short circut!

Simplest way to deal with it is IMO to time out 1 period of mains frequency between detection of undervoltage and starting up the other triac. This gives time for triac 1 to shut down before you enable triac2.

you saw my code?

I put 5ms delay between shutting down S2 and activating Source 1... now, frequency = 50 Hz so each period = 20ms. half period = 10ms... so, do you mean that I make the delay 10ms instead of 5ms? to ensure that only 1 is active?

Quote
Relying on software to keep power sequencing correct is a recipe for disaster.  Better to interlock it in hardware.

Ok, can you help me interlock it in hardware? I posted the full schematic and if you have a way to help please tell me.

thanks everyone.

Offline Kremmen

  • Super Contributor
  • ***
  • Posts: 1290
  • Country: fi
Re: Automatic Transfer Switch Design with Schematics and Code
« Reply #8 on: March 05, 2013, 08:33:05 am »
[...]
Ok, can you help me interlock it in hardware? I posted the full schematic and if you have a way to help please tell me.

thanks everyone.

First, but not necessarily sufficient safeguard: include a charge pump watchdog in the control circuit. To do this:
-reverse the opto diode control so that the PIC connects to the cathode. Diode conducts when the PIC output is low.
-connect the opto diode anodes to a switched rail voltage. The voltage to be switched on using a charge pump.
-dedicate one PIC output to generate the charge pump square wave ~10kHz or something similar. In software! - NOT an automatic hardware clock.
-include in your schematic the said charge pump. Input to be ~10kHz square wave and output is the supply voltage to the opto diode anodes via a suitable FET from the supply rail. When input frequency is absent, the FET does not conduct.

Now, when the PIC boots, you first raise the opto outputs, then initiate the charge pump and only then do you start the actual triac control.
This will only safeguard agains software crashes, but does not interlock the controls against each other. One possibility would be to include additional HW logic to create the exclusion. Note that a triac will conduct to the end of the current half-sine so switching on the next triac during that time will cause shoot-through. So you need to ensure that the first triac is turned off before firing the next one.

Old school double relays are still the surefire way to prevent trouble, but admittedly clunky, slow and won't last for too long if the switching is frequent.
Nothing sings like a kilovolt.
Dr W. Bishop
 

Offline VEGETATopic starter

  • Super Contributor
  • ***
  • Posts: 2289
  • Country: jo
  • I am the cult of personality
    • Thundertronics
Re: Automatic Transfer Switch Design with Schematics and Code
« Reply #9 on: March 05, 2013, 09:24:42 am »
well, I didn't quite understand what you mean, because I haven't tried using these techniques before.

can you put a simple schematic picture describing your idea?

this pump is the most thing i didn't understand really... the PIC pin to be connected to - terminal of the triac driver can be made, but the + terminal where to connect it? "switched rail voltage"?

I began to imagine what you mean... is it like some voltage detector ICs?

I'm interested in your idea... so please put some schematics and so. << maybe I'm tiring you with me but I can't understand everything you said ^_^



Offline VEGETATopic starter

  • Super Contributor
  • ***
  • Posts: 2289
  • Country: jo
  • I am the cult of personality
    • Thundertronics
Re: Automatic Transfer Switch Design with Schematics and Code
« Reply #10 on: March 05, 2013, 05:09:28 pm »
[...]
Ok, can you help me interlock it in hardware? I posted the full schematic and if you have a way to help please tell me.

thanks everyone.

First, but not necessarily sufficient safeguard: include a charge pump watchdog in the control circuit. To do this:
-reverse the opto diode control so that the PIC connects to the cathode. Diode conducts when the PIC output is low.
-connect the opto diode anodes to a switched rail voltage. The voltage to be switched on using a charge pump.
-dedicate one PIC output to generate the charge pump square wave ~10kHz or something similar. In software! - NOT an automatic hardware clock.
-include in your schematic the said charge pump. Input to be ~10kHz square wave and output is the supply voltage to the opto diode anodes via a suitable FET from the supply rail. When input frequency is absent, the FET does not conduct.

Now, when the PIC boots, you first raise the opto outputs, then initiate the charge pump and only then do you start the actual triac control.
This will only safeguard agains software crashes, but does not interlock the controls against each other. One possibility would be to include additional HW logic to create the exclusion. Note that a triac will conduct to the end of the current half-sine so switching on the next triac during that time will cause shoot-through. So you need to ensure that the first triac is turned off before firing the next one.

Old school double relays are still the surefire way to prevent trouble, but admittedly clunky, slow and won't last for too long if the switching is frequent.

well, I tried like the image in attachments... but it didn't work as you said.

____

anyway, I tried the circuit without using PIC, instead I used normal switches (manual) and it worked well...

I then tried a 1Hz clock (on-off) on both sources (inverted) and it worked nicely!!!

SO, is it proper to think that this is a problem caused by the PIC program?

to make it easy, I will post the FULL code here... :


Code: [Select]
float  v, v1, v2;
unsigned int adc1, adc2;
unsigned char l_byte, h_byte;
unsigned int ADR;
unsigned short channel;


/////* Definitions */////

#define v_rms_min 200                          // lowest alloable RMS voltage
#define adc_rms_min 117

#define source_1  RD0_bit                      // source_1 @ pin RD0
#define source_2  RD1_bit                      // source_2 @ pin RD1
#define no_active_source  RD2_bit              // no_active_source indication LED @ pin RD2
#define source_1_on  RD3_bit                   // source_1_on indication LED @ pin RD3
#define source_2_on  RD4_bit                   // source_2_on indication LED @ pin RD4



unsigned int ADCRead(unsigned short channel){

        if (channel == 0) {ADCON0 = 0x81;}          // convert from channel0
        if (channel == 1) {ADCON0 = 0x89;}          // convert from channel1
       
        delay_us(80);                               // Acquisition Delay
        GO_DONE_bit = 1;                            // Set GO_DONE bit to start conversion
        while (GO_DONE_bit == 1);                   // Wait for bit to be cleared
                                                    // If bit is cleared, this means conversion is over
        l_byte = ADRESL;
        h_byte = ADRESH;
        ADR = (h_byte<<8)|l_byte;
        return ADR;
}

unsigned int RMS_calculator (unsigned short source) {

                channel = source;
                v = ( ADCRead(channel)*350 )/(205);  // outputs a 0-350v RMS voltage
               
               return v;
}



 void main(void){


        CMCON = 7; //Disable comparator

        PORTA = 0;
        TRISA = 0xff;
       
        PORTD = 0;
        TRISD = 0;
       
        PORTC = 0;
        TRISC = 0;
       
        PORTB = 0;
        TRISB = 0;
       
        ADCON0 = 0x81;
        ADCON1 = 0xC0;                            // all portA pins are analog   // was 0xCE
       
        source_1 = 0;                             // source_1 off
        source_2 = 0;                             // source_2 off
        source_1_on = 0;                          // source_1_on LED is OFF
        source_2_on = 0;                          // source_2_on LED is OFF
        no_active_source = 0;                     // no_active_source LED is OFF
        v1 = 0;
        v2 = 0;
        adc1 = 0;
        adc2 = 0;
while (1){

                                   // calculate channel0 voltage

        v1 = RMS_calculator (0);
        adc1 = ADR;
       // if (ADR >= 205 ) { RD5_bit = 1;}
      //  else { RD5_bit = 0; }

                                   // calculate channel1 voltage
        v2 = RMS_calculator (1);
        adc2 = ADR;
       
        if ( adc1 < adc_rms_min ) {                       // if source_1 is not active:
       
          if ( adc2 >= adc_rms_min ) {                    // if source_2 is active:
           
            source_1 = 0;                             // deactivate source_1
            delay_ms(5);                              // wait 5ms
            source_2 = 1;                             // activate source_2
            source_1_on = 0;                          // source_1_on LED is OFF
            source_2_on = 1;                          // source_2_on LED is ON
            no_active_source = 0;                     // no_active_source LED is OFF
           
            }
          else {
         
            source_1 = 0;                               // source_1 off
            source_2 = 0;                               // source_2 off
            no_active_source = 1;                       // no_active_source LED is ON
            source_1_on = 0;                            // source_1_on LED is OFF
            source_2_on = 0;                            // source_2_on LED is OFF
         
            }
          }
         
        if ( adc1 >= adc_rms_min ) {                      // if source_1 is active:
       
          source_2 = 0;                               // source_2 off
          delay_ms(5);                                // wait 5ms
          source_1 = 1;                               // source_1 on
          no_active_source = 0;                       // no_active_source LED is OFF
          source_1_on = 1;                            // source_1_on LED is ON
          source_2_on = 0;                            // source_2_on LED is OFF
       
       
        }
       

       delay_ms(100);
       //portb = v1;
       //portc = v2;
       
  }
}

is it caused (maybe) by keep triggering every cycle? i.e, if source1 is active now we activate it... next cycle it will still be nice but the program also keep deactivating source2 and activating source 1.

Do you find using some kinda status program?

something like:

status1 - status2 - status 3 -....

it will activate status 1 (source 1 active for example) and store it in a variable as prev_status... now in the next cycle, if it reads that the status = prev_status, it shouldn't do anything but return... that will ensure the program only trigger stuff when status changes.

what is your opinion?

forgive me for this long explanation ^_^ but I'm suffering cuz of this problem!

thx

Offline Kremmen

  • Super Contributor
  • ***
  • Posts: 1290
  • Country: fi
Re: Automatic Transfer Switch Design with Schematics and Code
« Reply #11 on: March 05, 2013, 06:30:44 pm »
well, I didn't quite understand what you mean, because I haven't tried using these techniques before.

can you put a simple schematic picture describing your idea?

this pump is the most thing i didn't understand really... the PIC pin to be connected to - terminal of the triac driver can be made, but the + terminal where to connect it? "switched rail voltage"?

I began to imagine what you mean... is it like some voltage detector ICs?

I'm interested in your idea... so please put some schematics and so. << maybe I'm tiring you with me but I can't understand everything you said ^_^

The charge pump ensures that your PIC and its software must operate correctly before critical output control signals are enabled. This kind of circuit is often used in CNC machine control done via PC parallel port, because after boot the parport signals can be all over the place before the control software is active. You don't want a big fast machine going berserk on you...

Attached is a circuit in simulation, and a virtual scope capture. What you see in the schematic is this:

- Source V1 is (your PIC) power supply, 5 V in this simulation but whatever you actually use.
- Sources V3 and V2 are simulations of the incoming pulse train. V2 is a voltage controlled square wave oscillator, control range 0-1V == 0-20kHz at 3.5 V output amplitude. V3 is a sawtooth generator producing a voltage ramps 0 to 1V in 50 ms, thus driving source V2 from 0 to 20 kHz in the 50 ms period.
- The actual charge pump is everything between, and connecting the coloured wires on top, is a virtual 4 channel oscilloscope. The trace of that one is shown in the next picture.

The charge pump works like this:
- the incoming square wave is pumped into C3 using C2 and diodes D1,D2 (google how that works). R4 is there to quickly discharge C3 when the pulses stop.
- Rising pump voltage in C3 eventually turns on FET Q3 that in turn pulls down the voltage accumulated in C1 via R3. This then turns on the P-FET Q1, causing R5 - the load - to get supply voltage.

So your opto diode anodes should be connected to FET Q1 in place of R3, and the cathodes to PIC outputs. When the output is low, current will flow through the diode, provided the pump is on.
To turn the pump on, you need to provide a min. 12 kHz square wave signal to C2 (Vin) from the PIC, generated in your code to make sure the code is actually running.

What you see in the other picture, the virtual scope trace:
- The color of the trace corresponds to the color of the connection in the schematic. Thus yellow = incoming pulse train 0 - 20 kHz, green is the Q3 drain voltage, red is Q1 gate voltage and blue is the actual pump output.
- All traces are 5 V / div, each offset 5V from the next to make the picture clearer. So all signal swings are actually 0-5V in their "lanes". The X direction is 10 ms/div. So you can see almost 2 complete cycles of the V3 driving generator.
- The frequency (yellow) increases linearly from 0 to 20 kHz during one cycle of source V3. You can see that at 30 ms point in the trace, the blue output voltage is fully up, and at that point the input frequency will be at 12 kHz (since it is a linear ramp).
- At 50 ms the Source V3 output drops to 0, as does the pump input frequency. You can see that the pump output drops to 0 volts almost instantly. Then the cycle begins again. This means that the pump must be driven by a square wave of at least 12 kHz to enable the output. Make the FET Q1 a robust one and it can supply most circuits where this kind of safeguard is needed.

Clear? If not just ask and i will give more details.
Nothing sings like a kilovolt.
Dr W. Bishop
 

Offline VEGETATopic starter

  • Super Contributor
  • ***
  • Posts: 2289
  • Country: jo
  • I am the cult of personality
    • Thundertronics
Re: Automatic Transfer Switch Design with Schematics and Code
« Reply #12 on: March 05, 2013, 07:20:43 pm »
thanks for this great info!

I will look at it in details later cuz I'm busy now.

but you but 2 sources before C2 which are V2 and V3... all you wanted is a 20KHz square-wave right?

so no need for a saw-tooth signal and you said it's just a simulation... meaning I can make a MikroC code like this:

pwm1_init(20000);
pwm1_set_duty(128); // 50% duty cycle
pwm1_start();

then connecting it's pin to C2? also, here there will be no ground... but C2 and other will be connected.

other thing is that I will connect a PIC pin to the Cathod and here current will flow into the PIC right? here, it will damage it or what?

TRIAC driver will be connected as follow:

Anode: instead of R3
Cathode: PIC pin

ok?

you said R5 is a load.... in my design there are 2 sources and I will pick 1 of them to activate...

I needed your help only to make sure no short circuit occurs and I assume this pump guarantees that?

the load will (eventually) be just a normal connector so you can connect it to any device... and my ATS design will have 2 inputs for you.

if I have 2 sources, that means I should put your pump circuit into each one of them, isn't it?

look at my schematic again and you will imagine how it will be...

never to mention the software part... my software is quite easy, if you look at it you will understand it with no hardships so please do.


___

BTW, what is that program u used?
thanks
« Last Edit: March 05, 2013, 07:22:44 pm by VEGETA »
 

Offline Kremmen

  • Super Contributor
  • ***
  • Posts: 1290
  • Country: fi
Re: Automatic Transfer Switch Design with Schematics and Code
« Reply #13 on: March 05, 2013, 07:47:06 pm »
thanks for this great info!

I will look at it in details later cuz I'm busy now.

but you but 2 sources before C2 which are V2 and V3... all you wanted is a 20KHz square-wave right?

so no need for a saw-tooth signal and you said it's just a simulation... meaning I can make a MikroC code like this:

pwm1_init(20000);
pwm1_set_duty(128); // 50% duty cycle
pwm1_start();
Yes, but i also said "... generated in your _code_...". If the code snippet you included programs a hardware timer to create the square wave, then that is _not_ what i meant. You should insert the output commands explicitly in your source such that the code must continue to run to produce the pulses. If not, the pulses stop. A hardware counter may keep on counting after a program crash, defeating the purpose of the pump.
Quote

then connecting it's pin to C2? also, here there will be no ground... but C2 and other will be connected.

other thing is that I will connect a PIC pin to the Cathod and here current will flow into the PIC right? here, it will damage it or what?
Yes it will flow into the PIC and no, it will not damage it. Of course you must provide resistors in series to limit the current (which were missing from your original schematic, by the way). But the direction of current is not a problem. Often the pins can sink more current than they can source.
Quote

TRIAC driver will be connected as follow:

Anode: instead of R3
Cathode: PIC pin

ok?

you said R5 is a load.... in my design there are 2 sources and I will pick 1 of them to activate...
R5 is load only in the simulation. In your circuit connect loads there as you would connect to the +5V normal supply.
Quote

I needed your help only to make sure no short circuit occurs and I assume this pump guarantees that?
Actually, no. The purpose of this circuit is only to ensure that your software is alive before the PIC tries to mess with the outside world. Avoidance of shorts is your responsibility as circuit designer.
Quote

the load will (eventually) be just a normal connector so you can connect it to any device... and my ATS design will have 2 inputs for you.

if I have 2 sources, that means I should put your pump circuit into each one of them, isn't it?
Again, no. One PIC, one pump. The pump turns on the voltage that activates interface circuits, in this case the optos. You need anything else activated as well, just include it in the pump output voltage same as the optos.
Quote

look at my schematic again and you will imagine how it will be...

never to mention the software part... my software is quite easy, if you look at it you will understand it with no hardships so please do.


___

BTW, what is that program u used?
thanks

The simulation is done in National Instruments Multisim. Not free and not cheap. LTSpice is a good free alternative, i recommend you get familiar with that.
Nothing sings like a kilovolt.
Dr W. Bishop
 

Offline VEGETATopic starter

  • Super Contributor
  • ***
  • Posts: 2289
  • Country: jo
  • I am the cult of personality
    • Thundertronics
Re: Automatic Transfer Switch Design with Schematics and Code
« Reply #14 on: March 05, 2013, 09:05:22 pm »
Quote
Actually, no. The purpose of this circuit is only to ensure that your software is alive before the PIC tries to mess with the outside world. Avoidance of shorts is your responsibility as circuit designer.

The reason I posted this thread is to get help with this short circuit problem. I made initial stuff in the program before the infinite loop... this stuff is deactivating everything so no any source is active, after that it will activate the required source as voltage reading through AD736 True RMS-to-DC converter WHILE ensuring no short circuit occurs.

So, can you help me in solving this problem?

Quote
Again, no. One PIC, one pump. The pump turns on the voltage that activates interface circuits, in this case the optos. You need anything else activated as well, just include it in the pump output voltage same as the optos.

That's quite I don't get. in order to activate interface circuits I need a simple pulse and my pulses will occur very rarely...

Quote
The simulation is done in National Instruments Multisim. Not free and not cheap. LTSpice is a good free alternative, i recommend you get familiar with that.

What do you think of Proteus ISIS? Does your program simulates microcontrollers? cuz proteus does.

Offline VEGETATopic starter

  • Super Contributor
  • ***
  • Posts: 2289
  • Country: jo
  • I am the cult of personality
    • Thundertronics
Re: Automatic Transfer Switch Design with Schematics and Code
« Reply #15 on: March 06, 2013, 09:00:34 pm »
well... can this be caused by linking both sources' neutrals at the same ground? or linking them to ground in the 1st place? (I linked it to ground for the simulation to work).

any clues?

forget the short circuiting thing... Is there any error in wiring/connecting stuff in the circuit? and triac driving?

for triac driving... should I connect the neutral line to the triac gate too?


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

-->