Pages: [1]   Go Down
Author Topic: Hex file for Atmega328 gen. by Arduino 1.0.1 does not run on Atmega8  (Read 1504 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 109
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How to generate a Hex file, using Arduino 1.0.1, that can run on a stand alone Atmega8?

I have an Arduino Uno R3 board with Atmega328.
1) I run the Blink Led example on this board and it works.
2) I saved the hex file generated by Arduino 1.0.1 for the Blink Led example and run it in Proteus ISIS circuit simulator on a virtual stand alone Atmega328 without a bootloader. The hex file works. I see how one pin of the simulated Atmega328 changes its status periodically from 0 to 1 and 1 to 0.
3) I replaced the virtual Atmega328 with a virtual Atmega8. I loaded the same hex file but no pin is blinking.

Is there any way to determine Arduino 1.0.1 generate a hex file that can run on a stand alone Atmega8?
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16514
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

We will have to wait for the experts to check in, but I would think that a hex file that was compiled when being told the program was for a 328p chip (via IDE board selection menu) could not or should not be assumed would run correctly on a mega8 chip. While those two chips share a lot in common, there are differences and I would not think a single compiled hex file would run successfully on both chips? Now of course if you selected one of the meg8 based board on the IDE and then compiled, that of course would be able to run on a mega8 chip.

Lefty
« Last Edit: September 05, 2012, 04:21:26 pm by retrolefty » Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 109
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good answer. I have just done what you suggested.
I selected in Arduino 1.0.1->Tools->Board the Atmega8 option and recompiled the Blink Led example.
The new hex file works now on the virtual Atmega8 from ISIS Proteus. One pin is blinking.

New question:
How can I map better the pin declared in Arduino 1.0.1 with that on the stand alone Atmega8 micro-controller.

For instance, I declare in the Blink Led example source code:
Code:
...
int led = 13;
...
When I run the hex file on Atmega8, pin 17 is blinking.

For more complicated programs the fact that pins do not correspond introduces huge complications. How can I fix this.

Logged

SF Bay Area (USA)
Online Online
Tesla Member
***
Karma: 106
Posts: 6373
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Get some of these: http://www.adafruit.com/products/554


* duinosticker_MED.jpg (20.45 KB, 400x308 - viewed 20 times.)
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 109
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Atmega I work with is a virtual one (see the attachment). All the pins are already nicely labeled.

This is the illogical code that blinks pin 17 (marked with blue in the attachment).

Code:
// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(13, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(100);               // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(100);               // wait for a second
}

I want to write things like "pinMode(17, OUTPUT);" and blink 17 not "pinMode(13, OUTPUT);" and blink 17.


* Atmega8 blink led.jpg (192.15 KB, 1024x600 - viewed 45 times.)
Logged

SF Bay Area (USA)
Online Online
Tesla Member
***
Karma: 106
Posts: 6373
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your virtual chip is nicely labeled with the pin numbers of the actual AVR *CHIP*.
The pin numbers used in the Arduino environment are the pin numbers of the BOARD.
That way you can't try to do a digitalWrite() to a power pin, for example.

It's theoretically possible to define a new variant "board type" in arduino with a different chip-pin to board-pin mapping, even one where the numbers used ARE the chip pins.  But this would be relatively difficult to accomplish.

It might also be possible to change the picture associated with your "virtual" AVR.  (What software are you using?)
Perhaps you can easily add the Arduino Pin Number as text in the schematic portion, rather than defining a separate arduin "part."

Or you can just keep this diagram in mind:  http://arduino.cc/en/Hacking/PinMapping

(except: Arduino pin 13 should be chip pin 19, not 17 ?)  (Oh, I see - it's the 32pin mlf/lqfp package version of the AVR, rather than the 28pin DIP version.  Another reason that the mapping to board pin numbers comes in handy.)
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 109
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Perhaps you can easily add the Arduino Pin Number as text in the schematic portion, rather than defining a separate arduin "part."
Yes, this is a good and simple idea. In ISIS Proteus simulator I can attach wires to each pin and label them according to the picture from here http://arduino.cc/en/Hacking/PinMapping as you say, supposing I have a DIP28 Atmega8 in the simulator, which I do not.
Anyway, it will work also with the SMD Atmega8 32Pins but I have to do some more work to identify which pin in Arduino 1.0.1 corresponds to which pin on the SMD Atmega8.

There is another small problem, SMD Atmega8 32Pins has two more ADC pins (ADC6 and ADC7) that do not exist on DIP28 Atmega8.

I guess there is no way to make use of ADC6 and ADC7 in Arduino 1.0.1? I will not be able to program them?



Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16514
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I guess there is no way to make use of ADC6 and ADC7 in Arduino 1.0.1? I will not be able to program them?

Actually the Arduino  analogRead() function will work with those added two analog inputs if you have selected the proper arduino board type. It's all done with smoke and mirrors, but the source code does ship with the IDE distribution so can be figured out by some.

Lefty
Logged

SF Bay Area (USA)
Online Online
Tesla Member
***
Karma: 106
Posts: 6373
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
it will work also with the SMD Atmega8 32Pins but I have to do some more work to identify which pin in Arduino 1.0.1 corresponds to which pin on the SMD Atmega8.
Not that much more work.  Just use the Atmel pin names (which are on both the Arduino Pin Map diagram, and on your schematic) instead of the pin  numbers.  So Arduino "Pin 13" is PB5, and PB5 on your schematic is pin 17 on the ISIS schematic.
Logged

Pages: [1]   Go Up
Jump to: