标签,我认为您应该使用“突发模式”。这是我所拥有的 ADC 初始化代码:
void adcHandlerInit()
{
// Clear all bits of the analog pin registers except for the filter disable
// bit.
*((uint32_t *)(LPC_IOCON_BASE + ((BRD_ADC_CH_PORT_0 * 32
+ BRD_ADC_CH_PIN_23)*sizeof(uint32_t)))) = 1 << 8;
*((uint32_t *)(LPC_IOCON_BASE + ((BRD_ADC_CH_PORT_0 * 32
+ BRD_ADC_CH_PIN_24)*sizeof(uint32_t)))) = 1 << 8;
*((uint32_t *)(LPC_IOCON_BASE + ((BRD_ADC_CH_PORT_0 * 32
+ BRD_ADC_CH_PIN_25)*sizeof(uint32_t)))) = 1 << 8;
*((uint32_t *)(LPC_IOCON_BASE + ((BRD_ADC_CH_PORT_0 * 32
+ BRD_ADC_CH_PIN_26)*sizeof(uint32_t)))) = 1 << 8;
*((uint32_t *)(LPC_IOCON_BASE + ((BRD_ADC_CH_PORT_1 * 32
+ BRD_ADC_CH_PIN_30)*sizeof(uint32_t)))) = 1 << 8;
*((uint32_t *)(LPC_IOCON_BASE + ((BRD_ADC_CH_PORT_1 * 32
+ BRD_ADC_CH_PIN_31)*sizeof(uint32_t)))) = 1 << 8;
*((uint32_t *)(LPC_IOCON_BASE + ((BRD_ADC_CH_PORT_0 * 32
+ BRD_ADC_CH_PIN_12)*sizeof(uint32_t)))) = 1 << 8;
*((uint32_t *)(LPC_IOCON_BASE + ((BRD_ADC_CH_PORT_0 * 32
+ BRD_ADC_CH_PIN_13)*sizeof(uint32_t)))) = 1 << 8;
PINSEL_ConfigPin(BRD_ADC_CH_PORT_0, BRD_ADC_CH_PIN_23, BRD_ADC_CH_FUNC_NO_1);
PINSEL_ConfigPin(BRD_ADC_CH_PORT_0, BRD_ADC_CH_PIN_24, BRD_ADC_CH_FUNC_NO_1);
PINSEL_ConfigPin(BRD_ADC_CH_PORT_0, BRD_ADC_CH_PIN_25, BRD_ADC_CH_FUNC_NO_1);
PINSEL_ConfigPin(BRD_ADC_CH_PORT_0, BRD_ADC_CH_PIN_26, BRD_ADC_CH_FUNC_NO_1);
PINSEL_ConfigPin(BRD_ADC_CH_PORT_1, BRD_ADC_CH_PIN_30, BRD_ADC_CH_FUNC_NO_3);
PINSEL_ConfigPin(BRD_ADC_CH_PORT_1, BRD_ADC_CH_PIN_31, BRD_ADC_CH_FUNC_NO_3);
PINSEL_ConfigPin(BRD_ADC_CH_PORT_0, BRD_ADC_CH_PIN_12, BRD_ADC_CH_FUNC_NO_3);
PINSEL_ConfigPin(BRD_ADC_CH_PORT_0, BRD_ADC_CH_PIN_13, BRD_ADC_CH_FUNC_NO_3);
/* Configuration for ADC :
* ADC conversion rate = 400Khz
*/
ADC_Init(LPC_ADC, 400000);
ADC_IntConfig(LPC_ADC, BRD_ADC_INTR_0, DISABLE);
ADC_IntConfig(LPC_ADC, BRD_ADC_INTR_1, DISABLE);
ADC_IntConfig(LPC_ADC, BRD_ADC_INTR_2, DISABLE);
ADC_IntConfig(LPC_ADC, BRD_ADC_INTR_3, DISABLE);
ADC_IntConfig(LPC_ADC, BRD_ADC_INTR_4, DISABLE);
ADC_IntConfig(LPC_ADC, BRD_ADC_INTR_5, DISABLE);
ADC_IntConfig(LPC_ADC, BRD_ADC_INTR_6, DISABLE);
ADC_IntConfig(LPC_ADC, BRD_ADC_INTR_7, DISABLE);
// Start burst mode.
ADC_ChannelCmd(LPC_ADC, ADC_CHANNEL_0, ENABLE);
ADC_ChannelCmd(LPC_ADC, ADC_CHANNEL_1, ENABLE);
ADC_ChannelCmd(LPC_ADC, ADC_CHANNEL_2, ENABLE);
ADC_ChannelCmd(LPC_ADC, ADC_CHANNEL_3, ENABLE);
ADC_ChannelCmd(LPC_ADC, ADC_CHANNEL_4, ENABLE);
ADC_ChannelCmd(LPC_ADC, ADC_CHANNEL_5, ENABLE);
ADC_ChannelCmd(LPC_ADC, ADC_CHANNEL_6, ENABLE);
ADC_ChannelCmd(LPC_ADC, ADC_CHANNEL_7, ENABLE);
ADC_StartCmd(LPC_ADC, ADC_START_CONTINUOUS);
ADC_BurstCmd(LPC_ADC, ENABLE);
}
底部的部分很重要。它将使微控制器对所有 ADC 通道执行重复测量。之后,您可以通过以下方式获得通道电压值:
uint16_t getADCChannelValue(uint8_t adcChannel)
{
return (uint16_t)ADC_ChannelGetData(LPC_ADC, adcChannel);
}
这应该可以帮助你。但是,很高兴看到不使用突发模式的方法来做到这一点,因此任何其他不依赖突发模式的正确答案的人都应该代替我获得接受的答案。