打印
[技术问答]

NM1200 ADC Sequential Mode 使用问题

[复制链接]
987|9
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
ltbkey|  楼主 | 2019-1-10 22:57 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
我在使用NM1200使用PWM触发ADC时,当使能ADC模块的SEQEN(ADC_SEQCTL[0])时,PWM触发ADC动作就不工作了。当清除SEQEN时,PWM才可以正常的触发ADC,并完成转换。请问这是什么问题?
沙发
ltbkey|  楼主 | 2019-1-10 23:11 | 只看该作者
使用  ADC Sequential Mode 时,目前有问题的配置如下
        ADC->CTL = 0;
        ADC->EXTSMPT = 0;                                                                                                                        //6 SAMPLE CLK
        ADC->CHEN = ADC3_V_BUS;
        ADC->SEQCTL = (RISING_TRIGGER << ADC_SEQCTL_TRG1TYPE_Pos);       
        ADC->TRGDLY = 8;                                                                                                                        //4*DELAY*ADC_CLK = 4us
        ADC->CTL |= ADC_CTL_ADCIEN_Msk;
        ADC->SEQCTL |= ADC_SEQCTL_SEQEN_Msk;
        ADC->CTL |= ADC_CTL_HWTRGEN_Msk | ADC_CTL_HWTRGSEL_Msk | ADC_CTL_ADCEN_Msk;
        ADC->CTL |= ADC_CTL_SWTRG_Msk;
pwm已经正常运行并输出波形,pwm触发信号配置如下;
        PWM->ADCTCTL0 = PWM_ADCTCTL0_CDTRGEN0_Msk;
目前没有找到问题,请教有经验的大神,看看配置哪里有问题。谢谢!

使用特权

评论回复
板凳
antusheng| | 2019-1-10 23:30 | 只看该作者
SEQEN这个是啥,不清楚啊。这个系列资料不公开吧

使用特权

评论回复
地板
yiy| | 2019-1-10 23:36 | 只看该作者
看手册说明,这个位的作用是啥。

使用特权

评论回复
5
ltbkey|  楼主 | 2019-1-11 08:49 | 只看该作者
手册里这样说:
6.12.5.8 PWM Sequential
Support sequential mode for 2 channels to reduce half interrupt frequency. When the SEQEN
(ADC_SEQCTL[0]) is set to high to enable A/D PWM sequential function, setting the
TRG1SRC/TRG1TYPE (ADC_SEQCTL[11:8]) and TRG2SRC/TRG2TYPE
(ADC_SEQCTL[19:16]) are to select external trigger input from the PWM channel 0/2/4, type can
be rising/center/falling/period, When ADC sequential mode is enabled, two of three ADC channels
from 0 to 2 will automatically convert analog data in the sequence of channel [0, 1] or channel[1,2]
or channel[0,2] defined by MODESEL (ADC_SEQCTL[3:2]). By the way, if SEQTYPE
(ADC_SEQCTL[1]) is set to low, ADC delay time is only inserted before the first conversion. The
second conversion starts immediately after the first conversion is completed. (for 2/3-shunt type),
if SEQTYPE (ADC_SEQCTL[1]) is set to high, ADC delay time is inserted before each
conversion. (for 1-shunt type), By the way, Valid ADC channel are CH0~2 in 2/3-shunt type, Valid
ADC channel are CH0~7 in 1-shunt type, Figure 6.12-8 and Figure 6.12-9 show the function
diagram.
For 2-shunt Mode (SEQTYPE=0), ADC uses 2 channels among channel 0, 1 and 2, selected by
MODESEL and 1 PWM trigger sources are selected TRG1SRC, then ADC start to convert and
save data to ADC_SEQDAT0. Then, immediately start next conversion without delay and store
data to ADC_SEQDAT1. It also supports trigger delay timer DELAY (ADC_TRGDLY[7:0]).

For 1-shunt Mode (SEQTYPE=1), ADC uses 1 channel and 2 PWM trigger sources are selected
TRG1SRC and TRG2SRC. It’s first-come-first-service strategy if TRG2 triggers first, then ADC
start to convert and save data to ADC_SEQDAT0. Then, wait for TRG1 for next conversion and
store data to ADC_SEQDAT1. It also supports trigger delay timer DELAY (ADC_TRGDLY[7:0]).

不知道有没有用过的大神?

使用特权

评论回复
6
734774645| | 2019-1-12 14:21 | 只看该作者
能完成你要的功能吗,如果那么设置。

使用特权

评论回复
7
xuanhuanzi| | 2019-1-12 23:36 | 只看该作者
/****************************************************************************
* [url=home.php?mod=space&uid=288409]@file[/url]     main.c
* [url=home.php?mod=space&uid=895143]@version[/url]  V2.0
* $Revision: 4 $
* $Date: 14/11/27 2:37p $
* [url=home.php?mod=space&uid=247401]@brief[/url]    Demonstrate how to trigger ADC by PWM.
* @note
* Copyright (C) 2014 Nuvoton Technology Corp. All rights reserved.
*
******************************************************************************/
#include <stdio.h>
#include "NUC200Series.h"


#define PLL_CLOCK       50000000


/*---------------------------------------------------------------------------------------------------------*/
/* Define Function Prototypes                                                                              */
/*---------------------------------------------------------------------------------------------------------*/
void SYS_Init(void);
void UART0_Init(void);
void ADC_PWMTrigTest_SingleOpMode(void);


void SYS_Init(void)
{
    /*---------------------------------------------------------------------------------------------------------*/
    /* Init System Clock                                                                                       */
    /*---------------------------------------------------------------------------------------------------------*/

    /* Enable Internal RC 22.1184MHz clock */
    CLK_EnableXtalRC(CLK_PWRCON_OSC22M_EN_Msk);

    /* Waiting for Internal RC clock ready */
    CLK_WaitClockReady(CLK_CLKSTATUS_OSC22M_STB_Msk);

    /* Switch HCLK clock source to Internal RC and HCLK source divide 1 */
    CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HIRC, CLK_CLKDIV_HCLK(1));

    /* Enable external XTAL 12MHz clock */
    CLK_EnableXtalRC(CLK_PWRCON_XTL12M_EN_Msk);

    /* Waiting for external XTAL clock ready */
    CLK_WaitClockReady(CLK_CLKSTATUS_XTL12M_STB_Msk);

    /* Set core clock as PLL_CLOCK from PLL */
    CLK_SetCoreClock(PLL_CLOCK);

    /* Enable UART module clock */
    CLK_EnableModuleClock(UART0_MODULE);

    /* Enable ADC module clock */
    CLK_EnableModuleClock(ADC_MODULE);

    /* Enable PWM01 module clock */
    CLK_EnableModuleClock(PWM01_MODULE);

    /* Select UART module clock source */
    CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_HXT, CLK_CLKDIV_UART(1));

    /* Select PWM01 module clock source */
    CLK_SetModuleClock(PWM01_MODULE, CLK_CLKSEL1_PWM01_S_HXT, 0);

    /* ADC clock source is 22.1184MHz, set divider to 7, ADC clock is 22.1184/7 MHz */
    CLK_SetModuleClock(ADC_MODULE, CLK_CLKSEL1_ADC_S_HIRC, CLK_CLKDIV_ADC(7));

    /*---------------------------------------------------------------------------------------------------------*/
    /* Init I/O Multi-function                                                                                 */
    /*---------------------------------------------------------------------------------------------------------*/

    /* Set GPB multi-function pins for UART0 RXD and TXD */
    SYS->GPB_MFP &= ~(SYS_GPB_MFP_PB0_Msk | SYS_GPB_MFP_PB1_Msk);
    SYS->GPB_MFP |= SYS_GPB_MFP_PB0_UART0_RXD | SYS_GPB_MFP_PB1_UART0_TXD;

    /* Disable the GPA0 - GPA3 digital input path to avoid the leakage current. */
    GPIO_DISABLE_DIGITAL_PATH(PA, 0xF);

    /* Configure the GPA0 - GPA3 ADC analog input pins */
    SYS->GPA_MFP &= ~(SYS_GPA_MFP_PA0_Msk | SYS_GPA_MFP_PA1_Msk | SYS_GPA_MFP_PA2_Msk | SYS_GPA_MFP_PA3_Msk) ;
    SYS->GPA_MFP |= SYS_GPA_MFP_PA0_ADC0 | SYS_GPA_MFP_PA1_ADC1 | SYS_GPA_MFP_PA2_ADC2 | SYS_GPA_MFP_PA3_ADC3 ;
    SYS->ALT_MFP1 = 0;

    /* Configure the PA12 as PWM0 output pin */
    SYS->GPA_MFP &= ~SYS_GPA_MFP_PA12_Msk;
    SYS->GPA_MFP |= SYS_GPA_MFP_PA12_PWM0;


}

/*---------------------------------------------------------------------------------------------------------*/
/* Init UART                                                                                               */
/*---------------------------------------------------------------------------------------------------------*/
void UART0_Init()
{
    /* Reset IP */
    SYS_ResetModule(UART0_RST);

    /* Configure UART0 and set UART0 Baudrate */
    UART_Open(UART0, 115200);
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function: ADC_PWMTrigTest_SingleOpMode                                                                  */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*   None.                                                                                                 */
/*                                                                                                         */
/* Returns:                                                                                                */
/*   None.                                                                                                 */
/*                                                                                                         */
/* Description:                                                                                            */
/*   ADC hardware trigger test.                                                                            */
/*---------------------------------------------------------------------------------------------------------*/
void ADC_PWMTrigTest_SingleOpMode()
{
    printf("\n<<< PWM trigger test (Single mode) >>>\n");

    /* Set the ADC operation mode as single, input mode as single-end and enable the analog input channel 2 */
    ADC_Open(ADC, ADC_ADCR_DIFFEN_SINGLE_END, ADC_ADCR_ADMD_SINGLE, 0x1 << 2);

    /* Power on ADC module */
    ADC_POWER_ON(ADC);

    /* Configure the hardware trigger condition and enable hardware trigger; PWM trigger delay: (4*10) system clock cycles*/
    ADC_EnableHWTrigger(ADC, ADC_ADCR_TRGS_PWM, 0);

    /* Clear the A/D interrupt flag for safe */
    ADC_CLR_INT_FLAG(ADC, ADC_ADF_INT);

    /* Center-aligned type; one-shot mode. */
    PWM_SET_ALIGNED_TYPE(PWMA, 0x1, PWM_CENTER_ALIGNED);
    /* Clock prescaler */
    PWM_SET_PRESCALER(PWMA, 0, 2);
    /* Timer 0 divisor=1 */
    PWM_SET_DIVIDER(PWMA, 0, PWM_CLK_DIV_1);
    /* PWM counter value */ /* PWM frequency = PWM clock source/(clock prescaler setting + 1)/divisor/(CNR+1) */
    PWM_SET_CNR(PWMA, 0, 5);
    /* PWM compare value */
    PWM_SET_CMR(PWMA, 0, 1);
    /* Enable PWM0 to trigger ADC */
    PWM_EnableADCTrigger(PWMA, 0, 0);
    /* PWM0 pin output enabled. PWM frequency 1MHz, duty 30%. */
    PWM_EnableOutput(PWMA, 0x1);

    /* Start PWM module */
    PWM_Start(PWMA, 0x1);

    /* Wait conversion done */
    while(!ADC_GET_INT_FLAG(ADC, ADC_ADF_INT));

    /* Clear the ADC interrupt flag */
    ADC_CLR_INT_FLAG(ADC, ADC_ADF_INT);

    printf("Channel 2: 0x%X\n", ADC_GET_CONVERSION_DATA(ADC, 2));

    /* Disable ADC */
    ADC_POWER_DOWN(ADC);
    /* Stop PWM generation */
    PWM_ForceStop(PWMA, 0x1);

}





/*---------------------------------------------------------------------------------------------------------*/
/* MAIN function                                                                                           */
/*---------------------------------------------------------------------------------------------------------*/
main(void)
{

    /* Unlock protected registers */
    SYS_UnlockReg();

    /* Init System, IP clock and multi-function I/O */
    SYS_Init();

    /* Lock protected registers */
    SYS_LockReg();

    /* Init UART0 for printf */
    UART0_Init();

    /*---------------------------------------------------------------------------------------------------------*/
    /* SAMPLE CODE                                                                                             */
    /*---------------------------------------------------------------------------------------------------------*/

    printf("\nSystem clock rate: %d Hz", SystemCoreClock);

    /* ADC hardware trigger test */
    ADC_PWMTrigTest_SingleOpMode();

    /* Disable ADC module */
    ADC_Close(ADC);

    /* Disable ADC IP clock */
    CLK_DisableModuleClock(ADC_MODULE);

    /* Disable External Interrupt */
    NVIC_DisableIRQ(ADC_IRQn);

    printf("\nExit ADC sample code\n");

    while(1);

}

使用特权

评论回复
8
xuanhuanzi| | 2019-1-12 23:37 | 只看该作者
用库函数操作啊。寄存器的,看不太懂。

使用特权

评论回复
9
xuanhuanzi| | 2019-1-12 23:40 | 只看该作者
搞错了,上面不是1200的,看错了。

使用特权

评论回复
10
xuanhuanzi| | 2019-1-12 23:41 | 只看该作者

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

3

帖子

0

粉丝