PWM
 
Component PWM
Pulse width modulation
Component Level: High
Methods:
(Methods are user-callable functions/subroutines intended for the component functions control. Please see the Embedded Components page for more information.)
  • Enable - This method enables the component - it starts the signal generation. Events may be generated (DisableEvent/EnableEvent).

      ANSIC prototype: byte Enable(void)
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode

  • Disable - This method disables the component - it stops the signal generation and events calling. When the timer is disabled, it is possible to call ClrValue and SetValue methods.

      ANSIC prototype: byte Disable(void)
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode

  • EnableEvent - This method enables the events. The method is available only if any event is selected.

      ANSIC prototype: byte EnableEvent(void)
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode

  • DisableEvent - This method disables the events. The method is available only if any event is selected.

      ANSIC prototype: byte DisableEvent(void)
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode

  • SetRatio8 - This method sets a new duty-cycle ratio. Ratio is expressed as an 8-bit unsigned integer number. 0 - FF value is proportional to ratio 0 - 100%. The method is available only if it is not selected list of predefined values in Starting pulse width property.
    Note: Calculated duty depends on the timer capabilities and on the selected period.

      ANSIC prototype: byte SetRatio8(byte Ratio)
    • Ratio:byte - Ratio to set. 0 - 255 value is proportional to ratio 0 - 100%
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode

  • SetRatio16 - This method sets a new duty-cycle ratio. Ratio is expressed as a 16-bit unsigned integer number. 0 - FFFF value is proportional to ratio 0 - 100%. The method is available only if it is not selected list of predefined values in Starting pulse width property.
    Note: Calculated duty depends on the timer possibilities and on the selected period.

      ANSIC prototype: byte SetRatio16(word Ratio)
    • Ratio:word - Ratio to set. 0 - 65535 value is proportional to ratio 0 - 100%
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode

  • SetDutyTicks16 - This method sets the new duty value of the output signal. The duty is expressed in main oscillator (usually external osc., internal osc. if exits and external osc. is disabled) ticks as a 16-bit unsigned integer number. The method is available only if it is not selected list of predefined values in Starting pulse width property.

      ANSIC prototype: byte SetDutyTicks16(word Ticks)
    • Ticks:word - Duty to set in Xtal ticks
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode
      ERR_MATH - Overflow during evaluation
      ERR_RANGE - Parameter out of range

  • SetDutyTicks32 - This method sets the new duty value of the output signal. The duty is expressed in main oscillator (usually External osc., internal osc. if exits and external osc. is disabled) ticks as a 32-bit unsigned integer number. The method is available only if it is not selected list of predefined values in Starting pulse width property.

      ANSIC prototype: byte SetDutyTicks32(dword Ticks)
    • Ticks:dword - Duty to set in Xtal ticks
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode
      ERR_MATH - Overflow during evaluation
      ERR_RANGE - Parameter out of range

  • SetDutyUS - This method sets the new duty value of the output signal. The duty is expressed in microseconds as a 16-bit unsigned integer number. The method is available only if it is not selected list of predefined values in Starting pulse width property.

      ANSIC prototype: byte SetDutyUS(word Time)
    • Time:word - Duty to set [in microseconds]
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode
      ERR_MATH - Overflow during evaluation
      ERR_RANGE - Parameter out of range

  • SetDutyMS - This method sets the new duty value of the output signal. The duty is expressed in milliseconds as a 16-bit unsigned integer number. The method is available only if it is not selected list of predefined values in Starting pulse width property.

      ANSIC prototype: byte SetDutyMS(word Time)
    • Time:word - Duty to set [in milliseconds]
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode
      ERR_MATH - Overflow during evaluation
      ERR_RANGE - Parameter out of range

  • SetDutySec - This method sets the new duty value of the output signal. The duty is expressed in seconds as a 16-bit unsigned integer number. The method is available only if it is not selected list of predefined values in Starting pulse width property.

      ANSIC prototype: byte SetDutySec(word Time)
    • Time:word - Duty to set [in seconds]
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode
      ERR_MATH - Overflow during evaluation
      ERR_RANGE - Parameter out of range

  • SetDutyReal - This method sets the new duty value of the output signal. The duty is expressed in seconds as a real number. In order to use this method the compiler have to support floating point operations. The method is available only if it is not selected list of predefined values in Starting pulse width property.

      ANSIC prototype: byte SetDutyReal(float Time)
    • Time:float - Duty to set [in seconds]
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode
      ERR_MATH - Overflow during evaluation
      ERR_RANGE - Parameter out of range

  • SetValue - This method sets (set to "1" = "High") timer flip-flop output signal level. It allows to the user to directly set the output pin value (=flip-flop state), and can set the signal polarity. This method only works when the timer is disabled (Disable method) otherwise it returns the error code. ClrValue and SetValue methods are used for setting the initial state.

      ANSIC prototype: byte SetValue(void)
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode
      ERR_ENABLED - Component is enabled. Component must be disabled (see "Disable method")

  • ClrValue - This method clears (set to "0" = "Low") timer flip-flop output signal level. It allows to the user to directly set the output pin value (=flip-flop state), and can set the signal polarity. This method only works when the timer is disabled (Disable otherwise it returns the error code. ClrValue and SetValue methods are used for setting the initial state.

      ANSIC prototype: byte ClrValue(void)
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode
      ERR_ENABLED - Component is enabled. Component must be disabled (see "Disable method")

  • Methods for HC08 derivatives.
    • MaximumDuty - This method forces the duty cycle of PWM signal to 100%.

        ANSIC prototype: void MaximumDuty(bool Max)
      • Max:bool - Force the duty cycle of output signal.
        true - enable function
        false - disable function

  • Methods for HC08 and HCS08 derivatives.
    • SetDutyMode - This method switches the component to a specified mode (changes the duty using the mode values). This method reduces the time needed for setting of a new period value. This method is enabled only if a list of possible period settings is specified at design time in Starting pulse width property (for details about settings refer to chapter Timing dialog box - Runtime setting - from a list of values). Each of these settings represents a mode and Processor Expert assigns them a mode identifier, which can be used as a parameter of this method (see generated header file). The prescaler and compare values corresponding to each mode are calculated at a design time, so tum-time calculations are not necessary.

        ANSIC prototype: byte SetDutyMode(byte Mode)
      • Mode:byte - Specifies a Mode to switch to
      • Return value:byte - Error code, possible codes:
        ERR_OK - OK
        ERR_SPEED - This device does not work in the active speed mode
        ERR_VALUE - Value out of range, requested timing mode is not defined


Note: Some methods can be implemented as macros.