Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

LPC2142's ADC problem

2005-10-05 by Eugene Rybkin

Hi ALL!
I tryed to work with ADC on my LPC2142 but I failed :-(
I  adjusted  ADC  to  hardware-triggered  conversion  mode. Conversion  
start by  rising
edge on the MAT1.0 signal and when is DONE release IRQ. I read ADC's value  
in ISR and send
it via UART. IRQ occur  normally but extracted values are trash! Also, ADC  
fail selftest
when input pin assign to port pin, always read off 0's independently of  
port pin
signals. I  checked  all the power pins (Vdd=Vref=Vdda=3V, Vss=Vssa=0V),  
it's connected OK.
Can anybody help me find a mistake?

void T1_setup(void)
{
	FIO0DIR |= BIT(12);
	PINSEL0 = (PINSEL0 & ~(BIT(25) | BIT(24))) | BIT(25); // P0.12 as Match  
1.0 signal
	T1TCR = 2;      // stop & reset T0
	T1PR = 0;
	T1MR0 = PCLK / F_ADC / 2 + 0.5; // F_ADC = 24000 Hz
	T1MCR = BIT(1); // Reset on MR1: the TC will be reset if MR1 matches it
	T1EMR = (3 << 4) | BIT(0); // toggle External Match bit/output to 1 on  
match
	T1TCR = 1;      // run T0
}

void ADC_setup(void)
{
	AD0INTEN = 0;
	FIO0DIR |= BIT(22) | BIT(29);
	FIO0CLR = BIT(29);
//	PINSEL1 = (PINSEL1 & ~(BIT(27) | BIT(26))) | BIT(26); // Activate P0.29  
as ADC
	AD0CR = BIT(21) | ((PCLK / 4000000 - 1) << 8) | BIT(2); // activate AD0.2

	VICVectAddr0 = (unsigned int)&AD0_ISR;
	VICVectCntl0 = 0x20 | VIC_AD0;
	VICIntEnable |= BIT(VIC_AD0);

	AD0INTEN = BIT(2);

	AD0CR |= (0x6 << 24); // AD0.2 is sampled by rising edge on the MAT1.0  
signal
}

#pragma type_attribute = __arm
void AD0_ISR(void)
{
	FIO0SET = BIT(22);

	while ((U0LSR & ULSR_THRE) == 0);
	U0THR = (AD0DR2 >> 8) & 0xFF;

	FIO0CLR = BIT(22);
}

-- 
Regards
Eugene

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.