1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

same code but different output!

Discussion in 'Arduino' started by whiz115, Dec 27, 2014.

  1. whiz115

    whiz115 Member

    Joined:
    Jan 29, 2007
    Messages:
    742
    Likes:
    2
    Location:
    DotGR
    i had no choice since i don't have the needed crystal right now..

    what do you mean by saying "to download via the serial port"? after you upload
    the bootloader then it's serial programmed.

    the problem is that the second atmega behaves weird, first thing it's the frequency it outputs..
    which still it's not clear to me what's the reason..

    and second thing it's that i have to choose the "ATmega328 on a breadboard (8 MHz internal clock)" setting or else it can't be programmed.
     
  2. tunedwolf

    tunedwolf Well-Known Member

    Joined:
    Aug 9, 2006
    Messages:
    1,080
    Likes:
    62
    Location:
    UK
    I think burt nailed it in post #16, your code thinks it's running at 16mhz, all your delays etc will be calculated for this, but your actual clock is only running at 8mhz on the chip. I initially assumed from your original post that there was only a small difference in pitch, but you confirmed in post #8 that you are only getting half the expected output frequency. Either way, it's a clocking issue between your code and what the chip is actually running at :)
     
  3. whiz115

    whiz115 Member

    Joined:
    Jan 29, 2007
    Messages:
    742
    Likes:
    2
    Location:
    DotGR
    seems you're right... but why it is running at 8Mhz? the crystal on the arduino board is at 16MHz
    if it is a bootloader issue how do you think i could correct it?
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. tunedwolf

    tunedwolf Well-Known Member

    Joined:
    Aug 9, 2006
    Messages:
    1,080
    Likes:
    62
    Location:
    UK

    I think the point burt was making, is that you have code loaded that expects and assumes a 16Mhz external clock oscillator, however, when you come to actually uploading it using the uno board, you are somehow actually telling the chip to use the internal 8Mhz clock oscillator instead. If you can read back the configuration fuses, you could compare those between the working chip and the non working chip. I don't think the bootloader is necessarily affecting the way the code is running, but it may do when you are actually uploading it :)

    I don't use the Arduino stuff personally, so have little experience of the platform, but I have used enough of the ATmega devices to say it's definitely a screw up between what you are telling the device to use for it's clock (or what your bootloader is defaulting to, for example) and what your code expects/ believes :)
     
  6. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,306
    Likes:
    914
    Location:
    Rochdale UK
    My point exactly..... The bootloader isn't working..... The bootloader is supposed to work at 19200 baud.. But as your bootloader has been "incorectly" installed, you would need to go to settings in your IDE and set the baud to half that... 9600 baud and then you will be able to run direct from the IDE.. Your chip will still be running at half speed because of the "ATmega328 on a breadboard (8 MHz internal clock)". Once you can talk to the firmware as an arduino you will be okay...
     
  7. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    There a file you have to use to use the breadboard where you get it or do you have it.
    The bootloader sets the clock speed I no you can load code to the chip after installing the bootloader some how your loading code for 16mhz clock into a 8 mhz chip.

    You need a hardware folder with this in it do you have it
    Code (text):
    ##############################################################

    atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock)

    atmega328bb.upload.protocol=stk500
    atmega328bb.upload.maximum_size=30720
    atmega328bb.upload.speed=57600

    atmega328bb.bootloader.low_fuses=0xE2
    atmega328bb.bootloader.high_fuses=0xDA
    atmega328bb.bootloader.extended_fuses=0x05
    atmega328bb.bootloader.path=arduino:atmega
    atmega328bb.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex
    atmega328bb.bootloader.unlock_bits=0x3F
    atmega328bb.bootloader.lock_bits=0x0F

    atmega328bb.build.mcu=atmega328p
    atmega328bb.build.f_cpu=8000000L
    atmega328bb.build.core=arduino:arduino
    atmega328bb.build.variant=arduino:standard
     
     
    Last edited: Jan 1, 2015
  8. whiz115

    whiz115 Member

    Joined:
    Jan 29, 2007
    Messages:
    742
    Likes:
    2
    Location:
    DotGR
    so thank you all for the useful posts..
    i was away for awhile that's why my delayed response...
    now i have all the mandatory, 16mhz crystals, e.g but still i need
    to use the arduino uno board as ISP, no matter what the link i gave says,
    i know it can be done by replacing some files and using an older
    IDE version (one thing is what be80be said).

    so i'm going to do some tests to see if it is problem free and i'll let you know
    from the beginning it shouldn't be that hard, but seems tha semebody doesn't
    want it to be that simple for the arduino uno.
     
  9. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    The ardiuino as programmer is easy to do but it will burn the bootloader to any chip as long as it fits from what I hear.
    I know you can put a 168 or 328 and pick one and load it I just clone chips I made a bunch of 328 with the 16 mhz clock that I breadboarded.
     
  10. b.james

    b.james Member

    Joined:
    Feb 4, 2014
    Messages:
    167
    Likes:
    9
    I would try uploading same bootloader to both chips then comparing . Clearly something is different between the chips at present. Why bother with the reason
     
  11. whiz115

    whiz115 Member

    Joined:
    Jan 29, 2007
    Messages:
    742
    Likes:
    2
    Location:
    DotGR
  12. b.james

    b.james Member

    Joined:
    Feb 4, 2014
    Messages:
    167
    Likes:
    9
    I think you have to have a programmer of some sort available . I have a usbtinyISP -(In Serial Programmer I think)
    The IDE shows " Arduino as ISP " in the tools menu but I don't have any experience with that. If you search the Arduino.cc Forum I am sure I have seen something on this being done.
     
    Last edited: Feb 7, 2015
  13. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    B james you are right. The only thing is the ide don't do it without a crystal you have to add to you folder a file that tells it how to set fuses. Which is in the playgroun .
     
  14. b.james

    b.james Member

    Joined:
    Feb 4, 2014
    Messages:
    167
    Likes:
    9
    Well I tried it with none of the above and it seemed to work but I'm not sure how to test that.

    On the 1.5.8 IDE open the example ArduinoISP (ArduinoISP version 04m3)
    Make sure board and port are right . Upload code

    Then I tried a blink example and all seemed OK.

    Now I suspect that this example just makes the arduino board into a programmer and that you must then connect up another chip to be able to upload the bootloader to it ?

    Anyone know for sure? Typically they are not very clear on arduino playground
     
    Last edited: Feb 14, 2015
  15. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    Yes you use a uio as a programmer it works great i got 10 blank chips and loaded them with the arduino uio bootloader
     
  16. whiz115

    whiz115 Member

    Joined:
    Jan 29, 2007
    Messages:
    742
    Likes:
    2
    Location:
    DotGR
    i dont exactly understand what you want to say...
    did you tried to upload a bootloader using the tutorials from the link i gave?

    if you did then you can see that you dont need another programmer, its
    pointless...

    what i dont undertand is why there's no "official" way to do that for the uno
    board while for other arduino boards it's possible , it is supposed that arduino
    is an open project...they dont after the money....or they do??
     

Share This Page