阅 3658|回 13
- 最后登录
- 2024-11-24
- 在线时间
- 4843 小时
- 威望
- 13434分
- 芯积分
- 3887分(兑换)
- E金币
- 1459枚(兑换)(兑换)
- 好友
- 60
版主
|
[SAM R21]发现R21的ADC稳定性不太好
[复制链接]
这几天发现SAM R21的ADC转换不是太稳定,数据波动比较大。测试时将电位器接到ADC6上,使用内部1V基准,转换后发送到串口。
从图中可以看到,数据波动较大,最大991,最小967,波动有24,这还不是波动最大的数据。即使设置ADC采样数据平均,效果也没有任何改善。
参考代码:
- /**
- * \file
- *
- * \brief SAM ADC Quick Start
- *
- * Copyright (C) 2013-2014 Atmel Corporation. All rights reserved.
- *
- * \asf_license_start
- *
- * \page License
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * 3. The name of Atmel may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * 4. This software may only be redistributed and used in connection with an
- * Atmel microcontroller product.
- *
- * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
- * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * \asf_license_stop
- *
- */
- /**
- * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
- */
- #include <asf.h>
- #include <stdio.h>
- char str[50];
- void configure_adc(void);
- //! [module_inst]
- struct adc_module adc_instance;
- //! [module_inst]
- //! [setup]
- void configure_adc(void)
- {
- //! [setup_config]
- struct adc_config config_adc;
- //! [setup_config]
- //! [setup_config_defaults]
- adc_get_config_defaults(&config_adc);
- //! [setup_config_defaults]
- //! [setup_set_config]
- adc_init(&adc_instance, ADC, &config_adc);
- //! [setup_set_config]
- //! [setup_enable]
- adc_enable(&adc_instance);
- //! [setup_enable]
- }
- //! [setup]
- void configure_usart(void);
- //! [module_inst]
- struct usart_module usart_instance;
- //! [module_inst]
- //! [setup]
- void configure_usart(void)
- {
- //! [setup_config]
- struct usart_config config_usart;
- //! [setup_config]
- //! [setup_config_defaults]
- usart_get_config_defaults(&config_usart);
- //! [setup_config_defaults]
- //! [setup_change_config]
- config_usart.baudrate = 9600;
- config_usart.mux_setting = EDBG_CDC_SERCOM_MUX_SETTING;
- config_usart.pinmux_pad0 = EDBG_CDC_SERCOM_PINMUX_PAD0;
- config_usart.pinmux_pad1 = EDBG_CDC_SERCOM_PINMUX_PAD1;
- config_usart.pinmux_pad2 = EDBG_CDC_SERCOM_PINMUX_PAD2;
- config_usart.pinmux_pad3 = EDBG_CDC_SERCOM_PINMUX_PAD3;
- //! [setup_change_config]
- //! [setup_set_config]
- while (usart_init(&usart_instance,
- EDBG_CDC_MODULE, &config_usart) != STATUS_OK) {
- }
- //! [setup_set_config]
- //! [setup_enable]
- usart_enable(&usart_instance);
- //! [setup_enable]
- }
- //! [setup]
- int main(void)
- {
- system_init();
- //! [setup_init]
- delay_init();
- configure_adc();
- configure_usart();
- //! [setup_init]
- //! [main]
- //! [get_res]
- uint16_t result;
- while(1)
- {
- //! [start_conv]
- adc_start_conversion(&adc_instance);
- //! [start_conv]
- do {
- /* Wait for conversion to be done and read out result */
- } while (adc_read(&adc_instance, &result) == STATUS_BUSY);
-
- sprintf(str, "%d\r\n", result);
- usart_write_buffer_wait(&usart_instance, str, sizeof(str));
-
- delay_ms(500);
-
- //! [get_res]
- }
- //! [inf_loop]
- while (1) {
- /* Infinite loop */
- }
- //! [inf_loop]
- //! [main]
- }
复制代码
|
|