Skip to content

DAC Slope Compensation Ramp Output Configuration Example for dsPIC33CK-MP devices

License

Notifications You must be signed in to change notification settings

microchip-pic-avr-examples/dspic33ck-power-dac-slope-compensation

Repository files navigation

MCHP

dsPIC33C DAC Configuration: Lab 10

DAC Slope Compensation Ramp Waveform Generation

dsPIC33CK Digital Power Plug-In Module


Summary

Learning how to use the DAC of dsPIC33C MP devices, Lab 10: Code example for dsPIC33CK and dsPIC33CH devices showing a basic configuration of the DAC generating a slope compensation ramp waveform


Related Documentation

Please always check for the latest data sheets on the respective product websites:

Software Used

Hardware Used

  • Digital Power Development Board, Part-No. DM330029
  • dsPIC33CK Digital Power Plug-In Module (DP PIM), Part-No. MA330048
  • Alternatively: dsPIC33CH Digital Power Plug-In Module (DP PIM), Part-No. MA330049

Supported Target Devices


Setup

  • Plug-In the dsPIC33CK or dsPIC33CH Digital Power Plug In Module into the Digital Power Development Board PIM socket J1
  • Open and compile the firmware and program the DSC



Operation

After the device has been programmed and the MCU starts up, a Slope Compensation ramp with 100mV/uS slope rate is generated at DACOUT1 pin see below screen capture. The PWM Generator 1 with 200Khz and 20% Duty Cycle triggers the start and end of the slope.




CH1(blue):DACOUT1 CH2(green):PWM1H

By pressing the on-board push button USER on the Digital Power Development Board, the ramp slope rate is toggled between the initial 100mV/uS and 300mV/uS see below screen capture.




CH1(blue):DACOUT1 CH2(green):PWM1H

Please refer to section FIRMWARE QUICK-START GUIDE below for more information on the initialization process and code structure.




FIRMWARE QUICK-START GUIDE

This code example builds on previous code examples showing how to use Microchip Code Configurator (MCC) to set up device clock domains. Although MCC also supports configuration tools for the DAC module, DAC configuration in this example builds on generic peripheral drivers to help users better understand the peripheral architecture and key aspects of specific configurations and operating modes. In each DAC example code project the DAC configuration procedure is located in the user file dac.c, where each register bit required to achieve/enable the specific function or mode of interest is set and its function described with comments. Once users are familiar with the architecture, features and capabilities, both configuration options (generic peripheral library or MCC) may be used.

a) Project Directory Structure

The project contains four sub-directories

  1. config: location of all hardware abstraction header files
  2. common: location of generic peripheral drivers
  3. MCC Generated Files: all device configuration files auto-generated by MCC
  4. root: application user code

On the hard drive, main.c/h are located in the MPLAB X project directory. All other user files, incl. peripheral drivers, are located in the sub-directory sources. Files generated by MCC are always located in their own sub-directory mcc_generated-files

b) Using the generic DAC peripheral driver

The DAC peripheral driver files p33c_dac.c/h provide data structures representing the Special Function Register (SFR) sets of DAC instance and the DAC base module. These 'virtual' DAC objects are used to load, read and modify DAC configurations without the need for hard-coded instructions, which would make the code hard to migrate from one peripheral to another or even across devices. To simplify DAC configurations, in these examples, each register is reset to a known default state before the user configuration of interest is set. Thus, only the register setting which really matters for a certain features/function are shown.

To learn more about the generic DAC driver, its supported features and intended use cases, please read the comments inside p33c_dac.c.

c) Executing the Code Example

This code has been written to automatically start up and perform the function of interest. Please read the demo instructions on top of file main.c to learn more about the code example, test points, expected signals and demo mode operation.


© 2022, Microchip Technology Inc.