Difference between revisions of "Component: PWM (Outputs: General)"

From Flowcode Help
Jump to navigationJump to search
(XML import)
 
(XML import BR)
 
(2 intermediate revisions by the same user not shown)
Line 7: Line 7:
 
|-
 
|-
 
| width="20%" style="color: gray;" | Version
 
| width="20%" style="color: gray;" | Version
| 1.5 (Release)
+
| 1.6 (Release)
 
|-
 
|-
 
| width="20%" style="color: gray;" | Category
 
| width="20%" style="color: gray;" | Category
Line 21: Line 21:
  
 
==Examples==
 
==Examples==
 
 
Here is a basic example to control the PWM duty based on an ADC reading.
 
Here is a basic example to control the PWM duty based on an ADC reading.
 
{{Fcfile|PWMDemo.fcfx|PWMDemo}}
 
{{Fcfile|PWMDemo.fcfx|PWMDemo}}
 
 
Digital PWM trace
 
Digital PWM trace
  
Line 40: Line 38:
 
'''Parameters'''
 
'''Parameters'''
  
:[[Variable Types|BYTE]] ''Period''
+
:[[Variable Types|UINT]] ''Period''
::The maximum number that will represent 100% on, 0-255
+
::The maximum number that will represent 100% on, PIC/AVR: 0-255 16-bit PIC: 0-65535
  
 
:[[Variable Types|INT]] ''Prescaler''
 
:[[Variable Types|INT]] ''Prescaler''
Line 69: Line 67:
  
 
E.g. if period = 255 then duty of 128 is equal to 50% on and 50% off.
 
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.
  
 
'''Parameters'''
 
'''Parameters'''
Line 95: Line 95:
  
 
===<span style="font-weight: normal;"><u><tt>SetDutyCycle10Bit</tt></u></span>===
 
===<span style="font-weight: normal;"><u><tt>SetDutyCycle10Bit</tt></u></span>===
Sets the 10-bit PWM duty cycle in terms of on/off based on the current period setting.
+
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%.
  
E.g. if period = 255 then Duty of 512 is equal to 50% on and 50% off.
+
 
 +
 
 +
16-bit PICs have a 16-bit period range available.
 +
 
 +
If period = 65535 then Duty of 32768 is equal to 50%.
  
 
'''Parameters'''
 
'''Parameters'''
  
 
:[[Variable Types|UINT]] ''Duty''
 
:[[Variable Types|UINT]] ''Duty''
::10-bit PWM duty 0-1023
+
::PWM duty PIC/AVR: 0-1023 16-bit PIC: 0-65535
  
  
Line 136: Line 142:
  
 
Specifies the pin assigned to the PWM channel selected
 
Specifies the pin assigned to the PWM channel selected
 +
 +
<span style="font-weight: normal;"><u>Remap Pin</u></span>
 +
 +
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''RemapPin''.
 +
 +
Allows the PWM hardware pin to be reassigned to another pin
 +
 +
<span style="font-weight: normal;"><u>PWM Timer</u></span>
 +
 +
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''timer''.
 +
 +
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.
  
 
<span style="font-weight: normal;"><u>Period Overflow</u></span>
 
<span style="font-weight: normal;"><u>Period Overflow</u></span>
  
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''period''.
+
This property is of type ''Unsigned integer'' and can be referenced with the variable name ''period''.
 +
 
 +
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
  
Allows the user to change the number of counts for the whole PWM period. 0 - 255.
+
16-bit PIC Range: 0 - 65535
  
 
<span style="font-weight: normal;"><u>Prescaler</u></span>
 
<span style="font-weight: normal;"><u>Prescaler</u></span>
Line 147: Line 173:
 
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''prescale''.
 
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''prescale''.
  
Allows the user to change the number of program cycles per PWM cycle count.
+
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.
  
 
<span style="font-weight: normal;"><u>Period (us)</u></span>
 
<span style="font-weight: normal;"><u>Period (us)</u></span>
Line 166: Line 194:
  
 
Edits how the PWM is shown on the simulation panel.
 
Edits how the PWM is shown on the simulation panel.
 
<span style="font-weight: normal;"><u>Displayed Periods</u></span>
 
 
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''DispPeriods''.
 
 
''<span style="color:red;">No additional information</span>''
 

Latest revision as of 15:46, 16 February 2017


Author Matrix Ltd
Version 1.6 (Release)
Category Outputs: General


Image PWM component

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.

Examples

Here is a basic example to control the PWM duty based on an ADC reading. FC6 Icon.png PWMDemo Digital PWM trace

PWMDigital.jpg


Here is another basic example which ramps the PWM duty cycle up and down. If the PWM output pin is connected to a LED and series resistor then the LED will smoothly transition between on bright and off. FC6 Icon.png PWM Fader

Downloadable macro reference

ChangePeriod

Sets the overall period and prescaler of the output PWM signal.

Parameters

UINT Period
The maximum number that will represent 100% on, PIC/AVR: 0-255 16-bit PIC: 0-65535
INT Prescaler
The scaler used to divide the system clock speed down to the PWM rate.


Return value

This call does not return a value


Disable

Disables a PWM channel and allows the default output / input state to be resumed

Parameters

This macro has no parameters


Return value

This call does not return a value


SetDutyCycle

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.

Parameters

BYTE Duty
8-bit PWM duty 0-255


Return value

This call does not return a value


Enable

Enables a PWM channel as an output overriding the default output pin state.

Parameters

This macro has no parameters


Return value

This call does not return a value


SetDutyCycle10Bit

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%.

Parameters

UINT Duty
PWM duty PIC/AVR: 0-1023 16-bit PIC: 0-65535


Return value

This call does not return a value


Simulation macro reference

This component does not contain any simulation macros


Property reference

Channel

This property is of type Fixed list of ints and can be referenced with the variable name channel.

Selects which PWM channel the component is connected to.

Alternative pin

This property is of type True or false and can be referenced with the variable name altpin.

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.

PWM Pin

This property is of type Single digital pin and can be referenced with the variable name pwm_pin.

Specifies the pin assigned to the PWM channel selected

Remap Pin

This property is of type Fixed list of ints and can be referenced with the variable name RemapPin.

Allows the PWM hardware pin to be reassigned to another pin

PWM Timer

This property is of type Fixed list of ints and can be referenced with the variable name timer.

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.

Period Overflow

This property is of type Unsigned integer and can be referenced with the variable name period.

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

Prescaler

This property is of type Fixed list of ints and can be referenced with the variable name prescale.

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.

Period (us)

This property is of type Floating point and can be referenced with the variable name period_calc.

Displays the length of time to complete one PWM cycle.

Frequency (KHz)

This property is of type Floating point and can be referenced with the variable name frequency_calc.

Displays the frequency of PWM cycles per second.

Representation

This property is of type Fixed list of ints and can be referenced with the variable name SimRep.

Edits how the PWM is shown on the simulation panel.