<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: LPC1549: How to use the DMA with the ADC in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC1549-How-to-use-the-DMA-with-the-ADC/m-p/1218700#M43680</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;"Maybe the ADC interrupt is not correctly setup?"&lt;/P&gt;
&lt;P&gt;-&amp;gt; No, when you use breakpoint, there is some delay by software.&lt;/P&gt;
&lt;P&gt;I recommend you set block to lock problem, for example without DMA, just check whether ADC&lt;/P&gt;
&lt;P&gt;, then add DMA...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 21 Jan 2021 09:15:52 GMT</pubDate>
    <dc:creator>Alice_Yang</dc:creator>
    <dc:date>2021-01-21T09:15:52Z</dc:date>
    <item>
      <title>LPC1549: How to use the DMA with the ADC</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC1549-How-to-use-the-DMA-with-the-ADC/m-p/1216661#M43624</link>
      <description>&lt;P&gt;I found this example:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.nxp.com/t5/LPC-Microcontrollers-Knowledge/DMA-Ping-Pong-application/ta-p/1120977" target="_blank" rel="noopener"&gt;https://community.nxp.com/t5/LPC-Microcontrollers-Knowledge/DMA-Ping-Pong-application/ta-p/1120977&lt;/A&gt;&lt;/P&gt;&lt;P&gt;for the&amp;nbsp;&lt;SPAN&gt;LPCXpressor54114 Board and changed it to match the &amp;nbsp;LPC1549 LPCXpresso™ board.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;There are some ADC results in the buffer. But there are zeros and not compleately processed data there too.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'm using the SCT2_Out3 to ADC0_SEQA to DMA. I'm not sure if the ADC_SEQA is setup correctly.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What could be wrong?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The code is shown below:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;//-------------------------------------------------------------&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;#if defined (__USE_LPCOPEN)&lt;BR /&gt;#if defined(NO_BOARD_LIB)&lt;BR /&gt;#include "chip.h"&lt;BR /&gt;#else&lt;BR /&gt;#include "board.h"&lt;BR /&gt;#endif&lt;BR /&gt;#endif&lt;/P&gt;&lt;P&gt;#include &amp;lt;cr_section_macros.h&amp;gt;&lt;/P&gt;&lt;P&gt;#define NUM_BUFFERS 4&lt;BR /&gt;#define DMA_TRANSFER_SIZE 8&lt;BR /&gt;#define ADC_INPUT_CHANNEL 0&lt;/P&gt;&lt;P&gt;#define SCT_PWM_RATE 10000 /* PWM frequency 10 KHz */&lt;BR /&gt;#define SCT_PWM_PIN_OUT 3 /* COUT3 Generate square wave */&lt;BR /&gt;#define SCT_PWM_OUT 3 /* Index of OUT PWM */&lt;/P&gt;&lt;P&gt;uint16_t adcOut;&lt;/P&gt;&lt;P&gt;DMA_CHDESC_T ADC_TransferDescriptors[NUM_BUFFERS] __attribute__ ((aligned(512)));&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;uint16_t CapturedData[32];&lt;/P&gt;&lt;P&gt;uint16_t DMA_Sum=0;&lt;/P&gt;&lt;P&gt;/**&lt;BR /&gt;*&lt;BR /&gt;* ADC IRQ not Used right now... Only for testing&lt;BR /&gt;*/&lt;BR /&gt;void ADC_SEQA_IRQHandler(void)&lt;BR /&gt;{&lt;BR /&gt;/* If SeqA flags is set i.e. data in global register is valid then read it */&lt;BR /&gt;Chip_ADC_ClearFlags(LPC_ADC0,0xFFFFFFFF);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;void DMA_IRQHandler(void)&lt;BR /&gt;{&lt;BR /&gt;static uint16_t DMA_Sum=0;&lt;/P&gt;&lt;P&gt;DMA_Sum++;&lt;/P&gt;&lt;P&gt;if(DMA_Sum ==8)&lt;BR /&gt;{&lt;BR /&gt;DMA_Sum=4;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/* Rrror interrupt on channel 0? */&lt;BR /&gt;if ((Chip_DMA_GetIntStatus(LPC_DMA) &amp;amp; DMA_INTSTAT_ACTIVEERRINT) != 0)&lt;BR /&gt;{&lt;BR /&gt;/* This shouldn't happen for this simple DMA example, so set the LED&lt;BR /&gt;to indicate an error occurred. This is the correct method to clear&lt;BR /&gt;an abort. */&lt;BR /&gt;Chip_DMA_DisableChannel(LPC_DMA, DMA_CH0);&lt;BR /&gt;while ((Chip_DMA_GetBusyChannels(LPC_DMA) &amp;amp; (1 &amp;lt;&amp;lt; DMA_CH0)) != 0) {}&lt;BR /&gt;Chip_DMA_AbortChannel(LPC_DMA, DMA_CH0);&lt;BR /&gt;Chip_DMA_ClearErrorIntChannel(LPC_DMA, DMA_CH0);&lt;BR /&gt;Chip_DMA_EnableChannel(LPC_DMA, DMA_CH0);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;/* Clear DMA interrupt for the channel */&lt;BR /&gt;Chip_DMA_ClearActiveIntAChannel(LPC_DMA, DMA_CH0);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/***&lt;BR /&gt;* ____ __ __ _&lt;BR /&gt;* | _ \| \/ | / \&lt;BR /&gt;* | | | | |\/| | / _ \&lt;BR /&gt;* | |_| | | | |/ ___ \&lt;BR /&gt;* |____/|_| |_/_/ \_\&lt;BR /&gt;* / ___| ___| |_ _ _ _ __&lt;BR /&gt;* \___ \ / _ \ __| | | | '_ \&lt;BR /&gt;* ___) | __/ |_| |_| | |_) |&lt;BR /&gt;* |____/ \___|\__|\__,_| .__/&lt;BR /&gt;* |_|&lt;BR /&gt;*/&lt;BR /&gt;void DMA_Setup(void)&lt;BR /&gt;{&lt;BR /&gt;DMA_CHDESC_T Initial_DMA_Descriptor;&lt;/P&gt;&lt;P&gt;ADC_TransferDescriptors[0].source = (uint32_t)&amp;amp;LPC_ADC0-&amp;gt;SEQ_GDAT[0];&lt;BR /&gt;ADC_TransferDescriptors[1].source = (uint32_t)&amp;amp;LPC_ADC0-&amp;gt;SEQ_GDAT[0];&lt;BR /&gt;ADC_TransferDescriptors[2].source = (uint32_t)&amp;amp;LPC_ADC0-&amp;gt;SEQ_GDAT[0];&lt;BR /&gt;ADC_TransferDescriptors[3].source = (uint32_t)&amp;amp;LPC_ADC0-&amp;gt;SEQ_GDAT[0];&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;ADC_TransferDescriptors[0].dest = DMA_ADDR(&amp;amp;CapturedData[(0+1)*DMA_TRANSFER_SIZE-1]);&lt;BR /&gt;ADC_TransferDescriptors[1].dest = DMA_ADDR(&amp;amp;CapturedData[(1+1)*DMA_TRANSFER_SIZE-1]);&lt;BR /&gt;ADC_TransferDescriptors[2].dest = DMA_ADDR(&amp;amp;CapturedData[(2+1)*DMA_TRANSFER_SIZE-1]);&lt;BR /&gt;ADC_TransferDescriptors[3].dest = DMA_ADDR(&amp;amp;CapturedData[(3+1)*DMA_TRANSFER_SIZE-1]);&lt;/P&gt;&lt;P&gt;//The initial DMA desciptor is the same as the 1st transfer descriptor. It&lt;BR /&gt;//Will link into the 2nd of the main descriptors.&lt;/P&gt;&lt;P&gt;ADC_TransferDescriptors[0].next = (uint32_t)&amp;amp;ADC_TransferDescriptors[1];&lt;BR /&gt;ADC_TransferDescriptors[1].next = (uint32_t)&amp;amp;ADC_TransferDescriptors[2];&lt;BR /&gt;ADC_TransferDescriptors[2].next = (uint32_t)&amp;amp;ADC_TransferDescriptors[3];&lt;/P&gt;&lt;P&gt;//Link back to the 1st descriptor&lt;BR /&gt;ADC_TransferDescriptors[3].next = (uint32_t)&amp;amp;ADC_TransferDescriptors[0];&lt;/P&gt;&lt;P&gt;//For a test, stop the transfers here. The sine wave will look fine.&lt;BR /&gt;//ADC_TransferDescriptors[3].next = 0;&lt;/P&gt;&lt;P&gt;ADC_TransferDescriptors[0].xfercfg = (DMA_XFERCFG_CFGVALID |&lt;BR /&gt;DMA_XFERCFG_RELOAD |&lt;BR /&gt;DMA_XFERCFG_SETINTA |&lt;BR /&gt;DMA_XFERCFG_WIDTH_16 |&lt;BR /&gt;DMA_XFERCFG_SRCINC_0 |&lt;BR /&gt;DMA_XFERCFG_DSTINC_1 |&lt;BR /&gt;DMA_XFERCFG_XFERCOUNT(DMA_TRANSFER_SIZE));&lt;/P&gt;&lt;P&gt;ADC_TransferDescriptors[1].xfercfg = ADC_TransferDescriptors[0].xfercfg;&lt;BR /&gt;ADC_TransferDescriptors[2].xfercfg = ADC_TransferDescriptors[0].xfercfg;&lt;/P&gt;&lt;P&gt;ADC_TransferDescriptors[3].xfercfg = (DMA_XFERCFG_CFGVALID |&lt;BR /&gt;DMA_XFERCFG_RELOAD |&lt;BR /&gt;DMA_XFERCFG_SETINTA |&lt;BR /&gt;DMA_XFERCFG_WIDTH_16 |&lt;BR /&gt;DMA_XFERCFG_SRCINC_0 |&lt;BR /&gt;DMA_XFERCFG_DSTINC_1 |&lt;BR /&gt;DMA_XFERCFG_XFERCOUNT(DMA_TRANSFER_SIZE));&lt;/P&gt;&lt;P&gt;Initial_DMA_Descriptor.source = ADC_TransferDescriptors[0].source;&lt;BR /&gt;Initial_DMA_Descriptor.dest = ADC_TransferDescriptors[0].dest;&lt;BR /&gt;Initial_DMA_Descriptor.next = (uint32_t)&amp;amp;ADC_TransferDescriptors[1];&lt;BR /&gt;Initial_DMA_Descriptor.xfercfg = ADC_TransferDescriptors[0].xfercfg;&lt;/P&gt;&lt;P&gt;/* DMA initialization - enable DMA clocking and reset DMA if needed */&lt;BR /&gt;Chip_DMA_Init(LPC_DMA);&lt;/P&gt;&lt;P&gt;/* Enable DMA controller and use driver provided DMA table for current descriptors */&lt;BR /&gt;Chip_DMA_Enable(LPC_DMA);&lt;BR /&gt;Chip_DMA_SetSRAMBase(LPC_DMA, DMA_ADDR(Chip_DMA_Table));&lt;/P&gt;&lt;P&gt;/* Setup channel 0 for the following configuration:&lt;BR /&gt;- High channel priority&lt;BR /&gt;- Interrupt A fires on descriptor completion */&lt;BR /&gt;Chip_DMA_EnableChannel(LPC_DMA, DMA_CH0);&lt;BR /&gt;Chip_DMA_EnableIntChannel(LPC_DMA, DMA_CH0);&lt;BR /&gt;Chip_DMA_SetupChannelConfig(LPC_DMA, DMA_CH0, //(DMA_CFG_PERIPHREQEN |&lt;BR /&gt;(DMA_CFG_HWTRIGEN |&lt;BR /&gt;DMA_CFG_TRIGBURST_BURST |&lt;BR /&gt;DMA_CFG_TRIGTYPE_EDGE |&lt;BR /&gt;DMA_CFG_TRIGPOL_HIGH | //DMA_CFG_TRIGPOL_HIGH&lt;BR /&gt;DMA_CFG_BURSTPOWER_1 |&lt;BR /&gt;DMA_CFG_CHPRIORITY(0)&lt;BR /&gt;)&lt;BR /&gt;);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;//make sure ADC Sequence A interrupts is selected for for a DMA trigger&lt;BR /&gt;Chip_INMUX_SetDMATrigger(DMA_CH0, DMATRIG_ADC0_SEQA_IRQ);&lt;/P&gt;&lt;P&gt;/* Enable DMA interrupt */&lt;BR /&gt;NVIC_EnableIRQ(DMA_IRQn);&lt;/P&gt;&lt;P&gt;// The 1st descriptor is set up through the registers.&lt;/P&gt;&lt;P&gt;/* Setup transfer descriptor and validate it */&lt;BR /&gt;Chip_DMA_SetupTranChannel(LPC_DMA, DMA_CH0, &amp;amp;Initial_DMA_Descriptor);&lt;/P&gt;&lt;P&gt;//Use the transfer configuration for our 4 main descriptors&lt;BR /&gt;Chip_DMA_SetupChannelTransfer(LPC_DMA, DMA_CH0, ADC_TransferDescriptors[0].xfercfg);&lt;BR /&gt;Chip_DMA_SetValidChannel(LPC_DMA, DMA_CH0);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void SCT_PWM_Generate(void)&lt;BR /&gt;{&lt;BR /&gt;/* Initialize the SCT2 as PWM and set frequency */&lt;BR /&gt;Chip_SCTPWM_Init(LPC_SCT2);&lt;BR /&gt;Chip_SCTPWM_SetRate(LPC_SCT2, SCT_PWM_RATE);&lt;/P&gt;&lt;P&gt;/* Use SCT2_OUT3 pin */&lt;BR /&gt;Chip_SCTPWM_SetOutPin(LPC_SCT2, SCT_PWM_OUT, SCT_PWM_PIN_OUT);&lt;/P&gt;&lt;P&gt;/* Start with 50% duty cycle */&lt;BR /&gt;Chip_SCTPWM_SetDutyCycle(LPC_SCT2, SCT_PWM_OUT, Chip_SCTPWM_PercentageToTicks(LPC_SCT2, 50));&lt;BR /&gt;Chip_SCTPWM_Start(LPC_SCT2);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/***&lt;BR /&gt;* _ ____ ____&lt;BR /&gt;* / \ | _ \ / ___|&lt;BR /&gt;* / _ \ | | | | |&lt;BR /&gt;* / ___ \| |_| | |___&lt;BR /&gt;* /_/__ \_\____/ \____|&lt;BR /&gt;* / ___| ___| |_ _ _ _ __&lt;BR /&gt;* \___ \ / _ \ __| | | | '_ \&lt;BR /&gt;* ___) | __/ |_| |_| | |_) |&lt;BR /&gt;* |____/ \___|\__|\__,_| .__/&lt;BR /&gt;* |_|&lt;BR /&gt;*/&lt;BR /&gt;void ADC_Setup(void)&lt;BR /&gt;{&lt;BR /&gt;/*Set Asynch Clock to the Main clock*/&lt;BR /&gt;// LPC_SYSCON-&amp;gt;ADCCLKSEL = 0;&lt;BR /&gt;// Chip_Clock_SetADCASYNCSource(SYSCTL_ADCASYNCCLKSRC_IRC);&lt;BR /&gt;//Set the divider to 1 and enable. note, the HALT bit (30) and RESET (29) are not in the manual&lt;BR /&gt;// LPC_SYSCON-&amp;gt;ADCCLKDIV = 0;&lt;/P&gt;&lt;P&gt;/* Initialization ADC to 12 bit and set clock divide to 1 to operate synchronously at System clock */&lt;BR /&gt;Chip_ADC_Init(LPC_ADC0, ADC_CR_BITACC(0) | ADC_CR_CLKDIV(0)| ADC_CR_ASYNMODE);&lt;BR /&gt;Chip_ADC_SetClockRate(LPC_ADC0, ADC_MAX_SAMPLE_RATE);&lt;BR /&gt;//select ADC Channel 0 as input&lt;BR /&gt;Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 8, IOCON_FUNC0 | IOCON_MODE_INACT | IOCON_ADMODE_EN);&lt;BR /&gt;Chip_SWM_Init();&lt;BR /&gt;Chip_SWM_EnableFixedPin(SWM_FIXED_ADC0_0); //P0_8&lt;/P&gt;&lt;P&gt;Chip_ADC_SetADC0Input(LPC_ADC0, ADC_INSEL_ADC0);&lt;/P&gt;&lt;P&gt;//Setup ADC0_SEQA_IRQ&lt;BR /&gt;Chip_ADC_SetupSequencer(LPC_ADC0,ADC_SEQA_IDX,&lt;BR /&gt;ADC_SEQ_CTRL_SEQ_ENA |&lt;BR /&gt;ADC_SEQ_CTRL_CHANSEL(ADC_INPUT_CHANNEL) |&lt;BR /&gt;ADC0_SEQ_CTRL_HWTRIG_SCT2_OUT3 |&lt;BR /&gt;// ADC_SEQ_CTRL_HWTRIG_POLPOS |&lt;BR /&gt;// ADC_SEQ_CTRL_HWTRIG_SYNCBYPASS |&lt;BR /&gt;ADC_SEQ_CTRL_MODE_EOS);&lt;BR /&gt;/* Enable Sequence A interrupt */&lt;BR /&gt;Chip_ADC_EnableInt(LPC_ADC0, ADC_INTEN_SEQA_ENABLE);&lt;/P&gt;&lt;P&gt;/* Calibrate ADC */&lt;BR /&gt;Chip_ADC_StartCalibration(LPC_ADC0);&lt;BR /&gt;while (!(Chip_ADC_IsCalibrationDone(LPC_ADC0))) {}&lt;/P&gt;&lt;P&gt;Chip_ADC_ClearFlags(LPC_ADC0, Chip_ADC_GetFlags(LPC_ADC0));&lt;BR /&gt;// Chip_ADC_EnableInt(LPC_ADC0, ADC_INTEN_SEQA_ENABLE);&lt;BR /&gt;// NVIC_EnableIRQ(ADC0_SEQA_IRQn);&lt;BR /&gt;Chip_ADC_EnableSequencer(LPC_ADC0, ADC_SEQA_IDX);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;int main(void)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;/* Setup SystemCoreClock and any needed board code */&lt;BR /&gt;SystemCoreClockUpdate();&lt;BR /&gt;Board_Init();&lt;/P&gt;&lt;P&gt;DMA_Setup();&lt;BR /&gt;ADC_Setup();&lt;BR /&gt;SCT_PWM_Generate();&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;while(1)&lt;BR /&gt;{}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 08:14:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC1549-How-to-use-the-DMA-with-the-ADC/m-p/1216661#M43624</guid>
      <dc:creator>jespermadsen</dc:creator>
      <dc:date>2021-01-19T08:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: LPC1549: How to use the DMA with the ADC</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC1549-How-to-use-the-DMA-with-the-ADC/m-p/1217580#M43645</link>
      <description>&lt;P&gt;Hello Jesper,&lt;/P&gt;
&lt;P&gt;“There are some ADC results in the buffer. But there are zeros and not completely processed data there too.”&lt;/P&gt;
&lt;P&gt;-&amp;gt; Dose the data all right when only use ADC,without DMA?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BR&lt;/P&gt;
&lt;P&gt;Alice&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2021 03:43:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC1549-How-to-use-the-DMA-with-the-ADC/m-p/1217580#M43645</guid>
      <dc:creator>Alice_Yang</dc:creator>
      <dc:date>2021-01-20T03:43:55Z</dc:date>
    </item>
    <item>
      <title>Re: LPC1549: How to use the DMA with the ADC</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC1549-How-to-use-the-DMA-with-the-ADC/m-p/1217876#M43653</link>
      <description>&lt;P&gt;Hello Alice&lt;/P&gt;&lt;P&gt;If I keep a breakpoint in the loop and break it every time the interrupt fires, the value is not updated.&lt;/P&gt;&lt;P&gt;But if the MCU runs free for a while, and then I stop it, the value is correct.&lt;/P&gt;&lt;P&gt;Maybe the ADC interrupt is not correctly setup?&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Jesper&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2021 10:45:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC1549-How-to-use-the-DMA-with-the-ADC/m-p/1217876#M43653</guid>
      <dc:creator>jespermadsen</dc:creator>
      <dc:date>2021-01-20T10:45:28Z</dc:date>
    </item>
    <item>
      <title>Re: LPC1549: How to use the DMA with the ADC</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC1549-How-to-use-the-DMA-with-the-ADC/m-p/1218700#M43680</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;"Maybe the ADC interrupt is not correctly setup?"&lt;/P&gt;
&lt;P&gt;-&amp;gt; No, when you use breakpoint, there is some delay by software.&lt;/P&gt;
&lt;P&gt;I recommend you set block to lock problem, for example without DMA, just check whether ADC&lt;/P&gt;
&lt;P&gt;, then add DMA...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2021 09:15:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC1549-How-to-use-the-DMA-with-the-ADC/m-p/1218700#M43680</guid>
      <dc:creator>Alice_Yang</dc:creator>
      <dc:date>2021-01-21T09:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: LPC1549: How to use the DMA with the ADC</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC1549-How-to-use-the-DMA-with-the-ADC/m-p/1218829#M43687</link>
      <description>&lt;P&gt;Hello Alice.&lt;/P&gt;&lt;P&gt;Now the values comes into the buffer.. Thanks.&lt;/P&gt;&lt;P&gt;I removed the boardlib and made some small changes:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;#include "chip.h"

#include &amp;lt;cr_section_macros.h&amp;gt;

#define NUM_BUFFERS 4
#define DMA_TRANSFER_SIZE 8
#define ADC_INPUT_CHANNEL 0

#define SCT_PWM_RATE   10000          /* PWM frequency 10 KHz */
#define SCT_PWM_PIN_OUT    3          /* COUT3 Generate square wave */
#define SCT_PWM_OUT        3          /* Index of OUT PWM */

uint16_t adcOut;

DMA_CHDESC_T ADC_TransferDescriptors[NUM_BUFFERS] __attribute__ ((aligned(512)));


uint16_t CapturedData[32];

uint16_t DMA_Sum=0;

/**
 *
 * ADC IRQ not Used right now... Only for testing
 */
void ADC_SEQA_IRQHandler(void)
{
            /* If SeqA flags is set i.e. data in global register is valid then read it */
        Chip_ADC_ClearFlags(LPC_ADC0,0xFFFFFFFF);
}


void DMA_IRQHandler(void)
{
        static uint16_t DMA_Sum=0;

        DMA_Sum++;

         if(DMA_Sum ==8)
         {
           DMA_Sum=4;
         }


     /* Error interrupt on channel 0? */
     if ((Chip_DMA_GetIntStatus(LPC_DMA) &amp;amp; DMA_INTSTAT_ACTIVEERRINT) != 0)
     {
          /* This shouldn't happen for this simple DMA example, so set the LED
             to indicate an error occurred. This is the correct method to clear
             an abort. */
          Chip_DMA_DisableChannel(LPC_DMA, DMA_CH0);
          while ((Chip_DMA_GetBusyChannels(LPC_DMA) &amp;amp; (1 &amp;lt;&amp;lt; DMA_CH0)) != 0) {}
          Chip_DMA_AbortChannel(LPC_DMA, DMA_CH0);
          Chip_DMA_ClearErrorIntChannel(LPC_DMA, DMA_CH0);
          Chip_DMA_EnableChannel(LPC_DMA, DMA_CH0);
     }

     /* Clear DMA interrupt for the channel */
	Chip_DMA_ClearActiveIntAChannel(LPC_DMA, DMA_CH0);
}





     /***
      *      ____  __  __    _
      *     |  _ \|  \/  |  / \
      *     | | | | |\/| | / _ \
      *     | |_| | |  | |/ ___ \
      *     |____/|_|  |_/_/   \_\
      *     / ___|  ___| |_ _   _ _ __
      *     \___ \ / _ \ __| | | | '_ \
      *      ___) |  __/ |_| |_| | |_) |
      *     |____/ \___|\__|\__,_| .__/
      *                          |_|
      */
void DMA_Setup(void)
{
        DMA_CHDESC_T Initial_DMA_Descriptor;

     ADC_TransferDescriptors[0].source = (uint32_t)&amp;amp;LPC_ADC0-&amp;gt;SEQ_GDAT[0];
     ADC_TransferDescriptors[1].source = (uint32_t)&amp;amp;LPC_ADC0-&amp;gt;SEQ_GDAT[0];
     ADC_TransferDescriptors[2].source = (uint32_t)&amp;amp;LPC_ADC0-&amp;gt;SEQ_GDAT[0];
     ADC_TransferDescriptors[3].source = (uint32_t)&amp;amp;LPC_ADC0-&amp;gt;SEQ_GDAT[0];


     ADC_TransferDescriptors[0].dest = DMA_ADDR(&amp;amp;CapturedData[(0+1)*DMA_TRANSFER_SIZE-1]);
     ADC_TransferDescriptors[1].dest = DMA_ADDR(&amp;amp;CapturedData[(1+1)*DMA_TRANSFER_SIZE-1]);
     ADC_TransferDescriptors[2].dest = DMA_ADDR(&amp;amp;CapturedData[(2+1)*DMA_TRANSFER_SIZE-1]);
     ADC_TransferDescriptors[3].dest = DMA_ADDR(&amp;amp;CapturedData[(3+1)*DMA_TRANSFER_SIZE-1]);

     //The initial DMA desciptor is the same as the 1st transfer descriptor.   It
     //Will link into the 2nd of the main descriptors.

     ADC_TransferDescriptors[0].next = (uint32_t)&amp;amp;ADC_TransferDescriptors[1];
     ADC_TransferDescriptors[1].next = (uint32_t)&amp;amp;ADC_TransferDescriptors[2];
     ADC_TransferDescriptors[2].next = (uint32_t)&amp;amp;ADC_TransferDescriptors[3];

     //Link back to the 1st descriptor
     ADC_TransferDescriptors[3].next = (uint32_t)&amp;amp;ADC_TransferDescriptors[0];

     //For a test,  stop the transfers here.   The sine wave will look fine.
     //ADC_TransferDescriptors[3].next = 0;

     ADC_TransferDescriptors[0].xfercfg = (DMA_XFERCFG_CFGVALID |
                               DMA_XFERCFG_RELOAD  |
                               DMA_XFERCFG_SETINTA |
                               DMA_XFERCFG_WIDTH_16 |
                               DMA_XFERCFG_SRCINC_0 |
                               DMA_XFERCFG_DSTINC_1 |
                               DMA_XFERCFG_XFERCOUNT(DMA_TRANSFER_SIZE));

     ADC_TransferDescriptors[1].xfercfg = ADC_TransferDescriptors[0].xfercfg;
     ADC_TransferDescriptors[2].xfercfg = ADC_TransferDescriptors[0].xfercfg;

     ADC_TransferDescriptors[3].xfercfg = (DMA_XFERCFG_CFGVALID |
                               DMA_XFERCFG_RELOAD  |
                               DMA_XFERCFG_SETINTA |
                              DMA_XFERCFG_WIDTH_16 |
                              DMA_XFERCFG_SRCINC_0 |
                              DMA_XFERCFG_DSTINC_1 |
                              DMA_XFERCFG_XFERCOUNT(DMA_TRANSFER_SIZE));

     Initial_DMA_Descriptor.source = ADC_TransferDescriptors[0].source;
     Initial_DMA_Descriptor.dest =   ADC_TransferDescriptors[0].dest;
     Initial_DMA_Descriptor.next =  (uint32_t)&amp;amp;ADC_TransferDescriptors[1];
     Initial_DMA_Descriptor.xfercfg = ADC_TransferDescriptors[0].xfercfg;

     /* DMA initialization - enable DMA clocking and reset DMA if needed */
     Chip_DMA_Init(LPC_DMA);

     /* Enable DMA controller and use driver provided DMA table for current descriptors */
     Chip_DMA_Enable(LPC_DMA);
     Chip_DMA_SetSRAMBase(LPC_DMA, DMA_ADDR(Chip_DMA_Table));

     /* Setup channel 0 for the following configuration:
        - High channel priority
        - Interrupt A fires on descriptor completion */
     Chip_DMA_EnableChannel(LPC_DMA, DMA_CH0);
     Chip_DMA_EnableIntChannel(LPC_DMA, DMA_CH0);
     Chip_DMA_SetupChannelConfig(LPC_DMA, DMA_CH0,     //(DMA_CFG_PERIPHREQEN     |
                                   (DMA_CFG_HWTRIGEN        |
                                    DMA_CFG_TRIGBURST_BURST |
                                    DMA_CFG_TRIGTYPE_EDGE   |
                                    DMA_CFG_TRIGPOL_HIGH  |    //DMA_CFG_TRIGPOL_HIGH
                                    DMA_CFG_BURSTPOWER_1    |
                                    DMA_CFG_CHPRIORITY(0)
                                    )
                                    );


     //make sure ADC Sequence A interrupts is selected for for a DMA trigger
     Chip_INMUX_SetDMATrigger(DMA_CH0, DMATRIG_ADC0_SEQA_IRQ);

     /* Enable DMA interrupt */
     NVIC_EnableIRQ(DMA_IRQn);

     // The 1st descriptor is set up through the registers.

     /* Setup transfer descriptor and validate it */
     Chip_DMA_SetupTranChannel(LPC_DMA, DMA_CH0, &amp;amp;Initial_DMA_Descriptor);

     //Use the transfer configuration for our 4 main descriptors
     Chip_DMA_SetupChannelTransfer(LPC_DMA, DMA_CH0,     ADC_TransferDescriptors[0].xfercfg);
     Chip_DMA_SetValidChannel(LPC_DMA, DMA_CH0);
}

void SCT_PWM_Generate(void)
{
     /* Initialize the SCT2 as PWM and set frequency */
     Chip_SCTPWM_Init(LPC_SCT2);
     Chip_SCTPWM_SetRate(LPC_SCT2, SCT_PWM_RATE);

     /* Use SCT2_OUT3 pin */
     Chip_SCTPWM_SetOutPin(LPC_SCT2, SCT_PWM_OUT, SCT_PWM_PIN_OUT);

     /* Start with 50% duty cycle */
     Chip_SCTPWM_SetDutyCycle(LPC_SCT2, SCT_PWM_OUT, Chip_SCTPWM_PercentageToTicks(LPC_SCT2, 50));
     Chip_SCTPWM_Start(LPC_SCT2);
}


     /***
           *         _    ____   ____
           *        / \  |  _ \ / ___|
           *       / _ \ | | | | |
           *      / ___ \| |_| | |___
           *     /_/__ \_\____/ \____|
           *     / ___|  ___| |_ _   _ _ __
           *     \___ \ / _ \ __| | | | '_ \
           *      ___) |  __/ |_| |_| | |_) |
           *     |____/ \___|\__|\__,_| .__/
           *                          |_|
           */
void ADC_Setup(void)
{
     /* Initialization ADC to 12 bit and set clock divide to 1 to operate synchronously at System clock */
    Chip_ADC_Init(LPC_ADC0, ADC_CR_BITACC(0) | ADC_CR_CLKDIV(0)| ADC_CR_ASYNMODE);
	Chip_ADC_SetClockRate(LPC_ADC0, ADC_MAX_SAMPLE_RATE);
    //select ADC Channel 0 as input
    Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 8, IOCON_FUNC0 | IOCON_MODE_INACT | IOCON_ADMODE_EN);

    Chip_SWM_Init();
	Chip_SWM_EnableFixedPin(SWM_FIXED_ADC0_0);	//P0_8

    Chip_ADC_SetADC0Input(LPC_ADC0, ADC_INSEL_ADC0);

    //Setup ADC0_SEQA_IRQ
    Chip_ADC_SetupSequencer(LPC_ADC0,ADC_SEQA_IDX,
                              ADC_SEQ_CTRL_SEQ_ENA |
                              ADC_SEQ_CTRL_CHANSEL(ADC_INPUT_CHANNEL) |
                              ADC0_SEQ_CTRL_HWTRIG_SCT2_OUT3 |
//                              ADC_SEQ_CTRL_HWTRIG_POLPOS |
//                              ADC_SEQ_CTRL_HWTRIG_SYNCBYPASS |
                              ADC_SEQ_CTRL_MODE_EOS);

    /* Enable Sequence A interrupt */
	Chip_ADC_EnableInt(LPC_ADC0, ADC_INTEN_SEQA_ENABLE);

	/* Calibrate ADC */
	Chip_ADC_SetTrim(LPC_ADC0, ADC_TRIM_VRANGE_HIGHV);
	Chip_ADC_StartCalibration(LPC_ADC0);
	while (!(Chip_ADC_IsCalibrationDone(LPC_ADC0))) {}

	Chip_ADC_ClearFlags(LPC_ADC0, Chip_ADC_GetFlags(LPC_ADC0));
//	NVIC_EnableIRQ(ADC0_SEQA_IRQn);
	Chip_ADC_EnableSequencer(LPC_ADC0, ADC_SEQA_IDX);

}

int main(void) {
    // Read clock settings and update SystemCoreClock variable
    SystemCoreClockUpdate();

	Chip_GPIO_Init(LPC_GPIO);
	Chip_GPIO_SetPinDIROutput(LPC_GPIO, 0, 0);

    DMA_Setup();
    ADC_Setup();
    SCT_PWM_Generate();


    while(1)
    {}
    return 0 ;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2021 11:48:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC1549-How-to-use-the-DMA-with-the-ADC/m-p/1218829#M43687</guid>
      <dc:creator>jespermadsen</dc:creator>
      <dc:date>2021-01-21T11:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: LPC1549: How to use the DMA with the ADC</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC1549-How-to-use-the-DMA-with-the-ADC/m-p/1219634#M43709</link>
      <description>&lt;P&gt;There are still some problems in the program.&lt;/P&gt;&lt;P&gt;I tried to set it up with&lt;/P&gt;&lt;P&gt;DMA_TRANSFER_SIZE 64&lt;/P&gt;&lt;P&gt;SCT_PWM_RATE 5000&lt;/P&gt;&lt;P&gt;And a 70 Hz triangle signal on the ADC-input.&lt;/P&gt;&lt;P&gt;The samples with DMA are chopped as you see in the pictures&lt;/P&gt;&lt;P&gt;The samples without DMA has only one jump.&lt;/P&gt;&lt;P&gt;How can this be?&lt;/P&gt;&lt;P&gt;PS: The curves in the figurs are not in fase.&lt;/P&gt;&lt;P&gt;ADC-input:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ADC_input.png" style="width: 999px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/135579iB635D15A99744CA9/image-size/large?v=v2&amp;amp;px=999" role="button" title="ADC_input.png" alt="ADC_input.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Samples without DMA:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ADC_samples_no_DMA.png" style="width: 999px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/135580i2D61B279CAE18F36/image-size/large?v=v2&amp;amp;px=999" role="button" title="ADC_samples_no_DMA.png" alt="ADC_samples_no_DMA.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Samples with DMA:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ADC_samples.png" style="width: 999px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/135581i9D0E1A8BD1FCABCE/image-size/large?v=v2&amp;amp;px=999" role="button" title="ADC_samples.png" alt="ADC_samples.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2021 13:05:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC1549-How-to-use-the-DMA-with-the-ADC/m-p/1219634#M43709</guid>
      <dc:creator>jespermadsen</dc:creator>
      <dc:date>2021-01-22T13:05:44Z</dc:date>
    </item>
  </channel>
</rss>

