startup issues when burnt without bootloader

I’m using some Atmeg8s programmed via an AVR ISP mkII. They don;t have the bootloader on as I ran out of things to do in the 5 seconds.

A strange thing is now happening:
The atmega only runs once every five or so times once the power is connected, meaning I have to power the board up and down a few times before it starts doing its job. This wasn’t happening when I was using chips with the bootloader.

Can anyone tell me why this might be happening? I’m looking for a way out of this so I can just power them up and off they go without using the bootloader.

here is the code (serial stuff used for debugging is commented out):

int incomingByte = 0; // for incoming serial data
int transistorPin = 2;
int ultraSoundSignal = 7; // Ultrasound signal pin
int val = 0;
int ultrasoundValue = 0;
int timecount = 0; // Echo counter
int ledPin = 13; // LED connected to digital pin 13
int waitTime;

void setup() {
//Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode(transistorPin, OUTPUT);
pinMode(ledPin, OUTPUT);
}

void loop() {
timecount = 0;
val = 0;
waitTime = 0;
pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output

// Send low-high-low pulse to activate the trigger pulse of the sensor

digitalWrite(ultraSoundSignal, LOW); // Send low pulse
delayMicroseconds(2); // Wait for 2 microseconds
digitalWrite(ultraSoundSignal, HIGH); // Send high pulse
delayMicroseconds(5); // Wait for 5 microseconds
digitalWrite(ultraSoundSignal, LOW); // Holdoff

// Listening for echo pulse

pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input
val = digitalRead(ultraSoundSignal); // Append signal value to val
while(val == LOW) { // Loop until pin reads a high value
val = digitalRead(ultraSoundSignal);
}

while(val == HIGH) { // Loop until pin reads a high value
val = digitalRead(ultraSoundSignal);
timecount = timecount +1; // Count echo pulse time
}

//Writing out values to the serial port:

ultrasoundValue = timecount; // Append echo pulse time to ultrasoundValue
/*
serialWrite(‘A’); // Example identifier for the sensor
printInteger(ultrasoundValue);
serialWrite(10);
serialWrite(13);
*/

// ***** Motor Stuff *****

//digitalWrite(transistorPin, LOW); // turn motor off.
//digitalWrite(ledPin, LOW);

if (ultrasoundValue < 2600) { // Set activation threshold

/* for loop adds a “tail” to the motors activation, so that movement continues
for a short time after it has been activated.
remove for loop to have direct maping of ultrasoundValue onto motor speed. */

for (int i=0; i < random(60, 140); i++) {
digitalWrite(transistorPin, LOW); // turn motor off.
digitalWrite(ledPin, LOW);
delay(random(5, 25));
digitalWrite(transistorPin, HIGH); // turn motor on;
digitalWrite(ledPin, HIGH);
delay(10);
}
}

else {
digitalWrite(transistorPin, LOW); // turn motor off.
digitalWrite(ledPin, LOW);
delay(100);
}
}

here is a picture:

(Ultrasound triggers the motor which is attached to things with a nice resonance).

any pointers are greatly appreciated.

Will.

sounds like the bootloader does some sort of initialisation that you’re missing

Sure, any idea what that might be so I can have a slightly more informed dig around in the bootloader source (as far as my brain is concerned it means <= 0 at the moment).

The strange thing is that it does work, just not everytime… the ultrasound is a good indicator, if the led on the back of the srf05 gets going then everything is fine, I’m not sure this might potentially be able to tell me anything…?

W.

Hi,

If there is no bootloader on the chip, it can't interfere with your code. What happens when you reset the Chip via the reset-pin, does it start then? Inductive loads (read "the motor") can produce a lot of electrical noise. Does unplugging it help?

Eberhard

The noise isn't really a problem, as I've had this working for a while now, until I got rid of the bootloader that is.

What happens when you reset the Chip via the reset-pin, does it start then?

Would this have any effect if the bootloader is absent? I was under the impression that that's all the reset pin was being used for. I haven't tried it on the strip board version pictured as I didn't think it was necessary. If ypu think it might work for some reason (care to explain a bit more?) then I'll give it ago.

cheer,

W.

Hi,

What happens when you reset the Chip via the reset-pin, does it start then?

Would this have any effect if the bootloader is absent? I was under the impression that that’s all the reset pin was being used for. I haven’t tried it on the strip board version pictured as I didn’t think it was necessary. If ypu think it might work for some reason (care to explain a bit more?) then I’ll give it ago.

The Reset-Pin is not a feature of the bootloader. If a bootloader is present it will be started, otherwise your code will be run immediatly. So Reset should work unless you haven’t disabled it explicitly when burning the fuses on the chip.
Did you wire the reset-pin at all? If not, maybe that is your problem.
Connect the reset with a 10k pull-up resistor to vcc

then you can reset the board with a piece of wire from the reset-pin to GND.

Eberhard

Cheers, I'll give that a shot when the next lot of parts arrive.

W.

How do you have the fuses set?

I'm not exactly sure what that means so I couldn't really tell you, care to enlighten me a little?

When burning the bootloader, something is done to the fuses, as I see in the console report once bootloader has been burnt. could this be what I'm missing when burnin without the bootloader?