Wiki source code of 3.5.03 MC_PWM
Version 3.1 by xingzhi lin on 2025/12/03 23:05
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
2.1 | 1 | == **Instruction format** == |
| 2 | |||
| 3 | |**Instruction**|(% colspan="2" %)MC_PWM (FB) | ||
| 4 | |**Name**|(% colspan="2" %)Pulse width modulation | ||
| 5 | |(% colspan="2" %)**Graphical performance**|**ST performance** | ||
| |
3.1 | 6 | |(% colspan="2" %)((( |
| |
2.1 | 7 | (% style="text-align:center" %) |
| 8 | [[image:1764774334496-387.png]] | ||
| 9 | )))|((( | ||
| 10 | MC_PWM( | ||
| 11 | |||
| 12 | Enable: = | ||
| 13 | |||
| 14 | OutputPort: = | ||
| 15 | |||
| 16 | PulsePeriod: = | ||
| 17 | |||
| 18 | PulseWidth: = | ||
| 19 | |||
| 20 | InVelocity=>, | ||
| 21 | |||
| 22 | Busy=>, | ||
| 23 | |||
| 24 | Error=>, | ||
| 25 | |||
| 26 | ErrorID=>); | ||
| 27 | ))) | ||
| 28 | |||
| 29 | |||
| 30 | |||
| 31 | == **Related variables** == | ||
| 32 | |||
| 33 | |**Input variables**|**Name**|**Data type**|**Effective range**|**Initial value**|**Description** | ||
| 34 | |Enable|Enable|BOOL|[FALSE, TRUE]|FALSE|Level trigger | ||
| 35 | |OutputPort|Pulse output port|BYTE|[0, 2, 4, 6]|0|PWM output port, support D0, D2, D4, D6 only | ||
| 36 | |PulsePeriod|Pulse width|UINT|[0,65535]|0|Period: The width of the complete square wave. Unit: 1us | ||
| 37 | |PulseWidth|High-level pulse width|UINT|[0,65535]|0|The width of the high level of the square wave. Unit: 1us | ||
| 38 | |||
| 39 | |||
| 40 | |||
| 41 | |**Output variables**|**Name**|**Data type**|**Effective range**|**Initial value**|**Description** | ||
| 42 | |InVelocity|Reaching set value flag|BOOL|[FALSE, TRUE]|FALSE|The pulse width frequency reaches the set value. | ||
| 43 | |Busy|Execution flag|BOOL|[FALSE, TRUE]|FALSE|Execute output PWM square wave. | ||
| 44 | |Error|Error flag|BOOL|[FALSE, TRUE]|FALSE|TRUE when an error occurred inside the function block. | ||
| 45 | |ErrorID|Error ID|MC_ERROR|-|MC_NO_ERROR|Error ID, refer to MC_ERROR. | ||
| 46 | |||
| 47 | |||
| 48 | |||
| 49 | == **Function description** == | ||
| 50 | |||
| 51 | (1) This function block realizes dynamic pulse width modulation; | ||
| 52 | |||
| 53 | (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. | ||
| 54 | |||
| 55 | |||
| 56 | == **Sequence diagram** == | ||
| 57 | |||
| 58 | (% style="text-align:center" %) | ||
| 59 | [[image:1764774322875-747.png]] | ||
| 60 | |||
| 61 | |||
| 62 | |||
| 63 | |||
| 64 |