Atmega8 16PU Delay Problem

Hi There !

The code which I upload in Atmega328P works OK but when the same code uploaded in Atmega8 16PU works
with a delay :0 . The Board I am using is Arduino Duemilanove. I have tried it in other boards with a crystal 16 MHz also But this problem of delay exists.

Please help me to resolve this problem.

Harnam

Please help me to resolve this problem.

What code? There could be any number of reasons for the different behavior, depending on that the code is doing.

Sir,

First I uploaded this program:

#include <EEPROM.h>

// CONSTANTS
// INPUT PINS
#define ReedSwA1  6  //Tank1 Level1
#define ReedSwA2  7  //Tank1 Level2
#define ReedSwA3  8  //Tank1 Level3
#define AutoMan   10 //Auto/manual button
// OUTPUT PINS
#define ledpinA1  2 //Tank1 Level1 Display
#define ledpinA2  3 //Tank1 Level2 Display
#define ledpinA3  4 //Tank2 Level1 Display
#define AutoManLed  11  //Auto/manual operation
#define RelayPIN 12 // Pin for water pump activation

// EEPROM MEMORY POSITIONS
#define memposL1  2  // set constant eeprom position 0 to save Level1

// variables
int state=0;
int level = 0;
int lastlevel = 0;

void setup (){
pinMode(AutoMan,INPUT);            // default mode is INPUT
pinMode(ReedSwA1,INPUT);            // default mode is INPUT
pinMode(ReedSwA2,INPUT);            // default mode is INPUT
pinMode(ReedSwA3,INPUT);            // default mode is INPUT

digitalWrite(AutoMan, HIGH);     // Turn on the internal pull-up resistor, default state is HIGH
digitalWrite(ReedSwA1, HIGH);     // Turn on the internal pull-up resistor, default state is HIGH
digitalWrite(ReedSwA2, HIGH);     // Turn on the internal pull-up resistor, default state is HIGH
digitalWrite(ReedSwA3, HIGH);     // Turn on the internal pull-up resistor, default state is HIGH


pinMode(RelayPIN, OUTPUT);
pinMode(ledpinA1, OUTPUT);
pinMode(ledpinA2, OUTPUT);
pinMode(AutoManLed, OUTPUT);
pinMode(ledpinA3, OUTPUT);


// Restore tank water Level from eeprom 
level = EEPROM.read(memposL1); // Read from eeprom memPos1 the value of Level1
lastlevel = level;                        // also update the according lastLevel variable
if ((level == 0)||(level>3)) { 	 // if eeprom has illegal value
level=1;			 // set level to 1 (minimum)
updateprom(); // call updateprom function to set eeprom memory value to minimum too.
}
setleds(); // restore the reed states from EEPROM stored value.
delay(1000);
startstoppump();
}


void setleds() {
  digitalWrite(ledpinA1, LOW );
  digitalWrite(ledpinA2, LOW );
  digitalWrite(ledpinA3, LOW );
  if (level > 0)   digitalWrite(ledpinA1, HIGH );
  if (level > 1)   digitalWrite(ledpinA2, HIGH );
  if (level > 2)   digitalWrite(ledpinA3, HIGH );
 }

void  startstoppump(){ 
  if (level < 3)   digitalWrite(RelayPIN, HIGH );
  if ((level == 3) & (state == 0)) {
    digitalWrite(RelayPIN, LOW );
}
else {
    digitalWrite(RelayPIN, HIGH );
}
}

void updateprom() {
  // UPDATE LEVEL 1
lastlevel = level;      // update lastLevel variable
EEPROM.write(memposL1, level);   // and store new Level value to eeprom
}

void loop () {
  if ( (digitalRead(AutoMan) == LOW) & (state == 0) ) { // Button  pushed
         state=1;  
         digitalWrite(AutoManLed, state );        // Turn on the LED
         startstoppump();
         delay(400);
  }
  
  if ( (digitalRead(AutoMan) == LOW) & (state == 1)  ) { // Button  pushed
         state=0;  
         digitalWrite(AutoManLed, state );        // Turn off the LED
         startstoppump();
         delay(400);
   } 
 
  if ( digitalRead(ReedSwA1) == LOW  ) { // Button  pushed
 level = 1;
 }
 
  if ( digitalRead(ReedSwA2) == LOW  ) { // Button  pushed
 level = 2;
 }

  if ( digitalRead(ReedSwA3) == LOW  ) { // Button  pushed
 level = 3;
 }

 
 if (level != lastlevel) {
   setleds();
   startstoppump();
   updateprom();
 }   
  
}

When this problem started then I tried Examples------Basic-----Blink Program, same problem existing

The Board I am using is Arduino Duemilanove.

The Duemilanove uses a Atmega328 chip. If you change that chip to a different chip with different characteristics, it is no longer a Duemilanove, so you need to chose something different in the Tools + Board menu. What are you choosing in each case?

I am using Arduino-1.0 Ver
and I selected Arduino NG or older w/Atmega8

I am using Arduino-1.0 Ver
and I selected Arduino NG or older w/Atmega8

In both cases?

Yes Sir, In both cases

Do you still get a delay if you have the switch in manual mode or Auto mode?

I wonder if you need a debounce routine on your reed switches also. It should not cause a problem when the switches are stable but, when their states change they could bounce several times causing your "if" tests to go back and forth.

This is a wild guess but, what happens when you comment out part of the code? In the below code I would comment out each function separately and see if you notice an improvement.

 if (level != lastlevel) {
   setleds();
   startstoppump();
   updateprom();
 }

Yes Sir, In both cases

Well, then, in at least one case you are choosing the wrong board type.

Sir,

I have uploaded the program in Atmega8 by choosing Atmega8 in Tools.
The system works after a time delay
I have tested it by resetting the reset switch, this problem occurs in the initial state of RESET or restoring
the power supply to the system, afterwards everything is normal.