FB_PWDutyOutput

 Function Block - Accepts an input value between the minimum and maximum input range and converts this to a duty cycle percentage.

Inputs

Input

Data Type

Range

Unit

Default

Description

uEN01

BOOL

0 to 1

N/A

No default

Enable for the block.

uInputCommand

REAL

0 to --

N/A

No default

Signal Input.

Sometimes the output of a PID block.

uPeriod

TIME

0 to --

N/A

No default

Period of the duty cycle.

uMaxInput

REAL

uMinInput to --

N/A

No default

uInputCommand at or above this number that sets DutyOutput =1.

uMinInput

REAL

0 (zero)to uMaxInput

N/A

No default

uInputCommand at or below this number set DutyOutput = 0 (zero).

uMaxTime

TIME

uMinTime to uPeriod

N/A

No default

Maximum on time for the output.

uMinTime

TIME

0 (zero)to uMaxTime

N/A

No default

Minimum on-time for the PW Duty Output.

Outputs

Output

Data Type

Range

Unit

Description

OK

BOOL

0 to 1

N/A

Function block is operational.

TM1

TIME

0 (zero) to uPeriod

N/A

On-time of the Output.

DutyOutput

BOOL

0 to 1

N/A

PW signal ( switching between 0 and 1).

DutyOutput is set to 0 (zero) when the function block is not active (not eabled by the first input).

Remarks

The output is then cycled on and off over the period of the duty cycle at the duty cycle percentage.

  • To have the output ON time range from 0 (zero) to the duty cycle period, the minimum should be set to 0 (zero) and the maximum to the duty cycle period.
  • If the calculated duty cycle is:
    • Based on the input and the range values are less than the minimum ON time (MinTime), the output does not come on.
    • Between or equal to the range values the output is cycled by the duty cycle.
    • Greater than the maximum ON time (MaxTime) the output will remain on.

This image shows the function or function block I/O.

Figure 1: Pulse Width Duty Cycle

Usage

Flash a warning light for operators.

Function Block Calculations

IF (uInputCommand - uMinInput) < 0 then     //If Command less than MinInput turn out put off
   DutyOutput := 0;
ELSIF (uInputCommand - uMaxInput) > 0 then     //If Command greater than MaxInput turn out put on
   DutyOutput := 1;
ELSE
   DutyCycle := (uInputCommand - uMinInput)/(uMaxInput - uMinInput);     //Calculate Duty Cycle
   ONTimeFromInput := DutyCycle * any_to_REAL(uPeriod) ;     //Calculate Ontime

   IF any_to_TIME(ONTimeFromInput) < uMinTime then
      DutyOutput := 0;
   ELSIF any_to_TIME(ONTimeFromInput) > uMaxTime then
      DutyOutput := 1;
   ELSE
      TM1 := any_to_TIME(ONTimeFromInput) ;
      TM0 := uPERIOD - TM1;     //Calculate offtime
      DutyOutput := Inst_blinkA( 1 , TM0 , TM1 );     //Use BlinkA function to set PW output
   END_IF ;
END_IF ;

FBD Language Example

FFLD Language Example

IL Language Example

Not available.

ST Language Example

Inst_FB_PWDutyOutput( PWDuty_3_Switch, PWDuty_In3, PWDuty_3_Period, PWDuty_3_MaxInput, PWDuty_3_MinInput, PWDuty_3_MaxTime, PWDuty_3_MinTime);
PWDuty_3_OK:=Inst_FB_PWDutyOutput.OK;
PWDuty_3_Time:=Inst_FB_PWDutyOutput.TM1;
PWDuty_3_Output:=Inst_FB_PWDutyOutput.DutyOutput;

See Also

Timers