def Protection_Controller(arg):

    # Check Solar
    time.sleep(.01)  # Wait .01 seconds to prevent segmentation fault
    Solar_Voltage = PWM_Measure_Voltage(
        'Solar') / Parameters.Voltage_Multiplier  # Measure solar volatge
    DC_Link_Voltage = PWM_Measure_Voltage(
        'DC_Link') / Parameters.Voltage_Multiplier  # Measure DC link voltage

    if (Solar_Voltage >= Parameters.Solar_VDC_Max
            or Solar_Voltage <= Parameters.Solar_VDC_Min):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"),
                     3)  # Stop motor
        Transfer_Switch(0)  # Switch to grid source
        PWM.PWM_Write(
            Parameters.PWMPin, Parameters.PID_OLD_INIT *
            Parameters.Range)  # Reset PWM duty cycle to initial value
        DC_Relay(0)  # Set solar relay to open
        UPS_Error('Error_Solar_Voltage')

    if (DC_Link_Voltage >= Parameters.DCLink_VDC_Max
            or DC_Link_Voltage <= Parameters.DCLink_VDC_Min):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"),
                     3)  # Stop motor
        Transfer_Switch(0)  # Switch to grid source
        PWM.PWM_Write(
            Parameters.PWMPin, Parameters.PID_OLD_INIT *
            Parameters.Range)  # Reset PWM duty cycle to initial value
        DC_Relay(0)  # Set solar relay to open position
        UPS_Error('Error_DC_Link_Voltage')

    # Check Grid

    # Check VFD
    VFD_Freq = VFD.VFDRead(reg.get("ReadFunc",
                                   {}).get("Output_Frequency")) / 100
    VFD_Volt = VFD.VFDRead(reg.get("ReadFunc", {}).get("Output_Voltage"))
    VFD_Amps = VFD.VFDRead(reg.get("ReadFunc", {}).get("Output_Current")) / 100
    VFD_Power = VFD.VFDRead(reg.get("ReadFunc", {}).get("Output_Power")) / 10
    VFD_BusVolt = VFD.VFDRead(reg.get("ReadFunc", {}).get("Bus_Voltage"))
    VFD_Temp = VFD.VFDRead(reg.get("ReadFunc", {}).get("Temperature"))

    if (VFD_Freq >= Parameters.VFD_Freq_Max):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"), 3)
        UPS_Error('Error_VFD_Freq')
    if (VFD_Volt >= Parameters.VFD_Volt_Max):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"), 3)
        UPS_Error('Error_VFD_Volt')
    if (VFD_Amps >= Parameters.VFD_Amps_Max):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"), 3)
        UPS_Error('Error_VFD_Amps')
    if (VFD_Power >= Parameters.VFD_Power_Max):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"), 3)
        UPS_Error('Error_VFD_Power')
    if (VFD_BusVolt >= Parameters.VFD_BusVolt_Max):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"), 3)
        UPS_Error('Error_VFD_BusVolt')
    if (VFD_Temp >= Parameters.VFD_Temp_Max):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"), 3)
        UPS_Error('Error_VFD_Temp')
示例#2
0
def PWM_Controller(arg):
    global D_PID_OLD

    # Get DC link voltage measurement and calculate actual value
    DC_Volts = PWM_Measure_Voltage('DC_Link')
    DC_Link_Actual_Volts = DC_Volts/Parameters.Voltage_Multiplier
    print("DC link voltage=", DC_Actual_Volts)
    # Get DC link voltage measurement and calculate actual value
    Solar_Volts = PWM_Measure_Voltage('Solar')
    Solar_Actual_Volts = Solar_Volts/Parameters.Voltage_Multiplier

    if (Solar_Actual_Volts <= Parameters.DCLink_VDC_Min) and (Solar_Actual_Volts >= Parameters.DCLink_VDC_Max):
        DC_Relay(0)# Set solar relay to open
        time.sleep(10) # Wait 10 seconds
    elif Solar_Actual_Volts (DC_Actual_Volts > Parameters.DCLink_VDC_Min) and (Solar_Actual_Volts < Parameters.DCLink_VDC_Max):
        DC_Relay(1) # Set solar relay to closed position
        time.sleep(5) # Wait 5 seconds
    else:
        UPS_Error('Error_Solar_Voltage_Relay')

    # Calculate the updated DC-DC converter duty cycle
    D_PID = PWM_PID(DC_Link_Actual_Volts,D_PID_OLD)
    print("Duty cyle=",D_PID)
    Convert = int(round(D_PID*Parameters.Range,0)) # Convert to integer from float, value of 0 to 96
    PWM.PWM_Write(Parameters.PWMPin,Convert)

    # Update the duty cycle variable for the next iteration
    D_PID_OLD = D_PID
示例#3
0
def PWM_Measure_Voltage(Measurement):
    ads = ADS1256()
    ads.cal_self()

    if Measurement == 'DC_Link':
        adsread = ads.read_oneshot(EXT3)
        DCVolts = adsread * ads.v_per_digit
    elif Measurement == 'Solar':
        adsread = ads.read_oneshot(EXT4)
        DCVolts = adsread * ads.v_per_digit
    else:
        UPS_Error('Error_Voltage_Measurement')

    return DCVolts
def Protection_Controller(arg):
    # Check Solar setpoints
    time.sleep(.01)
    Solar_Voltage = PWM_Measure_Voltage(
        'Solar') / Parameters.Voltage_Multiplier
    DC_Link_Voltage = PWM_Measure_Voltage(
        'DC_Link') / Parameters.Voltage_Multiplier
    if (Solar_Voltage >= Parameters.SolarMax):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"), 3)
        PWM.PWM_Write(Parameters.PWMPin, 0)
        UPS_Error('Error_Solar_Voltage')
    if (DC_Link_Voltage >= Parameters.DCLinkMax):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"), 3)
        PWM.PWM_Write(Parameters.PWMPin, 0)

        UPS_Error('Error_DC_Link_Voltage')
    # Check Grid setpoints

    # Check VFD setpoint
    VFD_Freq = VFD.VFDRead(reg.get("ReadFunc",
                                   {}).get("Output_Frequency")) / 100
    VFD_Volt = VFD.VFDRead(reg.get("ReadFunc", {}).get("Output_Voltage"))
    VFD_Amps = VFD.VFDRead(reg.get("ReadFunc", {}).get("Output_Current")) / 100
    VFD_Power = VFD.VFDRead(reg.get("ReadFunc", {}).get("Output_Power")) / 10
    VFD_BusVolt = VFD.VFDRead(reg.get("ReadFunc", {}).get("Bus_Voltage"))
    VFD_Temp = VFD.VFDRead(reg.get("ReadFunc", {}).get("Temperature"))

    if (VFD_Freq >= 61):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"), 3)
        UPS_Error('Error_VFD_Freq')
    if (VFD_Volt >= 240):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"), 3)
        UPS_Error('Error_VFD_Volt')
    if (VFD_Amps >= 15):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"), 3)
        UPS_Error('Error_VFD_Amps')
    if (VFD_Power >= 2000):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"), 3)
        UPS_Error('Error_VFD_Power')
    if (VFD_BusVolt >= 400):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"), 3)
        UPS_Error('Error_VFD_BusVolt')
    if (VFD_Temp >= 40):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"), 3)
        UPS_Error('Error_VFD_Temp')
    Protection_Sched.enter(10, 1, Protection_Controller, ("", ))
    Protection_Sched.run()
示例#5
0
def PWM_PID(DC_Voltage, D_PID_OLD):
    DC_PID.update(DC_Voltage)
    D_update = DC_PID.output
    D = D_PID_OLD - D_update
    if D > .9:
        D_out = .9
    elif D < .7:
        D_out = .7
    elif D <= .8 and D >= .7:
        D_out = D
    else:
        UPS_Error('Error_Duty_Cycle')
        print("ErrorD = ", D)
        D_out = .5
    return D_out
示例#6
0
def PWM_PID(DC_Voltage, D_PID_OLD):
    DC_PID.update(DC_Voltage)  # Run the PID update function
    D_update = DC_PID.output  # Get the updated PID duty cycle value
    D = D_PID_OLD - D_update  # Calculate the change in the duty cycle

    # Duty cycle protection statement to ensure acceptable operating range
    if D > Parameters.D_Max:
        D_out = Parameters.D_Max
    elif D < Parameters.D_Min:
        D_out = Parameters.D_Min
    elif D <= Parameters.D_Max and D >= Parameters.D_Min:
        D_out = D
    else:
        UPS_Error('Error_Duty_Cycle')
        D_out = Parameters.PID_OLD_INIT  # Reset duty cycle to default initial value
    return D_out
示例#7
0
def PWM_Measure_Voltage(Measurement):
    # Connect to ADS1256 chip
    ads = ADS1256()

    # Calibrate gain and offset
    #ads.cal_self()

    # Measure DC link or solar voltage
    if Measurement == 'DC_Link':
        adsread = ads.read_oneshot(EXT3)
        DCVolts = adsread * ads.v_per_digit
    elif Measurement == 'Solar':
        adsread = ads.read_oneshot(EXT4)
        DCVolts = adsread * ads.v_per_digit
    else:
        UPS_Error('Error_Voltage_Measurement')

    return DCVolts
示例#8
0
def PWM_PID(DC_Voltage, D_PID_OLD):
    DC_PID.update(DC_Voltage)
    D_update = DC_PID.output
    #print("D_update = ",D_update)
    D = D_PID_OLD - D_update
    #print(D)
    if D > .8:
        D_out = .8
    elif D < .4:
        D_out = .4
    elif D <= .8 and D >= .4:
        D_out = D
    else:
        UPS_Error('Error_Duty_Cycle')
        print("ErrorD = ", D)
        D_out = .5
    #print(D_out)
    return D_out
示例#9
0
def Protection_Controller():
    # Check Solar setpoints
    Solar_Voltage = PWM_Measure_Voltage('Solar')
    DC_Link_Voltage = PWM_Measure_Voltage('DC_Link')
    if (Solar_Voltage >=Parameters.SolarMax):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"), 3)
        PWM_Output(Parameters.PWMPin,0)
        UPS_Error('Error_Solar_Voltage')
    if (DC_Link_Voltage >= Parameters.DCLinkMax):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"), 3)
        PWM_Output(Parameters.PWMPin, 0)
        UPS_Error('Error_DC_Link_Voltage')
    # Check Grid setpoints

    # Check VFD setpoint
    VFD_Freq = VFD.VFDRead(reg.get("ReadFunc",{}).get("Output_Frequency"))/100
    VFD_Volt = VFD.VFDRead(reg.get("ReadFunc",{}).get("Output_Voltage"))
    VFD_Amps = VFD.VFDRead(reg.get("ReadFunc",{}).get("Output_Current"))/100
    VFD_Power =VFD.VFDRead(reg.get("ReadFunc",{}).get("Output_Power"))/10
    VFD_BusVolt = VFD.VFDRead(reg.get("ReadFunc",{}).get("Bus_Voltage"))
    VFD_Temp = VFD.VFDRead(reg.get("ReadFunc",{}).get("Temperature"))

    if (VFD_Freq >=61):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"), 3)
        UPS_Error('Error_VFD_Freq')
    if (VFD_Volt >=240):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"), 3)
        UPS_Error('Error_VFD_Volt')
    if (VFD_Amps >=10):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"), 3)
        UPS_Error('Error_VFD_Amps')
    if (VFD_Power >=2000):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"), 3)
        UPS_Error('Error_VFD_Power')
    if (VFD_BusVolt >=400):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"), 3
        UPS_Error('Error_VFD_BusVolt')
    if (VFD_Temp >=40):
        VFD.VFDWrite(reg.get("WriteFunc", {}).get("Motor_Start_Stop"), 3)
        UPS_Error('Error_VFD_Temp')
def PWM_Voltage_Measure(Measurement):
    gain = 1  # ADC's Gain parameter
    sps = 25  # ADC's SPS parameter
    ads1256.start(str(gain), str(sps))

    if Measurement == 'DC_Link':
        ChannelValue = ads1256.read_channel(3)
        ChannelValueVolts = ((
            (ChannelValue * 100) / 167.0) / int(gain)) / 1000000.0
        DCVolts = ChannelValueVolts
    elif Measuremnet == 'Solar':
        ChannelValue = ads1256.read_channel(3)
        ChannelValueVolts = ((
            (ChannelValue * 100) / 167.0) / int(gain)) / 1000000.0
        DCVolts = ChannelValueVolts
    else:
        UPS_Error('Error_Voltage_Measurement')
    ads1256.stop()

    return DCVolts