arunbharathi.arasu
Full Member level 2
- Joined
- Feb 28, 2013
- Messages
- 134
- Helped
- 7
- Reputation
- 14
- Reaction score
- 6
- Trophy points
- 1,298
- Location
- Chennai, Tamil Nadu, India
- Activity points
- 2,151
#ifdef __USE_CMSIS
#include "LPC17xx.h"
#endif
void vADC_Init(void)
{
uint32_t SystemFrequency=12000000;
uint32_t ADC_CLK=5000000;
uint32_t PCLKDIV, PCLK;
LPC_SC->PCONP |=(1<<15);
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 << 1 ) |
( ( PCLK / ADC_CLK - 1 ) << 8 ) |
( 0 << 16 ) |
( 0 << 17 ) |
( 1 << 21 ) |
( 0 << 24 ) |
( 0 << 27 );
}
void main(void)
{
uint32_t i,j;
LPC_GPIO2->FIODIR=0x00000FFF;
LPC_GPIO2->FIOCLR=0x00000FFF;
vADC_Init();
LPC_ADC->ADCR |= (1<<0)
| ( 3 << 8 )
| ( 1 << 21 );
LPC_ADC->ADCR |= 1 << 24;
while(!(LPC_ADC->ADGDR & (1 << 31)));
LPC_ADC->ADCR |= 0 << 24;
int curVal=( LPC_ADC->ADDR0 >> 4 ) & 0xFFF;
LPC_GPIO2->FIOSET=curVal;
}
void main(void)
{
LPC_GPIO2->FIODIR=0x00000FFF;
LPC_GPIO2->FIOCLR=0x00000FFF;
vADC_Init();
LPC_ADC->ADCR |= (1<<0)
| ( 3 << 8 )
| ( 1 << 21 );
while(1)
{
LPC_ADC->ADCR |= 1 << 24;
while(!(LPC_ADC->ADGDR & (1 << 31)));
LPC_ADC->ADCR |= 0 <<24;
int curVal=( LPC_ADC->ADDR0 >> 4 ) & 0xFFF;
LPC_GPIO2->FIOSET=curVal;
}
}
Sorry i Don't get any error,But after fuse this program in to hardware(LPC 1768). output pins all high.(port2.0to Port2.8)
Code C - [expand] 1 LPC_ADC->ADCR |= 0 <<24;
Code C - [expand] 1 2 3 4 5 6 7 8 9 int curVal; while(1) { LPC_ADC->ADCR |= 1 << 24; while(!((LPC_ADC->ADGDR) & (1 << 31))); curVal = ( LPC_ADC->ADDR0 >> 4 ) & 0xFFF; LPC_GPIO2->FIOSET = curVal; }
/*
#ifdef __USE_CMSIS
#include "LPC17xx.h"
#endif
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<<1)
|((PCLK / ADC_CLK -1) << 8)
|(0<<16)
|(0<<17)
|(1<<21)
|(0<<24)
|(0<<27);
}
int main(void)
{
uint32_t i,cur_val;
LPC_GPIO2->FIODIR = 0X00000FFF;
LPC_GPIO2->FIOCLR = 0X00000FFF;
ADC_INT();
LPC_ADC->ADCR |= (1<<0)
|(3<<8)
|(1<<21);
while(1)
{
LPC_ADC->ADCR |=(1<<24);
while(!(LPC_ADC->ADGDR & (1<<31)));
cur_val = (LPC_ADC->ADDR0 >>4) & 0XFFF;
LPC_GPIO2->FIOSET = cur_val;
for(i=0;i<12000;i++);
}
}
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 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<<1) |((PCLK / ADC_CLK -1) << 8) |(0<<16) |(0<<17) |(1<<21) |(0<<24) |(0<<27); // Not oring... } int main(void) { uint32_t i,cur_val; LPC_GPIO2->FIODIR = 0X00000FFF; LPC_GPIO2->FIOCLR = 0X00000FFF; ADC_INT(); // removed starting while(1) { while(!(LPC_ADC->ADGDR & (1<<31))); // wait for end of first conv cur_val = (LPC_ADC->ADDR0 >>4) & 0XFFF; LPC_GPIO2->FIOSET = cur_val; LPC_ADC->ADCR = (1<<1) |((PCLK / ADC_CLK -1) << 8) |(0<<16) |(0<<17) |(1<<21) |(0<<24) |(0<<27); // now start second } }
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 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<<1) |((PCLK / ADC_CLK -1) << 8) |(0<<16) |(0<<17) |(1<<21) |(1<<24) |(0<<27); // (1<<24) } int main(void) { uint32_t i,cur_val; LPC_GPIO2->FIODIR = 0X00000FFF; LPC_GPIO2->FIOCLR = 0X00000FFF; ADC_INT(); // removed starting while(1) { while(!(LPC_ADC->ADGDR & (1<<31))); // wait for end of first conv cur_val = (LPC_ADC->ADDR0 >>4) & 0XFFF; LPC_GPIO2->FIOSET = cur_val; LPC_ADC->ADCR = (1<<1) |((PCLK / ADC_CLK -1) << 8) |(0<<16) |(0<<17) |(1<<21) |(1<<24) |(0<<27); // (1<<24) } }
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?