821|1

107

帖子

1

TA的资源

一粒金砂(高级)

楼主
 

【国民技术车规MCU N32A455开发板】 N32A455 ADC模块测试 [复制链接]

本帖最后由 尹小舟 于 2024-2-27 08:58 编辑

  实验目的:使用软件触发采集板子的电位计的电压信号。

  N32A455 ADC简介:

         N32A455xxL7系列采用 32 bit ARM Cortex-M4F内核,最高工作主频144MHz,内部有4 个 12bit 4.7Msps 高速 ADC,可配置为 12/10/8/6bit 模式,6bit 模式下采样率高达 8.9Msps,多达 38 路外部单端输入通道,支持差分模式,ADC1 支持 9 个外部通道,ADC2 支持 12 个外部通道,ADC3 支持 15 个外部通道,ADC4 支持 13 个 外部通道,并且 ADC 的输入时钟的最大频率为 80MHz,还支持模拟看门狗,所有模拟接口支持 1.8~3.6V 全电压工作。

ADC特性:

       

ADC 使能控制: 

        只有在上电过程完成后,才能进行下一步,可以通过轮询 ADC_CTRL3.RDY 来检查上电是否完成。设置 ADC_CTRL2.ON 来打开 或关闭ADC,打开ADC或重新打开后要校准ADC

 

函数说明:启用或禁用指定的ADC外设。

参数说明:ADCx 其中x可以为1,2,3或4来选择ADC外设。

                  Cmd   ADCx外设的新状态,取值包括:ENABLE或DISABLE。

void ADC_Enable(ADC_Module* ADCx, FunctionalState Cmd)
{
    uint32_t i =0;
    /* Check the parameters */
    assert_param(IsAdcModule(ADCx));
    assert_param(IS_FUNCTIONAL_STATE(Cmd));
    if (Cmd != DISABLE)
    {
        /* Set the AD_ON bit to wake up the ADC from power down mode */
        ADCx->CTRL2 |= CTRL2_AD_ON_SET;
    }
    else
    {
        /* Disable the selected ADC peripheral */
        ADCx->CTRL2 &= CTRL2_AD_ON_RESET;
    }
    /*Wait for ADC to filter burr after a delay of more than 8us */
    for(i=0;i<0x128;i++);
}

 

函数说明:启用ADC校准

void ADC_StartCalibration(ADC_Module* ADCx)
{
    uint32_t i =0;
    /* Check the parameters */
    assert_param(IsAdcModule(ADCx));
    /* Enable the selected ADC calibration process */
    if(ADCx->CALFACT==0)
        ADCx->CTRL2 |= CTRL2_CAL_SET;
    /*Wait for ADC to filter burr after a delay of more than 8us */
    for(i=0;i<0x128;i++);
}

 

ADC 初始化:

         1.配置ADC 初始化结构体,调用初始化参数

         2.使能ADC

         3.校准ADC

typedef struct
{
    uint32_t WorkMode; /*!< Configures the ADC to operate in independent or
                            dual mode.
                            This parameter can be a value of @ref  ADC_mode */

    FunctionalState MultiChEn; /*!< Specifies whether the conversion is performed in
                                           Scan (multichannels) or Single (one channel) mode.
                                           This parameter can be set to ENABLE or DISABLE */

    FunctionalState ContinueConvEn; /*!< Specifies whether the conversion is performed in
                                                 Continuous or Single mode.
                                                 This parameter can be set to ENABLE or DISABLE. */

    uint32_t ExtTrigSelect; /*!< Defines the external trigger used to start the analog
                                        to digital conversion of regular channels. This parameter
                                        can be a value of @ref
                               ADC_external_trigger_sources_for_regular_channels_conversion */

    uint32_t DatAlign; /*!< Specifies whether the ADC data alignment is left or right.
                                 This parameter can be a value of @ref ADC_data_align */

    uint8_t ChsNumber; /*!< Specifies the number of ADC channels that will be converted
                                   using the sequencer for regular channel group.
                                   This parameter must range from 1 to 16. */
} ADC_InitType;

 

硬件电路:

 

 

 

 

使用的是PB15  用的是ADC4

软件代码:

#include "main.h"
#include "stdio.h"

/** @addtogroup ADC_ADC1_DMA
 * @{
 */

ADC_InitType ADC_InitStructure;
DMA_InitType DMA_InitStructure;
__IO uint16_t ADC4ConvertedValue[5];

void RCC_Configuration(void);
void GPIO_Configuration(void);
uint16_t ADC_GetData(ADC_Module* ADCx, uint8_t ADC_Channel);
void ADC_Initial(ADC_Module* ADCx);

void ADC_Initial(ADC_Module* ADCx)
{
    /* ADC configuration ------------------------------------------------------*/
    ADC_InitStructure.WorkMode       = ADC_WORKMODE_INDEPENDENT;
    ADC_InitStructure.MultiChEn      = DISABLE;
    ADC_InitStructure.ContinueConvEn = DISABLE;
    ADC_InitStructure.ExtTrigSelect  = ADC_EXT_TRIGCONV_NONE;
    ADC_InitStructure.DatAlign       = ADC_DAT_ALIGN_R;
    ADC_InitStructure.ChsNumber      = 1;
    ADC_Init(ADCx, &ADC_InitStructure);


    /* Enable ADC */
    ADC_Enable(ADCx, ENABLE);
    /*Check ADC Ready*/
    while(ADC_GetFlagStatusNew(ADCx,ADC_FLAG_RDY) == RESET)
        ;
    /* Start ADC calibration */
    ADC_StartCalibration(ADCx);
    /* Check the end of ADC calibration */
    while (ADC_GetCalibrationStatus(ADCx))
        ;
}
/**
 * [url=home.php?mod=space&uid=159083]@brief[/url]   Main program
 */
int main(void)
{
    /* System clocks configuration ---------------------------------------------*/
    RCC_Configuration();

    /* GPIO configuration ------------------------------------------------------*/
    GPIO_Configuration();
    
    uart_print_init();
    ADC_Initial(ADC4);

    while (1)
    {
        ADC4ConvertedValue[0]=ADC_GetData(ADC4,ADC4_Channel_05_PB15);
			  printf("ADC4 P15 = %d \r\n",ADC4ConvertedValue[0]);
        
    }
}

/**
 * @brief  Configures the different system clocks.
 */
void RCC_Configuration(void)
{
    /* Enable peripheral clocks ------------------------------------------------*/

    /* Enable GPIOC clocks */
    RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOF|RCC_APB2_PERIPH_GPIOG|RCC_APB2_PERIPH_GPIOA|RCC_APB2_PERIPH_GPIOB|RCC_APB2_PERIPH_GPIOC|RCC_APB2_PERIPH_GPIOD|RCC_APB2_PERIPH_GPIOE, ENABLE);
    /* Enable  ADC4 clocks */
    RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_ADC4, ENABLE);

    /* RCC_ADCHCLK_DIV16*/
    ADC_ConfigClk(ADC_CTRL3_CKMOD_AHB,RCC_ADCHCLK_DIV16);
    RCC_ConfigAdc1mClk(RCC_ADC1MCLK_SRC_HSE, RCC_ADC1MCLK_DIV8);  //selsect HSE as RCC ADC1M CLK Source		
}

/**
 * @brief  Configures the different GPIO ports.
 */
void GPIO_Configuration(void)
{
    GPIO_InitType GPIO_InitStructure;
    
    
    GPIO_InitStructure.Pin       = GPIO_PIN_15;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
    GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure);
  
}

uint16_t ADC_GetData(ADC_Module* ADCx, uint8_t ADC_Channel)
{
    uint16_t dat;
    
    ADC_ConfigRegularChannel(ADCx, ADC_Channel, 1, ADC_SAMP_TIME_239CYCLES5);
    /* Start ADC Software Conversion */
    ADC_EnableSoftwareStartConv(ADCx, ENABLE);
    while(ADC_GetFlagStatus(ADCx, ADC_FLAG_ENDC)==0){
    }
    ADC_ClearFlag(ADCx, ADC_FLAG_ENDC);
    ADC_ClearFlag(ADCx, ADC_FLAG_STR);
    dat=ADC_GetDat(ADCx);
    return dat;
}

实验结果:

 

 

 

 

 

此帖出自汽车电子论坛

最新回复

在打印的函数中,把转换的电压值也打印出来,这样看的人就直观一点。  详情 回复 发表于 2024-3-18 11:08
点赞 关注

回复
举报

7059

帖子

11

TA的资源

版主

沙发
 
在打印的函数中,把转换的电压值也打印出来,这样看的人就直观一点。
此帖出自汽车电子论坛
 
 

回复
您需要登录后才可以回帖 登录 | 注册

查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/6 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表