3.3 CMP DAC Driver

Overview

The high-speed analog comparator module provides a method to monitor voltage, current and other critical signals in a power conversion application that may be too fast for the CPU and ADC to capture.

The high-speed analog comparator module is comprised of a high-speed comparator, Pulse Density Modulation (PDM) DAC and a slope compensation unit. The slope compensation unit provides a user-defined slope which can be used to alter the DAC output. This feature is useful in applications, such as Peak Current mode control, where slope compensation is required to maintain the stability of the power supply

Features

  • The user can configure the DAC Mode based on their application needs.
  • There are four modes supported : DC-Mode, Slope Mode, Hysteretic Mode and Triangle Wave Mode.
  • The Clock and Divider settings can be configured in the PLIB dependency of the driver module.

DAC Modes

DC-Mode

The DC mode is the default mode of operation of the DAC. The other modes use slope generator to vary the DAC data value at a user-defined rate to reach a desired endpoint value.
Figure . 

Slope Mode

The slope generator function can be utilized in Peak Current mode control-based power supply applications, where slope compensation is required. The slope function modifies the non-slope PDM DAC value repeatedly, at a user-defined rate, until the DAC data value reaches its endpoint.
Figure . 

Hysteretic Mode

Hysteretic mode control is sometimes called “Bang-Bang” control, where a signal within a power converter is controlled within an upper cutoff and a lower cutoff limit. The Hysteretic mode is used in power supply applications utilizing hysteretic control, such as LED drivers.
Figure . 

Triangle Wave Mode

Triangle Wave mode generates an output voltage that rises and falls with a triangle wave pattern.
Figure . 

3.3.1 Module Documentation

3.3.1.1 CMP Driver

High Speed Analog Comparator with Slope Compensation DAC driver using dsPIC MCUs.

3.3.1.1.1 Module description

High Speed Analog Comparator with Slope Compensation DAC driver using dsPIC MCUs.

Data structures
  • struct DAC_DC_INTERFACE

    Structure containing the function pointers of DAC driver in DC mode.

  • struct DAC_SLOPE_INTERFACE

    Structure containing the function pointers of DAC driver in Slope mode.

  • struct CMP_INTERFACE

    Structure containing the function pointers of CMP driver.

Definitions
Functions
  • void CMP1_Initialize (void)

    Initialize the CMP1 module.

  • void CMP1_Deinitialize (void)

    Deinitializes the CMP1 to POR values.

  • void CMP1_Calibrate (void)

    Calibrates the CMP1 module and enables ripple reduction mode.

  • static bool CMP1_StatusGet (void)

    This inline function returns the comparator output status.

  • static void CMP1_Enable (void)

    This inline function enables the common DAC module.

  • static void CMP1_Disable (void)

    This inline function disables the common DAC module.

  • static void CMP1_DACEnable (void)

    This inline function enables the individual DAC module.

  • static void CMP1_DACDisable (void)

    This inline function disables the individual DAC module.

  • static void CMP1_DACDataWrite (size_t value)

    This inline function writes DAC data to register.

  • void CMP1_EventCallbackRegister (void(*handler)(void))

    This function can be used to override default callback and to define custom callback for CMP1 Event event.

  • void CMP1_EventCallback (void)

    This is the default callback with weak attribute. The user can override and implement the default callback without weak attribute or can register a custom callback function using  

    CMP1_EventCallbackRegister.

  • void CMP1_Tasks (void)

    The Task function can be called in the main application using the High Speed Comparator, when interrupts are not used. This would thus introduce the polling mode feature of the Analog Comparator.

Variables
  • const struct CMP_INTERFACE CMP_DAC1

    Structure object of type CMP_INTERFACE with the custom name given by the user in the Melody Driver User interface. The default name e.g. CMP_DAC1 can be changed by the user in the CMP user interface. This allows defining a structure with application specific name using the 'Custom Name' field. Application specific name allows the API Portability.

3.3.1.1.2 Definition Documentation

CMP1_CLOCK_FREQUENCY

#define CMP1_CLOCK_FREQUENCY 8000000UL

This macro defines input clock for CMP1.

CMP_DAC1_DACDataWrite

#define CMP_DAC1_DACDataWrite CMP1_DACDataWrite

This macro defines the Custom Name for CMP1_DACDataWrite API.

CMP_DAC1_DACDisable

#define CMP_DAC1_DACDisable CMP1_DACDisable

This macro defines the Custom Name for CMP1_DACDisable API.

CMP_DAC1_DACEnable

#define CMP_DAC1_DACEnable CMP1_DACEnable

This macro defines the Custom Name for CMP1_DACEnable API.

CMP_DAC1_Deinitialize

#define CMP_DAC1_Deinitialize CMP1_Deinitialize

This macro defines the Custom Name for CMP1_Deinitialize API.

CMP_DAC1_Disable

#define CMP_DAC1_Disable CMP1_Disable

This macro defines the Custom Name for CMP1_Disable API.

CMP_DAC1_Enable

#define CMP_DAC1_Enable CMP1_Enable

This macro defines the Custom Name for CMP1_Enable API.

CMP_DAC1_EventCallbackRegister

#define CMP_DAC1_EventCallbackRegister CMP1_EventCallbackRegister

This macro defines the Custom Name for CMP1_EventCallbackRegister API.

CMP_DAC1_Initialize

#define CMP_DAC1_Initialize CMP1_Initialize

This macro defines the Custom Name for CMP1_Initialize API.

CMP_DAC1_StatusGet

#define CMP_DAC1_StatusGet CMP1_StatusGet

This macro defines the Custom Name for CMP1_StatusGet API.

CMP_DAC1_Tasks

#define CMP_DAC1_Tasks CMP1_Tasks

This macro defines the Custom Name for CMP1_Tasks API.

3.3.1.1.3 Function Documentation

CMP1_Calibrate()

void CMP1_Calibrate (void )

Calibrates the CMP1 module and enables ripple reduction mode.

Parameters:
none
Returns:

none  

CMP1_DACDataWrite()

inline static void CMP1_DACDataWrite (size_t value)

This inline function writes DAC data to register.

Parameters:
in value

- DAC Data write value

Returns:

none

CMP1_DACDisable()

inline static void CMP1_DACDisable (void )

This inline function disables the individual DAC module.

Parameters:
none
Returns:

none

CMP1_DACEnable()

inline static void CMP1_DACEnable (void )

This inline function enables the individual DAC module.

Parameters:
none
Returns:

none

CMP1_Deinitialize()

void CMP1_Deinitialize (void )

Deinitializes the CMP1 to POR values.

Parameters:
none
Returns:

none  

CMP1_Disable()

inline static void CMP1_Disable (void )

This inline function disables the common DAC module.

Parameters:
none
Returns:

none  

CMP1_Enable()

inline static void CMP1_Enable (void )

This inline function enables the common DAC module.

Parameters:
none
Returns:

none

CMP1_EventCallback()

void CMP1_EventCallback (void )

This is the default callback with weak attribute. The user can override and implement the default callback without weak attribute or can register a custom callback function using  

CMP1_EventCallbackRegister.

Parameters:
none
Returns:

none  

CMP1_EventCallbackRegister()

void CMP1_EventCallbackRegister (void(*)(void) handler)

This function can be used to override default callback and to define custom callback for CMP1 Event event.

Parameters:
in handler

- Address of the callback function.  

Returns:

none  

CMP1_Initialize()

void CMP1_Initialize (void )

Initialize the CMP1 module.

Parameters:
none
Returns:

none  

CMP1_StatusGet()

inline static bool CMP1_StatusGet (void )

This inline function returns the comparator output status.

Parameters:
none
Returns:

true - Comparator output is high

false - Comparator output is low

CMP1_Tasks()

void CMP1_Tasks (void )

The Task function can be called in the main application using the High Speed Comparator, when interrupts are not used. This would thus introduce the polling mode feature of the Analog Comparator.

Parameters:
none
Returns:

none  

3.3.1.1.4 Variable Documentation

CMP_DAC1

const struct CMP_INTERFACE CMP_DAC1

Structure object of type CMP_INTERFACE with the custom name given by the user in the Melody Driver User interface. The default name e.g. CMP_DAC1 can be changed by the user in the CMP user interface. This allows defining a structure with application specific name using the 'Custom Name' field. Application specific name allows the API Portability.

3.3.2 Data Structure Documentation

3.3.2.1 CMP_INTERFACE Struct Reference

Structure containing the function pointers of CMP driver.

3.3.2.1.1 Detailed Description

Structure containing the function pointers of CMP driver.

#include <cmp_interface.h>

Data Fields

3.3.2.1.2 Field Documentation

The documentation for this struct was generated from the following file:

source/

cmp_interface.h

Calibrate

void(* Calibrate) (void)

Pointer to CMPx_Deinitialize e.g. CMP1_Deinitialize.

cmp_dac_dc_interface

const struct DAC_DC_INTERFACE* cmp_dac_dc_interface

Pointer to DAC_DC_INTERFACE.

cmp_dac_slope_interface

const struct DAC_SLOPE_INTERFACE* cmp_dac_slope_interface

Pointer to DAC_SLOPE_INTERFACE.

Deinitialize

void(* Deinitialize) (void)

Pointer to CMPx_Deinitialize e.g. CMP1_Deinitialize.

Disable

void(* Disable) (void)

Pointer to CMPx_Disable e.g. CMP1_Disable.

Enable

void(* Enable) (void)

Pointer to CMPx_Enable e.g. CMP1_Enable.

EventCallbackRegister

void(* EventCallbackRegister) (void(*handler)(void))

Pointer to CMPx_EventCallbackRegister e.g. CMP1_EventCallbackRegister.

Initialize

void(* Initialize) (void)

Pointer to CMPx_Initialize e.g. CMP1_Initialize.

StatusGet

bool(* StatusGet) (void)

Pointer to CMPx_StatusGet e.g. CMP1_StatusGet.

Tasks

void(* Tasks) (void)

Pointer to CMPx_Tasks e.g. CMP1_Tasks (Supported only in polling mode)

3.3.2.2 DAC_DC_INTERFACE Struct Reference

Structure containing the function pointers of DAC driver in DC mode.

3.3.2.2.1 Detailed Description

Structure containing the function pointers of DAC driver in DC mode.

#include <cmp_interface.h>

3.3.2.2.2 Field Documentation

The documentation for this struct was generated from the following file:

source/

cmp_interface.h

DataWrite

void(* DataWrite) (size_t value)

Pointer to CMPx_DACDataWrite e.g. CMP1_DACDataWrite.

Disable

void(* Disable) (void)

Pointer to CMPx_DACDisable e.g. CMP1_DACDisable.

Enable

void(* Enable) (void)

Pointer to CMPx_DACEnable e.g. CMP1_DACEnable.

3.3.2.3 DAC_SLOPE_INTERFACE Struct Reference

Structure containing the function pointers of DAC driver in Slope mode.

3.3.2.3.1 Detailed Description

Structure containing the function pointers of DAC driver in Slope mode.

#include <cmp_interface.h>

Data Fields

3.3.2.3.2 Field Documentation

The documentation for this struct was generated from the following file:

source/

cmp_interface.h

DataHighWrite

void(* DataHighWrite) (uint16_t dacHighLimit)

Pointer to CMPx_DACDataHighWrite e.g. CMP1_DACDataHighWrite.

DataLowWrite

void(* DataLowWrite) (uint16_t dacLowLimit)

Pointer to CMPx_DACDataLowWrite e.g. CMP1_DACDataLowWrite.

Disable

void(* Disable) (void)

Pointer to CMPx_DACDisable e.g. CMP1_DACDisable.

Enable

void(* Enable) (void)

Pointer to CMPx_DACEnable e.g. CMP1_DACEnable.

SlopeUpdateMode

void(* SlopeUpdateMode) (enum CMP_DAC_SLOPE_UPDATE_MODE updateMode)

Pointer to CMPx_DACSlopeUpdateMode e.g. CMP1_DACSlopeUpdateMode.

SlopeWrite

void(* SlopeWrite) (uint16_t slopeRate)

Pointer to CMPx_DACSlopeWrite e.g. CMP1_DACSlopeWrite.

3.3.3 File Documentation

3.3.3.1 source/cmp1.h File Reference

This is the generated driver header file for the CMP1 driver.

#include <stddef.h>
#include <stdbool.h>
#include <xc.h>
#include "cmp_interface.h"

3.3.3.1.1 Functions

  • void CMP1_Initialize (void)

    Initialize the CMP1 module.

  • void CMP1_Deinitialize (void)

    Deinitializes the CMP1 to POR values.

  • void CMP1_Calibrate (void)

    Calibrates the CMP1 module and enables ripple reduction mode.

  • static bool CMP1_StatusGet (void)

    This inline function returns the comparator output status.

  • static void CMP1_Enable (void)

    This inline function enables the common DAC module.

  • static void CMP1_Disable (void)

    This inline function disables the common DAC module.

  • static void CMP1_DACEnable (void)

    This inline function enables the individual DAC module.

  • static void CMP1_DACDisable (void)

    This inline function disables the individual DAC module.

  • static void CMP1_DACDataWrite (size_t value)

    This inline function writes DAC data to register.

  • void CMP1_EventCallbackRegister (void(*handler)(void))

    This function can be used to override default callback and to define custom callback for CMP1 Event event.

  • void CMP1_EventCallback (void)

    This is the default callback with weak attribute. The user can override and implement the default callback without weak attribute or can register a custom callback function using  

    CMP1_EventCallbackRegister.

  • void CMP1_Tasks (void)

    The Task function can be called in the main application using the High Speed Comparator, when interrupts are not used. This would thus introduce the polling mode feature of the Analog Comparator.

3.3.3.1.2 Macros

3.3.3.1.3 Variables

  • const struct CMP_INTERFACE CMP_DAC1

    Structure object of type CMP_INTERFACE with the custom name given by the user in the Melody Driver User interface. The default name e.g. CMP_DAC1 can be changed by the user in the CMP user interface. This allows defining a structure with application specific name using the 'Custom Name' field. Application specific name allows the API Portability.

3.3.3.1.4 Detailed Description

This is the generated driver header file for the CMP1 driver.

CMP1 Generated Driver Header File

3.3.3.2 source/cmp_interface.h File Reference

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "cmp_types.h"

3.3.3.2.1 Data structures

  • struct DAC_DC_INTERFACE

    Structure containing the function pointers of DAC driver in DC mode.

  • struct DAC_SLOPE_INTERFACE

    Structure containing the function pointers of DAC driver in Slope mode.

  • struct CMP_INTERFACE

    Structure containing the function pointers of CMP driver.

3.3.3.2.2 Detailed Description

CMP Generated Driver Interface Header File

3.3.3.3 source/cmp_types.h File Reference

This is the generated driver types header file for the CMP driver.

3.3.3.3.2 Detailed Description

This is the generated driver types header file for the CMP driver.

CMP Generated Driver Types Header File

3.3.3.3.3 Enumeration Type Documentation

CMP_DAC_SLOPE_UPDATE_MODE

enum CMP_DAC_SLOPE_UPDATE_MODE

CMP slope data registers update mode.

Note:

Applicable in slope mode

CMP_DAC_SLOPE_UPDATE_IMMIDIATE

Updates slope related data registers immidiately

CMP_DAC_SLOPE_UPDATE_TRIGGERED

Updates slope related data registers during the external trigger

CMP_DAC_TRANSISION_MODE

enum CMP_DAC_TRANSISION_MODE

This enum is used to set the transision mode between smooth and slow transision or fast and sharp transision to new data values.

CMP_DAC_TRANSISION_MODE_ENABLED

Smoother and slower transision to the target value

CMP_DAC_TRANSISION_MODE_DISABLED

Faster transision to the target value and ripple may be introduced