Microcontroller ADC Interrupt Not Working in Proteus Simulation?

  • Thread starter Thread starter TheRedDevil18
  • Start date Start date
  • Tags Tags
    Adc Microcontroller
Click For Summary
The discussion centers on issues with an Atmega32 microcontroller's ADC interrupt not functioning correctly in a Proteus simulation. Users point out that the infinite loop within the interrupt service routine (ISR) could prevent the interrupt from executing properly, suggesting that toggling a pin instead of sending data via UART may be a better approach. Additionally, there are concerns about the proper setup of the ADC and USART configurations, including ensuring that the interrupt is correctly attached and that the receiver is connected to avoid issues. Debugging steps are recommended, such as setting a flag in the ISR instead of performing extensive operations. Overall, the focus is on optimizing the interrupt handling to ensure reliable ADC operation and data transmission.
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
}
 
Give us more detail...

which pin is the interrupt attached to. what have you done to debug the problem.
 
  • 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.
 
I am trying to understand how transferring electric from the powerplant to my house is more effective using high voltage. The suggested explanation that the current is equal to the power supply divided by the voltage, and hence higher voltage leads to lower current and as a result to a lower power loss on the conductives is very confusing me. I know that the current is determined by the voltage and the resistance, and not by a power capability - which defines a limit to the allowable...