Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: ADC change program
PostPosted: Fri Jan 15, 2010 11:25 am 
Offline

Joined: Sun Dec 27, 2009 1:40 pm
Posts: 10
My program as below:
Code:

void getbat(void)                            //adc4
{
   unsigned int bat;
   adcinit();
   while(1)
   {
   *AT91C_ADC_CR = AT91C_ADC_START;                      // start ADC conversion     
    while ((*AT91C_ADC_SR & AT91C_ADC_EOC4) == 0);        // wait for ADC conversion 
   bat = (unsigned int) *AT91C_ADC_CDR4 & AT91C_ADC_DATA;   // Read result of ADC conversion
   putchar(bat);
   putchar(bat>>8);

   while ((*AT91C_ADC_SR & AT91C_ADC_EOC6) == 0);        // wait for ADC conversion 
   bat = (unsigned int) *AT91C_ADC_CDR6 & AT91C_ADC_DATA;
    putchar(bat);
   putchar(bat>>8);
   delay(3000000);
   }
}


void adcinit(void)
{
// Setup the A/D converter

   *AT91C_ADC_CR = AT91C_ADC_SWRST;        // reset ADC                             
   *AT91C_ADC_CHER = AT91C_ADC_CH4 | AT91C_ADC_CH6 ;        // enable ADC channels 0..3             
   *AT91C_ADC_MR = 0x0f1f3f00;            // 10bit,128div,software start 
   *AT91C_ADC_IDR = 0xffffffff;         // Disable adc interrupt
}


Top
 Profile  
 
 Post subject: Re: ADC change program
PostPosted: Fri Jan 15, 2010 11:48 am 
Offline

Joined: Sun Dec 27, 2009 1:40 pm
Posts: 10
Now my program can work success. What I need to modify it ,if I want to get a better result???
What I have to pay attention on the software and hardware during the ADC change?? How to select the input resistance,capacitance and so on?? Do I need to judge the flag one by one or I only need to judge the last tunnel ADC_EOC flag (*AT91C_ADC_SR & AT91C_ADC_EOC0,1...7)??? Why I have to read the ADC_CDR not the ADC_LCDR??

:?: :?: :?: :?:


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: