Difference between revisions of "Unit PWM"
(3 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
---- | ---- | ||
− | '''Ultibo PWM | + | '''Ultibo PWM Interface unit''' |
Pulse Width Modulation (PWM) is a technique of encoding a pulsed signal so as to control the ratio of on to off by switching the signal between on and off at a very high rate. | Pulse Width Modulation (PWM) is a technique of encoding a pulsed signal so as to control the ratio of on to off by switching the signal between on and off at a very high rate. | ||
Line 37: | Line 37: | ||
| <code>PWM_TYPE_NONE = 0;</code> | | <code>PWM_TYPE_NONE = 0;</code> | ||
| style="width: 50%;"| | | style="width: 50%;"| | ||
+ | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | | <code>PWM_TYPE_MAX = 0;</code> | ||
+ | | | ||
|- | |- | ||
|} | |} | ||
Line 94: | Line 99: | ||
| <code>PWM_MODE_SERIALIZED = 2;</code> | | <code>PWM_MODE_SERIALIZED = 2;</code> | ||
| Serialized mode (Device specific) | | Serialized mode (Device specific) | ||
+ | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | | <code>PWM_MODE_MAX = 2;</code> | ||
+ | | | ||
|- | |- | ||
|} | |} | ||
Line 107: | Line 117: | ||
|- | |- | ||
| <code>PWM_POLARITY_INVERSE = 1;</code> | | <code>PWM_POLARITY_INVERSE = 1;</code> | ||
+ | | | ||
+ | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | | <code>PWM_POLARITY_MAX = 1;</code> | ||
| | | | ||
|- | |- | ||
Line 1,024: | Line 1,039: | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">function PWMGetCount:LongWord | + | <pre style="border: 0; padding-bottom:0px;">function PWMGetCount:LongWord;</pre> |
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current PWM count</div> | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current PWM count</div> | ||
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
Line 1,036: | Line 1,051: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">function PWMDeviceGetDefault:PPWMDevice | + | <pre style="border: 0; padding-bottom:0px;">function PWMDeviceGetDefault:PPWMDevice;</pre> |
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current default PWM device</div> | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current default PWM device</div> | ||
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
Line 1,062: | Line 1,077: | ||
<pre style="border: 0; padding-bottom:0px;">function PWMDeviceCheck(PWM:PPWMDevice):PPWMDevice;</pre> | <pre style="border: 0; padding-bottom:0px;">function PWMDeviceCheck(PWM:PPWMDevice):PPWMDevice;</pre> | ||
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Check if the supplied PWM is in the PWM table</div> | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Check if the supplied PWM is in the PWM table</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Note | ||
+ | | None documented | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function PWMTypeToString(PWMType:LongWord):String;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Convert a PWM type value to a string</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Note | ||
+ | | None documented | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function PWMStateToString(PWMState:LongWord):String;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Convert a PWM state value to a string</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Note | ||
+ | | None documented | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function PWMModeToString(PWMMode:LongWord):String;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Convert a PWM mode value to a string</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Note | ||
+ | | None documented | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function PWMPolarityToString(PWMPolarity:LongWord):String;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Convert a PWM polarity value to a string</div> | ||
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" |
Latest revision as of 03:37, 15 December 2022
Return to Unit Reference
Contents
[hide]Description
Ultibo PWM Interface unit
Pulse Width Modulation (PWM) is a technique of encoding a pulsed signal so as to control the ratio of on to off by switching the signal between on and off at a very high rate.
This on and off switching allows control of the average power supplied to the load and therefore gives fine grained control of things such as motor speeds, lamp dimming and heating elements.
PWM is also used in many low power applications as well such as controlling servo motors and can even by used for audio applications such as class D amplifiers.
This unit deals with the usage of PWM for control applications (for audio applications see the Audio unit) and provides methods to control the state, frequency, duty cycle, range and mode of PWM host controllers. Not all devices support all of these concepts so this API includes a properties function to allow obtaining information about a PWM device and its capabilities.
Constants
PWM_*
PWM_TYPE_*
PWM_STATE_*
PWM_FLAG_*
PWM_MODE_*
PWM_POLARITY_*
PWM_LOG_*
Type definitions
PWM properties
PWM enumeration callback
TPWMEnumerate = function(PWM:PPWMDevice; Data:Pointer):LongWord;
|
PWM notification callback
TPWMNotification = function(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;
|
PWM device start
TPWMDeviceStart = function(PWM:PPWMDevice):LongWord;
|
PWM device stop
TPWMDeviceStop = function(PWM:PPWMDevice):LongWord;
|
PWM device write
TPWMDeviceWrite = function(PWM:PPWMDevice; Value:LongWord):LongWord;
|
PWM device get GPIO
TPWMDeviceGetGPIO = function(PWM:PPWMDevice):LongWord;
|
PWM device set GPIO
TPWMDeviceSetGPIO = function(PWM:PPWMDevice; GPIO:LongWord):LongWord;
|
PWM device get mode
TPWMDeviceGetMode = function(PWM:PPWMDevice):LongWord;
|
PWM device set mode
TPWMDeviceSetMode = function(PWM:PPWMDevice; Mode:LongWord):LongWord;
|
PWM device get range
TPWMDeviceGetRange = function(PWM:PPWMDevice):LongWord;
|
PWM device set range
TPWMDeviceSetRange = function(PWM:PPWMDevice; Range:LongWord):LongWord;
|
PWM device get frequency
TPWMDeviceGetFrequency = function(PWM:PPWMDevice):LongWord;
|
PWM device set frequency
TPWMDeviceSetFrequency = function(PWM:PPWMDevice; Frequency:LongWord):LongWord;
|
PWM device get polarity
TPWMDeviceGetPolarity = function(PWM:PPWMDevice):LongWord;
|
PWM device set polarity
TPWMDeviceSetPolarity = function(PWM:PPWMDevice; Polarity:LongWord):LongWord;
|
PWM device configure
TPWMDeviceConfigure = function(PWM:PPWMDevice; DutyNS,PeriodNS:LongWord):LongWord;
|
PWM device get properties
TPWMDeviceGetProperties = function(PWM:PPWMDevice; Properties:PPWMProperties):LongWord;
|
PWM device
Public variables
PWM logging
PWM_DEFAULT_LOG_LEVEL:LongWord = PWM_LOG_LEVEL_DEBUG;
|
Minimum level for PWM messages. Only messages with level greater than or equal to this will be printed. |
PWM_LOG_ENABLED:Boolean;
|
Function declarations
Initialization functions
PWM functions
function PWMDeviceStart(PWM:PPWMDevice):LongWord;
function PWMDeviceStop(PWM:PPWMDevice):LongWord;
function PWMDeviceWrite(PWM:PPWMDevice; Value:LongWord):LongWord;
function PWMDeviceGetGPIO(PWM:PPWMDevice):LongWord;
function PWMDeviceSetGPIO(PWM:PPWMDevice; GPIO:LongWord):LongWord;
function PWMDeviceGetMode(PWM:PPWMDevice):LongWord;
function PWMDeviceSetMode(PWM:PPWMDevice; Mode:LongWord):LongWord;
function PWMDeviceGetRange(PWM:PPWMDevice):LongWord;
function PWMDeviceSetRange(PWM:PPWMDevice; Range:LongWord):LongWord;
function PWMDeviceGetFrequency(PWM:PPWMDevice):LongWord;
function PWMDeviceSetFrequency(PWM:PPWMDevice; Frequency:LongWord):LongWord;
function PWMDeviceGetPolarity(PWM:PPWMDevice):LongWord;
function PWMDeviceSetPolarity(PWM:PPWMDevice; Polarity:LongWord):LongWord;
function PWMDeviceConfigure(PWM:PPWMDevice; DutyNS,PeriodNS:LongWord):LongWord;
function PWMDeviceProperties(PWM:PPWMDevice; Properties:PPWMProperties):LongWord; inline;
function PWMDeviceGetProperties(PWM:PPWMDevice; Properties:PPWMProperties):LongWord;
function PWMDeviceDestroy(PWM:PPWMDevice):LongWord;
function PWMDeviceRegister(PWM:PPWMDevice):LongWord;
function PWMDeviceDeregister(PWM:PPWMDevice):LongWord;
function PWMDeviceFindByName(const Name:String):PPWMDevice; inline;
function PWMDeviceFindByDescription(const Description:String):PPWMDevice; inline;
function PWMDeviceEnumerate(Callback:TPWMEnumerate; Data:Pointer):LongWord;
function PWMDeviceNotification(PWM:PPWMDevice; Callback:TPWMNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
RTL PWM functions
function SysPWMWrite(Value:LongWord):LongWord;
function SysPWMSetMode(Mode:LongWord):LongWord;
function SysPWMSetRange(Range:LongWord):LongWord;
function SysPWMSetFrequency(Frequency:LongWord):LongWord;
function SysPWMConfigure(DutyNS,PeriodNS:LongWord):LongWord;
PWM helper functions
function PWMDeviceSetDefault(PWM:PPWMDevice):LongWord;
function PWMDeviceCheck(PWM:PPWMDevice):PPWMDevice;
function PWMTypeToString(PWMType:LongWord):String;
function PWMStateToString(PWMState:LongWord):String;
function PWMModeToString(PWMMode:LongWord):String;
function PWMPolarityToString(PWMPolarity:LongWord):String;
procedure PWMLog(Level:LongWord; PWM:PPWMDevice; const AText:String);
procedure PWMLogInfo(PWM:PPWMDevice; const AText:String); inline;
procedure PWMLogWarn(PWM:PPWMDevice; const AText:String); inline;
procedure PWMLogError(PWM:PPWMDevice; const AText:String); inline;
procedure PWMLogDebug(PWM:PPWMDevice; const AText:String); inline;
Return to Unit Reference