Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

LPC2148 problem when ADC1.0 and ADC1.1 work together

Status
Not open for further replies.

hbaocr

Full Member level 4
Joined
May 13, 2007
Messages
232
Helped
25
Reputation
48
Reaction score
4
Trophy points
1,298
Location
Hochiminh City university of technology (VietNam)
Activity points
2,765
#include "LPC214x.H" // LPC2148 MPU Register
#include <stdio.h> // For Used Function printf

/* pototype section */
void init_serial0 (void); // Initil UART-0
int putchar (int ch); // Put Char to UART-0
int getchar (void); // Get Char From Uart-0
void delay(unsigned long int); // Delay Time Function
unsigned int count;
unsigned long int tempx,tempy;
unsigned int valx; // ADC Result (HEX)
unsigned int valy;
float voltx; // ADC Result Volt
float volty;
float ax,ay,a;


int main(void)
{

PCONP|=1<<20;//set PDA1 cap nguon cho adc1

init_serial0(); // Initial UART0 = 9600,N,8,1

//chon ADC1.1 = P0.8 va ADC1.0=P0.6
PINSEL0 |= 0x000033000; // Select ADC8 Pin Connect P0.6

// Initial ADC8 (ADCR=0x01210601)
AD1CR &= 0x00000000; // Clear All Bit Control
AD1CR |= 0x00000003; // Select ADC1.0 va ADC1.1
AD1CR |= 0x00000600; // ADC Clock = VBP(PCLK) / 7
AD1CR |= 0x00010000; // Busrt = 1 = Conversion Continue
AD1CR &= 0xFFF1FFFF; // CLKS = 000 = 10Bit : 11 Cycle Clock Conversion
AD1CR |= 0x00200000; // PDN = 1 = Active ADC Module
AD1CR &= 0xFF3FFFFF; // TEST[1:0] = 00 = Normal Mode
AD1CR &= 0xF7FFFFFF; // EDGE = 0 = Conversion on Falling Edge
AD1CR |= 0x01000000; // START = 001 = Start Conversion Now
//p0.6= Ax gia toc theo truc x
// Start Test Read ADC8 and Display on UART0 //
while(1) // Loop Continue
{
count=1;
tempx=tempy=0;
while(count--)
{
//doc gia tri ADC1.0=ax=valx

do
{
valx = AD1DR0; // Read A/D Data Register and clear DONE bit
}
while ((valx & 0x80000000) == 0); // Wait ADC Conversion Complete
valx = (valx >> 6) & 0x03FF;
// printf("volt");
// doc gia tri ADC1.1 =ay=valy
do // Loop Read ADC1.1(ADC8)
{
valy = AD1DR1;
// printf("voltx 1 "); // Read A/D Data Register and clear DONE bit
}
while ((valy & 0x80000000) == 0); // Wait ADC Conversion Complete
//why it loop forever here
valy = (valy >> 6) & 0x03FF;
tempx+=valx;
tempy+=valy;
}
volty = tempy * 3.3 / 1023.0/100.0;
voltx = tempx * 3.3 / 1023.0/500.0;
printf("voltx = %1.2f \n ",voltx);
printf("voly = %1.2f \n ",volty);
delay(10000);
}
}

/******************************/
/* Initial UART0 = 9600,N,8,1 */
/* VPB(pclk) = 60.00 MHz */
/******************************/
void init_serial0 (void)
{
PINSEL0 &= 0xFFFFFFF0; // Reset P0.0,P0.1 Pin Config
PINSEL0 |= 0x00000001; // Select P0.0 = TxD(UART0)
PINSEL0 |= 0x00000004; // Select P0.1 = RxD(UART0)

U0LCR &= 0xFC; // Reset Word Select(1:0)
U0LCR |= 0x03; // Data Bit = 8 Bit
U0LCR &= 0xFB; // Stop Bit = 1 Bit
U0LCR &= 0xF7; // Parity = Disable
U0LCR &= 0xBF; // Disable Break Control
U0LCR |= 0x80; // Enable Programming of Divisor Latches

// U0DLM:U0DLL = 60.00 MHz / [16 x Baud]
// = 60.00 MHz / [16 x 9600]
// = 390.6 = 391 = 0187H
U0DLM = 0x01; // Program Divisor Latch(391) for 9600 Baud
U0DLL = 0x87;

U0LCR &= 0x7F; // Disable Programming of Divisor Latches

U0FCR |= 0x01; // FIF0 Enable
U0FCR |= 0x02; // RX FIFO Reset
U0FCR |= 0x04; // TX FIFO Reset
U0FCR &= 0x3F;
}

/****************************/
/* Write Character To UART0 */
/****************************/
int putchar (int ch)
{
if (ch == '\n')
{
while (!(U0LSR & 0x20)); // Wait TXD Buffer Empty
U0THR = 0x0D; // Write CR
}
while (!(U0LSR & 0x20)); // Wait TXD Buffer Empty
return (U0THR = ch); // Write Character
}

/*****************************/
/* Read Character From UART0 */
/*****************************/
int getchar (void)
{
while (!(U0LSR & 0x01)); // Wait RXD Receive Data Ready
return (U0RBR); // Get Receice Data & Return
}

/***********************/
/* Delay Time Function */
/* 1-4294967296 */
/***********************/
void delay(unsigned long int count1)
{
while(count1 > 0) {count1--;} // Loop Decrease Counter
}
 

hbaocr said:
#include "LPC214x.H" // LPC2148 MPU Register
#include <stdio.h> // For Used Function printf

/* pototype section */
void init_serial0 (void); // Initil UART-0
int putchar (int ch); // Put Char to UART-0
int getchar (void); // Get Char From Uart-0
void delay(unsigned long int); // Delay Time Function
unsigned int count;
unsigned long int tempx,tempy;
unsigned int valx; // ADC Result (HEX)
unsigned int valy;
float voltx; // ADC Result Volt
float volty;
float ax,ay,a;


int main(void)
{

PCONP|=1<<20;//set PDA1 cap nguon cho adc1

init_serial0(); // Initial UART0 = 9600,N,8,1

//chon ADC1.1 = P0.8 va ADC1.0=P0.6
PINSEL0 |= 0x000033000; // Select ADC8 Pin Connect P0.6

// Initial ADC8 (ADCR=0x01210601)
AD1CR &= 0x00000000; // Clear All Bit Control
AD1CR |= 0x00000003; // Select ADC1.0 va ADC1.1
AD1CR |= 0x00000600; // ADC Clock = VBP(PCLK) / 7
AD1CR |= 0x00010000; // Busrt = 1 = Conversion Continue
AD1CR &= 0xFFF1FFFF; // CLKS = 000 = 10Bit : 11 Cycle Clock Conversion
AD1CR |= 0x00200000; // PDN = 1 = Active ADC Module
AD1CR &= 0xFF3FFFFF; // TEST[1:0] = 00 = Normal Mode
AD1CR &= 0xF7FFFFFF; // EDGE = 0 = Conversion on Falling Edge
AD1CR |= 0x01000000; // START = 001 = Start Conversion Now
//p0.6= Ax gia toc theo truc x
// Start Test Read ADC8 and Display on UART0 //
while(1) // Loop Continue
{
count=1;
tempx=tempy=0;
while(count--)
{
//doc gia tri ADC1.0=ax=valx

do
{
valx = AD1DR0; // Read A/D Data Register and clear DONE bit
}
while ((valx & 0x80000000) == 0); // Wait ADC Conversion Complete
valx = (valx >> 6) & 0x03FF;
// printf("volt");
// doc gia tri ADC1.1 =ay=valy
do // Loop Read ADC1.1(ADC8)
{
valy = AD1DR1;
// printf("voltx 1 "); // Read A/D Data Register and clear DONE bit
}
while ((valy & 0x80000000) == 0); // Wait ADC Conversion Complete
//why it loop forever here
valy = (valy >> 6) & 0x03FF;
tempx+=valx;
tempy+=valy;
}
volty = tempy * 3.3 / 1023.0/100.0;
voltx = tempx * 3.3 / 1023.0/500.0;
printf("voltx = %1.2f \n ",voltx);
printf("voly = %1.2f \n ",volty);
delay(10000);
}
}

/******************************/
/* Initial UART0 = 9600,N,8,1 */
/* VPB(pclk) = 60.00 MHz */
/******************************/
void init_serial0 (void)
{
PINSEL0 &= 0xFFFFFFF0; // Reset P0.0,P0.1 Pin Config
PINSEL0 |= 0x00000001; // Select P0.0 = TxD(UART0)
PINSEL0 |= 0x00000004; // Select P0.1 = RxD(UART0)

U0LCR &= 0xFC; // Reset Word Select(1:0)
U0LCR |= 0x03; // Data Bit = 8 Bit
U0LCR &= 0xFB; // Stop Bit = 1 Bit
U0LCR &= 0xF7; // Parity = Disable
U0LCR &= 0xBF; // Disable Break Control
U0LCR |= 0x80; // Enable Programming of Divisor Latches

// U0DLM:U0DLL = 60.00 MHz / [16 x Baud]
// = 60.00 MHz / [16 x 9600]
// = 390.6 = 391 = 0187H
U0DLM = 0x01; // Program Divisor Latch(391) for 9600 Baud
U0DLL = 0x87;

U0LCR &= 0x7F; // Disable Programming of Divisor Latches

U0FCR |= 0x01; // FIF0 Enable
U0FCR |= 0x02; // RX FIFO Reset
U0FCR |= 0x04; // TX FIFO Reset
U0FCR &= 0x3F;
}

/****************************/
/* Write Character To UART0 */
/****************************/
int putchar (int ch)
{
if (ch == '\n')
{
while (!(U0LSR & 0x20)); // Wait TXD Buffer Empty
U0THR = 0x0D; // Write CR
}
while (!(U0LSR & 0x20)); // Wait TXD Buffer Empty
return (U0THR = ch); // Write Character
}

/*****************************/
/* Read Character From UART0 */
/*****************************/
int getchar (void)
{
while (!(U0LSR & 0x01)); // Wait RXD Receive Data Ready
return (U0RBR); // Get Receice Data & Return
}

/***********************/
/* Delay Time Function */
/* 1-4294967296 */
/***********************/
void delay(unsigned long int count1)
{
while(count1 > 0) {count1--;} // Loop Decrease Counter
}


Your ADC1 stopped after the conversion.... Again you have to reconfigure it and START again.... I think thats y it gets hanged on your while loop....


;)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top