Using DMA for Pulse Counting on S32K

Similar documents
Emulating Dual SPI Using FlexIO

General C Functions for the etpu Covers the MCF523x, MPC5500, MPC5600, MPC5700, MPX40 and all etpu-equipped Devices

Generating a Quick and Controlled Waveform With the DAC

Emulating I2C Bus Master by using FlexIO

Working around ERR7026 according to application needs

DDR Validation Tool Getting Started Guide

FRDM-K64F Board Errata

i.mx 6Solo/6DualLite Product Lifetime Usage Estimates

Processor Expert Software for i.mx Processors Version 1.0

Adding a run control interface into an existing CodeWarrior for MCU v10.x project

HVP-KV10Z32 User s Guide

Integrate TWR-EPD Software with MQX RTOS Based on the TWR-K21F120M Platform

Getting Started with Freescale MQX RTOS for Kinetis SDK and Kinetis Design Studio IDE

Getting Started with Freescale MQX RTOS for Kinetis SDK and MDK-ARM Keil

How to setup pre-build steps in CodeWarrior for Microcontrollers v10.x

Kinetis Updater User's Guide

MQX RTOS Release Notes for Kinetis SDK FRDM- KV10Z Freescale Freedom Development Platform

MQX RTOS Release Notes for Kinetis SDK v1.2.0 for KL33Z64 for FRDM-KL43Z Freescale Freedom Development Platform

Using the Asynchronous DMA features of the Kinetis L Series

Freedom FRDM-MC-LVBLDC Development Platform User s Guide

Three-Phase Power Meter Hardware Design Reference Manual

Emulating I2S bus on KE06

Single Chip Module (SCM) Package-on- Package (PoP) Assembly Guide

HVP-MC56F82748 User s Guide

CodeWarrior Development Studio Processor Expert RTOS Adapter User Guide

Component Development Environment Getting Started Guide

TWR-KV10Z32 Sample Code Guide for IAR Board configuration, software, and development tools

PMSM Field-Oriented Control Using MC56F84789 DSC With Encoders Demo Guide

Intelligent Sensing Framework 2.1 for Kinetis Errata Sheet

Understanding S08P Internal Clock Source

TWR-KV10Z32 Sample Code Guide for CodeWarrior Board configuration, software, and development tools

Getting Started with the MCU Flashloader

Watt Saver Software Component (WSC)

MMPF0100 Errata for Mask 1N47F and 1N18J

Quick Start Guide for FRDM-FXS-MULTI-B

Getting Started with Freescale MQX RTOS for Kinetis SDK and ARM GCC

HVP-KV31F120M User s Guide

Load Position-Independent Code (PIC) on a Kinetis Platform Using the IAR EWARM Compiler

Building U-Boot in CodeWarrior ARMv8

TWR-LS1021A Getting Started

Table of Contents 1 Typical Applications General Description Block Diagram Pinout System Connections Typical A

i.mx 6UltraLite Product Usage Lifetime Estimates

Kinetis Bootloader to Update Multiple Devices in a Field Bus Network

i.mx 6 Android JB 4.3_1.1.1 Patch Release Notes

Kinetis KE1xF512 MCUs

i.mx 6ULL Product Usage Lifetime Estimates

CodeWarrior Development Studio for StarCore 3900FP DSP v SP3 Release Notes

S12VR Hardware Design. Guidelines. 1 Introduction. 2 Hardware Design. Guidelines. 2.1 Voltage regulator. Freescale Semiconductor

Kinetis SDK Release Notes for the TWR-K24F120M Tower System Module

Kinetis USB-KW41Z Wireless Protocol Sniffer Quick Start Guide

i.mx 7 Dual/Solo Product Lifetime Usage

Using FCCU on MPC5744P

Differences Between P4080 Rev. 2 and P4080 Rev. 3

Using DMA to Emulate ADC Flexible Scan Mode on Kinetis K Series

Configuring DDR in U-Boot using QCVS

Mask Set Errata for Mask 0N22G

FRDM-KL03Z User s Guide

Flash Core Voltage Supply Requirements and Considerations

AIOP Task Aware Debug

How to use FlexMemory as D-Flash and EEPROM in KE1xF

Freescale Semiconductor Data Sheet: Technical Data

Measuring Interrupt Latency

TWR-LS1021A Getting Started

MPXHZ6130A, 15 to 130 kpa, Absolute, Integrated Pressure Sensor

Using an External GCC Toolchain with CodeWarrior for Power Architecture

Freedom FRDM-KV31F Development Platform User s Guide

MM912_634, Silicon Analog Mask (M91W) / Digital Mask (N53A) Errata

i.mxrt1050 Product Lifetime Usage Estimates

KIT34901EFEVB Evaluation Board

Using an FFT on the Sigma-Delta ADCs

Using the MPC5777M MCAN Module to Exchange CAN FD Messages

Kinetis SDK Freescale Freedom FRDM-KL03Z Platform User s Guide

Collecting Linux Trace without using CodeWarrior

KIT33972AEWEVBE Evaluation Board

Freescale MKW40Z IEEE Software Quick Start Guide

SPI topics: watchdog, serial output and parity check

P1010RDB-PB Quick Start Guide

PCIe Certification Guide for i.mx 6Dual/6Quad and i.mx 6Solo/6DualLite

Getting Started with MQX RTOS for Kinetis SDK

Table 1 provides silicon errata information that relates to the masks 0M55B, 1M55B, and M55B of the MC9328MX21S (i.mx21s) applications processor.

Kinetis Bootloader v1.2.0 Release Notes

MP3V5050V, -50 to 0 kpa, Gauge Pressure Sensor

MAG3110 Frequently Asked Questions

Mask Set Errata for Mask 3N86B

Installing Service Pack Updater Archive for CodeWarrior Tools (Windows and Linux) Quick Start

High Volume Pressure Sensor for Disposable Applications

Offline Flash Programmer for Kinetis K- and L-series MCUs

Getting Started with Pins Tool User's Guide

Kinetis SDK v Release Notes for KV5x Derivatives

Using the Xtrinsic FXLS8471CQ Transient-Acceleration Function

WPR1500-LDO MP Receiver V2.1 Reference Design User s Guide

OpenSDA on TWR-KW2x. User s Guide Rev 1.1

Kinetis KV5x Real-Time Control MCUs with Ethernet Up to 1 MB Flash and 256 KB SRAM

Power Consumption and Measurement of i.mx RT1020

Getting Started with Qorivva Fast

FRDM-KE02Z User s Manual

MPXH6300A, 20 to 300 kpa, Absolute, Integrated, Pressure Sensor

Interrupts in Decoupled Parallel Mode for MPC5675K Configuration and Usage

MC34708, Silicon Errata

Freescale MQX USB Stack for TWR-K24F120M GA User s Guide

Transcription:

Freescale Semiconductor, Inc. Document Number: AN5258 Application Note Rev. 0, 02/2016 Using DMA for Pulse Counting on S32K 1. Introduction This application note describes pulse counting on the S32K product series of 32-bit automotive MCUs using the Enhanced Direct Memory Access (edma) and PORT modules. The number of the signal pulses can be counted using the Low-Power Timer (LPTMR) or the FlexTimer (FTM). However, the number of pulse inputs is limited, because the FTM module is usually used for PWM generation and LPTMR has only one counter inside. In this application note, the PORT module is utilized to capture multiple pulse inputs and the edma channel s Current Major Iteration Counter (CITER) register is used as a simple pulse counter. This S32K chip configuration offers up to five pulse input channels that can be evaluated simultaneously. This way, the CPU load is also rapidly reduced. This application note addresses primarily the S32K product series of 32-bit automotive MCUs. Contents 1. Introduction... 1 2. Functional Description... 2 3. Initialization and Application... 3 4. Functional Limitations... 5 4.1. Maximum edma transfer... 5 4.2. edma major loop counter... 5 5. Conclusion... 5 6. Revision History... 6 2016 Freescale Semiconductor, Inc. All rights reserved. Preliminary Information, Subject to Change without Notice

Initialization and Application 2. Functional Description The edma is used primarily for data transfers between the main memory and another peripheral register space without CPU interference. CITER is a part of the edma structure and it can be also used for pulse counting. After receiving the peripheral request, the minor loop of the edma module starts to perform a basic data transfer. After the minor loop completes, CITER decrements. To capture the active edge from a port pin, set the major loop counter of the edma module to the maximum value. The CITER register value then reflects the actual pulse count. The S32K device includes DMA Multiplexer (DMAMUX) that enables mapping up to 63 edma request signals to any of the 16 edma channels. To capture multiple pulse inputs, PORTA PORTE can be set as sources for channels 0 5 of the edma module. Table 1. Channel request source edma channel number edma request source number Source description 0 49 PORTA request 1 50 PORTB request 2 51 PORTC request 3 52 PORTD request 4 53 PORTE request This code shows how to configure the edma channel request source to the corresponding PORT request: DMAMUX->CHCFG[0] = DMAMUX_CHCFG_SOURCE(49) DMAMUX_CHCFG_ENBL_MASK; DMAMUX->CHCFG[1] = DMAMUX_CHCFG_SOURCE(50) DMAMUX_CHCFG_ENBL_MASK; DMAMUX->CHCFG[2] = DMAMUX_CHCFG_SOURCE(51) DMAMUX_CHCFG_ENBL_MASK; DMAMUX->CHCFG[3] = DMAMUX_CHCFG_SOURCE(52) DMAMUX_CHCFG_ENBL_MASK; DMAMUX->CHCFG[4] = DMAMUX_CHCFG_SOURCE(53) DMAMUX_CHCFG_ENBL_MASK; NOTE Because a single PORT instance can generate a single edma request signal, only a single pin within the PORT instance has to be configured as a pulse input. Therefore, the maximum number of the pulse inputs equals the number of chip s PORT module instances. Each PORT instance must have only a single pin configured as a pulse input. // PORTA request // PORTB request // PORTC request // PORTD request // PORTE request 2 Preliminary Information, Subject to Change without Notice Freescale Semiconductor, Inc.

Initialization and Application 3. Initialization and Application To capture multiple pulse inputs, follow these edma and PORT initialization steps: PORT module: 1. Enable the PORT clock. 2. Set the PORT pin multiplexer to the GPIO mode. 3. Enable the edma request on the rising/falling edge. edma module: 1. Enable the DMAMUX and edma clocks. 2. Configure the DMA channel request source in DMAMUX. 3. Set the edma channel source and destination addresses to dummy variable addresses. 4. Set the edma channel source and destination minor and major address adjustment and offset to 0. 5. Set each edma channel CITER and BITER registers to the maximum value. 6. Enable the edma channel requests. Application: 1. Initialize the edma and PORT modules. 2. Read the edma channel CITER register value to determine the actual pulse count. This is the example code: /* Variables declaration */ uint32_t dummy1; uint32_t frequency_ch1; void PORT_Init() { /* Enable clock for PORTA-PORTE */ PCC->PCCn[PCC_PORTA_INDEX] = PCC_PCCn_CGC_MASK; PCC->PCCn[PCC_PORTB_INDEX] = PCC_PCCn_CGC_MASK; PCC->PCCn[PCC_PORTC_INDEX] = PCC_PCCn_CGC_MASK; PCC->PCCn[PCC_PORTD_INDEX] = PCC_PCCn_CGC_MASK; PCC->PCCn[PCC_PORTE_INDEX] = PCC_PCCn_CGC_MASK; /* Configure PORT pin to GPIO mode and enable edma request on rising/falling edge */ PORTA->PCR[8] = PORT_PCR_MUX(1) PORT_PCR_IRQC(1); PORTB->PCR[8] = PORT_PCR_MUX(1) PORT_PCR_IRQC(1); PORTC->PCR[8] = PORT_PCR_MUX(1) PORT_PCR_IRQC(1); PORTD->PCR[8] = PORT_PCR_MUX(1) PORT_PCR_IRQC(1); PORTE->PCR[8] = PORT_PCR_MUX(1) PORT_PCR_IRQC(1); } void DMAMUX_Init() { /* Enable clock for DMAMUX */ Freescale Semiconductor, Inc. Preliminary Information, Subject to Change without Notice 3

Functional Limitations PCC->PCCn[PCC_DMAMUX0_INDEX] = PCC_PCCn_CGC_MASK; /* Select an enable edma channel trigger source */ DMAMUX->CHCFG[0] = DMAMUX_CHCFG_SOURCE(49) DMAMUX_CHCFG_ENBL_MASK; DMAMUX->CHCFG[1] = DMAMUX_CHCFG_SOURCE(50) DMAMUX_CHCFG_ENBL_MASK; DMAMUX->CHCFG[2] = DMAMUX_CHCFG_SOURCE(51) DMAMUX_CHCFG_ENBL_MASK; DMAMUX->CHCFG[3] = DMAMUX_CHCFG_SOURCE(52) DMAMUX_CHCFG_ENBL_MASK; DMAMUX->CHCFG[4] = DMAMUX_CHCFG_SOURCE(53) DMAMUX_CHCFG_ENBL_MASK; } Before initializing edma register, it is necessary to fill in edma source and destination address into a dummy variable s address value. edma module initialization for one channel is performed as follows: void DMA_Init() { /* Enable clock for edma */ PCC->PCCn[PCC_DMA0_INDEX] = PCC_PCCn_CGC_MASK; /* Source Configuration */ DMA->TCD0_SADDR = &dummy1; DMA->TCD0_ATTR = DMA_TCD0_ATTR_SSIZE(0); DMA->TCD0_SOFF = 0; // no address shift after each transfer DMA->TCD0_SLAST = 0; /* Destination Configuration */ DMA->TCD0_DADDR = &dummy1; DMA->TCD0_ATTR = DMA_TCD0_ATTR_DSIZE(0); DMA->TCD0_DOFF = 0; // no address shift after each transfer DMA->TCD0_DLASTSGA = 0; /* Set Citer and Biter to Maximum Value */ DMA->TCD0_CITER.TCD0_CITER_ELINKNO = DMA_TCD0_CITER_ELINKNO_CITER_MASK; DMA->TCD0_BITER.TCD0_BITER_ELINKNO = DMA_TCD0_BITER_ELINKNO_BITER_MASK; DMA->TCD0_NBYTES.TCD0_NBYTES_MLNO = 1; // transfer one byte on each trigger arrived /* Start Transfer for Channel0 */ DMA->SERQ = DMA_SERQ_SERQ(0); } Read edma channel counter in your application. Pulse counting value equals to BITTER minus CITTER register value: frequency_ch1 = (DMA->TCD0_BITER.TCD0_BITER_ELINKNO & DMA_TCD0_BITER_ELINKNO_BITER_MASK)- (DMA->TCD0_CITER.TCD0_CITER_ELINKNO & DMA_TCD0_CITER_ELINKNO_CITER_MASK); NOTE You can read the edma channel counter at any time in your application before the major iteration count is exhausted (when CITER reaches 0). When CITER reaches 0, it is user s responsibility to reset the CITER register to BITER and restart the counting operation. Configure the edma channel to generate an interrupt when CITER reaches 0 by setting the INTMAJOR bit in the TCDn_CSR register. 4 Preliminary Information, Subject to Change without Notice Freescale Semiconductor, Inc.

Conclusion 4. Functional Limitations Consider the limitations of the implementation demonstrated in this application note. 4.1. Maximum edma transfer The maximum frequency of the measured signal is limited by the maximum transfer rate of the edma engine and the number of signals measured simultaneously using the method described in this application note. Consider the other edma transfers enabled in the final application as a limiting factor. 4.2. edma major loop counter CITER is limited to 15 bits. Check the CITER register and make sure it does not reach zero. When the CITER register reaches zero, CITER reloads the value from the BITER register and continues to decrement. 5. Conclusion The edma multiple pulse counter implementation can be completed using the internal hardware logic, without the CPU intervention. The CPU only reads the edma channel CITER register to get the actual pulse count value. The figure below shows three test square signals with different frequencies (20 khz, 10 khz, and 1 khz). The frequency of the particular signal was determined using the edma module. Figure 1. Input square waves Freescale Semiconductor, Inc. Preliminary Information, Subject to Change without Notice 5

Revision History To measure the frequency of the input signals, follow these steps: 1. Enable the PIT timer to generate a one-second interrupt. 2. In the interrupt routine, read the difference between the BITER and CITER registers and reset the edma counter. 3. Check the values in the Expression tab in S32 Design Studio. 6. Revision History Figure 2. Frequency of testing square waves in S32 Design Studio This table summarizes the changes done to this document since the initial release. Table 2. Revision history Revision number Date Substantive changes 0 02/2016 Initial release. 6 Preliminary Information, Subject to Change without Notice Freescale Semiconductor, Inc.

How to Reach Us: Home Page: freescale.com Web Support: freescale.com/support Information in this document is provided solely to enable system and software implementers to use Freescale products. There are no express or implied copyright licenses granted hereunder to design or fabricate any integrated circuits based on the information in this document. Freescale reserves the right to make changes without further notice to any products herein. Freescale makes no warranty, representation, or guarantee regarding the suitability of its products for any particular purpose, nor does Freescale assume any liability arising out of the application or use of any product or circuit, and specifically disclaims any and all liability, including without limitation consequential or incidental damages. Typical parameters that may be provided in Freescale data sheets and/or specifications can and do vary in different applications, and actual performance may vary over time. All operating parameters, including typicals, must be validated for each customer application by customer's technical experts. Freescale does not convey any license under its patent rights nor the rights of others. Freescale sells products pursuant to standard terms and conditions of sale, which can be found at the following address: freescale.com/salestermsandconditions. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc., Reg. U.S. Pat. & Tm. Off. All other product or service names are the property of their respective owners. All rights reserved. 2016 Freescale Semiconductor, Inc. Document Number: AN5258 Rev. 0 02/2016 Preliminary Information, Subject to Change without Notice