CE PSoC 4: Time-Stamped ADC Data Transfer Using DMA

Similar documents
THIS SPEC IS OBSOLETE

Clock Programming Kit

Filter_ADC_VDAC_poll Example Project Features. General Description. Development Kit Configuration

Writing to Internal Flash in PSoC 3 and PSoC 5

Use the Status Register when the firmware needs to query the state of internal digital signals.

AN1090. NoBL : The Fast SRAM Architecture. Introduction. NoBL SRAM Description. Abstract. NoBL SRAM Operation

Use the Status Register when the firmware needs to query the state of internal digital signals.

CE56273 Associated Part Families: CY8C38xx/CY8C55xx Software: PSoC Creator Related Hardware: CY8CKIT-001 Author: Anu M D

THIS SPEC IS OBSOLETE

AN SIO Tips and Tricks in PSoC 3 / PSoC 5. Application Note Abstract. Introduction

This optional pin is present if the Mode parameter is set to SyncMode or PulseMode. Otherwise, the clock input does not show.

This optional pin is present if the Mode parameter is set to SyncMode or PulseMode. Otherwise, the clock input does not show.

CE CY8CKIT-042-BLE F-RAM Data Logger

Reviving Bit-slice Technology in a Programmable Fashion

Voltage Reference (Vref) Features. General Description. Input/Output Connections. When to Use a Vref Voltage references and supplies

HX2VL Development Kit Guide. Doc. # Rev. *A

Cypress HX2VL Configuration Utility Blaster User Guide

Comparator (Comp) Features. General Description. When to use a Comparator 1.60

HX2VL Development Kit Guide. Doc. # Rev. **

THIS SPEC IS OBSOLETE

PSoC 4 Low Power Comparator (LPComp) Features. General Description. When to Use a LPComp 2.0. Low input offset. User controlled offset calibration

The following table lists user modules used in this code example and the hardware resources occupied by each user module.

CE58957 demonstrates how to implement the fade and toggle feature to the backlight LEDs of CapSense buttons.

CE95314 PSoC 3, PSoC 4, and PSoC 5LP EZI2C

Cypress HX2VL Configuration Utility Blaster User Guide

CY3660-enCoRe V and encore V LV DVK Kit Guide

For one or more fully configured, functional example projects that use this user module go to

CY7C603xx CYWUSB

FTG Programming Kit CY3670. Spec. # Rev. *C

8 to 1 Analog Multiplexer Datasheet AMux8 V 1.1. Features and Overview

Next-Generation Hot-Swap Controllers

Preliminary. Gas Sensor Analog Front End Datasheet GasSensorAFE V Features and Overview. This datasheet contains Preliminary information.

PSoC 1 I 2 C Bootloader

PSoC Creator Component Datasheet

GPIF II Designer - Quick Start Guide

4 to 1 Analog Multiplexer Data Sheet

DMX512 Receiver Datasheet DMX512Rx V 1.0. Features and Overview

THIS SPEC IS OBSOLETE

Programmable Threshold Comparator Data Sheet

Use the IDAC8 when a fixed or programmable current source is required in an application.

LPF (Optional) CY8C24x93. Without LPF and ISR to 3* With LPF only** to 3* With ISR only to 3*

CYClockMaker Programming Kit Guide CY3675. Doc. # Rev. **

Incremental ADC Data Sheet

CYClockMaker Programming Kit Guide CY3675. Doc. # Rev. *C

Programmable Gain Amplifier Datasheet PGA V 3.2. Features and Overview

AN EZ-USB FX3 I 2 C Boot Option. Application Note Abstract. Introduction. FX3 Boot Options

This Application Note demonstrates an SPI-LIN slave bridge using a PSoC device. Demonstration projects are included.

The color of the Clock component waveform symbol will change based on the clock's domain (as shown in the DWR Clock Editor), as follows:

LVDS Crystal Oscillator (XO)

16-Bit Hardware Density Modulated PWM Data Sheet

12-Mbit (512 K 24) Static RAM

Shadow Registers Datasheet ShadowRegs V 1.1. Features and Overview

EZ-USB FX3 Development Kit Guide

Supported Devices: CY8C28x13, CY8C28x33, CY8C28x43, CY8C28x45, CY8C28x52, CY8C21x45, CY8C22x45, CY8C24x93. CY8C24x

PSoC Programmer 3.12 Release Notes

Programmer User Guide

THIS SPEC IS OBSOLETE

Multifunction Serial Interface (PDL_MFS) Features. General Description. When to Use a PDL_MFS Component. Quick Start 1.0

One 32-bit counter that can be free running or generate periodic interrupts

24-Bit Pseudo Random Sequence Generator Data Sheet

144-Mbit QDR -II SRAM 2-Word Burst Architecture

This input determines the next value of the output. The output does not change until the next rising edge of the clock.

EZ-USB NX2LP USB 2.0 NAND Flash Controller

F²MC-8FX Family MB95200H/210H Series Capacitance Touch Sensor

Use the Status Register when the firmware needs to query the state of internal digital signals.

Base Timer Channel (BT) Features. General Description. When to Use a PDL_BT Component 1.0

PSoC Designer Release Notes

CapSense I 2 C/SPI Timer Flash RAM

This section describes the various input and output connections for the SysInt Component.

This section describes the various input and output connections for the Voltage Fault Detector.

Use the Status Register when the firmware needs to query the state of internal digital signals.

100 MHz LVDS Clock Generator

Digital Multiplexer and Demultiplexer. Features. General Description. Input/Output Connections. When to Use a Multiplexer. Multiplexer 1.

Libraries Guide. Arithmetic Libraries User Guide. Document #: Rev. *A

Sequencing Successive Approximation ADC (ADC_SAR_Seq) Features. General Description. When to Use the ADC_SAR_Seq 2.0. Supports PSoC 5LP devices

Capable of adjusting detection timings for start bit and data bit

4K x 8 Dual-Port Static RAM and 4K x 8 Dual-Port SRAM with Semaphores

EZ I 2 C Slave. Features. General Description. When to use a EZ I 2 C Slave 1.50

The AMuxSeq is capable of having between 2 and 32 analog inputs. The paired inputs are present when the MuxType parameter is set to "Differential.

This optional pin is present if the Mode parameter is set to SyncMode or PulseMode. Otherwise, the clock input does not show.

FM3 MB9B100A/300A/400A/500A Series Inverter Solution GUI User Guide

PSoC Blocks. CY8C20xx6/6A/6AS/6H/6L, CY8C20xx7/7S, CY7C643xx, CY7C604xx, CYONS2xxx, CYONSxNxxxx, CYRF89x35, CY8C20065, CY8C24x93, CY7C69xxx

Digital Logic Gates. Features. General Description. Input/Output Connections. When to Use a Logic Gate. Input 1. Input 2. Inputs 3-8 * 1.

PSoC 6 Current Digital to Analog Converter (IDAC7)

PSoC Creator Quick Start Guide

W H I T E P A P E R. Introduction. Devices. Energy Comparison of Cypress F-RAM and EEPROM

Comparator (Comp) Features. General Description. When to use a Comparator Low input offset. User controlled offset calibration

Bootloader project - project with Bootloader and Communication components

Automatic reload of the period to the count register on terminal count

Optional Pause Pulse for constant frame length of 282 clock ticks

Use a DieTemp component when you want to measure the die temperature of a device.

This section describes the various input and output connections for the Voltage Fault Detector.

PSoC 4 Voltage Comparator (Comp) Features. General Description. When to Use Comparator Low input offset. User controlled offset calibration

For More Information Please contact your local sales office for additional information about Cypress products and solutions.

AN PSoC 3 and PSoC 5 SFF-8485 Serial GPIO (SGPIO) Initiator Interface. Application Note Abstract. Introduction

AN EZ-USB FX3 Hardware Design Guidelines and Schematic Checklist. Introduction. Booting. Schematic Design Checklist.

Release Notes SRN065 PSoC Programmer Version Release Date: November 9, 2009

Setting Oscillation Stabilization Wait Time of the main clock (CLKMO) and sub clock (CLKSO)

PSoC Programmer Release Notes

Voltage Fault Detector (VFD) Features. General Description. Input/Output Connections. When to Use a VFD. Clock Input 2.30

Transcription:

CE97091- PSoC 4: Time-Stamped ADC Data Transfer Using DMA Objective This code example uses a DMA channel with two descriptors to implement a time-stamped ADC data transfer. It uses the Watch Dog Timer (WDT) and SAR ADC. Overview This code example implements a time-stamped ADC using the DMA controller in PSoC 4. The timing is maintained with the WDT, which is clocked by the 32-kHz watch crystal oscillator (WCO). Two channels of the ADC are sampled and the results are transferred along with the timer value from the WDT. The transfers from the ADC and the WDT are accomplished using a single DMA channel. Requirements Tool: PSoC Creator 3.3 Associated Parts: PSoC 4200M and PSoC 4100M Related Hardware: CY8CKIT-044 Design Every DMA channel in PSoC 4 has two descriptor structures associated with it. The descriptor comprises information regarding the source and destination address, the modes of transfer, and other specifics related to a transfer. You can choose to use one or both the descriptors in the channel. Refer to the DMA Component datasheet for more details on the use of descriptors. In this code example, one DMA channel is configured with two descriptors: Descriptor 0 and Descriptor 1. The time-stamped data is a data structure with the two ADC channel results along with the corresponding time of the sampled data. The time stamp data is stored as a data structure (timestmp_data) in memory. Descriptor 0 is configured to transfer the time value from the WDT to the data structure, timestmp_data in memory. After completion, Descriptor 0 automatically triggers Descriptor 1, which transfers the ADC result for the two channels to consecutive locations in the data structure. The data structure is updated every time there is a switch press event on the mechanical switch SW2. Figure 1 illustrates this concept. www.cypress.com Document No. 001-97091 Rev.** 1

Figure 1: Time-Stamped ADC Data Transfer Timer 2 (WDT2) 32 bit DMA Channel Memory Data Structure Timestmp_Data ADC Channel 0 Channel 1 32 bit 32 bit Time data (32 bit) ADC Channel 0 (16 bit) Time (32 bit) ADC Channel 0 (16 bit) SW2 Trigger ADC Channel 0 (16 bit) ADC Channel 1 (16 bit) Descriptor 0 Descriptor 1 The mechanical switch SW2 is connected to trigger the DMA channel. A debouncer Component is used to avoid the switch from providing multiple trigger signals. The DMA channel is configured to transfer the time information from the WDT register using Descriptor 0 and then the two ADC channel results using Descriptor 1. This code example also integrates a UART Component to communicate the time-stamped data over a COM interface. This is done to observe the transferred data. The project uses the CPU to fetch the data, process it and convert it into a string that is readable on a terminal tool, and transmit it over UART. Figure 2 shows the PSoC Creator implementation of the time-stamped ADC using a DMA channel. The ADC in this design is configured to sample two channels at a sample rate of 3014 sps and resolution of 12 bits. Figure 2: Time-Stamped ADC Data Transfer to Memory- PSoC Creator Implementation The time stamp is implemented using the Timer 1 and Timer 2 blocks of the WDT. Timer 1 is used to divide the 32-kHz clock to get a 1-second timing. Timer 2 is clocked by Timer 1 to implement a timer counting in seconds. The Timer 2 value is used for time stamping. This configuration is done in the Design Wide resources/clocks configuration as shown in Figure 3. www.cypress.com Document No. 001-97091 Rev.** 2

Figure 3: WDT Configuration Cascading of the Timer 1 output to Timer 2 is done in the firmware using the following code: /* Configuring the WDT to cascade Timer1(WDT1) and Timer2 (WDT2) */ CySysWdtSetCascade(CY_SYS_WDT_CASCADE_12); For more details on the WDT and Timers, see the System Reference Guide. The DMA channel is configured to have two descriptors. The destination of all transfers is a data structure named timestmp_data. struct data_structure { int32 time; int16 Channel[2]; } timestmp_data; www.cypress.com Document No. 001-97091 Rev.** 3

Descriptor 0 Configuration Descriptor 0 is configured as shown in Figure 4. It transfers data from the Timer 2 (WDT2) counter register to the data structure (timestmp_data.time) in memory. Figure 4: Descriptor 0 Configuration 1 2 4 3 The settings for Descriptor 0 are as follows: 1. The source of the time data is the Timer 2 counter register. The data being transferred is the seconds count from Timer 2, which is a 32-bit value. The destination of the transfer is also a 32-bit element (timestmp_data.time) in the data structure. Therefore, the Data element size for the transfer is set as Word (four bytes). 2. Only a single 32-bit data is transferred as part of this descriptor; therefore, the Number of data elements to transfer is set to 1. 3. The data width of PSoC 4 peripheral registers is four bytes (word); therefore, typically, the Source or Destination transfer width should be set to Word when DMA is using a peripheral as its source or destination. The source and destination transfer width for the DMA Component must match the addressable width of the source and destination, regardless of the amount of data that needs to be moved. The memory can be accessed as 8-bit, 16-bit, or 32-bit. For Descriptor 0, the source is the timer register (peripheral register), which needs to be accessed as 32-bit. The destination is a 32-bit variable in memory. Because the source and destination for this transfer are 32 bits wide, the Source and destination transfer width is set as Word to Word. www.cypress.com Document No. 001-97091 Rev.** 4

4. The switch press will trigger a burst that will transfer the time stamp and ADC data one after the other. This DMA channel is set up to operate when a single trigger initiates all transfers. The Transfer mode is set to Entire descriptor chain per trigger. When this setting is selected, the trigger signal will initiate and complete both the descriptors in the DMA channel. The source and destination of this descriptor are set as a part of the DMA start routine in the main.c code. DMA_1_Start((void*)CY_SYS_WDT_CTRHIGH_PTR,(void*)&timestmp_Data.time); You can obtain the source register name from either the LFCLK datasheet under System Reference Guides or the cy_lfclk.h register definitions. The destination is set as timestmp_data.time. Descriptor 1 Configuration Figure 5 shows the Descriptor 1 configuration. Descriptor 1 is automatically triggered after the completion of Descriptor 0. Descriptor 1 transfers the ADC channel results from the ADC result registers to the data structure (timestmp_data.channel). Figure 5: Descriptor 1 Configuration 1 2 5 3 4 6 7 www.cypress.com Document No. 001-97091 Rev.** 5

The settings for Descriptor 1 are as follows: 1. The source of the data is the ADC result register. Only 16 bits of the ADC result register are valid. The destination is a 16-bit variable in the data structure. Therefore, the Data element size parameter is set as Half word (2 bytes). 2. Two ADC channel results are transferred as part of the descriptor; therefore, the Number of data elements to transfer is set as 2. 3. The data width of PSoC 4 peripheral registers is four bytes (word), so typically the Source or Destination transfer width should be set to Word when DMA is using a peripheral as its source or destination. The source and destination transfer width for the DMA Component must match the addressable width of the source and destination, regardless of the amount of data that needs to be moved. The memory can be accessed as 8-bit, 16-bit, or 32-bit. The source of the transfer for this descriptor is the ADC result register (peripheral register), which needs to be accessed as a 32-bit register. The destination of the transfer is a variable in memory that can be accessed as 16-bit. Because the source of this transfer is 32-bit and the destination is 16-bit, the Source and destination transfer width is set as Word to Half word. 4. The source is two ADC channel results that are in consecutive memory locations. The destination of the transfer is two 16-bit variables in consecutive locations in memory. Therefore, both the source and destination addresses are set to Increment. Note: Because the Source and destination transfer width was set as Word to Half word, the source increments in steps of 32 bits, and the destination in steps of 16 bits. 5. This DMA channel is set up to operate when a single trigger initiates all transfers, as described in Descriptor 0 Configuration. The Transfer mode is set to Entire descriptor chain per trigger. When this setting is selected, the trigger signal will initiate and complete both the descriptors in the DMA channel. 6. Once Descriptor 1 is completed, the DMA channel transfer is considered complete for the current trigger. However, the subsequent triggers should start the transfers from Descriptor0. For this reason, the Chain to descriptor0 option is enabled in Post completion actions. This selection makes sure that control is reset back to Descriptor 0. 7. The Generate interrupt request option generates an interrupt at the end of the descriptor transfer. This interrupt provides a flag for the CPU to initiate UART processing of the data in the data structure and transfer over UART. The Descriptor 1 source address is the ADC s result register and destination is the data structure (timestmp_data.channel). The ADC is sampling two channels, and the two channel results are in consecutive registers. The source and destination of transfer are set using the following code DMA_1_SetSrcAddress(DESCRIPTOR_1, (void*)adc_sar_seq_sar_chan0_result_ptr); DMA_1_SetDstAddress(DESCRIPTOR_1, timestmp_data.channel); Design Considerations Note that no code is present after the initializations. The CPU is free after the initialization steps. The DMA can be functional in the PSoC 4 Sleep mode, so you can optionally put the device to sleep after the initializations are done. This can help to reduce system power consumption. Note When the voltage on the ADC is close to zero, there is a chance of the ADC result going negative due to a negative offset. This may be noticed on either of the channel results when they are close to zero. Hardware Setup Input setup: Connect a voltage input to the pins P2[0] and P2[1]. To do this, you can use a potentiometer connected between Vdd and GND with the wiper pin connecting to one of the input pins. The project also has a switch input to trigger the transfer which connects to pin P0[7]. SW2 is already connected on this pin and hence does not require additional connections. Output setup: On the CY8CKIT-044, the UART TX output is already connected to pin P7[1] which connects to the PSoC 5LP RX line. The PSoC 5LP on the board implements a UART-to-USB bridge, which enumerates as a COM port on the PC. www.cypress.com Document No. 001-97091 Rev.** 6

If you are using a different hardware (not CY8CKIT-044), make sure you connect the UART TX pin from the project to the right pin where the UART bridge connection is made. You need to setup a terminal program such as Termite, to receive the UART data being transferred. You also need to find and connect to the COM port enumerated. The UART settings for the terminal are as follows: o Baud rate: 115,200 bps o Data bits : 8 bits o Stop bits : 1 bit o o Operation Parity: None Flow control: None 1. Make the input and output setup as described in the Hardware Setup section. 2. Start the terminal program and make sure it is connected to the right COM port for receiving data from the device. 3. Press the switch SW2 and verify that instantaneous time-stamped data is displayed on the terminal program. An example screen shot taken from Termite is shown in the Figure 6. The data is displayed in the following format: Time = [<time in seconds>]: Ch0= <Channel0 voltage in mv>, Ch1= <Channel1 voltage in mv>. Figure 6: Data streamed through UART 4. An instance of time stamped data is transferred every time the SW2 switch is pressed and this gets displayed on the screen. Note When the voltage on the ADC is close to zero, there is a chance of the ADC result going negative due to a negative offset. www.cypress.com Document No. 001-97091 Rev.** 7

Components Table 1 lists the PSoC Creator Components used in this example, as well as the hardware resources used by each. Table 1. List of PSoC Creator Components Component or User Module ADC_SAR_SEQ DMA Debouncer UART Hardware Resources SAR ADC 1 DMA channel PLD (5 macrocells) SCB Related Documents Table 2 lists all relevant application notes, code examples, knowledge base articles, device datasheets, and Component datasheets. Application Notes AN79953: Getting Started with PSoC 4 Code Examples CE97088 - PSoC 4: ADC TO PWM DMA TRANSFER CE97089 PSoC 4: ADC to Memory Buffer DMA Transfer Table 2. Related Documents CE95275:Sequencing SAR ADC and Die temperature sensor with PSoC 4 CE95272:SAR ADC in Differential Mode using Pre-Amplifier with PSoC 4 PSoC Creator Component Datasheets ADC_SAR_Seq: PSoC 4 Sequencing Successive Approximation ADC DMA: PSoC 4 Direct Memory Access (DMA) Channel Debouncer : Debouncer UART: PSoC 4 Serial Communication Block (SCB) Device Documentation PSoC 4 Datasheets PSoC 4 Technical Reference Manuals Development Kit (DVK) Documentation PSoC 4 M-Series Pioneer Kit www.cypress.com Document No. 001-97091 Rev.** 8

Document History Document Title: CE97091- PSoC 4: Time-Stamped ADC Data Transfer Using DMA Document Number: 001-97091 Revision ECN Orig. of Change Submission Date Description of Change ** 5021986 QVS 01/06/2016 New code example www.cypress.com Document No. 001-97091 Rev.** 9

Worldwide Sales and Design Support Cypress maintains a worldwide network of offices, solution centers, manufacturer s representatives, and distributors. To find the office closest to you, visit us at Cypress Locations. Products Automotive Clocks & Buffers Interface Lighting & Power Control Memory PSoC Touch Sensing USB Controllers Wireless/RF cypress.com/go/automotive cypress.com/go/clocks cypress.com/go/interface cypress.com/go/powerpsoc cypress.com/go/plc cypress.com/go/memory cypress.com/go/psoc cypress.com/go/touch cypress.com/go/usb cypress.com/go/wireless PSoC Solutions psoc.cypress.com/solutions PSoC 1 PSoC 3 PSoC 4 PSoC 5LP Cypress Developer Community Community Forums Blogs Video Training Technical Support cypress.com/go/support PSoC is a registered trademark and PSoC Creator is a trademark of Cypress Semiconductor Corp. All other trademarks or registered trademarks referenced herein are the property of their respective owners. Cypress Semiconductor 198 Champion Court San Jose, CA 95134-1709 Phone : 408-943-2600 Fax : 408-943-4730 Website : www.cypress.com Cypress Semiconductor Corporation, 2016. The information contained herein is subject to change without notice. Cypress Semiconductor Corporation assumes no responsibility for the use of any circuitry other than circuitry embodied in a Cypress product. Nor does it convey or imply any license under patent or other rights. Cypress products are not warranted nor intended to be used for medical, life support, life saving, critical control or safety applications, unless pursuant to an express written agreement with Cypress. Furthermore, Cypress does not authorize its products for use as critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress products in life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges. This Source Code (software and/or firmware) is owned by Cypress Semiconductor Corporation (Cypress) and is protected by and s ubject to worldwide patent protection (United States and foreign), United States copyright laws and international treaty provisions. Cypress hereby grants to licensee a personal, non-exclusive, non-transferable license to copy, use, modify, create derivative works of, and compile the Cypress Source Code and derivative works for the sole purpose of creating custom software and or firmware in support of licensee product to be used only in conjunction with a Cypress integrated circuit as specified in the applicable agreement. Any reproduction, modification, translation, compilation, or representation of this Source Code except as specified above is prohibited without the express written permission of Cypress. Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress reserves the right to make changes without further notice to the materials described herein. Cypress does not assume any liability arising out of the application or use of any product or circuit described herein. Cypress does not authorize its products for use as critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress product in a life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges. Use may be limited by and subject to the applicable Cypress software license agreement. www.cypress.com Document No. 001-97091 Rev.** 10