Automatic Transfer Switch Design with Schematics and Code - Page 1
Forum section: electronics / projects

author: VEGETA
author_rank: Super Contributor
timestamp: March 04, 2013, 09:35:06 pm
content: 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)

author: NiHaoMike
author_rank: Super Contributor
timestamp: March 05, 2013, 02:21:03 am
content: The contactors should be mechanically interlocked so they cannot turn on at the same time.

author: VEGETA
author_rank: Super Contributor
timestamp: March 05, 2013, 05:10:17 am
content: 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.

author: David_AVD
author_rank: Super Contributor
timestamp: March 05, 2013, 05:57:47 am
content: Hard to help when you can't even download the file (hosted on another site that requires a login).

author: VEGETA
author_rank: Super Contributor
timestamp: March 05, 2013, 06:25:31 am
content: Quote from: David_AVD on March 05, 2013, 05:57:47 amSorry, I thought it can be downloaded.HERE is the link on a great host:http://www.gulfup.com/?5XxfM5for schematic, here is the picture (and it's in attachments too):http://s10.postimage.org/wr19npjmf/pic_jpeg.jpg

author: Alana
author_rank: Frequent Contributor
timestamp: March 05, 2013, 06:59:26 am
content: 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.

author: David_AVD
author_rank: Super Contributor
timestamp: March 05, 2013, 07:03:24 am
content: Relying on software to keep power sequencing correct is a recipe for disaster. Better to interlock it in hardware.

author: VEGETA
author_rank: Super Contributor
timestamp: March 05, 2013, 07:07:19 am
content: Quote from: Alana on March 05, 2013, 06:59:26 amyou 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?QuoteOk, 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.

author: Kremmen
author_rank: Super Contributor
timestamp: March 05, 2013, 08:33:05 am
content: Quote from: VEGETA on March 05, 2013, 07:07:19 amFirst, 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.

author: VEGETA
author_rank: Super Contributor
timestamp: March 05, 2013, 09:24:42 am
content: 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 ^_^

author: VEGETA
author_rank: Super Contributor
timestamp: March 05, 2013, 05:09:28 pm
content: Quote from: Kremmen on March 05, 2013, 08:33:05 amwell, 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: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 RD4unsigned int ADCRead(unsigned short channel){if (channel == 0) {ADCON0 = 0x81;} // convert from channel0if (channel == 1) {ADCON0 = 0x89;} // convert from channel1delay_us(80); // Acquisition DelayGO_DONE_bit = 1; // Set GO_DONE bit to start conversionwhile (GO_DONE_bit == 1); // Wait for bit to be cleared// If bit is cleared, this means conversion is overl_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 voltagereturn v;}void main(void){CMCON = 7; //Disable comparatorPORTA = 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 0xCEsource_1 = 0; // source_1 offsource_2 = 0; // source_2 offsource_1_on = 0; // source_1_on LED is OFFsource_2_on = 0; // source_2_on LED is OFFno_active_source = 0; // no_active_source LED is OFFv1 = 0;v2 = 0;adc1 = 0;adc2 = 0;while (1){// calculate channel0 voltagev1 = RMS_calculator (0);adc1 = ADR;// if (ADR >= 205 ) { RD5_bit = 1;}// else { RD5_bit = 0; }// calculate channel1 voltagev2 = 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_1delay_ms(5); // wait 5mssource_2 = 1; // activate source_2source_1_on = 0; // source_1_on LED is OFFsource_2_on = 1; // source_2_on LED is ONno_active_source = 0; // no_active_source LED is OFF}else {source_1 = 0; // source_1 offsource_2 = 0; // source_2 offno_active_source = 1; // no_active_source LED is ONsource_1_on = 0; // source_1_on LED is OFFsource_2_on = 0; // source_2_on LED is OFF}}if ( adc1 >= adc_rms_min ) { // if source_1 is active:source_2 = 0; // source_2 offdelay_ms(5); // wait 5mssource_1 = 1; // source_1 onno_active_source = 0; // no_active_source LED is OFFsource_1_on = 1; // source_1_on LED is ONsource_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

author: Kremmen
author_rank: Super Contributor
timestamp: March 05, 2013, 06:30:44 pm
content: Quote from: VEGETA on March 05, 2013, 09:24:42 amThe 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.

author: VEGETA
author_rank: Super Contributor
timestamp: March 05, 2013, 07:20:43 pm
content: 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 cyclepwm1_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 R3Cathode: PIC pinok?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

author: Kremmen
author_rank: Super Contributor
timestamp: March 05, 2013, 07:47:06 pm
content: Quote from: VEGETA on March 05, 2013, 07:20:43 pmYes, 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.QuoteYes 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.QuoteR5 is load only in the simulation. In your circuit connect loads there as you would connect to the +5V normal supply.QuoteActually, 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.QuoteAgain, 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.QuoteThe 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.

author: VEGETA
author_rank: Super Contributor
timestamp: March 05, 2013, 09:05:22 pm
content: QuoteThe 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?QuoteThat's quite I don't get. in order to activate interface circuits I need a simple pulse and my pulses will occur very rarely...QuoteWhat do you think of Proteus ISIS? Does your program simulates microcontrollers? cuz proteus does.

author: VEGETA
author_rank: Super Contributor
timestamp: March 06, 2013, 09:00:34 pm
content: 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?