3.5.03 MC_PWM

Last modified by xingzhi lin on 2025/12/03 23:06

Instruction format

InstructionMC_PWM (FB)
NamePulse width modulation
Graphical performanceST performance

1764774334496-387.png

MC_PWM(

Enable: =

OutputPort: =

PulsePeriod: =

PulseWidth: =

InVelocity=>,

Busy=>,

Error=>,

ErrorID=>);

Related variables

Input variablesNameData typeEffective rangeInitial valueDescription
EnableEnableBOOL[FALSE, TRUE]FALSELevel trigger
OutputPortPulse output portBYTE[0, 2, 4, 6]0PWM output port, support D0, D2, D4, D6 only
PulsePeriodPulse widthUINT[0,65535]0Period: The width of the complete square wave. Unit: 1us
PulseWidthHigh-level pulse widthUINT[0,65535]0The width of the high level of the square wave. Unit: 1us
Output variablesNameData typeEffective rangeInitial valueDescription
InVelocityReaching set value flagBOOL[FALSE, TRUE]FALSEThe pulse width frequency reaches the set value.
BusyExecution flagBOOL[FALSE, TRUE]FALSEExecute output PWM square wave.
ErrorError flagBOOL[FALSE, TRUE]FALSETRUE when an error occurred inside the function block.
ErrorIDError IDMC_ERROR-MC_NO_ERRORError ID, refer to MC_ERROR.

Function description

(1) This function block realizes dynamic pulse width modulation;

(2) After D0/D2/D4/D6 is configured as PWM function, control of D0 + D1/ D2 + D3/ D4 + D5 /D6 + D7 outputs is not allowed, during the execution of MC_PWM function block.

Sequence diagram

1764774322875-747.png

Error description

ErrorID in MC_ERROR describes the cause of the corresponding error.

Error IDInitial valueDescription
0MC_NO_ERRORNo error
5MC_PWM_PORT_ERRORPort input error
6MC_PWM_PORT_WAS_RUNThe corresponding port is running
7MC_PWM_PERIOD_LESS_THAN_WIDTHThe pulse width is smaller than the high level pulse width
8MC_PWM_PORT_WASNT_ENABLEPort is not enabled