Coder Social home page Coder Social logo

microchip-pic-avr-examples / dspic33ck-power-pwm-adc-trigger Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 1.0 2 MB

PWM based ADC Trigger Configuration Example for dsPIC33CK-MP devices

License: Other

Makefile 0.31% C 18.16% C++ 81.53%
dsc dspic power power-conversion power-supply smps

dspic33ck-power-pwm-adc-trigger's Introduction

MCHP

dsPIC33C PWM/ADC Configuration: Lab 7

ADC Trigger using PWM Generator

dsPIC33CK Digital Power Plug-In Module


Summary

Learning how to use the PWM and ADC of dsPIC33C MP devices, Lab 7: Code example for dsPIC33CK and dsPIC33CH devices showing a basic configuration of PWM Generators triggering ADC inputs. Inside the ADC Interrupt Service Routine (ISR) a test pin toggled to allow the user to observe trigger response delays. Also, Early Interrupt Generation, Alternate Working register with Compiler attributes and Sampling Time adjustment optimization feature are used to adjust the trigger response time.


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, PWM1H triggers the Dedicated ADC Core 0. After around 277ns trigger response delay, the ADC Core O ISR test pin indicator TP55 toggles see screen capture below. The trigger response delay is optimized since the Early Interrupt Generator of ADC Core 0 is enabled.




PWM1H triggers Dedicated ADC Core 0

By pressing the on-board push button USER on the Digital Power Development Board, the PWM2H triggers the Dedicated ADC Core 1. After around 265ns trigger response delay, the ADC Core 1 ISR test pin indicator TP53 toggles see screen capture below. The trigger response delay is further reduced because aside from the Early Interrupt Generator is enabled, the ADC Core 1 ISR used the context attribute of the compiler to associate the ISR with alternate register set.




PWM2H triggers Dedicated ADC Core 1

By pressing the on-board push button USER again, the PWM3H triggers the Shared ADC Core 6. After around 335ns the ADC Core 6 ISR test pin indicator TP50 toggles see screen capture below. The configuration of Shared ADC is the same with the Dedicated ADC Core 1 except the Shared ADC Sampling Time is set to 8 TADCORE. Unlike the previous Dedicated ADC Cores, Shared ADC Core 6 does not have dedicated analog pin. This required extending the sampling time to ensure that the ADC connects to analog pin and properly sample the input signal before the conversion. However, this sample time adds trigger response delay.




PWM3H triggers Shared ADC Core 6

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 PWM and ADC module, PWM and ADC 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 PWM and ADC example code project the PWM and ADC configuration procedure is located in the user file pwm.c and adc.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 PWM and ADC peripheral driver

The PWM and ADC peripheral driver files p33c_pwm.c/h and p33c_adc.c/h provide data structures representing the Special Function Register (SFR) sets of PWM and ADC instance as well as the PWM and ADC base module. These 'virtual' PWM and ADC objects are used to load, read and modify PWM and ADC 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 the PWM and ADC 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 PWM and ADC driver, its supported features and intended use cases, please read the comments inside p33c_pwm.c and p33c_adc.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.


© 2020, Microchip Technology Inc.

dspic33ck-power-pwm-adc-trigger's People

Contributors

areiter128 avatar harishagari avatar mmpallones avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

picdew

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.