10 years, 9 months ago.

error 18, trying to set up ADC without using the libraries

include the mbed library with this snippet

#include "mbed.h"


/*
adc input using control register
*/

Serial pc(USBTX, USBRX);

// variable declarations
char channel = 1;           // ADC channel 1
int ADCdata;                    // this will hold result of the conversion
int DigOutData = 0;             // a buffer for the output display pattern
int ADCout[4];
// function prototype
void delay(void);

// define addresses of control registers, as pointers to volatile data
//(i.e the memory contents)




#define PINSEL3     (*(volatile unsigned long *)(0x4002C00C)
#define PINSEL1     (*(volatile unsigned long *)(0x4002C004))
#define PCONP       (*(volatile unsigned long *)(0x400FC0C4))
#define ADOCR       (*(volatile unsigned long *)(0x40034000))
#define ADOGDR      (*(volatile unsigned long *)(0x40034004))
#define FIO2DIR0    (*(volatile unsigned long *)(0x2009C040))
#define FIO2PIN0    (*(volatile unsigned long *)(0x2009C054))

int main(){
    
    // intilialize the ADC
    PINSEL1 = 0x150000;        // set bits 17-16, 19-18, 20-21 to 01 to enable AD0.1, AD0.2, AD0.3 (mbed pin 16,17,18)
    PINSEL3 = 0xF0000000;       // sets bits 29-28, 31-30 to 11 to enable AD0.4, AD0.5 (mbed pin 19, 20)
    PCONP   |=  (1 << 12);       // enable ADC clock 

    while(1){
        for(channel =1; channel <<5; channel += 1){ 
        ADOCR   = ( 1 << channel)|( 1 << 8)|(0 << 16)|(1<<21)|(1<<24);      // enable ADC clock, select channel, divide incoming by (1+1), giving 4.8MHz, BURST = 0, conversation under software control, PDN =1, enables power, START = 1 start A/D conversion now
            ADOCR = ADOCR | 0x01000000; // start conversion by setting bit 24 to 1 by ORing
                                    // wait for the conversion to finish by polling the ADC DONE bit

            while((ADOGDR & 0x80000000) == 0)
            {
            // test DONE bit, wait till it's 1
            }
            ADCdata = ADOGDR;           // get data from ADOGDR
            ADOCR &= 0xF8FFFFFF;        // stop ADC by setting START bits to zero
                                    // shift data 4 bits to right justify, and 2 more to give 10-bit ADC
                                    // value given a between 0 & 1024 = 2^8
            ADCdata=(ADCdata>>6)&0x03FF;    // and mask
            DigOutData = 0x00;              // clear the output buffer

            //displaying the data
            pc.printf("ADC reading in channel %d is %d  \n", channel, ADCdata);
            ADCout[channel-1] = ADCdata;
            if(channel == 5){
                channel = 1;
                }
        }
    }    
}

Error: Expected a ")" in "main.cpp", Line: 36, Col: 25

when i comment out the offending line the program works as much as i would expect it to without the offending part. Could you please point me in the right direction. the expected performance is reading the pins 16-18 without the offendng line and it does that, the line thats not working is for enabling pins 19 and 20. cheers forum.

1 Answer

10 years, 9 months ago.

PINSEL3 define misses a closing ')', thats a risk of defines, they are just pasted in one on one :).

Accepted Answer

legend, thanks a lot. i'm triying to go lower and find out what is happening behind the libraries. thanks a lot.

posted by Donald K 06 Feb 2014