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.

Sample code for ADC0.1 channel

Status
Not open for further replies.
Re: LPC 1768 cortex m3 ADC

before every time using IOSET you shd clear them with IOCLR....

- - - Updated - - -

IO set will enble the pins but not clear the ones already in the pins...
 

Re: LPC 1768 cortex m3 ADC

Try this code..

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
ADC_INT()
{
    uint32_t systemfrequency = 12000000;
    uint32_t ADC_CLK = 1000000;
    uint32_t PCLKDIV,PCLK;
 
    LPC_SC->PCONP |= (1<<12);
    LPC_PINCON->PINSEL1 |= (1<<14);
    PCLKDIV = (LPC_SC->PCLKSEL0 >>24) & 0X03;
    switch(PCLKDIV)
    {
    case 0x00:default: PCLK =systemfrequency/4;break;
    case 0x01: PCLK = systemfrequency;break;
    case 0x02: PCLK = systemfrequency/2;break;
    case 0x03: PCLK = systemfrequency/8;break;
    }
    LPC_ADC->ADCR |= (1<<0)
                    |((PCLK / ADC_CLK -1) << 8)
                    |(0<<16)
                    |(0<<17)
                    |(1<<21)
                    |(0<<24)
                    |(0<<27);
}
 
ADC_Read()
{
    uint32_t cur_val;
 
    LPC_ADC->ADCR |= (1<<24);
 
    while(!(LPC_ADC->ADGDR & (1<<31)));
 
    LPC_ADC->ADCR |=(0<<24);
 
    cur_val = (LPC_ADC->ADDR0 >>4) & 0XFFF;
 
    LPC_GPIO2->FIOCLR = 0x00;
    LPC_GPIO2->FIOSET = cur_val;
 
}
 
void delay(uint32_t val)
{
    uint32_t i,j;
    for(i=0;i<val;i++);
    for(j=0;j<100;j++);
}
void main()
{
 
    LPC_GPIO2->FIODIR = 0X00000FFF;
    LPC_GPIO2->FIOCLR = 0X00000FFF;
    ADC_INT();
    while(1)
    {
    ADC_Read();
    delay(1000);
    }
}


LPC 1768 is not avail in proteus...
 

Re: LPC 1768 cortex m3 ADC

Try this also..

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
void main()
{
    LPC_GPIO2->FIODIR = 0X00000FFF;
    LPC_GPIO2->FIOCLR = 0X00000FFF;
    while(1)
    {
    ADC_INT(); // inside while...
    ADC_Read();
    delay(1000);
    }
}



- - - Updated - - -

Go sorry Try this

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
ADC_INT()
{
    uint32_t systemfrequency = 12000000;
    uint32_t ADC_CLK = 1000000;
    uint32_t PCLKDIV,PCLK;
 
    LPC_SC->PCONP |= (1<<12);
    LPC_PINCON->PINSEL1 |= (1<<14);
    PCLKDIV = (LPC_SC->PCLKSEL0 >>24) & 0X03;
    switch(PCLKDIV)
    {
    case 0x00:default: PCLK =systemfrequency/4;break;
    case 0x01: PCLK = systemfrequency;break;
    case 0x02: PCLK = systemfrequency/2;break;
    case 0x03: PCLK = systemfrequency/8;break;
    }
    LPC_ADC->ADCR |= (1<<0)
                    |((PCLK / ADC_CLK -1) << 8)
                    |(0<<16)
                    |(0<<17)
                    |(1<<21)
                    |(0<<24)
                    |(0<<27);
}
 
ADC_Read()
{
    uint32_t cur_val;
 
    LPC_ADC->ADCR |= (1<<24);
 
    while(!(LPC_ADC->ADGDR & (1<<31)));
 
    LPC_ADC->ADCR |=(0<<24);
 
    cur_val = (LPC_ADC->ADDR0 >>4) & 0XFFF;
 
    LPC_GPIO2->FIOCLR = 0xFFF; // Chnaged
    LPC_GPIO2->FIOSET = cur_val;
 
}
 
void delay(uint32_t val)
{
    uint32_t i,j;
    for(i=0;i<val;i++);
    for(j=0;j<100;j++);
}
void main()
{
 
    LPC_GPIO2->FIODIR = 0X00000FFF;
    LPC_GPIO2->FIOCLR = 0X00000FFF;
    while(1)
    {
    ADC_INT();
    ADC_Read();
    delay(1000);
    }
}

 

Re: LPC 1768 cortex m3 ADC

As you are saying, its only works with LED blinking there are two possible reasons they are,
1, Delay made by LED BLINK
2, we are clearing the PORT in led blink

I stick with the second point and that is the main reason and also did you look on the maximum clock frequency can be given to ADC module??
 

Re: LPC 1768 cortex m3 ADC

Maximum clock Frequency is 13MHZ,But here i am using 1MZ only.
I accept your points.I tried one more type.
after send ADC output make delay(what i used in LED BLINK),and clear port2 and make delay in a function.
I couldn't get answer.
 

Re: LPC 1768 cortex m3 ADC

i dint work with proteus...
But i have hardware.i worked with that....
if i call one more function like LED blinlking in main function i get answer without any problem.
but remove that extra function answer won't come...
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top