Microcontroller ADC not firing

In summary, the person is using Proteus to simulate an ATmega32 and is trying to send a character 'A' continuously to USART through an interrupt. However, the interrupt is not firing and the person has attempted to troubleshoot the issue by removing an infinite loop in the interrupt handler and checking the pin and receiver connections. They have also mentioned that the MAX232 output should be connected directly to the TxD pin on the connector and the receiver part should also be connected to avoid potential problems.
  • #1
TheRedDevil18
408
1
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
  • #2
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
 
  • #3
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
}
 
  • #4
Give us more detail...

which pin is the interrupt attached to. what have you done to debug the problem.
 
  • #5
  • 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.
 

1. Why is my microcontroller ADC not firing?

There could be several reasons why your microcontroller ADC is not firing. Some common causes include incorrect configuration of the ADC, insufficient power supply, hardware malfunction, or incorrect programming of the microcontroller. It is important to carefully check all of these factors to determine the root cause of the issue.

2. How do I troubleshoot my microcontroller ADC not firing?

To troubleshoot your microcontroller ADC not firing, you can start by checking the ADC configuration settings. Make sure they are set correctly for your specific microcontroller and application. You should also check the power supply and make sure it is providing enough voltage for the ADC to function properly. If these settings are correct, you can then check the hardware connections and programming code for any errors.

3. Can a damaged microcontroller cause the ADC not to fire?

Yes, a damaged microcontroller can prevent the ADC from firing. If the microcontroller is damaged, it may not be able to process the ADC input signals correctly, resulting in the ADC not firing. It is important to check for any physical damage to the microcontroller and replace it if necessary.

4. What is the role of the ADC in a microcontroller?

The ADC (Analog-to-Digital Converter) in a microcontroller is responsible for converting analog signals, such as voltage or current, to digital signals that the microcontroller can process. This allows the microcontroller to read and interpret analog signals from sensors or other external devices.

5. Can a software issue cause the ADC not to fire?

Yes, a software issue can cause the ADC not to fire. If the programming code for the microcontroller is incorrect or contains bugs, it may prevent the ADC from functioning properly. It is important to carefully review and debug the code to ensure it is correctly configured for the ADC.

Back
Top