Go Down

Topic: One Crazy Sketch (Read 1 time) previous topic - next topic

Coding Badly

Apr 17, 2011, 08:28 am Last Edit: Apr 17, 2011, 08:31 am by Coding Badly Reason: 1
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: [Select]
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)



Sudar

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

Meanwhile are you using an external clock crystal?
Checkout some of my Arduino projects and tutorials

Coding Badly

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.

Udo Klein

If you think an ISR is involbed: add CLI() and see if the problem still happens.
Did you already try to disassemble it?
Check out my experiments http://blog.blinkenlight.net

Sudar

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

I was using Atmega 328P
Checkout some of my Arduino projects and tutorials

Coding Badly

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.

Coding Badly

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.

Coding Badly

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

What the heck is going on!  :0  =(

Udo Klein

What happens if you remove the analogWrite? What if you remove the jumper? What is you power supply?
Check out my experiments http://blog.blinkenlight.net

Coding Badly

#9
Apr 17, 2011, 10:06 am Last Edit: Apr 17, 2011, 10:12 am by Coding Badly Reason: 1
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).

Coding Badly


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

Code: [Select]
#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;
  }
}

Nick Gammon


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


On a Uno, the problem does not occur.
http://www.gammon.com.au/electronics

Nick Gammon


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.
http://www.gammon.com.au/electronics

Coding Badly

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?

Coding Badly

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?

Go Up