Microcontroller ADC Interrupt Not Working in Proteus Simulation?

  • Thread starter Thread starter TheRedDevil18
  • Start date Start date
  • Tags Tags
    Adc Microcontroller
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 2K views
TheRedDevil18
Messages
406
Reaction score
2
I am using proteus to simulate an atmega32. I load the code but I don't think the interrupt is firing
Code:
#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.
 
Engineering news on Phys.org
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
 
rbelli1 said:
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

Even without the infinite while loop, still doesn't send the letter

Code:
#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
}
 
  • 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.