PWM library

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

Library Routines

PWM_Init

Prototype

unsigned int PWM_Init(unsigned long freq_hz);

Description

This 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 function returns calculated counter period (used to set duty ratio).

Requires
  • MCU must have the HW PWM Module.
Example
pwm_period = PWM_Init(250000);
Notes

None.

PWM_ConfigChannel

Prototype

void PWM_ConfigChannel(unsigned int dutyRatio, unsigned char initState, unsigned char channel);

Description

This 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 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

void PWM_SoftReset();

Description

This function resets PWM module.

Parameters

None.

Returns

Nothing.

Requires

Nothing.

Example
// reset PWM module
PWM_SoftReset();
Notes

None.

PWM_EnableOutput

Prototype

void PWM_EnableOutput();

Description

This function enables PWM module output.

Parameters

None.

Returns

Nothing.

Requires

Nothing.

Example
// Enable PWM module output
PWM_EnableOutput();
Notes

None.

PWM_DisableOutput

Prototype

void PWM_DisableOutput();

Description

This function 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