Component: PWM (CAL) (Misc): Difference between revisions
Appearance
No edit summary |
m Text replacement - "style="background-color:#EAE1EA;"" to "class="mtx-class-propfolder"" |
||
| (14 intermediate revisions by 3 users not shown) | |||
| Line 15: | Line 15: | ||
CAL = Code Abstraction Layer - Allows one code base to run on a wide range of chips. A low level implementation giving direct access to the Pulse Width Modulation peripheral. | CAL = Code Abstraction Layer - Allows one code base to run on a wide range of chips. A low level implementation giving direct access to the Pulse Width Modulation peripheral. | ||
== | ==Version information== | ||
Library Version, Component Version, Date, Author, Info | |||
10, 2.2, 04-11-24, BR, Added pin caption to the remap port pin selection property | |||
11, 2.2, 04-11-24, BR, Cleaned up pin caption from none remap port pin property | |||
12, 2.2, 08-07-25, BR, Allowed the component to skip over unimplemented PWM channels | |||
12, 2.2, 08-07-25, BR, Added a bubble sort to the Remap Pin property to better present the Port/Pin data | |||
13, 2.2, 18-07-25, BR, Moved bubble sort to a timer to avoid it triggering multiple times | |||
==Detailed description== | ==Detailed description== | ||
The ChangePeriod macro must be called at least once before calling the Enable macro to configure and start the PWM timer resource. | |||
==Examples== | |||
| Line 33: | Line 38: | ||
''<span style="color:red;">No additional examples</span>'' | |||
| Line 47: | Line 51: | ||
| Line 55: | Line 58: | ||
==Macro reference== | ==Macro reference== | ||
=== | ===ChangeFrequency=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''ChangeFrequency''' | ||
|- | |- | ||
| colspan="2" | | | colspan="2" | Advanced function for the ESP32 hardware to set the PWM output frequency. | ||
|- | |- | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9- | | width="10%" align="center" | [[File:Fc9-u32-icon.png]] - ULONG | ||
| width="90%" | | | width="90%" | Frequency | ||
|- | |- | ||
| colspan="2" | | | colspan="2" | New PWM desired frequency in Hz | ||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9- | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
| Line 75: | Line 78: | ||
===ChangePeriod=== | ===ChangePeriod=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''ChangePeriod''' | ||
|- | |- | ||
| colspan="2" | Change the Period (and prescaler) for this PWM Channel | | colspan="2" | Change the Period (and prescaler) for this PWM Channel | ||
| Line 99: | Line 102: | ||
===Disable=== | ===Disable=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''Disable''' | ||
|- | |- | ||
| colspan="2" | Disable this PWM Channel | | colspan="2" | Disable this PWM Channel | ||
| Line 112: | Line 115: | ||
=== | ===Enable=== | ||
{| class=" | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | |||
| width="90%" class="mtx-class-macrohead" | '''Enable''' | |||
|- | |- | ||
| | | colspan="2" | Enable this PWM Channel, note the ChangePeriod macro must be called at least once before calling this function | ||
|- | |- | ||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
| Line 131: | Line 129: | ||
=== | ===GetList=== | ||
{| class="wikitable" | {| class="mtx-class-macrotable wikitable" | ||
|- | |||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | |||
| width="90%" class="mtx-class-macrohead" | '''GetList''' | |||
|- | |- | ||
| | | colspan="2" | Returns CHANNEL or PRESCALE list from the FCD and updates the internal property | ||
|- | |- | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING | |||
| width="90%" | Name | |||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9- | | colspan="2" | | ||
|- | |||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-string-icon.png]] - STRING | |||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
=== | ===GetValue=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''GetValue''' | ||
|- | |- | ||
| colspan="2" | | | colspan="2" | Returns Named property Value | ||
|- | |- | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9- | | width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING | ||
| width="90%" | | | width="90%" | Name | ||
|- | |- | ||
| colspan="2" | | | colspan="2" | | ||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9- | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-string-icon.png]] - STRING | ||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
=== | ===SetDuty10Bit=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''SetDuty10Bit''' | ||
|- | |- | ||
| colspan="2" | | | colspan="2" | Set the Duty Cycle for this PWM Channel. PIC/AVR - Range: 0-1023 16-bit PIC - Range: 0-65535 | ||
|- | |- | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9- | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | ||
| width="90%" | | | width="90%" | duty | ||
|- | |- | ||
| colspan="2" | | | colspan="2" | Duty value 0 - 1023 | ||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
| Line 188: | Line 186: | ||
=== | ===SetDuty8Bit=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''SetDuty8Bit''' | ||
|- | |- | ||
| colspan="2" | Set the Duty | | colspan="2" | Set the Duty cycle (0-255) for this PWM Channel | ||
|- | |- | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9- | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
| width="90%" | duty | | width="90%" | duty | ||
|- | |- | ||
| colspan="2" | | | colspan="2" | duty value 0 - 255 | ||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
| Line 208: | Line 206: | ||
===SetDutyFloat=== | ===SetDutyFloat=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''SetDutyFloat''' | ||
|- | |- | ||
| colspan="2" | Advanced function for the ESP32 hardware to set the PWM duty as a percentage between 0.0 and 100.0 | | colspan="2" | Advanced function for the ESP32 hardware to set the PWM duty as a percentage between 0.0 and 100.0 | ||
| Line 226: | Line 224: | ||
=== | ===SetValue=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''SetValue''' | ||
|- | |- | ||
| colspan="2" | | | colspan="2" | Sets the Value of the property PERIOD, PRESCALE or CHANNEL (if CHANNEL also updates the PORT from FCD) | ||
|- | |- | ||
|- | |- | ||
| Line 240: | Line 238: | ||
| colspan="2" | | | colspan="2" | | ||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9- | | width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING | ||
| width="90%" | Value | |||
|- | |||
| colspan="2" | | |||
|- | |||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | |||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
==Property reference== | ==Property reference== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-prop-icon.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''Properties''' | ||
|- | |- | ||
|- | |- | ||
| Line 260: | Line 261: | ||
| colspan="2" | | | colspan="2" | | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]] | ||
| width="90%" | | width="90%" class="mtx-class-propfolder" | Connections | ||
|- | |- | ||
|- | |- | ||
| Line 279: | Line 280: | ||
| colspan="2" | | | colspan="2" | | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]] | ||
| width="90%" | | width="90%" class="mtx-class-propfolder" | Configuration | ||
|- | |- | ||
|- | |- | ||
| Line 323: | Line 324: | ||
| colspan="2" | | | colspan="2" | | ||
|} | |} | ||
==Component Source Code== | |||
Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_PWM.fcfx FC_Comp_Source_PWM.fcfx] | |||
Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_PWM.fcfx FC_Comp_Source_PWM.fcfx] | |||
Latest revision as of 14:37, 13 July 2026
| Author | Matrix TSL |
| Version | 2.2 |
| Category | Misc |
PWM component
CAL = Code Abstraction Layer - Allows one code base to run on a wide range of chips. A low level implementation giving direct access to the Pulse Width Modulation peripheral.
Version information
Library Version, Component Version, Date, Author, Info 10, 2.2, 04-11-24, BR, Added pin caption to the remap port pin selection property 11, 2.2, 04-11-24, BR, Cleaned up pin caption from none remap port pin property 12, 2.2, 08-07-25, BR, Allowed the component to skip over unimplemented PWM channels 12, 2.2, 08-07-25, BR, Added a bubble sort to the Remap Pin property to better present the Port/Pin data 13, 2.2, 18-07-25, BR, Moved bubble sort to a timer to avoid it triggering multiple times
Detailed description
The ChangePeriod macro must be called at least once before calling the Enable macro to configure and start the PWM timer resource.
Examples
No additional examples
Macro reference
ChangeFrequency
| ChangeFrequency | |
| Advanced function for the ESP32 hardware to set the PWM output frequency. | |
| Frequency | |
| New PWM desired frequency in Hz | |
| Return | |
ChangePeriod
| ChangePeriod | |
| Change the Period (and prescaler) for this PWM Channel | |
| period | |
| period value PIC/AVR: 0-255 16-bit PIC: 0-65535 | |
| prescaler | |
| prescaler 1,4,16,64 | |
| Return | |
Disable
| Disable | |
| Disable this PWM Channel | |
| Return | |
Enable
| Enable | |
| Enable this PWM Channel, note the ChangePeriod macro must be called at least once before calling this function | |
| Return | |
GetList
| GetList | |
| Returns CHANNEL or PRESCALE list from the FCD and updates the internal property | |
| Name | |
| Return | |
GetValue
| GetValue | |
| Returns Named property Value | |
| Name | |
| Return | |
SetDuty10Bit
| SetDuty10Bit | |
| Set the Duty Cycle for this PWM Channel. PIC/AVR - Range: 0-1023 16-bit PIC - Range: 0-65535 | |
| duty | |
| Duty value 0 - 1023 | |
| Return | |
SetDuty8Bit
| SetDuty8Bit | |
| Set the Duty cycle (0-255) for this PWM Channel | |
| duty | |
| duty value 0 - 255 | |
| Return | |
SetDutyFloat
| SetDutyFloat | |
| Advanced function for the ESP32 hardware to set the PWM duty as a percentage between 0.0 and 100.0 | |
| Duty | |
| Return | |
SetValue
| SetValue | |
| Sets the Value of the property PERIOD, PRESCALE or CHANNEL (if CHANNEL also updates the PORT from FCD) | |
| Name | |
| Value | |
| Return | |
Property reference
Component Source Code
Please click here to download the component source project: FC_Comp_Source_PWM.fcfx
Please click here to view the component source code (Beta): FC_Comp_Source_PWM.fcfx