This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Use two channels of ADC (MCB4300)

Hello,

can anyone help me,how can I program the AD-Converter of the MCB4300. The program works with one channel (AD0 - Channel 1), but I need 2 channels (AD0 - Channel 1 and AD0 Channel 0).

int main(void)
{ int adcVal;

ADC_Initialize(); ADC_StartConversion();

while(ADC_ConversionDone () < 0);

adcVal = ADC_GetValue();
}

/* This is the program code from the Example of Keil for the MCB4300 */
#include "LPC43xx.h"
#include "SCU_LPC43xx.h"
#include "Board_ADC.h"

#define ADC_RESOLUTION 10 /* Number of A/D converter bits */

/* Clock Control Unit register bits */
#define CCU_CLK_CFG_RUN (1 << 0)
#define CCU_CLK_CFG_AUTO (1 << 1)
#define CCU_CLK_STAT_RUN (1 << 0)

static volatile uint16_t AD_last; /* Last converted value */
static volatile uint8_t AD_done; /* AD conversion done flag */

int32_t ADC_Initialize (void) {

/* Enable ADC0 clock */ LPC_CCU1->CLK_APB3_ADC0_CFG = CCU_CLK_CFG_AUTO | CCU_CLK_CFG_RUN; while (!(LPC_CCU1->CLK_APB3_ADC0_STAT & CCU_CLK_STAT_RUN));

/* Configure ADC0_1 */ LPC_ADC0->CR = (1 << 1) | /* Select ADC0_1 pin for conversion */ (2 << 8) | /* 12MHz / (2+1) = 4MHz */ (1 << 21) ; /* ADC is operational */

/* Enable ADC0 Channel 1 interrupt */ LPC_ADC0->INTEN |= (1 << 1); NVIC_EnableIRQ (ADC0_IRQn);

return 0;
}

int32_t ADC_Uninitialize (void) {

/* Disable ADC0 Channel 1 interrupt */ NVIC_DisableIRQ (ADC0_IRQn); LPC_ADC0->INTEN &= ~(1 << 1);

/* Disable ADC0 clock */ LPC_CCU1->CLK_APB3_ADC0_CFG = 0;

return 0;
}

int32_t ADC_StartConversion (void) {

LPC_ADC0->CR |= (1 << 24); /* Start conversion */

return 0;
}

int32_t ADC_ConversionDone (void) { return (AD_done ? 0 : -1);
}

int32_t ADC_GetValue (void) {

if (AD_done) { AD_done = 0; return AD_last; } return -1;
}

uint32_t ADC_GetResolution (void) { return ADC_RESOLUTION;
}

void ADC0_IRQHandler (void) {

LPC_ADC0->GDR; /* Clear IRQ request flag */ AD_last = (LPC_ADC0->DR[1] >> 6) & 0x3FF; /* Read value and clear IRQ */ AD_done = 1;
}

-----> LPC_ADC0->CR = (1 << 1) | (2 << 8) | (1 << 21) ; <-----

It says in the datasheet that for ADC0-CR where I can select the Channel for the AD0: "In software-controlled mode, only one of these bits should be 1. In hardware scan mode, any value containing 1 t0 8 ones is allowed"

My problem is, if I want to use Channel 0 and 1 of the ADC0 at the same time, how can I do this.

Thank you in advance for your help.