This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

MCB900, LPC938, A/D

I'm using the MCB900 with a P89LPC938 and the LPC900 development tools (demo version). I'm trying to test the A/D. Couple of things:

1. REG938.H doesn't list the A/D interrupt enable bit EADC (IEN2.1). So I added it to REG938.H:

sbit EADC = IEN2^1;   // ADC int


But afterwards, I get a compiler error:

REG938.H(184): error C146: 'IEN2': invalid base address

Any ideas?

For now, I bypassed it by doing this in code:

// EADC = 0x01;
IEN2 |= 0x02;   // Enable A/D interrupt

2. After much futzing around in the following code, if I set EA, it doesn't work; commented out, it works fine.

#include "REG938.H"

bit btADComp;

void main(void)
{
        P2M1 = 0x00;  // set P2 to quasi-bi
        P2M2 = 0x00;

        P0M1 = 0xFF;  // set P0 as input only (for A/D)
        P0M2 = 0x00;  // set P0 as input only

        ADCON0 &= 0xDC;  // disable all triggers
        ADMODA &= 0x0F;  // clear mode bits and boundary interrupt flag

        ADINS |= 0x04;  // select AD02 for sampling & conversion (P0.3)
        ADCON0 |= 0x44; // enable ADC
        ADMODA = 0x10;  // single conversion mode
        ADMODB = 0x00;  // no 4 conv. int. mode, no boundary, clk divider = 1
        IEN2 |= 0x02;   // Enable A/D interrupt

//      EA = 1;         // Enable all interrupts

        btADComp = 0;   // clear

        while(1)                // main loop
        {
                ADCON0 |= 0x01; // Immediate start
                while (btADComp == 0);  // wait until done

                P2 = AD0DAT2R;  // copy LSB result to Port 2 (LEDs)
                btADComp = 0;   // clear it
        }
}

void adc_isr (void) interrupt 14 using 1
{
        if (ADCON0 & 0x08) {
                ADCON0 &= ~0x08;    // clear ADCI0 flag
                btADComp = 1;   // set our flag
        }
}

Even Code Architect states to enable EA after init, although it's not in its code. Why would setting EA cause it to stop working?

Parents
  • Even Code Architect states to enable EA after init, although it's not in its code. Why would setting EA cause it to stop working?
    I do not know about this particular case, but many chips do 'strange bitflips' during I/O initialization. Thus, the interrupt enabling should always be the very last operation in the initialization.

    Erik

Reply
  • Even Code Architect states to enable EA after init, although it's not in its code. Why would setting EA cause it to stop working?
    I do not know about this particular case, but many chips do 'strange bitflips' during I/O initialization. Thus, the interrupt enabling should always be the very last operation in the initialization.

    Erik

Children
No data