PWM library

The PWM module is available with a number of MCUs. mikroPascal PRO for FT90x provides a library which simplifies usage of this module.

Library Routines

PWM_Init

Prototype

sub function PWM_Init(dim freq_hz as longword) as word

Description

This sub function enables PWM clock, calculates prescaler and counter based on frequency parameter, set continuous mode and disables trigger.

Parameters
  • freq_hz: PWM frequency in Hz (refer to device datasheet for correct values in respect with Fosc).
Returns

This sub function returns calculated counter period (used to set duty ratio).

Requires
  • MCU must have the HW PWM Module.
Example
duty = PWM_Init(10000)
Notes

None.

PWM_ConfigChannel

Prototype

sub procedure PWM_ConfigChannel(dim dutyRatio as word, dim initState as byte, dim channel as byte)

Description

This sub function configure PWM channel (sets duty ratio, outputs initial level), and enables PWM output to corresponding pad.

Parameters
  • dutyRatio: PWM duty ratio. Valid values: 0 to timer period returned by the PWM_Init sub function.
  • initState: initial level of PWM output. Valid values :
    Value Description
    _PWM_INIT_STATE_0 Initial PWM level set to zero.
    _PWM_INIT_STATE_1 Initial PWM level set to one.

  • channel: PWM channel.
    Value Description
    _PWM_CHANNEL_0 PWM channel 0.
    _PWM_CHANNEL_1 PWM channel 1.
    _PWM_CHANNEL_2 PWM channel 2.
    _PWM_CHANNEL_3 PWM channel 3.
    _PWM_CHANNEL_4 PWM channel 4.
    _PWM_CHANNEL_5 PWM channel 5.
    _PWM_CHANNEL_6 PWM channel 6.
    _PWM_CHANNEL_7 PWM channel 7.
Returns

Nothing.

Requires

Nothing.

Example
PWM_ConfigChannel(current_duty, _PWM_INIT_STATE_0, _PWM_CHANNEL_4)   ' PWM output on P52 pin
Notes

None.

PWM_SoftReset

Prototype

sub procedure PWM_SoftReset()

Description

This sub procedure resets PWM module.

Parameters

None.

Returns

Nothing.

Requires

Nothing.

Example
' reset PWM module
PWM_SoftReset()
Notes

None.

PWM_EnableOutput

Prototype

sub procedure PWM_EnableOutput()

Description

This sub procedure enables PWM module output.

Parameters

None.

Returns

Nothing.

Requires

Nothing.

Example
' Enable PWM module output
PWM_EnableOutput()
Notes

None.

PWM_DisableOutput

Prototype

sub procedure PWM_DisableOutput()

Description

This sub procedure disables PWM module output.

Parameters

None.

Returns

Nothing.

Requires

Nothing.

Example
' Disable PWM module output
PWM_DisableOutput()
Notes

None.

Copyright (c) 2002-2015 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code