oPWM Object

Main Index
Object List
Back to top of pageDescription:
 

An Object that controls the PIC's PWM Hardware Module. 

The PIC's PWM Hardware Module provides a clocked output with a variable sized pulse width (pulse-width-modulated).

The following table lists the size and availability of the oPWM Object.
 ObjectSizeDescriptionA1A2B1B2C1
oPWM3 ByteAn Object that controls the PIC's oPWM Hardware Module.xxxxx
Back to top of pageOperation:
 

An oPWM Object uses the PIC's PWM Module (PICPWMM) by configuring the I/O Line specified by the IOLine property as an output.  Once configured, the registers of the PICPWMM are set according to the values of the oPWM Object's properties. 

The DutyCycle property is copied to the PICPWMM DutyCycle register which controls the Pulse-Width of the logic-high portion of the clock cycle output. 

The Period property is copied to the PICPWMM Period register which controls the resolution of the clock cycle.

The PreScale property is copied to PIC Timer2's Prescale register which controls the base frequency of the Period property.

The Operate property controls the PICPWMM enable bit which specifies if the High going PWM pulse is generated. When the Operate property is set to 1, the PIC's PWM Module starts generating PWM pulses. When the Operate property is set to 0, the PWM pulses are discontinued and the specified I/O Line is set to 0-Volts. If a current PWM pulse was in progress it is cut short and the I/O line is immediately set to 0-Volts.

When enabled, the PICPWMM outputs a clock signal which has a variable width high going pulse.  At the beginning of each PWM clock cycle the output is set to 5-Volts. As the clock cycle progresses, an internal Period-Counter (Timer2) is incremented which is compared to the value specified by the DutyCycle. When Timer2 reaches the value specified by the DutyCycle, the I/O Line is set to 0-Volts. When Timer2 reaches the value specified by the Period, Timer2 is reset to 0 and the process repeats.

The Period property specifies the resolution of the clock cycle by specifying when to repeat the PWM cycle.  For example, if the Period property is set to 255 then the DutyCycle property's range is 0 - 255. Likewise if the Period property is set to 10 then the DutyCycle property's effective range is 0 - 10 because any value above 10 will never be reached by the Period-Duration Counter.

The PreScale property specifies the frequency that the Period-Counter (Timer2) counts by specifying how many times to divide a 5-Mhz clock which is used to increment Timer2. The PreScale property can be set to divide the 5-Mhz clock by 1, 4, or 16 giving frequencies of 5-Mhz, 1.25-Mhz, and 312.5-Khz.

Two physical Pulse-Width-Modulators are implemented within the PIC.  The oPWM object uses the value of the IOLine property to determine which of the two PICPWMMs to use.

Back to top of pageProperties:
 

The following table lists the properties of the oPWM Object:

Property

Description

DutyCycle
The duty cycle value for the oPWM Object.
Object Class: oByte Value Range: 0 - 255
Data Type: Numeric Default Value: 0
This is the count at which the PWM output switches state to 0.  For example, If the period = 250 and the DutyCycle = 125 then the PWM duty cycle would be 50%.
The following table list the values of the DutyCycle property (with period at 255).
 DutyCycleOperatePulse WidthOutput
Any00
0Any0
63125%
127150%
191175%
2551100%
Period
The Period property specifies the resolution of the clock cycle. 
Object Class: oVar8 Value Range: 0 - 255
Data Type: Numeric Default Value: 0
This is the number of counts for the total period of the PWM cycle. When the Period-Counter (Timer2) counts past this number then it resets the output state to 1, and starts the cycle over again.
PreScale
A value that selects the base frequency of the Period property.
Object Class: oSelect0to3 Value Range: 0 - 3
Data Type: Numeric Default Value: 0
PreScaleDescription
0

The base frequency is 5-Mhz

1

The base frequency of 5-Mhz is divided by 4 to get 1.25Mhz

2

The base frequency of 5-Mhz is divided by 16 to get 312 500hz

3

The base frequency of 5-Mhz is divided by 16 to get 312 500hz (same as 2)

IOLine
A value that specifies which PWM I/O Line is used to output the PWM.
Object Class: oIOLineP Value Range: 0 - 1
Data Type: Numeric Default Value: 0
IOLineDescription
0

The PWM signal is output on IOLine 18. 18 can be assigned to the IOLine in place of 0 but it will read back as 0.

1

The PWM signal is output on IOLine 17. 17 can be assigned to the IOLine in place of 1 but it will read back as 1.

Operate
A value that selects whether or not the PWM is outputted.
Object Class: oOperate Value Range: 0 - 1
Data Type: Numeric Default Value: 0
OperateConstantDescription
0cvOffThe PWM Hardware is not enabled.
1cvOnThe PWM Hardware is enabled.
Address
Returns a pointer to the address of the oCounter Object instance.
Object Class: oAddress Value Range: 0 - 127
Data Type:Pointer (Read Only) Default Value: Address of Object

Back to top of pageHardware Diagram:
 The PIC's PWM Module (PICPWMM).
Back to top of pageExample:
 In the following example, the oPWM Object is used.
'This program causes I/O Line 17 to 
'output a PWM signal which will cause 
'an LED to go bright/dim/bright

Dim A As New oPWM

Sub Main()
  A.IOLine = 17
  A.Operate = 1
  Do
    For A.DutyCycle = 1 To 250
    Next A.DutyCycle
    For A.DutyCycle = 250 To 1 Step -1
    Next A.DutyCycle
  Loop
End Sub
Back to top of pageRelated Items:
 The following table lists objects that use the oPWM Object.
 ObjectDescriptionA1A2B1B2C1
oPWMHOutputs a high-speed Pulse-Width-Modulated output using hardware specific I/O lines.xxxxx
oHBridgeH, XOutputs the I/O for driving an H Bridge using hardware specific I/O lines for the PWM.xxx
 The following table lists other objects with related functions.
 ObjectDescriptionA1A2B1B2C1
oPWMLOutputs a low-speed Pulse-Width-Modulated output on any I/O line.xxx
oPWMSOutputs a RC-Servo timed Pulse-Width-Modulated output on any I/O line.xxxxx
Back to top of pageVersion History and Bug List:
 Firmware Ver A1: Introduced.

Bugs: No known bugs.


 

ooPIC Compiler Ver 6.0 (c) Copyright 1997 - 2007 Savage Innovations, LLC.