|
|
| (8 intermediate revisions by 2 users not shown) |
| Line 5: |
Line 5: |
| | |- | | |- |
| | | width="20%" style="color:gray;" | Version | | | width="20%" style="color:gray;" | Version |
| − | | 1.0 | + | | 12.0 |
| | |- | | |- |
| | | width="20%" style="color:gray;" | Category | | | width="20%" style="color:gray;" | Category |
| Line 15: |
Line 15: |
| | Pulse Width Modulation, a versitile way of generating a digital pulse using mark / space modulation. Uses the capture compare peripherals onboard most Microcontrollers to generate accurate waveforms without any intervention from the processor. Useful for generating audio, controlling the speed of motors, brightness of LED etc. | | Pulse Width Modulation, a versitile way of generating a digital pulse using mark / space modulation. Uses the capture compare peripherals onboard most Microcontrollers to generate accurate waveforms without any intervention from the processor. Useful for generating audio, controlling the speed of motors, brightness of LED etc. |
| | | | |
| − | ==Component Source Code== | + | ==Version information== |
| | | | |
| − | Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_PWM_Output.fcfx FC_Comp_Source_PWM_Output.fcfx]
| + | Library Version, Component Version, Date, Author, Info |
| | + | 11, 11.0, 15-10-24, BR, Fixed change frequency and duty for ESP32 |
| | + | 12, 12.0, 15-10-24, MW, Fixed Digital version as visually looks wrong |
| | + | |
| | | | |
| − | Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_PWM_Output.fcfx FC_Comp_Source_PWM_Output.fcfx]
| |
| | | | |
| | ==Detailed description== | | ==Detailed description== |
| | + | |
| | + | |
| | | | |
| | | | |
| Line 50: |
Line 54: |
| | | | |
| | ==Examples== | | ==Examples== |
| | + | |
| | + | |
| | | | |
| | | | |
| Line 82: |
Line 88: |
| | Digital PWM trace | | Digital PWM trace |
| | | | |
| − | [[File:PWMDigital.jpg]] | + | [[File:PWMDigital.png]] |
| | | | |
| | | | |
| Line 88: |
Line 94: |
| | | | |
| | {{Fcfile|PWM_fader.fcfx|PWM Fader}} | | {{Fcfile|PWM_fader.fcfx|PWM Fader}} |
| | + | |
| | + | |
| | | | |
| | ==Macro reference== | | ==Macro reference== |
| | | | |
| | + | ===ChangePeriod=== |
| | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" |
| | |- | | |- |
| Line 114: |
Line 123: |
| | | | |
| | | | |
| | + | ===Disable=== |
| | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" |
| | |- | | |- |
| Line 127: |
Line 137: |
| | | | |
| | | | |
| − | {| class="wikitable" style="width:60%; background-color:#FFFFFF;"
| + | ===Enable=== |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| |
| − | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetDutyCycle'''
| |
| − | |-
| |
| − | | colspan="2" | Sets the PWM duty cycle in terms of on/off based on the current period setting. E.g. if period = 255 then duty of 128 is equal to 50% on and 50% off. 16-bit PIC users should use the 10bit duty function to access the full range.
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| |
| − | | width="90%" | Duty
| |
| − | |-
| |
| − | | colspan="2" | 8-bit PWM duty 0-255
| |
| − | |-
| |
| − | | 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''
| |
| − | |}
| |
| − | | |
| − | | |
| | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" |
| | |- | | |- |
| Line 158: |
Line 151: |
| | | | |
| | | | |
| − | {| class="wikitable" style="width:60%; background-color:#FFFFFF;"
| + | ===SetDutyCycle=== |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| |
| − | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetFrequency'''
| |
| − | |-
| |
| − | | colspan="2" | Sets a PWM of the specifed frequency at a duty of 50% Ideal use is a frequency generator
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-u32-icon.png]] - ULONG
| |
| − | | width="90%" | Frequency
| |
| − | |-
| |
| − | | colspan="2" | Enter frequency in Hz
| |
| − | |-
| |
| − | | 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''
| |
| − | |}
| |
| − | | |
| − | | |
| − | {| class="wikitable" style="width:60%; background-color:#FFFFFF;"
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| |
| − | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetDutyCycle10Bit'''
| |
| − | |-
| |
| − | | colspan="2" | PIC/AVR - Sets the full scale PWM duty cycle based on the current period setting. If period = 255 then Duty of 512 is equal to 50%. 16-bit PICs have a 16-bit period range available. If period = 65535 then Duty of 32768 is equal to 50%.
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| |
| − | | width="90%" | Duty
| |
| − | |-
| |
| − | | colspan="2" | PWM duty PIC/AVR: 0-1023 16-bit PIC: 0-65535
| |
| − | |-
| |
| − | | 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''
| |
| − | |}
| |
| − | | |
| − | | |
| − | | |
| − | | |
| − | ==Property reference==
| |
| − | | |
| − | {| class="wikitable" style="width:60%; background-color:#FFFFFF;"
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]]
| |
| − | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties'''
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
| |
| − | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Connections
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| |
| − | | width="90%" | Channel
| |
| − | |-
| |
| − | | colspan="2" | Selects which PWM channel the component is connected to.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
| |
| − | | width="90%" | Alternative pin
| |
| − | |-
| |
| − | | colspan="2" | Allows an alternate pin to be used if available. Note that on some devices you will also have to change this setting in the device configuration.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
| |
| − | | width="90%" | PWM Pin
| |
| − | |-
| |
| − | | colspan="2" | Specifies the pin assigned to the PWM channel selected
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| |
| − | | width="90%" | Remap Pin
| |
| − | |-
| |
| − | | colspan="2" | Allows the PWM hardware pin to be reassigned to another pin
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
| |
| − | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | PWM Frequency
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| |
| − | | width="90%" | PWM Timer
| |
| − | |-
| |
| − | | colspan="2" | Timer associated with PWM to drive the output. Warning - All PWM channels linked to the same timer will share the same period and prescaler settings.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]]
| |
| − | | width="90%" | Period Overflow
| |
| − | |-
| |
| − | | colspan="2" | Allows the user to change the number of counts for the whole PWM period. Note that all PWM channels based on the same timer will share the same period overflow. PIC/AVR Range: 0 - 255 16-bit PIC Range: 0 - 65535
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| |
| − | | width="90%" | Prescaler
| |
| − | |-
| |
| − | | colspan="2" | Allows the user to change the number of program cycles per PWM cycle count. Note that all PWM channels based on the same timer will share the same prescaler.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-15-icon.png]]
| |
| − | | width="90%" | Period (us)
| |
| − | |-
| |
| − | | colspan="2" | Displays the length of time to complete one PWM cycle.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-15-icon.png]]
| |
| − | | width="90%" | Frequency (Hz)
| |
| − | |-
| |
| − | | colspan="2" |
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-15-icon.png]]
| |
| − | | width="90%" | Frequency (KHz)
| |
| − | |-
| |
| − | | colspan="2" | Displays the frequency of PWM cycles per second.
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
| |
| − | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Calculations
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-15-icon.png]]
| |
| − | | width="90%" | Required Frequency (Hz)
| |
| − | |-
| |
| − | | colspan="2" | Type in your required frequency in Hz and the component will automatically calculate the best prescaler and period to acheive the frequency with the maximum possible resolution.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-15-icon.png]]
| |
| − | | width="90%" | Calculated Frequency (Hz)
| |
| − | |-
| |
| − | | colspan="2" | The frequency we have ended up acheiving using the calculated period and prescaler
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]]
| |
| − | | width="90%" | Calculated Period
| |
| − | |-
| |
| − | | colspan="2" | The suggested period setting to use to acheive the calculated frequency.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]]
| |
| − | | width="90%" | Calculated Prescaler
| |
| − | |-
| |
| − | | colspan="2" | The suggested prescaler setting to use to acheive the calculated frequency.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
| |
| − | | width="90%" | Apply To Defaults
| |
| − | |-
| |
| − | | colspan="2" | Applies the calculated period and prescaler settings to the PWM component default settings.
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
| |
| − | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Simulation
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| |
| − | | width="90%" | Representation
| |
| − | |-
| |
| − | | colspan="2" | Edits how the PWM is shown on the simulation panel.
| |
| − | |}==Macro reference==
| |
| − | | |
| − | {| class="wikitable" style="width:60%; background-color:#FFFFFF;"
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| |
| − | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ChangePeriod'''
| |
| − | |-
| |
| − | | colspan="2" | Sets the overall period and prescaler of the output PWM signal.
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| |
| − | | width="90%" | Period
| |
| − | |-
| |
| − | | colspan="2" | The maximum number that will represent 100% on, PIC/AVR: 0-255 16-bit PIC: 0-65535
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-s16-icon.png]] - INT
| |
| − | | width="90%" | Prescaler
| |
| − | |-
| |
| − | | colspan="2" | The scaler used to divide the system clock speed down to the PWM rate.
| |
| − | |-
| |
| − | | 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''
| |
| − | |}
| |
| − | | |
| − | | |
| − | {| class="wikitable" style="width:60%; background-color:#FFFFFF;"
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| |
| − | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Disable'''
| |
| − | |-
| |
| − | | colspan="2" | Disables a PWM channel and allows the default output / input state to be resumed
| |
| − | |-
| |
| − | |-
| |
| − | | 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''
| |
| − | |}
| |
| − | | |
| − | | |
| | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" |
| | |- | | |- |
| Line 355: |
Line 170: |
| | | | |
| | | | |
| − | {| class="wikitable" style="width:60%; background-color:#FFFFFF;"
| + | ===SetDutyCycle10Bit=== |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| |
| − | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Enable'''
| |
| − | |-
| |
| − | | colspan="2" | Enables a PWM channel as an output overriding the default output pin state.
| |
| − | |-
| |
| − | |-
| |
| − | | 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''
| |
| − | |}
| |
| − | | |
| − | | |
| − | {| class="wikitable" style="width:60%; background-color:#FFFFFF;"
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| |
| − | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetFrequency'''
| |
| − | |-
| |
| − | | colspan="2" | Sets a PWM of the specifed frequency at a duty of 50% Ideal use is a frequency generator
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-u32-icon.png]] - ULONG
| |
| − | | width="90%" | Frequency
| |
| − | |-
| |
| − | | colspan="2" | Enter frequency in Hz
| |
| − | |-
| |
| − | | 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''
| |
| − | |}
| |
| − | | |
| − | | |
| | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" |
| | |- | | |- |
| Line 404: |
Line 189: |
| | | | |
| | | | |
| − | | + | ===SetFrequency=== |
| − | | |
| − | ==Property reference== | |
| − | | |
| − | {| class="wikitable" style="width:60%; background-color:#FFFFFF;"
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]]
| |
| − | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties'''
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
| |
| − | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Connections
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| |
| − | | width="90%" | Channel
| |
| − | |-
| |
| − | | colspan="2" | Selects which PWM channel the component is connected to.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
| |
| − | | width="90%" | Alternative pin
| |
| − | |-
| |
| − | | colspan="2" | Allows an alternate pin to be used if available. Note that on some devices you will also have to change this setting in the device configuration.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
| |
| − | | width="90%" | PWM Pin
| |
| − | |-
| |
| − | | colspan="2" | Specifies the pin assigned to the PWM channel selected
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| |
| − | | width="90%" | Remap Pin
| |
| − | |-
| |
| − | | colspan="2" | Allows the PWM hardware pin to be reassigned to another pin
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
| |
| − | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | PWM Frequency
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| |
| − | | width="90%" | PWM Timer
| |
| − | |-
| |
| − | | colspan="2" | Timer associated with PWM to drive the output. Warning - All PWM channels linked to the same timer will share the same period and prescaler settings.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]]
| |
| − | | width="90%" | Period Overflow
| |
| − | |-
| |
| − | | colspan="2" | Allows the user to change the number of counts for the whole PWM period. Note that all PWM channels based on the same timer will share the same period overflow. PIC/AVR Range: 0 - 255 16-bit PIC Range: 0 - 65535
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| |
| − | | width="90%" | Prescaler
| |
| − | |-
| |
| − | | colspan="2" | Allows the user to change the number of program cycles per PWM cycle count. Note that all PWM channels based on the same timer will share the same prescaler.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-15-icon.png]]
| |
| − | | width="90%" | Period (us)
| |
| − | |-
| |
| − | | colspan="2" | Displays the length of time to complete one PWM cycle.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-15-icon.png]]
| |
| − | | width="90%" | Frequency (Hz)
| |
| − | |-
| |
| − | | colspan="2" |
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-15-icon.png]]
| |
| − | | width="90%" | Frequency (KHz)
| |
| − | |-
| |
| − | | colspan="2" | Displays the frequency of PWM cycles per second.
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
| |
| − | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Calculations
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-15-icon.png]]
| |
| − | | width="90%" | Required Frequency (Hz)
| |
| − | |-
| |
| − | | colspan="2" | Type in your required frequency in Hz and the component will automatically calculate the best prescaler and period to acheive the frequency with the maximum possible resolution.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-15-icon.png]]
| |
| − | | width="90%" | Calculated Frequency (Hz)
| |
| − | |-
| |
| − | | colspan="2" | The frequency we have ended up acheiving using the calculated period and prescaler
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]]
| |
| − | | width="90%" | Calculated Period
| |
| − | |-
| |
| − | | colspan="2" | The suggested period setting to use to acheive the calculated frequency.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]]
| |
| − | | width="90%" | Calculated Prescaler
| |
| − | |-
| |
| − | | colspan="2" | The suggested prescaler setting to use to acheive the calculated frequency.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
| |
| − | | width="90%" | Apply To Defaults
| |
| − | |-
| |
| − | | colspan="2" | Applies the calculated period and prescaler settings to the PWM component default settings.
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
| |
| − | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Simulation
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| |
| − | | width="90%" | Representation
| |
| − | |-
| |
| − | | colspan="2" | Edits how the PWM is shown on the simulation panel.
| |
| − | |}==Macro reference==
| |
| − | | |
| − | {| class="wikitable" style="width:60%; background-color:#FFFFFF;"
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| |
| − | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ChangePeriod'''
| |
| − | |-
| |
| − | | colspan="2" | Sets the overall period and prescaler of the output PWM signal.
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| |
| − | | width="90%" | Period
| |
| − | |-
| |
| − | | colspan="2" | The maximum number that will represent 100% on, PIC/AVR: 0-255 16-bit PIC: 0-65535
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-s16-icon.png]] - INT
| |
| − | | width="90%" | Prescaler
| |
| − | |-
| |
| − | | colspan="2" | The scaler used to divide the system clock speed down to the PWM rate.
| |
| − | |-
| |
| − | | 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''
| |
| − | |}
| |
| − | | |
| − | | |
| − | {| class="wikitable" style="width:60%; background-color:#FFFFFF;"
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| |
| − | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Disable'''
| |
| − | |-
| |
| − | | colspan="2" | Disables a PWM channel and allows the default output / input state to be resumed
| |
| − | |-
| |
| − | |-
| |
| − | | 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''
| |
| − | |}
| |
| − | | |
| − | | |
| − | {| class="wikitable" style="width:60%; background-color:#FFFFFF;"
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| |
| − | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetDutyCycle'''
| |
| − | |-
| |
| − | | colspan="2" | Sets the PWM duty cycle in terms of on/off based on the current period setting. E.g. if period = 255 then duty of 128 is equal to 50% on and 50% off. 16-bit PIC users should use the 10bit duty function to access the full range.
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| |
| − | | width="90%" | Duty
| |
| − | |-
| |
| − | | colspan="2" | 8-bit PWM duty 0-255
| |
| − | |-
| |
| − | | 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''
| |
| − | |}
| |
| − | | |
| − | | |
| − | {| class="wikitable" style="width:60%; background-color:#FFFFFF;"
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| |
| − | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Enable'''
| |
| − | |-
| |
| − | | colspan="2" | Enables a PWM channel as an output overriding the default output pin state.
| |
| − | |-
| |
| − | |-
| |
| − | | 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''
| |
| − | |}
| |
| − | | |
| − | | |
| | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" |
| | |- | | |- |
| Line 594: |
Line 206: |
| | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | | | width="90%" style="border-top: 2px solid #000;" | ''Return'' |
| | |} | | |} |
| − |
| |
| − |
| |
| − | {| class="wikitable" style="width:60%; background-color:#FFFFFF;"
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| |
| − | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetDutyCycle10Bit'''
| |
| − | |-
| |
| − | | colspan="2" | PIC/AVR - Sets the full scale PWM duty cycle based on the current period setting. If period = 255 then Duty of 512 is equal to 50%. 16-bit PICs have a 16-bit period range available. If period = 65535 then Duty of 32768 is equal to 50%.
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| |
| − | | width="90%" | Duty
| |
| − | |-
| |
| − | | colspan="2" | PWM duty PIC/AVR: 0-1023 16-bit PIC: 0-65535
| |
| − | |-
| |
| − | | 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''
| |
| − | |}
| |
| − |
| |
| − |
| |
| | | | |
| | | | |
| Line 719: |
Line 311: |
| | |- | | |- |
| | | colspan="2" | Edits how the PWM is shown on the simulation panel. | | | colspan="2" | Edits how the PWM is shown on the simulation panel. |
| − | |}==Macro reference==
| |
| − |
| |
| − | {| class="wikitable" style="width:60%; background-color:#FFFFFF;"
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| |
| − | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ChangePeriod'''
| |
| − | |-
| |
| − | | colspan="2" | Sets the overall period and prescaler of the output PWM signal.
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| |
| − | | width="90%" | Period
| |
| − | |-
| |
| − | | colspan="2" | The maximum number that will represent 100% on, PIC/AVR: 0-255 16-bit PIC: 0-65535
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-s16-icon.png]] - INT
| |
| − | | width="90%" | Prescaler
| |
| − | |-
| |
| − | | colspan="2" | The scaler used to divide the system clock speed down to the PWM rate.
| |
| − | |-
| |
| − | | 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''
| |
| | |} | | |} |
| | | | |
| | + | ==Component Source Code== |
| | | | |
| − | {| class="wikitable" style="width:60%; background-color:#FFFFFF;"
| + | Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_PWM_Output.fcfx FC_Comp_Source_PWM_Output.fcfx] |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| |
| − | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Disable'''
| |
| − | |-
| |
| − | | colspan="2" | Disables a PWM channel and allows the default output / input state to be resumed
| |
| − | |-
| |
| − | |-
| |
| − | | 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''
| |
| − | |}
| |
| | | | |
| − | | + | Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_PWM_Output.fcfx FC_Comp_Source_PWM_Output.fcfx] |
| − | {| class="wikitable" style="width:60%; background-color:#FFFFFF;"
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| |
| − | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetDutyCycle'''
| |
| − | |-
| |
| − | | colspan="2" | Sets the PWM duty cycle in terms of on/off based on the current period setting. E.g. if period = 255 then duty of 128 is equal to 50% on and 50% off. 16-bit PIC users should use the 10bit duty function to access the full range.
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| |
| − | | width="90%" | Duty
| |
| − | |-
| |
| − | | colspan="2" | 8-bit PWM duty 0-255
| |
| − | |-
| |
| − | | 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''
| |
| − | |}
| |
| − | | |
| − | | |
| − | {| class="wikitable" style="width:60%; background-color:#FFFFFF;"
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| |
| − | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Enable'''
| |
| − | |-
| |
| − | | colspan="2" | Enables a PWM channel as an output overriding the default output pin state.
| |
| − | |-
| |
| − | |-
| |
| − | | 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''
| |
| − | |}
| |
| − | | |
| − | | |
| − | {| class="wikitable" style="width:60%; background-color:#FFFFFF;"
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| |
| − | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetFrequency'''
| |
| − | |-
| |
| − | | colspan="2" | Sets a PWM of the specifed frequency at a duty of 50% Ideal use is a frequency generator
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-u32-icon.png]] - ULONG
| |
| − | | width="90%" | Frequency
| |
| − | |-
| |
| − | | colspan="2" | Enter frequency in Hz
| |
| − | |-
| |
| − | | 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''
| |
| − | |}
| |
| − | | |
| − | | |
| − | {| class="wikitable" style="width:60%; background-color:#FFFFFF;"
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| |
| − | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetDutyCycle10Bit'''
| |
| − | |-
| |
| − | | colspan="2" | PIC/AVR - Sets the full scale PWM duty cycle based on the current period setting. If period = 255 then Duty of 512 is equal to 50%. 16-bit PICs have a 16-bit period range available. If period = 65535 then Duty of 32768 is equal to 50%.
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| |
| − | | width="90%" | Duty
| |
| − | |-
| |
| − | | colspan="2" | PWM duty PIC/AVR: 0-1023 16-bit PIC: 0-65535
| |
| − | |-
| |
| − | | 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''
| |
| − | |}
| |
| − | | |
| − | | |
| − | | |
| − | | |
| − | ==Property reference==
| |
| − | | |
| − | {| class="wikitable" style="width:60%; background-color:#FFFFFF;"
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]]
| |
| − | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties'''
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
| |
| − | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Connections
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| |
| − | | width="90%" | Channel
| |
| − | |-
| |
| − | | colspan="2" | Selects which PWM channel the component is connected to.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
| |
| − | | width="90%" | Alternative pin
| |
| − | |-
| |
| − | | colspan="2" | Allows an alternate pin to be used if available. Note that on some devices you will also have to change this setting in the device configuration.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
| |
| − | | width="90%" | PWM Pin
| |
| − | |-
| |
| − | | colspan="2" | Specifies the pin assigned to the PWM channel selected
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| |
| − | | width="90%" | Remap Pin
| |
| − | |-
| |
| − | | colspan="2" | Allows the PWM hardware pin to be reassigned to another pin
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
| |
| − | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | PWM Frequency
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| |
| − | | width="90%" | PWM Timer
| |
| − | |-
| |
| − | | colspan="2" | Timer associated with PWM to drive the output. Warning - All PWM channels linked to the same timer will share the same period and prescaler settings.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]]
| |
| − | | width="90%" | Period Overflow
| |
| − | |-
| |
| − | | colspan="2" | Allows the user to change the number of counts for the whole PWM period. Note that all PWM channels based on the same timer will share the same period overflow. PIC/AVR Range: 0 - 255 16-bit PIC Range: 0 - 65535
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| |
| − | | width="90%" | Prescaler
| |
| − | |-
| |
| − | | colspan="2" | Allows the user to change the number of program cycles per PWM cycle count. Note that all PWM channels based on the same timer will share the same prescaler.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-15-icon.png]]
| |
| − | | width="90%" | Period (us)
| |
| − | |-
| |
| − | | colspan="2" | Displays the length of time to complete one PWM cycle.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-15-icon.png]]
| |
| − | | width="90%" | Frequency (Hz)
| |
| − | |-
| |
| − | | colspan="2" |
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-15-icon.png]]
| |
| − | | width="90%" | Frequency (KHz)
| |
| − | |-
| |
| − | | colspan="2" | Displays the frequency of PWM cycles per second.
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
| |
| − | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Calculations
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-15-icon.png]]
| |
| − | | width="90%" | Required Frequency (Hz)
| |
| − | |-
| |
| − | | colspan="2" | Type in your required frequency in Hz and the component will automatically calculate the best prescaler and period to acheive the frequency with the maximum possible resolution.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-15-icon.png]]
| |
| − | | width="90%" | Calculated Frequency (Hz)
| |
| − | |-
| |
| − | | colspan="2" | The frequency we have ended up acheiving using the calculated period and prescaler
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]]
| |
| − | | width="90%" | Calculated Period
| |
| − | |-
| |
| − | | colspan="2" | The suggested period setting to use to acheive the calculated frequency.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]]
| |
| − | | width="90%" | Calculated Prescaler
| |
| − | |-
| |
| − | | colspan="2" | The suggested prescaler setting to use to acheive the calculated frequency.
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
| |
| − | | width="90%" | Apply To Defaults
| |
| − | |-
| |
| − | | colspan="2" | Applies the calculated period and prescaler settings to the PWM component default settings.
| |
| − | |-
| |
| − | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
| |
| − | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Simulation
| |
| − | |-
| |
| − | |-
| |
| − | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| |
| − | | width="90%" | Representation
| |
| − | |-
| |
| − | | colspan="2" | Edits how the PWM is shown on the simulation panel.
| |
| − | |}
| |