Pages: [1] 2   Go Down
Author Topic: [SOLVED] - Self made arduino...very SLOW  (Read 1864 times)
0 Members and 1 Guest are viewing this topic.
Chile
Offline Offline
Sr. Member
****
Karma: 0
Posts: 260
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I´ve built an Arduino clone with an ATMEGA8 to embed in a project, that looked pretty good except one problem. Is SLOW.

I´ve uploaded this code into the ATMEGA8

Code:
void setup(){
 pinMode(0,OUTPUT);
 pinMode(2,OUTPUT);
}

void loop() {
 digitalWrite(0, HIGH);
 delay(100);
 digitalWrite(0, LOW);
 digitalWrite(2, HIGH);
 delay(200);
 digitalWrite(2, LOW);
  
}

and I´ve attached a couple of leds to pin 0, and 2.
The led Attached to pin 0 keeps on for 1,5 seconds, and once off the other led keeps on for almost 3 seconds.
If I change the delay values, the proportion is equal.
I´ve used a 16Mhz Xtal and the 2 22pf capacitors (though I´m not able to test them).
Power is 5,7V straight off a 7805 with filter capacitors.
Any Ideas?
« Last Edit: May 29, 2011, 07:58:01 am by pgmartin » Logged

Chile
Offline Offline
Sr. Member
****
Karma: 0
Posts: 260
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

More data:
I´ve burnt the same code into an ATMEGA 168 anda placed it in the board I´ve built, and the result is the same. So, the micro is not to blame. Maybe something in the board or when I burn it using the Arduino IDE?

Help wil be very much appreciated.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8103
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So your chip is running at maybe 1/16th speed?  That would get you 1.6 seconds and 3.2 seconds.

Sounds like the chip is running at the default speed:  8MHz internal clock and /8 prescaler.  Did you burn an Arduino bootloader on it?  If not, did you at least set the fuses?
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Chile
Offline Offline
Sr. Member
****
Karma: 0
Posts: 260
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks johnwasser!
No, I didnt burn a bootloader. Since this is a microcontroller that will keep embeded, didn´t know there was a reason to and I was trying to save some memory.
Do I have to set the fuses then? How can I do that?

Thanks in advance
Logged

Humboldt, CA
Offline Offline
Full Member
***
Karma: 2
Posts: 223
Arduino BBB
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As I understand it, the highest you can get without an external resonator is 8mhz.  At 8mhz every ms of delay is 2ms.
Altertnatively you can edit boards.txt and add one (copy whatever board you're using right now, change the name to something else) and change the F_CPU value in your new boards.txt section to 1000000.  That should get millis/delay timed right for 1mhz operation.

Assuming I'm not totally out to lunch due to it being rather past my bedtime.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8103
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can set the fuses with 'avrdude' or let it be done by Arduino0022 as part of burning a bootloader.

The normal settings for the "Arduino NG or older w/ ATmega8" are:

Unlock Bits: 0x3F
Low Fuses:  0xDF
High Fuses: 0xCA
Lock Bits: 0x0F

The lock bits are what sets aside room for a bootloader so you should probably just use the Unlock Bits.

 You can put the lines below into (Arduino sketch folder)/hardware/boards.txt and re-start Arduino0022.  Then you can 'burn a bootloader' on your "Unlocked ATmega8" and it will set all the right fuses and but NOT create a protected bootloader area.

uatmega8.name=Unlocked  ATmega8
uatmega8.upload.protocol=stk500
uatmega8.upload.maximum_size=8192
uatmega8.upload.speed=19200
uatmega8.bootloader.low_fuses=0xdf
uatmega8.bootloader.high_fuses=0xca
uatmega8.bootloader.path=atmega8
uatmega8.bootloader.file=ATmegaBOOT.hex
uatmega8.bootloader.unlock_bits=0x3F
uatmega8.bootloader.lock_bits=03F
uatmega8.build.mcu=atmega8
uatmega8.build.f_cpu=16000000L
uatmega8.build.core=arduino
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Chile
Offline Offline
Sr. Member
****
Karma: 0
Posts: 260
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks again. Before trying this solution just one question:

You can set the fuses with 'avrdude' or let it be done by Arduino0022 as part of burning a bootloader.

The normal settings for the "Arduino NG or older w/ ATmega8" are:

Unlock Bits: 0x3F
Low Fuses:  0xDF
High Fuses: 0xCA
Lock Bits: 0x0F

The lock bits are what sets aside room for a bootloader so you should probably just use the Unlock Bits.

 You can put the lines below into (Arduino sketch folder)/hardware/boards.txt and re-start Arduino0022.  Then you can 'burn a bootloader' on your "Unlocked ATmega8" and it will set all the right fuses and but NOT create a protected bootloader area.

uatmega8.name=Unlocked  ATmega8
uatmega8.upload.protocol=stk500
uatmega8.upload.maximum_size=8192
uatmega8.upload.speed=19200
uatmega8.bootloader.low_fuses=0xdf
uatmega8.bootloader.high_fuses=0xca
uatmega8.bootloader.path=atmega8
uatmega8.bootloader.file=ATmegaBOOT.hex
uatmega8.bootloader.unlock_bits=0x3F
uatmega8.bootloader.lock_bits=03F
uatmega8.build.mcu=atmega8
uatmega8.build.f_cpu=16000000L
uatmega8.build.core=arduino

Is this value correct or should it be 0x3f?
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8103
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oops...  You're right.  0x3F.  It was a typing mistake.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Chile
Offline Offline
Sr. Member
****
Karma: 0
Posts: 260
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok. I tried to burn the bootloader, but I got this message:
Code:
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.
The connections were right, so I tried to upload a sketck into another Atmega. It worked. Then I tried to burn the bootloader, now I have the same error in the two micros.
Seems that I should have burnt the bootloader first...
Is there a way to "restore" the micro to its original state?
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8103
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Unless some of the fuses are badly screwed up the Burn Bootloader should be able to fully reset the chip.  Any previous contents will be erased.

What are you using for the ISP?
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Chile
Offline Offline
Sr. Member
****
Karma: 0
Posts: 260
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I´m using an USBTinyISP.
For uploading the sketches it worked. Problems started when trying to upload the Bootloader.

Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8103
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Perhaps if you can try in 'verbose' mode it will be clearer what has gone wrong.  For uploading sketches you just have to hold down the Shift key when you click on the upload button.  I don't know if holding down the shift key when you select "Burn Bootloader" will work.  It's worth a try.  If that doesn't get you a lot of debug output you will have to change your preferences.txt to include:
Quote
upload.verbose=true
build.verbose=true
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Chile
Offline Offline
Sr. Member
****
Karma: 0
Posts: 260
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Got this answer:

Code:
C:\Users\Pablo\arduino-0022\hardware/tools/avr/bin/avrdude -CC:\Users\Pablo\arduino-0022\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega8 -cusbtiny -e -Ulock:w:0x3F:m -Uhfuse:w:0xca:m -Ulfuse:w:0xdf:m

avrdude: Version 5.4-arduino, compiled on Oct 11 2007 at 19:12:32
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

         System wide configuration file is "C:\Users\Pablo\arduino-0022\hardware/tools/avr/etc/avrdude.conf"

         Using Port            : lpt1
         Using Programmer      : usbtiny
         AVR Part              : ATMEGA8
         Chip Erase delay      : 10000 us
         PAGEL                 : PD7
         BS2                   : PC2
         RESET disposition     : dedicated
         RETRY pulse           : SCK
         serial program mode   : yes
         parallel program mode : yes
         Timeout               : 200
         StabDelay             : 100
         CmdexeDelay           : 25
         SyncLoops             : 32
         ByteDelay             : 0
         PollIndex             : 3
         PollValue             : 0x53
         Memory Detail         :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom         4    20   128    0 no        512    0      0  9000  9000 0xff 0xff
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           flash         33    10    64    0 yes      8192   64    128  4500  4500 0xff 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           hfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
avrdude: Using SCK period of 10 usec
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lock           0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           calibration    0     0     0    0 no          4    0      0     0     0 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : USBTINY
         Description     : USBtiny simple USB programmer

CMD: [ac 53 00 00] [00 00 00 00]
CMD: [ac 53 00 00] [00 00 00 00]
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.

The only thing that I understand is the line refering to LPT1. The USBTiny is conected via USB to com3, and so states in the IDE. Is this relevant?
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8103
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, it dies awfully early in the process, like it can't even communicate properly with the USBTiny.  I don't know why that would be the case.  Have you used the USBTiny to program another Arduino?  Do you know it's works?
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Chile
Offline Offline
Sr. Member
****
Karma: 0
Posts: 260
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I´ve used this USBTiny to upload the first sketches into the ATMEGA8. It worked for that.
Never been able to burn a bootloader.
But I´m just starting to use it.
Can this be a hardware problem?
Since this is my first time working with a programmer, help is appreciated.
Regards

Logged

Pages: [1] 2   Go Up
Jump to: