Pages: [1] 2   Go Down
Author Topic: One Crazy Sketch  (Read 1582 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 208
Posts: 12933
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The hardware...
  • 328P processor on a breadboard.
  • Jumper from pin 3 to pin 8.

The environment...
  • Windows Vista
  • Arduino iDE 0022
  • All libraries removed.

The code...

Code:
void setup( void )
{
  Serial.begin( 115200 );
  analogWrite( 3, 127 );
}

void loop( void )
{
  static bool DoOnce = true;
  static unsigned Loops;
  
  if ( DoOnce )
  {
    ++Loops;
    Serial.println( Loops );
    DoOnce = false;
  }
}


The expected result...
  • A single "1" should be output to Serial.

The actual result...
  • Lots of "1' output to Serial.  (processor resets on its own)
  • Numbers greater than "1" output to Serial.

The question...
  • Can anyone reproduce the problem?  (please try it on any 328 or 168 based board)
« Last Edit: April 17, 2011, 01:31:55 am by Coding Badly » Logged

Bangalore, India
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I am setting it up in my breadboard to try it.

Meanwhile are you using an external clock crystal?
Logged

Checkout some of my Arduino projects and tutorials

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 208
Posts: 12933
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I am setting it up in my breadboard to try it.

Thank you!  This thing has been driving me batty.  At this point, my only theory is that the stack is becoming corrupt.  I believe, for the theory to be true, there has to be an interrupt service routine in the mix.  But, I'm down to USART RX (which should never fire) and TIMER0 OVF (which is used in every Arduino application every written).

Quote
Meanwhile are you using an external clock crystal?

16 MHz.  With the exception of no bootloader, it should be functionally equivalent to an Arduino.
Logged

0
Offline Offline
Faraday Member
**
Karma: 24
Posts: 3487
20 LEDs are enough
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you think an ISR is involbed: add CLI() and see if the problem still happens.
Did you already try to disassemble it?
Logged

Check out my experiments http://blog.blinkenlight.net

Bangalore, India
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well this is strange. For me nothing get's printed in the serial monitor.

I was using Atmega 328P
Logged

Checkout some of my Arduino projects and tutorials

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 208
Posts: 12933
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you think an ISR is involbed: add CLI() and see if the problem still happens.

Thanks!  Great idea...

Quote
void setup( void )
{
  cli();
  Serial.begin( 115200 );
...snip

...this is much worse.  I'm starting to think this processor has been damaged.

Quote
void loop( void )
{
  cli();
...snip

...this is much better.  But it still fails.

Quote
Did you already try to disassemble it?

I did.  I could not find anything suspicious.

I also tried Arduino 0021.  The behaviour is a bit better (less frequent failures; that could be coincidence) but it too fails.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 208
Posts: 12933
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Well this is strange. For me nothing get's printed in the serial monitor.

What happens if you remove the jumper?

Try putting a 3 second delay at the top of setup.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 208
Posts: 12933
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

For me, the three second delay has made the symptoms much worse.

What the heck is going on!  smiley-mad  smiley-cry
Logged

0
Offline Offline
Faraday Member
**
Karma: 24
Posts: 3487
20 LEDs are enough
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What happens if you remove the analogWrite? What if you remove the jumper? What is you power supply?
Logged

Check out my experiments http://blog.blinkenlight.net

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 208
Posts: 12933
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What happens if you remove the analogWrite?

Problem disappears.

Quote
What if you remove the jumper?

Problem disappears.

Quote
What is you power supply?

Powered USB hub.  Consistently provides 5.12 volts.

I've also tried the latest version of WinAVR (20100110).
« Last Edit: April 17, 2011, 03:12:07 am by Coding Badly » Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 208
Posts: 12933
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Another fun wrinkle.  This seems to behave correctly...

Code:
#include <avr/io.h>

void HardwareSerial_write(uint8_t c)
{
  while (!((UCSR0A) & (1 << UDRE0)));
  UDR0 = c;
}

void HardwareSerial_begin( long baud )
{
  uint16_t baud_setting;

  UCSR0A = 1 << U2X0;
  baud_setting = (F_CPU / 4 / baud - 1) / 2;
  UBRR0 = baud_setting;
//  UCSR0B |= (1 << RXEN0);
  UCSR0B |= (1 << TXEN0);
}

void setup( void )
{
  HardwareSerial_begin( 115200 );
  analogWrite( 3, 127 );
}

void loop( void )
{
  static bool DoOnce = true;
  static unsigned Loops;
 
  if ( DoOnce )
  {
    ++Loops;
    HardwareSerial_write( '*' );
    DoOnce = false;
  }
}
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18807
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Can anyone reproduce the problem?  (please try it on any 328 or 168 based board)

On a Uno, the problem does not occur.
Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18807
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The hardware...
  • 328P processor on a breadboard.
  • Jumper from pin 3 to pin 8.

What is your wiring, exactly? Maybe put a 0.1uF capacitor there for decoupling.
Logged


Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 208
Posts: 12933
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What is your wiring, exactly?

10K resistor from +5 to RESET.  Pushbutton to ground so I can reset the processor.

TX and RX connected to a Pololu AVR Programmer.

0.1uF capacitor across VCC and GND at the processor.

16 MHz crystal + capacitors from Evil Mad Science connected to XTAL pins.

AVCC connected to +5 volts.

Analog side GND connected to ground.

AREF unconnected.

SCK, MOSI, and MISO connected to the Programmer.

I've tried with and without and LED + series resistor on pin 3.

Quote
Maybe put a 0.1uF capacitor there for decoupling.

Across VCC and GND?
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 208
Posts: 12933
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
On a Uno, the problem does not occur.

Thank you for testing!

A single "1" was output?  Anything different if you click the Reset button?
Logged

Pages: [1] 2   Go Up
Jump to: