Difference between revisions of "Unit PWM"
Line 16: | Line 16: | ||
---- | ---- | ||
− | '' | + | |
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''PWM specific constants''' <code> PWM_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>PWM_NAME_PREFIX = 'PWM';</code> | ||
+ | | Name prefix for PWM Devices | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''PWM device type constants''' <code> PWM_TYPE_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>PWM_TYPE_NONE = 0;</code> | ||
+ | | style="width: 50%;"| | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''PWM device state constants''' <code> PWM_STATE_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>PWM_STATE_DISABLED = 0;</code> | ||
+ | | style="width: 50%;"| | ||
+ | |- | ||
+ | | <code>PWM_STATE_ENABLED = 1;</code> | ||
+ | | | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''PWM device flag constants''' <code> PWM_FLAG_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>PWM_FLAG_NONE = $00000000;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>PWM_FLAG_GPIO = $00000001;</code> | ||
+ | | Device supports Get/Set GPIO | ||
+ | |- | ||
+ | | <code>PWM_FLAG_MODE = $00000002;</code> | ||
+ | | Device supports Get/Set Mode | ||
+ | |- | ||
+ | | <code>PWM_FLAG_RANGE = $00000004;</code> | ||
+ | | Device supports Get/Set Range | ||
+ | |- | ||
+ | | <code>PWM_FLAG_FREQUENCY = $00000008;</code> | ||
+ | | Device supports Get/Set Frequency | ||
+ | |- | ||
+ | | <code>PWM_FLAG_POLARITY = $00000010;</code> | ||
+ | | Device supports Get/Set Polarity | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''PWM mode value constants''' <code> PWM_MODE_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>PWM_MODE_MARKSPACE = 0;</code> | ||
+ | | Standard PWM Mark / Space mode | ||
+ | |- | ||
+ | | <code>PWM_MODE_BALANCED = 1;</code> | ||
+ | | Balanced mode (Device specific) | ||
+ | |- | ||
+ | | <code>PWM_MODE_SERIALIZED = 2;</code> | ||
+ | | Serialized mode (Device specific) | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''PWM polarity value constants''' <code> PWM_POLARITY_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>PWM_POLARITY_NORMAL = 0;</code> | ||
+ | | style="width: 50%;"| | ||
+ | |- | ||
+ | | <code>PWM_POLARITY_INVERSE = 1;</code> | ||
+ | | | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''PWM logging constants''' <code> PWM_LOG_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>PWM_LOG_LEVEL_DEBUG = LOG_LEVEL_DEBUG;</code> | ||
+ | | PWM debugging messages | ||
+ | |- | ||
+ | | <code>PWM_LOG_LEVEL_INFO = LOG_LEVEL_INFO;</code> | ||
+ | | PWM informational messages, such as a device being attached or detached | ||
+ | |- | ||
+ | | <code>PWM_LOG_LEVEL_ERROR = LOG_LEVEL_ERROR;</code> | ||
+ | | PWM error messages | ||
+ | |- | ||
+ | | <code>PWM_LOG_LEVEL_NONE = LOG_LEVEL_NONE;</code> | ||
+ | | No PWM messages | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
=== Type definitions === | === Type definitions === |
Revision as of 04:55, 28 November 2016
Return to Unit Reference
Contents
[hide]Description
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
To be documented
Public variables
To be documented
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;
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 PWMDeviceGetDefault:PPWMDevice; inline;
function PWMDeviceSetDefault(PWM:PPWMDevice):LongWord;
function PWMDeviceCheck(PWM:PPWMDevice):PPWMDevice;
procedure PWMLog(Level:LongWord; PWM:PPWMDevice; const AText:String);
procedure PWMLogInfo(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