Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Microcontroller ADC not firing

  1. Aug 26, 2016 #1
    I am using proteus to simulate an atmega32. I load the code but I dont think the interrupt is firing
    Code (C):
    #include <avr/io.h>
    #include <avr/interrupt.h>

    #ifndef F_CPU
    #define F_CPU 8000000UL
    #endif

    #define BAUD 9600                           // define baud
    #define BAUDRATE ((F_CPU)/(BAUD*16UL)-1)


    void adcInitialize();
    void USARTInitialize();


    int main(void)
    {
        sei();
        USARTInitialize();
        adcInitialize();
        while(1)
        {
           
        }
    }
        ISR(ADC_vect)
        {
            char letter = 'A';
        while (1)
        {
                    while (!( UCSRA & (1<<UDRE)));
                    {
                    }
                    UDR = letter;
        }
       
            ADCSRA = (1<<ADIF); //Clear interrupt flag
            ADCSRA = (1<<ADSC); //Start conversion
        }
       
        void adcInitialize()
        {
                DDRA = 0x00;
                ADMUX = (1<<REFS0); //Vcc
                ADCSRA = (1<<ADEN)|(1<<ADIE)|(1<<ADPS0)|(1<<ADPS1)|(1<<ADPS2);
                ADCSRA = (1<<ADSC); //Start ADC conversion
        }
       
        void USARTInitialize()
        {
            UBRRL = BAUDRATE; //Set baud rate
            UCSRB = (1<<TXEN); // Enable transmitter
            UCSRC = (1<<URSEL)|(1<<UCSZ0)|(1<<UCSZ1); //8 bit data
        }
    Circuit:
    Capture2.PNG

    Once the interrupt fires it should send 'A' continuously to USART.
     
  2. jcsd
  3. Aug 26, 2016 #2

    rbelli1

    User Avatar
    Gold Member

    I see an infinite loop in your handler. That will cause problems.

    EDIT: I see what you are trying with that while(1). It still may cause problems. Try toggling a pin instead of fiddling with the UART.

    BoB
     
  4. Aug 26, 2016 #3
    Even without the infinite while loop, still doesn't send the letter

    Code (C):
    #include <avr/io.h>
    #include <avr/interrupt.h>

    #ifndef F_CPU
    #define F_CPU 8000000UL
    #endif

    #define BAUD 9600                           // define baud
    #define BAUDRATE ((F_CPU)/(BAUD*16UL)-1)


    void adcInitialize();
    void USARTInitialize();


    int main(void)
    {
        sei();
        USARTInitialize();
        adcInitialize();
        while(1)
        {
           
        }
    }

    ISR(ADC_vect)
    {
            char letter = 'A';
            while (!( UCSRA & (1<<UDRE)));
            {
            }
            UDR = letter;
       
        ADCSRA = (1<<ADIF); //Clear interrupt flag
        ADCSRA = (1<<ADSC); //Start conversion
    }

    void adcInitialize()
    {
        DDRA = 0x00;
        ADMUX = (1<<REFS0); //Vcc
        ADCSRA = (1<<ADEN)|(1<<ADIE)|(1<<ADPS0)|(1<<ADPS1)|(1<<ADPS2);
        ADCSRA = (1<<ADSC); //Start ADC conversion
    }

    void USARTInitialize()
    {
        UBRRL = BAUDRATE; //Set baud rate
        UCSRB = (1<<TXEN); // Enable transmitter
        UCSRC = (1<<URSEL)|(1<<UCSZ0)|(1<<UCSZ1); //8 bit data
    }
     
  5. Aug 30, 2016 #4

    donpacino

    User Avatar
    Gold Member

    Give us more detail....

    which pin is the interrupt attached to. what have you done to debug the problem.
     
  6. Aug 31, 2016 #5

    Svein

    User Avatar
    Science Advisor

    • Are you waiting for an internal interrupt from the ADC?
    • You should never do any extended handling inside an interrupt routine. Just set a flag and get out. Test and reset the flag in the main program.
    • I do not follow your logic in sending a character. Your choice of shorthand indicates that you test the receiver, not the transmitter.
    • The output (T1OUT) of the MAX232 should be connected directly to the TxD pin on the connector
    • Also connect the receiver part. An open receiver input will generate all sorts of problems.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Microcontroller ADC not firing
  1. 4 bit ADC and DAC (Replies: 4)

  2. Current ADC (Replies: 5)

Loading...