This project highlights the advanced core-independent peripherals found on the PIC18-Q71 family of devices to create a Serial-In Parallel-Out (SIPO) shift register. This project implements the Signal Routing Port (SRPORT) module to shift and store the incoming data based on a clock signal. The Direct Memory Access (DMA) module is used to transfer data between peripherals and the memory core independently without any CPU intervention. The Pulse-Width Modulator (PWM) modules are used to generate clock and data signals. The Universal Asynchronous Receiver Transmitter (UART) module is used to transmit data on the serial bus.
For more details and code examples on the PIC18F46Q71, click on the following links:
- MPLAB® X IDE v6.20 or newer
- MPLAB® XC8 v3.0 or newer
- PIC18F-Q_DFP v1.26.442 or newer Series Device Pack
Shift registers are important digital components that can be used to store and transfer data. An SIPO shift register can be used in applications where data buffering or data acquisition based on a clock is needed. An SIPO shift register consists of multiple flip flops chained together in series with data and clock signals as inputs. In this code example, the parallel output is stored as bytes of data in memory. A block diagram of a basic SIPO shift register is shown below:
The following peripheral configurations are set up using MPLAB® Code Configurator (MCC) Melody for the PIC18F46Q71:
-
SRPORT
In this code example, the Signal Routing Port module is used to shift and store data based on an incoming clock signal. The SRPORT is configured as a shift register by internally connecting the output of each signal routing pin to the input of the previous signal routing pin.The value of the signal is stored and shifted at each rising edge of the clock signal. After each eight clock cycles, an eight-bit value representing the data signal (for the previous eight clock cycle time frame) is stored in the PORTW register. The value of the PORTW register will be read or transferred to memory before the next rising edge of the clock. The timing diagram of an SIPO shift register is shown below:
Module configuration: -
UART1:
The UART module is used to transfer the stored data through the serial BUS. The Virtual COM Port on the Curiosity development board is used to transfer data to the terminal. The DMA2 module is used to load the UART transmit buffer with the stored data. -
PWM1
The PWM1 module is used to generate a 1 kHz clock signal. This clock signal is used as an input to the SRPORT and the Universal Timer modules. Data shift and storage is done based on the rising edge of this clock signal.Module configuration:
-
PWM2
The PWM2 module is used to generate a random data signal to be used as an input to the SRPORT module.Module configuration:
-
UTMR Driver
-
TU16A
In this project, the Universal Timer is used to monitor and count the rising edge of the input clock signal. This Universal Timer module triggers DMA1 to transfer data from PORTW register to RAM every eight clock cycles (one byte of data). The output of the timer is in pulse mode, which can be used to monitor or trigger any other modules/components (as necessary), based on the application.Module configuration:
-
TMR2
The Timer2 module is used in conjunction with the CLC module to create a hardware based code-free switch debouncer. The push button on the Curiosity HPC board is used to start each round of data shift, storage and transfer (based on the number of bytes configured by the user). Timer2 automates the debouncing process using its monostable mode of operation. In this mode, the first switch activation is used to start the timer counting, ignoring any subsequent bouncing. Once the timer count reaches a predetermined value, the timer peripheral will produce a signaling event that can be used to indicate a valid switch activation has been detected.Module configuration:
-
DMA1
The DMA1 module is configured to transfer one byte of data from PORTW register to a location in memory. The Start trigger of the DMA module is set to TU16APR (Universal Timer period match). The number of bytes of data to be transferred by the DMA module is configurable by the user.Module configuration:
- DMA: Disabled
- Start Trigger: TU16APR (Disabled)
- Abort Trigger: DMA1DCNT (Enabled)
- Source Region: SFR
- Source Module: PORTW
- Source SFR: PORTW
- Source Mode: Unchanged
- Source Message Size: 1
- Source Counter Reload Action: SIRQEN is not cleared
- Destination Region: GPR
- Destination Mode: Incremented
- Destination Counter Reload Action: SIRQEN is not cleared
- DMADCNTI Interrupt: Enabled
Note: Destination size and variable are defined in software.
-
DMA2
The DMA2 module is used to transfer all the stored data from memory to the UART module. The number of bytes of data that is transferred by DMA is configurable by the user.Module configuration:
- DMA: Disabled
- Start Trigger: U1TX (Disabled)
- Abort Trigger: None (Disabled)
- Source Region: GPR
- Source Mode: Incremented
- Source Counter Reload Action: SIRQEN is cleared
- Destination Region: SFR
- Destination Module: UART1
- Destination SFR: U1TXB
- Destination Mode: Unchanged
- Destination Counter Reload Action: SIRQEN is not cleared
Note: Source size and variable are defined in software.
-
CLC2
The CLC2 module is used in conjunction with the Timer2 module to create a hardware based code-free switch debouncer. Refer to the Timer2 module configuration for more details.Module configuration:
-
Clock Control:
- Clock Source: HFINTOSC
- HF Internal Clock: 64 MHz
- Clock Divider: 1
-
Configuration Bits:
- CONFIG1: Disable external oscillator, and change the reset oscillator to 64M
-
Pins
The following pin configuration must be made for this project:Pin Configuration Function RB3 Digital Output UART1 TX RB5 Digital Output TU16A OUT RB6 Digital Output PWM1OUT1 RB7 Digital Output PWM2OUT1 RC7 Digital Input PORTWIN7* RC4 Digital Input T2INPPS RA7 Digital Output LED1 RW0 Internal Connection PORTWIN0* RW1 Internal Connection PORTWIN1* RW2 Internal Connection PORTWIN2* RW3 Internal Connection PORTWIN3* RW4 Internal Connection PORTWIN4* RW5 Internal Connection PORTWIN5* RW6 Internal Connection PORTWIN6* *Note: Pin assignments to PORTWINx can be done either from PORTW module or Pin Grid View in MCC Melody.
When the push button (S2) on the Curiosity HPC board is pressed, the Universal Timer will monitor and count each rising edge of the clock signal. After eight clock cycles (at PR match), the DMA1 will start transferring 1 byte of data from the PORTW register to a location in memory (mem_block). The abort trigger of the DMA1 module is set to its destination counter reaching zero, and the destination message size is configurable by the user in code (NUM_BYTE). Changing the NUM_BYTE value in code will define the number of bytes of data that are acquired, shifted, and stored in memory. After data storage, the DMA2 module transfers the stored data to the UART1 transmit buffer. The hardware setup, signal diagrams (Data, CLK, LED and UART signals) and the MPLAB Data Visualizer output are shown below for NUM_BYTE = 1:
The Signal Routing Port peripheral offers advanced interconnectivity of multiple core-independent peripherals without requiring any external pins. The SRPORT is also connected to the input and output Peripheral Pin Select module, allowing connections to physical pins when desired, and is also equipped with dedicated Interrupt-on-Change and DMA/ADC triggers. Additionally, this peripheral has the option to be clocked, allowing it to be used to implement a shift register or hardware based state machines.
Using the DMA module is a great way to transfer data between different peripherals and memory regions. It allows for speed and ease of use, in addition to freeing up the CPU to perform other tasks.
Timer2 HLT can be combined with CLC for an excellent code-free switch debouncing technique.