Microchip | The Embedded Control Solutions Company Register Login
Browse All
Microchip Technology
 369 Code Snippets

Using the PIC18F26K42's ADC2 in Low-Pass Filter Mode

Microchip Technology

Check out this project's MPLAB Xpress Webpage to view the complete code example along with a detailed step by step write-up and description, or visit the PIC18F26K42 Device Product Page for more information.

About this Code Example

Objective:

The PIC18F26K42’s ADC2 with Computation module is a 12-bit ADC that integrates computation functions into module hardware. This application example highlights the use of the ADC2’s Low-Pass Filter with a focus on the relationship between the ADC Accumulated Calculation Right-Shift Select (CRS) bits, sampling time, and the low-pass filter result.

Demo Configuration:

The application demo consists of both hardware and software. Configuration for both hardware and software is covered in Application Note AN2749.

Hardware List:

  • Curiosity High Pin Count (HPC) Development Board (DM164136)
  • PIC18F26K42 28-lead microcontroller (PDIP package to fit Curiosity HPC)
  • MikroElektronika DAC2 Click Board (MIKROE – 1918)
  • MCP2200 Breakout Module (ADM00393)
  • Tektronix Digital Oscilloscope (TDS 2024B) or equivalent
  • Rigol Function Generator (DG1022A) or equivalent
  • USB, function generator, and oscilloscope cables
  • Jumper wires

The oscilloscope and function generator can be of any make and model. The oscilloscope must have a minimum of two channels for viewing input/output signals, but the use of a four-channel oscilloscope is recommended. The function generator must have a configurable sinewave generator.

Software List:

  • MPLABX IDE v4.15
  • Atmel Studio 7.0 IDE
  • XC8 C Compiler v1.45
  • Tektronix OpenChoice PC Communication Software
  • LPF APP NOTE.X source code
  • Data Stream Configuration File (included in the LPF APP NOTE.X project)

The Atmel Studio 7.0 IDE is used to display the filtered data in its Data Visualizer plug-in tool. The Data Visualizer tool reads the ADFLTR values transmitted by the PIC over UART, and reconstructs the data into a waveform which is displayed in the Data Visualizer’s oscilloscope window. The Data Visualizer requires a configuration file, which has been created specifically for this application, and is included in the LPF APP NOTE.X project. The Tektronix PC software is used to capture screen images, and is not required for this application.

Curiosity HPC with MCP2200 Breakout Module and DAC2 Click Board:

Application Operation:

The purpose of this application is to show the relationship between the CRS values, sampling time, and the filtered output. Testing can begin once both the hardware and software are configured. The PIC application source code comes configured for use with the DAC2 click board using the Serial Peripheral Interface (SPI) module in transmit-only mode. Two other test modes – SPI in full-duplex mode, and UART transmission – are commented out. Uncommenting either of the other modes (while commenting out the currently used mode) allows for comparison between the different types of transmission. Changing transmission types changes the total sampling time, and the total sampling time directly effects the filtered output characteristics, such as the -3dB roll-off frequency of a filtered AC waveform. It is important to note that the two SPI transmission methods work only with the DAC2 click; the UART transmission method only works with the Atmel Studio 7.0’s Data Visualizer. Software changes require the PIC to be reprogrammed with each modification, but the hardware does not need to be changed.

The application source code uses the ADC2 Threshold Interrupt function to transmit the filtered data. The Threshold ISR is configured to interrupt upon the completion of the threshold test regardless of the result of the threshold test, which simply means that the ISR is called after each sample has been processed and the filtered results are ready for use.

ADC2 Threshold Interrupt ISR Code Snippet:

Filtered Output (Channel 1) of a Noisy DC Input Signal (Channel 2)

Filtered Output of an AC (sinewave) Input Signal at the -3dB Roll-Off Frequency

Filtered output of an AC (sinewave) Input Signal Using the Data Visualizer at the -3dB Roll-Off Frequency

-3dB Roll-Off Frequency Comparison for each Transmission Method

Conclusion:

This application example shows the relationship between the CRS value, sampling time, and the filtered result’s output characteristics. Please visit www.microchip.com for other application notes, technical briefs, and code examples for the PIC18F26K42 or any other device of interest.

Categories

Release History

  • Dec 4, 2018

    Version: 1.0.0

    Initial Release

Download Contact the Developer

*Required Fields


  • Current Version:1.0.0
  • Created:Dec 4, 2018
  • Updated:Dec 4, 2018
  • Downloads:681
  • MPLAB Version:MPLABX
  • C Compiler:XC8 v1.45
  • Development Tools:Curiosity High Pin Count (HPC) Development Board
  • Supported Devices:PIC18F26K42

Corporate News

Resources

Stay Connected

Stay up to date with the latest news from Microchip Technology.