        volatile    uint16_t    Voltage_meas;
        volatile    uint16_t    Current_meas;
#define MAX_POWER_LOSS          100000

extern  void    PrerOutpTask ( void ) {
    uint32_t    pwmvalue;
    uint16_t    portvalue;

    // See if the maximum power loss is exceeded
     if  ( MAX_POWER_LOSS < Current_meas * (Prereg_meas - Voltage_meas) ) {
        // The max power was exceeded.
        // We need to calculate value that does not exceed it
        // U = P / I
        pwmvalue = (uint32_t)MAX_POWER_LOSS / Current_meas;
        pwmvalue += (Voltage_set + Voltage_off);
    }

    // Since it was not exceeded we set prereg = 20 Volts + Voltage_set
    else {
        pwmvalue = 200 + Voltage_set + Voltage_off;
    }

    // Convert into 8 bit PWM control byte
    pwmvalue *= 255;
    portvalue = pwmvalue / OUT_MAX_PRER;
    if  ( portvalue > 255 ) {
        portvalue = 255;
    }

    // Set the PWM
    OCR2 = portvalue;
}