Digital Power Starter Kit 3 Firmware
dsPIC33C Buck Converter Voltage Mode Control Example

Public functions of the HSPWM PRAL driver. More...

+ Collaboration diagram for Public Functions:

Functions

volatile uint16_t p33c_PwmGenerator_GetInstance (volatile struct P33C_PWM_GENERATOR_s *pg)
 Get the PWM generator instance index of a known PWM object pointer address. More...
 
volatile uint16_t p33c_PwmGenerator_GetGroup (volatile struct P33C_PWM_GENERATOR_s *pg)
 Get the PWM generator group. More...
 
volatile uint16_t p33c_PwmModule_Initialize (void)
 Initializes the PWM base module by resetting all its registers to default. More...
 
volatile struct P33C_PWM_MODULE_sp33c_PwmModule_GetHandle (void)
 Gets pointer to PWM module SFR set. More...
 
volatile uint16_t p33c_PwmModule_Dispose (void)
 Resets all PWM base module registers to their RESET default values. More...
 
volatile struct P33C_PWM_MODULE_s p33c_PwmModule_ConfigRead (void)
 Read the current configuration from the PWM base module registers. More...
 
volatile uint16_t p33c_PwmModule_ConfigWrite (volatile struct P33C_PWM_MODULE_s pwmConfig)
 Writes a user-defined configuration to the PWM base module registers. More...
 
volatile struct P33C_PWM_GENERATOR_s p33c_PwmGenerator_ConfigRead (volatile uint16_t pgInstance)
 Disposes a given PWM generator by resetting all its registers to default. More...
 
volatile uint16_t p33c_PwmGenerator_ConfigWrite (volatile uint16_t pgInstance, volatile struct P33C_PWM_GENERATOR_s pgConfig)
 Disposes a given PWM generator by resetting all its registers to default. More...
 
volatile uint16_t p33c_PwmGenerator_Initialize (volatile uint16_t pgInstance)
 Initializes a given PWM generator by resetting all its registers to default. More...
 
volatile uint16_t p33c_PwmGenerator_Dispose (volatile uint16_t pgInstance)
 Disposes a given PWM generator by resetting all its registers to default. More...
 
volatile uint16_t p33c_PwmGenerator_Enable (volatile struct P33C_PWM_GENERATOR_s *pg)
 Enables a given PWM generator with output pins disabled. More...
 
volatile uint16_t p33c_PwmGenerator_Disable (volatile struct P33C_PWM_GENERATOR_s *pg)
 Disables a given PWM generator. More...
 
volatile uint16_t p33c_PwmGenerator_Resume (volatile struct P33C_PWM_GENERATOR_s *pg)
 Disables a PWM generator IOs. More...
 
volatile uint16_t p33c_PwmGenerator_Suspend (volatile struct P33C_PWM_GENERATOR_s *pg)
 Disables the PWM generator outputs but keeps the module running. More...
 
volatile uint16_t p33c_PwmGenerator_SetPeriod (volatile struct P33C_PWM_GENERATOR_s *pg, volatile uint16_t period)
 Sets the period of a given PWM generator. More...
 
volatile uint16_t p33c_PwmGenerator_SetDutyCycle (volatile struct P33C_PWM_GENERATOR_s *pg, volatile uint16_t duty)
 Sets the on-time of a given PWM generator. More...
 
volatile uint16_t p33c_PwmGenerator_SetDeadTimes (volatile struct P33C_PWM_GENERATOR_s *pg, volatile uint16_t dead_time_rising, volatile uint16_t dead_time_falling)
 Sets the dead-times of a given PWM generator. More...
 
volatile struct P33C_PWM_GENERATOR_sp33c_PwmGenerator_GetHandle (volatile uint16_t pgInstance)
 Returns the PWM generator index. More...
 
volatile uint16_t p33c_PwmGenerator_SyncGenerators (volatile struct P33C_PWM_GENERATOR_s *pgHandleMother, volatile uint16_t pgMotherTriggerOutput, volatile struct P33C_PWM_GENERATOR_s *pgHandleChild, volatile bool ChildImmediateUpdate)
 Sets the synchronization triggers of two PWM generators, of which the Mother PWM generator is the trigger provider and the Child PWM generator is the synchronization trigger receiver. More...
 

Detailed Description

Public functions of the HSPWM PRAL driver.

This is the detailed description of public functions of the HSPWM PRAL driver

Function Documentation

◆ p33c_PwmGenerator_ConfigRead()

struct P33C_PWM_GENERATOR_s p33c_PwmGenerator_ConfigRead ( volatile uint16_t  pgInstance)

Disposes a given PWM generator by resetting all its registers to default.

Parameters
pgInstanceInstance of the PWM generator (e.g. 1 = PG1, 2=PG2, etc.) of type unsigned integer
Returns
Generic PWM generator Special Function Register set of type struct P33C_PWM_GENERATOR_s

This function copies the contents of all PWM generator registers of the specified generator instance (e.g. PG2) to a user variable of type P33C_PWM_GENERATOR_t. This 'virtual' PWM configuration can then , for
example, be analyzed and/or modified in user code and applied to another PWM generator using the function p33c_PwmGenerator_ConfigWrite(...).

Definition at line 158 of file p33c_pwm.c.

◆ p33c_PwmGenerator_ConfigWrite()

uint16_t p33c_PwmGenerator_ConfigWrite ( volatile uint16_t  pgInstance,
volatile struct P33C_PWM_GENERATOR_s  pgConfig 
)

Disposes a given PWM generator by resetting all its registers to default.

Parameters
pgInstanceInstance of the PWM generator of type unsigned integer (e.g. 1=PG1, 2=PG2, etc.)
pgConfigGeneric PWM generator Special Function Register set of type struct P33C_PWM_GENERATOR_s
Returns
0 = failure, disposing PWM generator was not successful
1 = success, disposing PWM generator was successful

This function writes a user-defined PWM generator configuration of type P33C_PWM_GENERATOR_t to the given PWM generator peripheral instance (e.g. PG2).

Definition at line 217 of file p33c_pwm.c.

+ Here is the caller graph for this function:

◆ p33c_PwmGenerator_Disable()

uint16_t p33c_PwmGenerator_Disable ( volatile struct P33C_PWM_GENERATOR_s pg)

Disables a given PWM generator.

Parameters
pgPointer to PWM generator peripheral instance register set of type struct P33C_PWM_GENERATOR_s
Returns
0 = failure, disabling PWM generator was not successful
1 = success, disabling PWM generator was successful

This function disables the PWM Generator and locks its PWM output pins in a safe state.

Definition at line 366 of file p33c_pwm.c.

+ Here is the caller graph for this function:

◆ p33c_PwmGenerator_Dispose()

uint16_t p33c_PwmGenerator_Dispose ( volatile uint16_t  pgInstance)

Disposes a given PWM generator by resetting all its registers to default.

Parameters
pgInstanceInstance of the PWM generator of type unsigned integer (e.g. 1=PG1, 2=PG2, etc.)
Returns
0 = failure, disposing PWM generator was not successful
1 = success, disposing PWM generator was successful

This function disables the specified PWM Generator and clears all its Special Function Registers (SFR) to their RESET default values.

Definition at line 290 of file p33c_pwm.c.

+ Here is the call graph for this function:

◆ p33c_PwmGenerator_Enable()

uint16_t p33c_PwmGenerator_Enable ( volatile struct P33C_PWM_GENERATOR_s pg)

Enables a given PWM generator with output pins disabled.

Parameters
pgPointer to PWM generator peripheral instance register set of type struct P33C_PWM_GENERATOR_s
Returns
0 = failure, enabling PWM generator was not successful
1 = success, enabling PWM generator was successful

This function enables the PWM Generator and adds delay before enabling
PWM output pins. After having successfully enabled the generator, users need to call function PWM_Generator_Resume to allow the PWM generator

Definition at line 316 of file p33c_pwm.c.

◆ p33c_PwmGenerator_GetGroup()

volatile uint16_t p33c_PwmGenerator_GetGroup ( volatile struct P33C_PWM_GENERATOR_s pg)

Get the PWM generator group.

volatile uint16_t p33c_PwmGenerator_GetGroup(volatile struct P33C_PWM_GENERATOR_s* pg)

Parameters
pgPointer to PWM generator peripheral instance register set of type struct P33C_PWM_GENERATOR_s
Returns
0 = error, PWM generator group not found
1 = PWM generator is in group #1
2 = PWM generator is in group #2

This function identify the group to which the PWM generator instance belongs (1 = [PG1-PG4], 2 = [PG5-PG8]) and verifies if the PWMgenerator group is valid and available. If no group is found, the function returns '0'

Definition at line 612 of file p33c_pwm.c.

◆ p33c_PwmGenerator_GetHandle()

struct P33C_PWM_GENERATOR_s * p33c_PwmGenerator_GetHandle ( volatile uint16_t  pgInstance)

Returns the PWM generator index.

Parameters
pgInstanceInstance of the PWM generator of type unsigned integer (e.g. 1=PG1, 2=PG2, etc.)
Returns
Pointer address to PWM generator instance of type struct P33C_PWM_GENERATOR_s specified by parameter pgInstance

This function returns the address pointer (pgHandle) of the PWM generator Special Function Register set specified by parameter pgInstance. pgHandle can be used to assign a global variable in user code, which allows to directly read from/write to PWM registers of the selected PWM generator with zero API overhead.

Definition at line 555 of file p33c_pwm.c.

+ Here is the caller graph for this function:

◆ p33c_PwmGenerator_GetInstance()

volatile uint16_t p33c_PwmGenerator_GetInstance ( volatile struct P33C_PWM_GENERATOR_s pg)

Get the PWM generator instance index of a known PWM object pointer address.

volatile uint16_t p33c_PwmGenerator_GetInstance(volatile struct P33C_PWM_GENERATOR_s* pg)

Parameters
pgPointer to PWM generator peripheral instance register set of type struct P33C_PWM_GENERATOR_s
Returns
index of PWM generator instance of type unsigned integer

This function returns the non-zero PWM generator instance index of the PWM generator of the PWM generator Special Function Register set referenced by the pointer address of function parameter pg. If the memory address does not match any available PWM generator instance start address, this function returns '0'.

Definition at line 580 of file p33c_pwm.c.

◆ p33c_PwmGenerator_Initialize()

uint16_t p33c_PwmGenerator_Initialize ( volatile uint16_t  pgInstance)

Initializes a given PWM generator by resetting all its registers to default.

Parameters
pgInstanceInstance of the PWM generator of type unsigned integer (e.g. 1=PG1, 2=PG2, etc.)
Returns
0 = failure, disposing PWM generator was not successful
1 = success, disposing PWM generator was successful

This function initializes the specified PWM Generator with default input clock settings and high resolution mode enabled. All other Special Function Registers (SFR) are reset to their RESET default values.

Definition at line 250 of file p33c_pwm.c.

+ Here is the call graph for this function:

◆ p33c_PwmGenerator_Resume()

uint16_t p33c_PwmGenerator_Resume ( volatile struct P33C_PWM_GENERATOR_s pg)

Disables a PWM generator IOs.

Parameters
pgPointer to PWM generator peripheral instance register set of type struct P33C_PWM_GENERATOR_s
Returns
0 = failure, enabling PWM generator IOs was not successful
1 = success, enabling PWM generator IOs was successful

This function enables the PWM Generator IO instance allowing signals to be routed to the output pins. This on/off transition occurs synchronously to the PWM period.

Definition at line 400 of file p33c_pwm.c.

◆ p33c_PwmGenerator_SetDeadTimes()

uint16_t p33c_PwmGenerator_SetDeadTimes ( volatile struct P33C_PWM_GENERATOR_s pg,
volatile uint16_t  dead_time_rising,
volatile uint16_t  dead_time_falling 
)

Sets the dead-times of a given PWM generator.

Parameters
pgPointer to PWM generator peripheral instance register set of type struct P33C_PWM_GENERATOR_s
dead_time_risingRising edge dead time counter value of type unsigned integer /
dead_time_fallingFalling edge dead time counter value of type unsigned integer
Returns
0 = failure, disabling PWM generator was not successful
1 = success, disabling PWM generator was successful

This function writes the value specified by 'duty' to the DUTY CYCLE register of the specified PWM generator.

Definition at line 524 of file p33c_pwm.c.

◆ p33c_PwmGenerator_SetDutyCycle()

uint16_t p33c_PwmGenerator_SetDutyCycle ( volatile struct P33C_PWM_GENERATOR_s pg,
volatile uint16_t  duty 
)

Sets the on-time of a given PWM generator.

Parameters
pgPointer to PWM generator peripheral instance register set of type struct P33C_PWM_GENERATOR_s
dutyDuty cycle counter value of type unsigned integer
Returns
0 = failure, disabling PWM generator was not successful
1 = success, disabling PWM generator was successful

This function writes the value specified by 'duty' to the DUTY CYCLE register of the specified PWM generator.

Definition at line 490 of file p33c_pwm.c.

◆ p33c_PwmGenerator_SetPeriod()

uint16_t p33c_PwmGenerator_SetPeriod ( volatile struct P33C_PWM_GENERATOR_s pg,
volatile uint16_t  period 
)

Sets the period of a given PWM generator.

Parameters
pgPointer to PWM generator peripheral instance register set of type struct P33C_PWM_GENERATOR_s
periodCounter compare value of type unsigned integer of the PWM generator time base
Returns
0 = failure, disabling PWM generator was not successful
1 = success, disabling PWM generator was successful

This function writes the value specified by 'period' to the PERIOD register of the specified PWM generator.

Definition at line 457 of file p33c_pwm.c.

◆ p33c_PwmGenerator_Suspend()

uint16_t p33c_PwmGenerator_Suspend ( volatile struct P33C_PWM_GENERATOR_s pg)

Disables the PWM generator outputs but keeps the module running.

Parameters
pgPointer to PWM generator peripheral instance register set of type struct P33C_PWM_GENERATOR_s
Returns
0 = failure, enabling PWM generator IOs was not successful
1 = success, enabling PWM generator IOs was successful

This function disables the PWM Generator IO instance preventing signals to be routed to the output pins. This on/off transition occurs synchronously to the PWM period.

Definition at line 428 of file p33c_pwm.c.

◆ p33c_PwmGenerator_SyncGenerators()

uint16_t p33c_PwmGenerator_SyncGenerators ( volatile struct P33C_PWM_GENERATOR_s pgHandleMother,
volatile uint16_t  pgMotherTriggerOutput,
volatile struct P33C_PWM_GENERATOR_s pgHandleChild,
volatile bool  ChildImmediateUpdate 
)

Sets the synchronization triggers of two PWM generators, of which the Mother PWM generator is the trigger provider and the Child PWM generator is the synchronization trigger receiver.

Parameters
pgHandleMotherPointer to PWM generator object of type struct P33C_PWM_GENERATOR_s of triggering PWM generator (sync trigger provider)
pgMotherTriggerOutputTrigger output selection of type unsigned integer of Sync Trigger Provider of the selected PWM generator instance 0 = EOC/SOC 1 = PGxTRIGA 2 = PGxTRIGB 3 = PGxTRIGC
pgHandleChildPointer to PWM generator object of type struct P33C_PWM_GENERATOR_s of triggered PWM generator (sync trigger receiver)
ChildImmediateUpdatetrue = synchronization trigger synchronizes Child PWM generator at trigger edge false = synchronization trigger synchronizes Child PWM generator at EOC/SOC
Returns
0 = failure, PWM generator synchronization was not successful
1 = success, PWM generator synchronization was successful

This function sets the synchronization triggers of two PWM generators, of which the Mother PWM generator is the trigger provider and the Child PWM generator is the synchronization trigger receiver.

The Mother PWM generator is configured to broadcast its UPDATE bit and provides one of four, selectable synchronization trigger outputs (EOC/SOC, PGxTRIGA, PGxTRIGB or PGxTRIGC). The Mother PWM generator can be independent or being triggered by another PWM generator.

The Child PWM generator is configured to trigger on the event generated by the Mother PWM generator as configured above. The optional selection of immediate synchronization or synchronization of the SOC event is set by parameter ChildImmediateUpdate.

Definition at line 670 of file p33c_pwm.c.

◆ p33c_PwmModule_ConfigRead()

struct P33C_PWM_MODULE_s p33c_PwmModule_ConfigRead ( void  )

Read the current configuration from the PWM base module registers.

Returns
struct P33C_PWM_MODULE_s

This function reads all registers with their current configuration into a data structure of type P33C_PWM_MODULE_s. Users can read and verify of modify the configuration to write it back to the PWM module
base registers.

Definition at line 104 of file p33c_pwm.c.

◆ p33c_PwmModule_ConfigWrite()

uint16_t p33c_PwmModule_ConfigWrite ( volatile struct P33C_PWM_MODULE_s  pwmConfig)

Writes a user-defined configuration to the PWM base module registers.

Parameters
pwmConfigPWM module register set of type struct P33C_PWM_MODULE_s
Returns
0 = failure, disposing PWM generator was not successful
1 = success, disposing PWM generator was successful

This function writes a user-defined PWM module configuration of type P33C_PWM_MODULE_s to the PWM module base registers. The individual register configurations have to be set in user-code before calling this function. To simplify the configuration process of standard functions, this driver provides templates, which can be loaded and written directly (see function p33c_PwmInitialize(void) for details)

Definition at line 158 of file p33c_pwm.c.

+ Here is the caller graph for this function:

◆ p33c_PwmModule_Dispose()

uint16_t p33c_PwmModule_Dispose ( void  )

Resets all PWM base module registers to their RESET default values.

Returns
0 = failure, disposing PWM generator was not successful
1 = success, disposing PWM generator was successful

This function clears all PWM module base registers to their default values set when the device comes out of RESET.

Default configuration:

  • no main input clock source and scalers are selected
  • all output logic functions are disabled
  • all output logic events are disabled
  • all master timing registers are cleared
  • all PWM register locks are removed, allowing unrestricted SFR writes

Definition at line 104 of file p33c_pwm.c.

+ Here is the call graph for this function:

◆ p33c_PwmModule_GetHandle()

struct P33C_PWM_MODULE_s * p33c_PwmModule_GetHandle ( void  )

Gets pointer to PWM module SFR set.

Returns
struct P33C_PWM_GENERATOR_s: PWM generator object of the selected PWM generator instance

This function returns the PWM generator index, the PWM generator group (1 = [PG1-PG4], 2 = [PG5-PG8]) and the address pointer (handle) of the PWM generator Special Function Register set. handle can be used to directly read from/write to PWM registers of the selected PWM generator with zero API overhead.

Definition at line 74 of file p33c_pwm.c.

+ Here is the caller graph for this function:

◆ p33c_PwmModule_Initialize()

uint16_t p33c_PwmModule_Initialize ( void  )

Initializes the PWM base module by resetting all its registers to default.

Returns
0 = failure, disposing PWM generator was not successful
1 = success, disposing PWM generator was successful

This function initializes the PWM module base registers with default values for maximum performance.

Default configuration:

  • auxiliary clock is selected as main input clock source
  • all output logic functions are disabled
  • all output logic events are disabled
  • all master timing registers are cleared
  • all PWM register locks are removed, allowing unrestricted SFR writes

Definition at line 50 of file p33c_pwm.c.

+ Here is the call graph for this function: