AC THREE PHASE ANALOG INPUTS DETECTOR C CODE

Discussion in 'The Projects Forum' started by dhananjaya, Jul 12, 2015.

  1. dhananjaya

    Thread Starter New Member

    Jan 18, 2014
    1
    0
    Dear Sir/Madam please give any idea/concept for AC Phase detecting either Present/Absent (Logic 1/0)without converting DC volt to detect TTL PIC16F676 microcontroller someone already implemented this products but know i am also implementing this concept on same circuits but I have dont know the logic/ C code for this know I am tried as follows but still i cant able to detecting phase


    three phase (RY & B) AC analog inputs directly connected microcontroller pin without converting DC volts / reduced the voltage by using resistor divider circuit series with of 2.2Mohm 0.5watt+5Mohm 0.25watt connected to microcontroller(PIC16F676 pins RA0,RA1 & RA2). and internal oscillator like


    #define _XTAl_FREQ 4000000

    __CONFIG(0x3FF4)

    #define R_phase RA0

    #define Y_phase RA1

    #define B_phase RA2


    #define Three_phase_LED RC0

    #define Two_phase_LED RC1

    #define Single_phase_LED RC2

    #define NO_phase_LED RC3


    char phaseRflag = 0; // flag variables for each phase

    char phaseYflag = 0;

    char phaseBflag = 0;


    char single_phase_flag = 0; // used for single phase detection test


    unsigned int sample = 0; // used to set "for loop" duration


    void main()

    {

    CMCON=0x07;

    ANSEL=0x00;

    TRISA =0b001111;

    PORTA=0b001111;

    TRISC=0b000000;

    PORTC=0b00000;


    while(1) // while loop to test phases continously

    {

    phaseRflag = 0; // phase flags are set to zero

    phaseYflag = 0;

    phaseBflag = 0;



    // a "for loop" tests the inputs for 20 milliseconds, setting a flag if a logic 1 is read


    for(sample = 16000; sample > 0; sample--) // test all phases for at least 20 milliseconds

    {

    if(R_phase) // if a 1 is detected on a phase set a flag to 1;

    phaseRflag = 1;

    if(Y_phase)

    phaseYflag = 1;

    if(B_phase)

    phaseBflag = 1;

    } // end of the for loop


    // phase tests running as before, except now looking at the flag settings

    // test for all phases on ------------------------------------------------------


    if(phaseRflag && phaseYflag && phaseBflag)

    Three_phase_LED = 1; // RC0 pin connected(Three_phase) LED will Glow ON

    else

    Three_phase_LED = 0;


    // test for phase R and B on ------------------------------------------------


    if(phaseRflag && phaseBflag && !phaseYflag)

    Two_phase_LED = 1; // RC1 pin connected(Two_phase) LED will Glow ON

    else

    Two_phase_LED = 0;


    // test for a single phase on -------------------------------------------------


    single_phase_flag = 0; // set if only a single phase was detected


    if(phaseRflag || !phaseYflag || !phaseBflag) // only R_phase is on

    single_phase_flag = 1;



    if(!phaseRflag || phaseYflag || !phaseBflag) // only Y_phase is on

    single_phase_flag = 1;



    if(!phaseRflag || !phaseYflag || phaseBflag) // only B_phase is on

    single_phase_flag = 1;



    if(single_phase_flag == 1) // if a single phase was detected

    Single_phase_LED = 1; // RC2 pin connected(Single_phase) LED will Glow ON

    else

    Single_phase_LED = 0; // single phase LED off



    // test for no phases on ------------------------------------------------------



    if(!phaseRflag && !phaseYflag && !phaseBflag)

    NO_phase_LED = 1; // RC3 pin connected(No_phase) LED will Glow On

    else

    NO_phase_LED = 0;

    } // end of while loop

    } // end of main



    In this program only

    NO_phase_LED = 1; LED is On always....
     
  2. AnalogKid

    Distinguished Member

    Aug 1, 2013
    4,520
    1,247
    No matter how large the resistors are, you cannot connect three-phase AC power directly to a microcontroller. Also, this topic is not allowed on this forum because it can kill you.

    ak
     
Loading...