0
\$\begingroup\$

I am currently working on a microcontroller based system, the issue i am facing is that my inputs pins 40 and 39 of atmega32 are somehow getting internally high, Pin40 shows 2.5 volts and Pin39 shows 5v on my voltmeter. As far as I understand the pins are getting high due to code but I have cross checked several times but still cant figure out the issue with my code. I am including the circuit diagram and code as well. Can any one please point out how my input pins are showing voltages. Atmega32 circuit with lcd interfaced

#ifndef F_CPU
#define F_CPU 16000000UL // 16 MHz clock speed
#endif

#define D0 eS_PORTD0
#define D1 eS_PORTD1
#define D2 eS_PORTD2
#define D3 eS_PORTD3
#define D4 eS_PORTD4
#define D5 eS_PORTD5
#define D6 eS_PORTD6
#define D7 eS_PORTD7
#define RS eS_PORTC6
#define EN eS_PORTC7

#include <avr/io.h>
#include <util/delay.h>
#include "lcd.h"

void Init_ADC(void)
{
ADMUX|=(1<<REFS0);
ADMUX&=~((1<<REFS1)|(1<<MUX0)|(1<<MUX1)|(1<<MUX2)|(1<<MUX3)|(1<<MUX4));
// SELECTING CHANNEL0
ADCSRA|=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS0);
// NORMAL CONVERSION WITHOUT INTERRUPT
ADCSRA&=~((1<<ADSC)|(1<<ADATE)|(1<<ADIF)|(1<<ADIE)|(1<<ADPS1));
// CLOCK/32 SPEED
}
unsigned int Read_ADC(uint8_t ch)
{
ADMUX&=0b11111000;
ch=ch&0b00000111;
ADMUX|=ch;
//Start Single Conversion

ADCSRA|= (1<<ADSC);
// Wait for conversion to complete
while(ADCSRA & (1<<ADSC));

// Clear ADIF by writing one to it
//ADCSRA|=(1<<ADIF);

return(ADCW);
}


void Wait()
{
uint8_t i;
for(i=0;i<20;i++)
_delay_loop_2(0);
}

int main(void)
{
int v,v1,v2,vref;
vref = 409;
DDRD = 0xFF; 
DDRB = 0xFF; 
DDRC = 0xFF;

Init_ADC();
Lcd8_Init();

while(1)
{
    v2 = Read_ADC(1);
    if(v2>=900)
    {
        Lcd8_Set_Cursor(1,1);
        vref = Read_ADC(0);
        Lcd8_Write_String(" Ref. Set");
        _delay_ms(2000);
        Lcd8_Clear();

    }
    else
    {
        Lcd8_Set_Cursor(1,1);

        v1=Read_ADC(0);

        if(v1>=1.05*vref)
        {
            v=0x01;
            Lcd8_Write_String(" HIGH");
        }
        else if(v1<=0.95*vref)
        {
            v=0x01;
            Lcd8_Write_String(" LOW");
        }
        else
        {
            v=0x00;
            Lcd8_Write_String(" OK");
        }
        PORTB=v;
        //Wait();
        _delay_ms(2000);
        Lcd8_Clear();
    }
}

}

Thnks everyone in advance !!

\$\endgroup\$
1
\$\begingroup\$

Setting PORTxn will enable the pullup on the associated input. Reset it in order to disable the pullup.

\$\endgroup\$
  • \$\begingroup\$ Can u please help me with code, I am not good at C !! \$\endgroup\$ – Dexi Jun 3 '15 at 5:11
  • 1
    \$\begingroup\$ Using port B pin 0 as an example: PORTB &= ~(1<<0); DDRB &= ~(1<<0); leaves the pin floating. PORTB |= (1<<0); DDRB &= ~(1<<0); pulls the pin up with an internal 10k resistor. PORTB &= ~(1<<0); DDRB |= (1<<0); drives the pin low. PORTB |= (1<<0); DDRB |= (1<<0); drives the pin high. \$\endgroup\$ – jms Jun 3 '15 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.