Microcontroller ADC Interrupt Not Working in Proteus Simulation?

  • Thread starter Thread starter TheRedDevil18
  • Start date Start date
  • Tags Tags
    Adc Microcontroller
Click For Summary

Discussion Overview

The discussion revolves around issues related to the ADC interrupt not functioning correctly in a Proteus simulation of an ATmega32 microcontroller. Participants explore potential causes and solutions, focusing on code structure, interrupt handling, and circuit connections.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant notes that an infinite loop in the interrupt handler could cause problems, suggesting that toggling a pin might be a better approach than using UART for output.
  • Another participant points out that even without the infinite loop, the character 'A' is still not being sent, indicating a potential issue with the interrupt handling or UART configuration.
  • A request for more details is made regarding which pin the interrupt is attached to and what debugging steps have been taken.
  • Concerns are raised about the handling of the interrupt, with a suggestion to set a flag and exit the interrupt routine quickly, rather than performing extended operations within it.
  • Clarification is sought on the logic of sending a character, with a note that the output of the MAX232 should be connected directly to the TxD pin, and that the receiver part should also be connected to avoid issues.

Areas of Agreement / Disagreement

Participants express differing views on the handling of the interrupt and the appropriate debugging steps. There is no consensus on the exact cause of the issue or the best solution, indicating multiple competing views remain.

Contextual Notes

Limitations include potential missing assumptions about the circuit setup, the specific connections made, and the handling of the UART communication. The discussion does not resolve these uncertainties.

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.