3.20.2 16-bit PWM

16-bit Pulse-Width Modulator

3.20.2.1 Introduction

This module is a 16-bit Pulse-Width Modulator (PWM) module that generates a pulse-width modulated signal determined by the duty cycle, period, and resolution.

3.20.2.2 Supported Device Families

PIC12/16F157xPIC16F176xPIC16F177x

3.20.2.3 Required Header Files

#include "mcc_generated_files/pwm/pwm[x].h"
Note: Replace [X] with the instance number of the selected PWM module.

3.20.2.4 Module Documentation

3.20.2.4.1 PWM1

This is the generated header file for the PWM1 driver.

Module description

This is the generated header file for the PWM1 driver.

Version: PWM1 Driver Version 1.0.0
Functions
  • void PWM1_Initialize (void)

    Initializes the PWM1 module. This routine is called only once during system initialization, before calling other APIs.

  • void PWM1_Start (void)

    Starts the PWM1 operation and must be called after the initialize routine is called.

  • void PWM1_Stop (void)

    Stops the PWM1 operation and must be called after the start routine is called.

  • bool PWM1_CheckOutputStatus (void)

    Check the output status of the PWM1 module and must be called after the start routine is called.

  • void PWM1_LoadBufferSet (void)

    Loads the PWM1 buffer at the end of the period and must be called after the initialize routine is called.

  • void PWM1_PhaseSet (uint16_t phaseCount)

    Sets the expected phase count for the PWM1 module.

  • void PWM1_DutyCycleSet (uint16_t dutyCycleCount)

    Sets the expected duty cycle for the PWM1 module.

  • void PWM1_PeriodSet (uint16_t periodCount)

    Sets the expected period for the PWM1 module.

  • void PWM1_OffsetSet (uint16_t offsetCount)

    Sets the required offset for the PWM1 module.

  • uint16_t PWM1_timerCountGet (void)

    Reads the measured timer count of the PWM1 module.

  • bool PWM1_IsOffsetMatchOccured (void)

    Gets the status of the Offset Interrupt Flag bit (OFIF) of the PWM1 module.

  • bool PWM1_IsPhaseMatchOccured (void)

    Gets the status of the Phase Interrupt Flag bit (PHIF) of the PWM1 module.

  • bool PWM1_IsDutyCycleMatchOccured (void)

    Gets the status of the Duty Cycle Interrupt Flag bit (DCIF) of the PWM1 module.

  • bool PWM1_IsPeriodMatchOccured (void)

    Gets the status of the Period Interrupt Flag bit (PRIF) of the PWM1 module.

  • void PWM1_ISR (void)

    Implements the Interrupt Servide Routine (ISR) for the PWM1 interrupt. The routine checks which particular interrupt has occurred and calls the respective function.

  • void PWM1_CallbackRegister (void(*customCallback)(void))

    Assigns a callback function that will be called from the ISR when an interrupt event occurs.

Function Documentation

PWM1_CallbackRegister()

void PWM1_CallbackRegister (void(*)(void) customCallback)

Assigns a callback function that will be called from the ISR when an interrupt event occurs.

Parameters:
(*customCallback)(void)

- Function pointer to the new callback

Returns:

None.

PWM1_CheckOutputStatus()

bool PWM1_CheckOutputStatus (void )

Check the output status of the PWM1 module and must be called after the start routine is called.

Parameters:
None.
Returns:

True - Output High

False - Output Low

PWM1_DutyCycleSet()

void PWM1_DutyCycleSet (uint16_t dutyCycleCount)

Sets the expected duty cycle for the PWM1 module.

Parameters:
dutyCycleCount

- 16-bit duty cycle count

Returns:

None.

PWM1_Initialize()

void PWM1_Initialize (void )

Initializes the PWM1 module. This routine is called only once during system initialization, before calling other APIs.

Section: Included Files Section: PWM1 APIs

Parameters:
None.
Returns:

None.

PWM1_IsDutyCycleMatchOccured()

bool PWM1_IsDutyCycleMatchOccured (void )

Gets the status of the Duty Cycle Interrupt Flag bit (DCIF) of the PWM1 module.

Parameters:
None.
Returns:

True - PWMTMR count is higher than or equal to the PWMDC value

False - PWMTMR count is lower than the PWMDC value

PWM1_IsOffsetMatchOccured()

bool PWM1_IsOffsetMatchOccured (void )

Gets the status of the Offset Interrupt Flag bit (OFIF) of the PWM1 module.

Parameters:
None.
Returns:

None.

PWM1_IsPeriodMatchOccured()

bool PWM1_IsPeriodMatchOccured (void )

Gets the status of the Period Interrupt Flag bit (PRIF) of the PWM1 module.

Parameters:
None.
Returns:

True - PWMTMR count is higher than or equal to the PWMPR value

False - PWMTMR count is lower than the PWMPR value

PWM1_IsPhaseMatchOccured()

bool PWM1_IsPhaseMatchOccured (void )

Gets the status of the Phase Interrupt Flag bit (PHIF) of the PWM1 module.

Parameters:
None.
Returns:

True - PWMTMR count is higher than or equal to the PWMPH value

False - PWMTMR count is lower than the PWMPH value

PWM1_ISR()

void PWM1_ISR (void )

Implements the Interrupt Servide Routine (ISR) for the PWM1 interrupt. The routine checks which particular interrupt has occurred and calls the respective function.

Parameters:
None.
Returns:

None.

PWM1_LoadBufferSet()

void PWM1_LoadBufferSet (void )

Loads the PWM1 buffer at the end of the period and must be called after the initialize routine is called.

Parameters:
None.
Returns:

None.

PWM1_OffsetSet()

void PWM1_OffsetSet (uint16_t offsetCount)

Sets the required offset for the PWM1 module.

Parameters:
offsetCount

- 16-bit offset count

Returns:

None.

PWM1_PeriodSet()

void PWM1_PeriodSet (uint16_t periodCount)

Sets the expected period for the PWM1 module.

Parameters:
periodCount

- 16-bit period count

Returns:

None.

PWM1_PhaseSet()

void PWM1_PhaseSet (uint16_t phaseCount)

Sets the expected phase count for the PWM1 module.

Parameters:
phaseCount

- 16-bit phase count

Returns:

None.

PWM1_Start()

void PWM1_Start (void )

Starts the PWM1 operation and must be called after the initialize routine is called.

Parameters:
None.
Returns:

None.

PWM1_Stop()

void PWM1_Stop (void )

Stops the PWM1 operation and must be called after the start routine is called.

Parameters:
None.
Returns:

None.

PWM1_timerCountGet()

uint16_t PWM1_timerCountGet (void )

Reads the measured timer count of the PWM1 module.

Parameters:
None.
Returns:

16-bit timer count

3.20.2.5 File Documentation

3.20.2.5.1 source/source-files/pwm1.c File Reference

This is the generated driver implementation file for the PWM1 driver.

#include <xc.h>
#include "../pwm1.h"

Functions

  • static void PWM1_DefaultCallback (void)

    Default callback function for interrupt events.

  • void PWM1_Initialize (void)

    Initializes the PWM1 module. This routine is called only once during system initialization, before calling other APIs.

  • void PWM1_Start (void)

    Starts the PWM1 operation and must be called after the initialize routine is called.

  • void PWM1_Stop (void)

    Stops the PWM1 operation and must be called after the start routine is called.

  • bool PWM1_CheckOutputStatus (void)

    Check the output status of the PWM1 module and must be called after the start routine is called.

  • void PWM1_LoadBufferSet (void)

    Loads the PWM1 buffer at the end of the period and must be called after the initialize routine is called.

  • void PWM1_PhaseSet (uint16_t phaseCount)

    Sets the expected phase count for the PWM1 module.

  • void PWM1_DutyCycleSet (uint16_t dutyCycleCount)

    Sets the expected duty cycle for the PWM1 module.

  • void PWM1_PeriodSet (uint16_t periodCount)

    Sets the expected period for the PWM1 module.

  • void PWM1_OffsetSet (uint16_t offsetCount)

    Sets the required offset for the PWM1 module.

  • uint16_t PWM1_timerCountGet (void)

    Reads the measured timer count of the PWM1 module.

  • bool PWM1_IsOffsetMatchOccured (void)

    Gets the status of the Offset Interrupt Flag bit (OFIF) of the PWM1 module.

  • bool PWM1_IsPhaseMatchOccured (void)

    Gets the status of the Phase Interrupt Flag bit (PHIF) of the PWM1 module.

  • bool PWM1_IsDutyCycleMatchOccured (void)

    Gets the status of the Duty Cycle Interrupt Flag bit (DCIF) of the PWM1 module.

  • bool PWM1_IsPeriodMatchOccured (void)

    Gets the status of the Period Interrupt Flag bit (PRIF) of the PWM1 module.

  • void PWM1_ISR (void)

    Implements the Interrupt Servide Routine (ISR) for the PWM1 interrupt. The routine checks which particular interrupt has occurred and calls the respective function.

  • void PWM1_CallbackRegister (void(*customCallback)(void))

    Assigns a callback function that will be called from the ISR when an interrupt event occurs.

Detailed Description

PWM1 Generated Driver API Header File

Function Documentation

PWM1_CallbackRegister()

void PWM1_CallbackRegister (void(*)(void) customCallback)

Assigns a callback function that will be called from the ISR when an interrupt event occurs.

Parameters:
(*customCallback)(void)

- Function pointer to the new callback

Returns:

None.

PWM1_DefaultCallback()

static void PWM1_DefaultCallback (void )[static]

Default callback function for interrupt events.

Section: PWM1 APIs

Parameters:
None.
Returns:

None.

Variable Documentation

PWM1_Callback

void(* PWM1_Callback) (void)[static]

Section: Included Files

3.20.2.5.2 source/source-files/pwm1.h File Reference

#include <stdbool.h>
#include <stdint.h>

Functions

  • void PWM1_Initialize (void)

    Initializes the PWM1 module. This routine is called only once during system initialization, before calling other APIs.

  • void PWM1_Start (void)

    Starts the PWM1 operation and must be called after the initialize routine is called.

  • void PWM1_Stop (void)

    Stops the PWM1 operation and must be called after the start routine is called.

  • bool PWM1_CheckOutputStatus (void)

    Check the output status of the PWM1 module and must be called after the start routine is called.

  • void PWM1_LoadBufferSet (void)

    Loads the PWM1 buffer at the end of the period and must be called after the initialize routine is called.

  • void PWM1_PhaseSet (uint16_t phaseCount)

    Sets the expected phase count for the PWM1 module.

  • void PWM1_DutyCycleSet (uint16_t dutyCycleCount)

    Sets the expected duty cycle for the PWM1 module.

  • void PWM1_PeriodSet (uint16_t periodCount)

    Sets the expected period for the PWM1 module.

  • void PWM1_OffsetSet (uint16_t offsetCount)

    Sets the required offset for the PWM1 module.

  • uint16_t PWM1_timerCountGet (void)

    Reads the measured timer count of the PWM1 module.

  • bool PWM1_IsOffsetMatchOccured (void)

    Gets the status of the Offset Interrupt Flag bit (OFIF) of the PWM1 module.

  • bool PWM1_IsPhaseMatchOccured (void)

    Gets the status of the Phase Interrupt Flag bit (PHIF) of the PWM1 module.

  • bool PWM1_IsDutyCycleMatchOccured (void)

    Gets the status of the Duty Cycle Interrupt Flag bit (DCIF) of the PWM1 module.

  • bool PWM1_IsPeriodMatchOccured (void)

    Gets the status of the Period Interrupt Flag bit (PRIF) of the PWM1 module.

  • void PWM1_ISR (void)

    Implements the Interrupt Servide Routine (ISR) for the PWM1 interrupt. The routine checks which particular interrupt has occurred and calls the respective function.

  • void PWM1_CallbackRegister (void(*customCallback)(void))

    Assigns a callback function that will be called from the ISR when an interrupt event occurs.

Detailed Description

PWM1 Generated Driver API Header File

Function Documentation

PWM1_CallbackRegister()

void PWM1_CallbackRegister (void(*)(void) customCallback)

Assigns a callback function that will be called from the ISR when an interrupt event occurs.

Parameters:
(*customCallback)(void)

- Function pointer to the new callback

Returns:

None.

PWM1_CheckOutputStatus()

bool PWM1_CheckOutputStatus (void )

Check the output status of the PWM1 module and must be called after the start routine is called.

Parameters:
None.
Returns:

True - Output High

False - Output Low

PWM1_DutyCycleSet()

void PWM1_DutyCycleSet (uint16_t dutyCycleCount)

Sets the expected duty cycle for the PWM1 module.

Parameters:
dutyCycleCount

- 16-bit duty cycle count

Returns:

None.

PWM1_Initialize()

void PWM1_Initialize (void )

Initializes the PWM1 module. This routine is called only once during system initialization, before calling other APIs.

Section: Included Files Section: PWM1 APIs

Parameters:
None.
Returns:

None.

PWM1_IsDutyCycleMatchOccured()

bool PWM1_IsDutyCycleMatchOccured (void )

Gets the status of the Duty Cycle Interrupt Flag bit (DCIF) of the PWM1 module.

Parameters:
None.
Returns:

True - PWMTMR count is higher than or equal to the PWMDC value

False - PWMTMR count is lower than the PWMDC value

PWM1_IsOffsetMatchOccured()

bool PWM1_IsOffsetMatchOccured (void )

Gets the status of the Offset Interrupt Flag bit (OFIF) of the PWM1 module.

Parameters:
None.
Returns:

None.

PWM1_IsPeriodMatchOccured()

bool PWM1_IsPeriodMatchOccured (void )

Gets the status of the Period Interrupt Flag bit (PRIF) of the PWM1 module.

Parameters:
None.
Returns:

True - PWMTMR count is higher than or equal to the PWMPR value

False - PWMTMR count is lower than the PWMPR value

PWM1_IsPhaseMatchOccured()

bool PWM1_IsPhaseMatchOccured (void )

Gets the status of the Phase Interrupt Flag bit (PHIF) of the PWM1 module.

Parameters:
None.
Returns:

True - PWMTMR count is higher than or equal to the PWMPH value

False - PWMTMR count is lower than the PWMPH value

PWM1_ISR()

void PWM1_ISR (void )

Implements the Interrupt Servide Routine (ISR) for the PWM1 interrupt. The routine checks which particular interrupt has occurred and calls the respective function.

Parameters:
None.
Returns:

None.

PWM1_LoadBufferSet()

void PWM1_LoadBufferSet (void )

Loads the PWM1 buffer at the end of the period and must be called after the initialize routine is called.

Parameters:
None.
Returns:

None.

PWM1_OffsetSet()

void PWM1_OffsetSet (uint16_t offsetCount)

Sets the required offset for the PWM1 module.

Parameters:
offsetCount

- 16-bit offset count

Returns:

None.

PWM1_PeriodSet()

void PWM1_PeriodSet (uint16_t periodCount)

Sets the expected period for the PWM1 module.

Parameters:
periodCount

- 16-bit period count

Returns:

None.

PWM1_PhaseSet()

void PWM1_PhaseSet (uint16_t phaseCount)

Sets the expected phase count for the PWM1 module.

Parameters:
phaseCount

- 16-bit phase count

Returns:

None.

PWM1_Start()

void PWM1_Start (void )

Starts the PWM1 operation and must be called after the initialize routine is called.

Parameters:
None.
Returns:

None.

PWM1_Stop()

void PWM1_Stop (void )

Stops the PWM1 operation and must be called after the start routine is called.

Parameters:
None.
Returns:

None.

PWM1_timerCountGet()

uint16_t PWM1_timerCountGet (void )

Reads the measured timer count of the PWM1 module.

Parameters:
None.
Returns:

16-bit timer count