集成 4 路 12 比特 ADC,最高采样率 1KHz。ADC基于Sigma-Delta ADC 的采集模块,完成最多 4 路模拟信号的采集,采样率通过外部输入时钟控制,可采集输入电压,也可采集芯片温度,支持输入校准和温度补偿校准。
#define A0 PA1
#define A1 PA4
#define A2 PA3
#define A4 PA2
特别注意!!!
)https://h.hlktech.com/Mobile/download/fdetail/170.html
/*****************************************************************************
*
* File Name : wm_adc_demo.c
*
* Description: adc demo function
*
* Copyright (c) 2014 Winner Micro Electronic Design Co., Ltd.
* All rights reserved.
*
* Author : dave
*
* Date : 2014-8-18
*****************************************************************************/
#include "wm_include.h"
#include "wm_adc.h"
#include "wm_gpio_afsel.h"
#if DEMO_ADC
int adc_input_voltage_demo()
{
u8 chan =0;
int voltage =0;
for(;chan<4;chan++)//全部读一遍各个ADC通道的值
{
if (chan <= 1)
{
wm_adc_config(chan);
}
else if (chan == 8 )
{
wm_adc_config(0);
wm_adc_config(1);
}
voltage = adc_get_inputVolt(chan);
if (voltage < 0)
{
voltage = 0 - voltage;
printf("chan:%d, -%d(mV) or -%d.%03d(V)\r\n", chan, voltage, voltage/1000, voltage%1000);
}
else
{
printf("chan:%d, %d(mV) or %d.%03d(V)\r\n", chan, voltage, voltage/1000, voltage%1000);
}
}
return 0;
}
int adc_chip_temperature_demo(void)
{
char temperature[8] = {0};
int temp;
temp = adc_temp();
if (temp < 0)
{
temp = 0 - temp;
sprintf(temperature, "-%d.%03d", temp/1000, temp%1000);
}
else
{
sprintf(temperature, "%d.%03d", temp/1000, temp%1000);
}
printf("tem: %s\r\n", temperature);
return 0;
}
int adc_power_voltage_demo(void)
{
int voltage =0;
voltage = adc_get_interVolt();
printf("Power voltage:%d(mV) or %d.%03d(V)\r\n",voltage, voltage/1000, voltage%1000);
return 0;
}
#endif
ADC Demo测试菜单
t-adcvolt
)t-adctemp
)✨这个温度有点高,手指轻轻触压在芯片上,确实有点烫手,又没有带散热片的。
基于board707/w80x_arduino固件平台:https://kgithub.com/board707/w80x_arduino
/*
W801 ADC引脚映射关系:
#define A0 PA1
#define A1 PA4
#define A2 PA3
#define A4 PA2
W801:4x ADC(16 位,1KHz 采样率)
*/
#include "Arduino.h"
#define led PB5
static volatile bool led_flag = 0;
float volt = 0;
double value;
void setup()
{
Serial.begin(115200);
Serial.printf("ADC Demo\r\n");
pinMode(led, OUTPUT);//W801 :LED_BUILTIN_1 - LED_BUILTIN_7
pinMode(A2, ANALOG_INPUT);//PA3引脚
}
void loop()
{
value = analogRead(A2);
volt = 2.3 * value / 2337; //MAX电压:2.3V --> MAX:2337,
Serial.printf("ADC value: [%.2f]->Volt:%.2fV \r\n", value, volt);
digitalWrite(led, led_flag);
led_flag = !led_flag;
delay (1000);
}