標籤,我認爲你應該使用「突發模式」。下面是我的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);
}
這應該會幫助你。然而,如果沒有使用突發模式,很高興看到這樣做的方式,所以任何有正確答案但不依賴突發模式的人應該被授予接受的答案來代替我。
謝謝。這很好。 – Tagc