Difference between revisions of "Unit PWM"
Line 136: | Line 136: | ||
---- | ---- | ||
− | '' | + | |
+ | '''PWM properties''' | ||
+ | |||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;"> | ||
+ | <code>PPWMProperties = ^TPWMProperties;</code> | ||
+ | |||
+ | <code>TPWMProperties = record</code> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>Flags:LongWord;</code> | ||
+ | | Device flags (eg PWM_FLAG_MODE) | ||
+ | |- | ||
+ | | <code>GPIO:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>Mode:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>Range:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>Frequency:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>Polarity:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>DutyNS:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>PeriodNS:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>MinPeriod:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | |||
+ | '''PWM enumeration callback''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TPWMEnumerate = function(PWM:PPWMDevice; Data:Pointer):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''PWM notification callback''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TPWMNotification = function(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''PWM device start''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TPWMDeviceStart = function(PWM:PPWMDevice):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''PWM device stop''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TPWMDeviceStop = function(PWM:PPWMDevice):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''PWM device write''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TPWMDeviceWrite = function(PWM:PPWMDevice; Value:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''PWM device get GPIO''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TPWMDeviceGetGPIO = function(PWM:PPWMDevice):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''PWM device set GPIO''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TPWMDeviceSetGPIO = function(PWM:PPWMDevice; GPIO:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''PWM device get mode''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TPWMDeviceGetMode = function(PWM:PPWMDevice):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''PWM device set mode''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TPWMDeviceSetMode = function(PWM:PPWMDevice; Mode:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''PWM device get range''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TPWMDeviceGetRange = function(PWM:PPWMDevice):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''PWM device set range''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TPWMDeviceSetRange = function(PWM:PPWMDevice; Range:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''PWM device get frequency''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TPWMDeviceGetFrequency = function(PWM:PPWMDevice):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''PWM device set frequency''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TPWMDeviceSetFrequency = function(PWM:PPWMDevice; Frequency:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''PWM device get polarity''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TPWMDeviceGetPolarity = function(PWM:PPWMDevice):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''PWM device set polarity''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TPWMDeviceSetPolarity = function(PWM:PPWMDevice; Polarity:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''PWM device configure''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TPWMDeviceConfigure = function(PWM:PPWMDevice; DutyNS,PeriodNS:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''PWM device properties''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TPWMDeviceProperties = function(PWM:PPWMDevice; Properties:PPWMProperties):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''PWM device''' | ||
+ | |||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;"> | ||
+ | <code>PPWMDevice = ^TPWMDevice;</code> | ||
+ | |||
+ | <code>TPWMDevice = record</code> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | |colspan="2"|''Device Properties'' | ||
+ | |- | ||
+ | | <code>Device:TDevice;</code> | ||
+ | | The Device entry for this PWM | ||
+ | |- | ||
+ | |colspan="2"|''PWM Properties'' | ||
+ | |- | ||
+ | | <code>PWMId:LongWord;</code> | ||
+ | | Unique Id of this PWM in the PWM table | ||
+ | |- | ||
+ | | <code>PWMState:LongWord;</code> | ||
+ | | PWM state (eg PWM_STATE_ENABLED) | ||
+ | |- | ||
+ | | <code>DeviceStart:TPWMDeviceStart;</code> | ||
+ | | A Device specific DeviceStart method implementing the standard PWM device interface (Mandatory) | ||
+ | |- | ||
+ | | <code>DeviceStop:TPWMDeviceStop;</code> | ||
+ | | A Device specific DeviceStop method implementing the standard PWM device interface (Mandatory) | ||
+ | |- | ||
+ | | <code>DeviceWrite:TPWMDeviceWrite;</code> | ||
+ | | A Device specific DeviceWrite method implementing the standard PWM device interface (Mandatory) | ||
+ | |- | ||
+ | | <code>DeviceGetGPIO:TPWMDeviceGetGPIO;</code> | ||
+ | | A Device specific DeviceGetGPIO method implementing the standard PWM device interface (Or nil if the operation is not supported) | ||
+ | |- | ||
+ | | <code>DeviceSetGPIO:TPWMDeviceSetGPIO;</code> | ||
+ | | A Device specific DeviceSetGPIO method implementing the standard PWM device interface (Or nil if the operation is not supported) | ||
+ | |- | ||
+ | | <code>DeviceGetMode:TPWMDeviceGetMode;</code> | ||
+ | | A Device specific DeviceGetMode method implementing the standard PWM device interface (Or nil if the operation is not supported) | ||
+ | |- | ||
+ | | <code>DeviceSetMode:TPWMDeviceSetMode;</code> | ||
+ | | A Device specific DeviceSetMode method implementing the standard PWM device interface (Or nil if the operation is not supported) | ||
+ | |- | ||
+ | | <code>DeviceGetRange:TPWMDeviceGetRange;</code> | ||
+ | | A Device specific DeviceGetRange method implementing the standard PWM device interface (Or nil if the operation is not supported) | ||
+ | |- | ||
+ | | <code>DeviceSetRange:TPWMDeviceSetRange;</code> | ||
+ | | A Device specific DeviceSetRange method implementing the standard PWM device interface (Or nil if the operation is not supported) | ||
+ | |- | ||
+ | | <code>DeviceGetFrequency:TPWMDeviceGetFrequency;</code> | ||
+ | | A Device specific DeviceGetFrequency method implementing the standard PWM device interface (Or nil if the operation is not supported) | ||
+ | |- | ||
+ | | <code>DeviceSetFrequency:TPWMDeviceSetFrequency;</code> | ||
+ | | A Device specific DeviceSetFrequency method implementing the standard PWM device interface (Or nil if the operation is not supported) | ||
+ | |- | ||
+ | | <code>DeviceGetPolarity:TPWMDeviceGetPolarity;</code> | ||
+ | | A Device specific DeviceGetPolarity method implementing the standard PWM device interface (Or nil if the operation is not supported) | ||
+ | |- | ||
+ | | <code>DeviceSetPolarity:TPWMDeviceSetPolarity;</code> | ||
+ | | A Device specific DeviceSetPolarity method implementing the standard PWM device interface (Or nil if the operation is not supported) | ||
+ | |- | ||
+ | | <code>DeviceConfigure:TPWMDeviceConfigure;</code> | ||
+ | | A Device specific DeviceConfigure method implementing the standard PWM device interface (Mandatory) | ||
+ | |- | ||
+ | | <code>DeviceProperties:TPWMDeviceProperties;</code> | ||
+ | | A Device specific DeviceProperties method implementing the standard PWM device interface (Or nil if the default method is suitable) | ||
+ | |- | ||
+ | |colspan="2"|''Statistics Properties'' | ||
+ | |- | ||
+ | | <code>GetCount:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>SetCount:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>WriteCount:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>ConfigCount:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | |colspan="2"|''Driver Properties'' | ||
+ | |- | ||
+ | | <code>Lock:TMutexHandle;</code> | ||
+ | | Device lock | ||
+ | |- | ||
+ | | <code>GPIO:LongWord;</code> | ||
+ | | GPIO Pin | ||
+ | |- | ||
+ | | <code>Mode:LongWord;</code> | ||
+ | | Device Mode | ||
+ | |- | ||
+ | | <code>Range:LongWord;</code> | ||
+ | | Device Range | ||
+ | |- | ||
+ | | <code>Frequency:LongWord;</code> | ||
+ | | Clock Frequency | ||
+ | |- | ||
+ | | <code>Polarity:LongWord;</code> | ||
+ | | Output Polarity | ||
+ | |- | ||
+ | | <code>DutyNS:LongWord;</code> | ||
+ | | Duty Nanoseconds | ||
+ | |- | ||
+ | | <code>PeriodNS:LongWord;</code> | ||
+ | | Period Nanonseconds | ||
+ | |- | ||
+ | | <code>Properties:TPWMProperties;</code> | ||
+ | | Device properties | ||
+ | |- | ||
+ | |colspan="2"|''Internal Properties'' | ||
+ | |- | ||
+ | | <code>Prev:PPWMDevice;</code> | ||
+ | | Previous entry in PWM table | ||
+ | |- | ||
+ | | <code>Next:PPWMDevice;</code> | ||
+ | | Next entry in PWM table | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
=== Public variables === | === Public variables === |
Revision as of 03:12, 25 January 2017
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 properties
TPWMDeviceProperties = 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;
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