Skip to content

This repository contains one MPLAB® X project: Biphase Encoder, using Core Independent Peripherals (CIPs) by following the interaction between CLB, SPI and UART peripherals.

License

Notifications You must be signed in to change notification settings

microchip-pic-avr-examples/pic16f13276-biphase-encoder-mplab-mcc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Microchip Technologies Inc.

Bi-Phase Encoder With Configurable Bitrate Based on CLB Using the PIC16F13276 Microcontroller With MCC Melody

The repository contains the Bi-Phase Encoder, an MPLAB® X project which uses Core Independent Peripherals (CIPs) by following the interaction between the Custom Logic Block (CLB), Serial Peripheral Interface (SPI) and Universal Asynchronous Receiver-Transmitter (UART) peripherals.

The CLB peripheral is a collection of logic elements that can be programmed to perform a wide variety of digital logic functions. The logic function may be completely combinatorial, sequential, or a combination of the two, enabling users to incorporate hardware-based custom logic into their applications.

The Bi-Phase Mark Code (BMC) combines both data and clock in a single signal. One clock cycle is a BMC bit period. A transition always occurs at the beginning of each bit period. A logic ‘1’ is represented by a transition (rising or falling edge) in the middle of the bit period and a logic ‘0’ is represented by no transition in the middle of the period. A BMC encoder accepts a data signal and a clock signal as inputs and produces a single BMC-encoded output. A BMC decoder accepts a BMC-encoded signal as input and produces two outputs: data and clock. BMC is used in USB 3.1 Power Delivery Specification CC signaling, AES3 digital audio or S/PDIF audio standards; an example of this type can be seen in the figure below.


Related Documentation

More details and code examples on the PIC16F13276 can be found at the following links:

Software Used

Hardware Used

Operation

To program the Curiosity Nano board with this MPLAB X project, follow the steps provided in the How to Program the Curiosity Nano Board chapter.

Concept

This project is an implementation of a Bi-Phase encoder using CIPs by following the interaction between CLB, SPI and UART peripherals. The raw data is received via serial communication, encoded using the circuit composed in the CLB peripheral mentioned above and sent through a single data wire. The CLB circuit is captured in the figure below:


The raw data is received via serial communication by the UART peripheral. This data is then stored in a buffer and used as input for the SPI peripheral which generates a Non-Return-to-Zero (NRZ) data signal and a clock signal. Those signals are selected as inputs for the circuit composed inside the CLB peripheral which outputs the Bi-Phase encoded signal. A First-In-First-Out (FIFO) buffer mechanism is used from the generated libraries for the UART peripheral to facilitate the data storage and minimize data loss.

After initializing all peripherals, a Start byte is sent for calibration purposes. The data received from the PC terminal is received by the UART peripheral and stored into the internal eusart1RxBuffer via a Receive interrupt. In the main function, the data from the receive buffer is read byte by byte until the end and follows the flowchart below. A Start byte and a Stop byte describe every message stored in the internal buffer. A GAP_DURATION delay is needed between the Start byte and the first read byte from the PC terminal to avoid the scenario when the FIFO buffer is empty.

In this example, the SPI peripheral can be initialized in multiple configurations, so the frequency of the encoded message can be chosen between different predefined values: 31.25 kHz, 62.5 kHz, 125 kHz, 250 kHz or 500 kHz.

Setup

The following peripheral and clock configurations are set up using the MPLAB Code Configurator (MCC) Melody for the PIC16F13276:

  1. Configuration Bits:

    • External Oscillator mode selection bits: Oscillator not enabled
    • Power-up default value for COSC bits: HFINTOSC (1 MHz)
    • Brown-out reset enable bits: Brown-out reset disabled
    • WDT operating mode: WDT Disabled, SEN is ignored
  2. Clock Control:

    • Clock Source: HFINTOSC
    • HF Internal Clock: 32_MHz
    • Clock Divider: 1
  3. Interrupt Manager:

    • Enable Single ISR Execution per entry: Enabled
  4. MSSP1 (SPI):

    • Serial Protocol: SPI
    • Mode: Host
    • SPI Mode: SPI Mode 1
    • Input Data Sampled At: Middle
    • Clock Source Selection: FOSC/4_SSPxADD
    • SPI Clock Frequency (Hz): 31250
  5. CLB Synthesizer Library:

    • Clock Divider: Divide clock source by 8
    • Clock Selection: HFINTOSC
  6. CLB1:

    • Enable CLB: Enabled
  7. CRC:

    • Auto-configured by CLB
  8. UART2:

    • Requested Baudrate: 38400
    • Data Size: 8
    • Interrupt Driven: Enabled
    • Software Receive Buffer Size: 128
  9. EUSART2:

    • Receive Enable: Enabled
    • Serial Port Enable: Enabled
    • RCI Interrupt Enable: Enabled
  10. Pin Grid View and Pins:

    • EUSART2 RX2: RD7 (Data from terminal)
    • CLBPPSOUT0: RD2 (Encoded Message)
    • LED0: RC2

Demo

If the UART does not receive any character for 0.5s, the PIC16F13276 CLB Bi-Phase Encoder Example\r\n message is transmitted via the RD2 pin (BMC out). The output of the encoder can be visualized using a logic analyzer.


In the demo, the Microchip! message was inserted by the user in the terminal. The RD2 pin - BMC out (the output pin for the Bi-Phase encoded signal) is visualized using a logic analyzer.


To use the embedded decoder from the Logic software, the next analyzers settings must be set:

The output pin of the encoder platform (positioned on the left side), BMC out (the output pin for the Bi-Phase encoded signal), is connected to the input pin of the decoder board (positioned on the right side) and visualized using the MPLAB Data Visualizer plug-in.


Summary

This example demonstrates the capabilities of the CLB, a CIP that can encode a message from the SPI and UART modules.

How to Program the Curiosity Nano Board

This chapter demonstrates how to use the MPLAB X IDE to program a PIC® device with an Example_Project.X. This is applicable to other projects, too.

  1. Connect the board to the PC.

  2. Open the Example_Project.X project in MPLAB X IDE.

  3. Set the Example_Project.X project as main project.
    Right click the project in the Projects tab and click Set as Main Project.

  4. Clean and build the Example_Project.X project.
    Right click the Example_Project.X project and select Clean and Build.

  5. Select PICxxxxx Curiosity Nano in the Connected Hardware Tool section of the project settings:
    Right click the project and click Properties.
    Click the arrow under the Connected Hardware Tool.
    Select PICxxxxx Curiosity Nano (click the SN), click Apply and then click OK:

  6. Program the project to the board.
    Right click the project and click Make and Program Device.



Menu

About

This repository contains one MPLAB® X project: Biphase Encoder, using Core Independent Peripherals (CIPs) by following the interaction between CLB, SPI and UART peripherals.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published