atmega128 now acting oddly

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have been doing development on a robostix (which is basically an atmega 128 with pinouts), and I have been programming to it using the STK500. I am relatively new to developing on AVRs.

I was developing with it fine and then all of sudden it appears as if something with the clock got messed up. Any program that I try to load onto it now doesn't always do what it's supposed to do. For example, I had a test program which would turn three LEDs on and off for half a second in an infinite loop. Sometimes it will execute the program correctly, other times it will only turn on some of the LEDs, and sometimes it will turn them all on, like it's supposed to, but now it's going much slower than it should (i.e. instead of a half second delay, it will be a several second delay).

I'm not sure if I somehow messed up one of the settings on the chip, and I would like to see if there was a way to set everything back to factory default.

I appreciate any advice or help anyone has to offer.

Thank you,
Dan

"I only speak one language .... 101001 ..." - Mr. Rat from The Core (r)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
it will be a several second delay
What is the clock frequency supposed to be? Have you set the divide by 8 fuse? Then the flash rate would be 4 seconds instead of 0.5s.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As it turns out, apparently either the external crystal went bad, or it's a bad solder joint. After switching the fuse settings to use the internal 8 Mhz crystal, everything worked fine. The behavior while using the external crystal (16 Mhz) is very erratic. Apparently, the problem I am having has happened to other people before with the robostix.

"I only speak one language .... 101001 ..." - Mr. Rat from The Core (r)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is it a Mega128 or Mega128L? Mega128L versions can only be used up to 8MHz, and Mega128 can only be used at voltages over 4.5V. (That is what the datasheets say, I know the real world is not that explicit).

- Jani

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Datasheet says turn on CKOPT fuse above 8mhz... makes the 16mhz swing 0-5V. Try That.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jepael wrote:
Is it a Mega128 or Mega128L? Mega128L versions can only be used up to 8MHz, and Mega128 can only be used at voltages over 4.5V. (That is what the datasheets say, I know the real world is not that explicit).

- Jani

It's the Mega128 not the Mega128L.

Quote:

Datasheet says turn on CKOPT fuse above 8mhz... makes the 16mhz swing 0-5V. Try That.

I checked and that was already turned on, so the 16 Mhz still isn't working properly. It still gives very inconsistent results.

"I only speak one language .... 101001 ..." - Mr. Rat from The Core (r)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can you see 5V sine wave on X2? If not, try fuse the other way. 0 is programmed, factory=erased=0xff just like a rom

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bobgardner wrote:
Can you see 5V sine wave on X2? If not, try fuse the other way. 0 is programmed, factory=erased=0xff just like a rom

Okay, I just hooked the scope up again and now there is a 16 Mhz sine wave (5v) that is showing. However, no programs I load are running correctly at 16 Mhz.

"I only speak one language .... 101001 ..." - Mr. Rat from The Core (r)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What does not "correctly" mean?

Are they running at 1/16 speed?

Is this a non-L part?

Does it happen on more than one part?

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
What does not "correctly" mean?

Are they running at 1/16 speed?

Is this a non-L part?

Does it happen on more than one part?

Lee

The results are inconsistent and erratic. Right now, I have a program that is just looping through three different LEDs and turns one of them on for 1 second, and then turns it off, and goes to the next one on for 1 second, etc. and loops back through. The program is hard coded so that if the clock is at 16 Mhz, the LED will be on for 1 second (so using the internal 8 Mhz, the program runs fine except they are one for 2 seconds each which is to be expected). However, it is not currently doing this when I try to use the external 16 Mhz clock.

Sometimes it will go through all of them really quickly, and sometimes it will stop on one for an indefinite amount of time. Other times, no LEDs will light up at all.

By non-L part, are you referring to a non low voltage part? If yes, then yes this is a non-L part.

The errors don't always happen at exactly the same place in the code.

"I only speak one language .... 101001 ..." - Mr. Rat from The Core (r)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Umm, so how are you doing the delays? Do you use avr-libc macros like delay_ms? Are you sure your delay is small enough to fit in the 8 or 16 bit loop counter?

Show the code, maybe it will help? And the schematics?

- Jani

EDIT: What size capacitors you have on the crystal? Do they correspond to the load cap requirement of the crystal? (Hint: 22pF will be fine propably)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jepael wrote:
Umm, so how are you doing the delays? Do you use avr-libc macros like delay_ms? Are you sure your delay is small enough to fit in the 8 or 16 bit loop counter?

Show the code, maybe it will help? And the schematics?

- Jani

EDIT: What size capacitors you have on the crystal? Do they correspond to the load cap requirement of the crystal? (Hint: 22pF will be fine propably)

I know that the program works correctly with the 16 Mhz crystal because it was working a few days ago just fine. Also, I know the capacitor values should be good because they are already installed on the robostix. As far as the schematics, it's basically just a Mega128 with pinouts on it (http://docwiki.gumstix.org/Robos...)

However, here is the source code:

/****************************************************************************
*
*   Copyright (c) 2006 Dave Hylands      gmail.com>
*
*   This program is free software; you can redistribute it and/or modify
*   it under the terms of the GNU General Public License version 2 as
*   published by the Free Software Foundation.
*
*   Alternatively, this software may be distributed under the terms of BSD
*   license.
*
*   See README and COPYING for more details.
*
****************************************************************************/

#include 
#include 

#include "a2d.h"
#include "Hardware.h"
#include "Timer.h"
#include "UART.h"

uint8_t gADC[ 8 ];

int main(void)
{
    int     i;
    int     led = 0;
    FILE   *u0;
    FILE   *u1;

    InitHardware();

    // The first handle opened for read goes to stdin, and the first handle
    // opened for write goes to stdout. So u0 is stdin, stdout, and stderr

#if defined( __AVR_LIBC_VERSION__ )
    u0 = fdevopen( UART0_PutCharStdio, UART0_GetCharStdio );
    u1 = fdevopen( UART1_PutCharStdio, NULL );
#else
    u0 = fdevopen( UART0_PutCharStdio, UART0_GetCharStdio, 0 );
    u1 = fdevopen( UART1_PutCharStdio, NULL, 0 );
#endif

    printf( "*****\n" );
    printf( "***** Flash-LED program\n" );
    printf( "*****\n" );

    fprintf( u1, "***** Output written to UART1 *****\n" );
    
    while( 1 )
    {
        // Turn all of the LEDs off

        LED_OFF( RED );
        LED_OFF( BLUE );
        LED_OFF( YELLOW );

        switch ( led )
        {
            case    0:  LED_ON( RED );      printf( "R " );      break;
            case    1:  LED_ON( BLUE );     printf( "B " );     break;
            case    2:  LED_ON( YELLOW );   printf( "Y " );   break;
        }

        if ( ++led > 2 )
        {
            led = 0;
        }

        // Read the ADC

        for ( i = 0; i < 8; i++ ) 
        {
            gADC[ i ] = a2d_8( i );

            printf( "%02x ", gADC[ i ]);
        }
        printf( "C: %02x\n", PINC );

        // Tick rate is 100/sec so waiting for 100 waits for 1 sec

        for ( i = 0; i < 50; i++ ) 
        {
            WaitForTimer0Rollover();

            if ( UART0_IsCharAvailable() )
            {
                char    ch = getchar();

                printf( "Read: '%c'\n", ch );

                if ( ch == ' ' )
                {
                    printf( "*** Press a key to continue\n" );
                    ch = getchar();
                    printf( "*** Continuing...\n" );
                }
            }
        }
    }

    return 0;
}

"I only speak one language .... 101001 ..." - Mr. Rat from The Core (r)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What are your fuses set to? In addition to the CKOPT fuse I always use the very bottom setting for xtals of 8-16MHz (CKSEL 1111 SUT11)

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:
What are your fuses set to? In addition to the CKOPT fuse I always use the very bottom setting for xtals of 8-16MHz (CKSEL 1111 SUT11)

I have:
boot flash section size = 4096 words (BOOTSZ=00)
CKOPT fuse (CKOPT=0)
Brown out at 2.7v (BODLEVEL=1)
Brown out enabled (BODEN=0)
Ext. crystal high freq; startup time 16k CK + 64 ms (CKSEL=1111 SUT=11)

"I only speak one language .... 101001 ..." - Mr. Rat from The Core (r)