[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Problem reading from port (ADC)

From: Matthew Smith
Subject: [avr-gcc-list] Problem reading from port (ADC)
Date: Sun, 28 Aug 2005 16:47:48 +0930
User-agent: Mozilla Thunderbird 1.0 (X11/20041206)

Hi All

I am having some trouble reading from PORTA of an AT90S8518, which is
connected to a Maxim MX7820 ADC (parallel bus connection).

Running the code with a load of huge delays in it has allowed me to
check things with a logic probe - the data is sitting there, but not
registering. (Any value on the pins reads as 0)

I *did* remember to set DDRA to 0; I tried turning pullup on for the
port, but the ADC doesn't seem to be able to pull it back down again.

I'm sure that I've missed something really stupid. (Probably as a result
of blowing too hard into the pressure transducer to check the analogue
input ;-)

Any sanity-saving suggestions would be much appreciated.



>>> The Code In Question >>>


#define _OUT    1       // PC0 (pump out)
#define _NC1    2       // PC1, unused
#define _NC2    4       // PC2, unused
#define _INT    8       // PC3 (/INT)           MX7820 pin 9
#define _RD     16      // PC4 (/RD)            MX7820 pin 8
#define _MODE   32      // PC5 (MODE)           MX7820 pin 7
#define _WR     64      // PC6 (/WR)            MX7820 pin 6
#define _CS     128     // PC7 (/CS)            MX7820 pin 13

uint8_t readadc(void);
void longdly(uint8_t);
void smalldly(void);
void pump(uint8_t);
void led(uint8_t);

int main(void)
        uint8_t x=96;   // Cut in pressure
        uint8_t y=146;  // Cut out pressure (unless too soon)
        uint8_t z=166;  // Must stop pressure
        DDRA=0;         // Port A is input from ADC
        DDRC=255;       // Set PORTC to output (we will define inputs later)
        DDRD=128;       // Set PD7 to output (diags LED)
        PORTC|=_RD;     // Set /RD high
        PORTC|=_WR;     // Set /WR high
        PORTC|=_MODE;   // Set MODE high
        DDRC&=~_INT;    // Set /INT in as input
        PORTC|=_INT;    // Set pull-up on /INT pin

        for (;;)
                uint8_t v=readadc();
                for (uint8_t i=0; i<v; i++)

uint8_t readadc(void)
        uint8_t v=0;
        //Start conversion
        PORTC&=~_CS;    // Set /CS low
        PORTC&=~_WR;    // Set /WR low
        smalldly();     // Give the ADC a chance to catch up
        PORTC|=_WR;     // Set /WR high
        PORTC|=_CS;     // Set /CS high
        //Wait for INT to show up...
        while (PORTC & _INT) { asm volatile("nop"); }
        //Start the read process
        PORTC&=~_CS;    // Set /CS low
        PORTC&=~_RD;    // Set /RD low
        v=PORTA;        // Read value from PORTA
        PORTC|=_RD;     // Set /RD high
        PORTC|=_CS;     // Set /CS high
        return(v);      // Return ADC reading to calling function

void smalldly(void)
        for (uint8_t i=0; i<10; i++)
        { asm volatile("nop"); }

void longdly(uint8_t n)
        for (uint16_t i=0; i<65535; i++)
                for (uint16_t j=0; j<n; j++) { asm volatile("nop"); }

void pump(uint8_t c)
        if (c==1) { PORTC|=1; }
        else { PORTC&=0; }

void led(uint8_t c)
        if (c==1) { PORTD|=128; }
        else { PORTD&=~128; }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]