Atmega328P stops working

akimata

Joined Mar 6, 2016
9
Hello guys,
I've got really big problem with this microcontroller. It likes to freeze/stop working at any time when i put 5V on INPUT.
I'm trying to make RF communication but when it's freezing i don't want to restart it like once a week...

So what i noticed:
- when i send a 5V signal transmitter start working but voltage is dropping from like 4,3 V to like ~3V

Alec_t

Joined Sep 17, 2013
13,326
Welcome to AAC!
You need to give more details of your setup. Can you post a schematic? Which INPUT gets the 5V signal? What is doing the transmitting? Which voltage is dropping? What is sending the 5V signal and where is it sent? What is your power supply rating?

akimata

Joined Mar 6, 2016
9
I'm sending 5V to 15leg of atmega.Transmitter is sending short message to receiver, it's working fine most of the time untill uC freeze. Main voltage is dropping, coming from power supply through stabilizer, i tried also connecting to 5V of my arduino, same thing. At the moment i take 5V from my power supply just to check if it's working as i want, by the time i want to connect a motion sensor to it.

Strange thing is also when i use stabilizer 5V i don't get 5V at output but like 4,3 with nothing even connected to it.

nerdegutta

Joined Dec 15, 2009
2,684
Hi.

A circuit diagram/ close up picture of the circuit is needed, along with the source code.

To get the best help/answers, you need to provide a lot of detailed information. I guess you've been working on the circuits for some time before you ask a question. We have never seen the circuit or the source code. Can't read minds.

Papabravo

Joined Feb 24, 2006
19,846
I will say this: when properly connected, I have never had this type of problem with an Atmel ATMega part. They are IMHO ultra reliable and very robust. Extraordinary claims require extraordinary evidence. So far you have provided very little. The probability that this problem is self inflicted is seemingly quit high.

akimata

Joined Mar 6, 2016
9
So i tried to use GND instead of 5V and looks like it fixed problem by now, i hope so gonna test a little bit more. Next thing i noticed that when i hold wire connected to 5V of transmitter it stops transmitting, wires are insolated.

I can draw you simple diagram when you really need it but it's really simple.

Code

C:
#include <VirtualWire.h>
int LED=2;
boolean LEDON=false;
char stan;
void setup()
{

Serial.begin(9600);
pinMode (LED,OUTPUT);
vw_setup(2000);
vw_set_rx_pin(4);
vw_rx_start();
Serial.print(9600);
}

void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

if (vw_get_message(buf, &buflen))
{
int i;
String stan;
for (i = 0; i < buflen; i++)
{
stan +=char(buf[I]);
}
if ( stan =="on")
{

digitalWrite (LED, HIGH);
Serial.print(stan);
Serial.println("");
delay(100);

}
else
{
digitalWrite (LED, LOW);
}
} }
//Transmitter
C:
#include <VirtualWire.h>
int guzik=4;
void setup()
{
pinMode(guzik, INPUT_PULLUP);
vw_set_tx_pin(9);
vw_setup(2000);    // Bits per sec
}

void loop()
{
char *msg;
digitalWrite(13, true);

else {msg="off"; } ;

vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
delay(200);
}

Last edited by a moderator:

Papabravo

Joined Feb 24, 2006
19,846
So it looks like the code is from the Arduino IDE. Is that correct? You didn't mention that in your original post. You talk about pin 15 but we have no idea what you're talking about because we have no point of reference. Is it the ATMega328P chip, or the connector. Do you really expect help when you won't give us the information that we requested?

So from the datasheet, pin 15 on the DIP part is PB1 which can be a general purpose I/O, or OC1A (Timer/Counter1 Output Compare Match A Output), or PCINT1 (Pin Change Interrupt 1). Which is it? Connecting +5V or GND to this pin if it is an output is a bad bad thing. Connecting 5V or GND to it if it is an input should not affect the operation unless Pin Change interrupts are enabled or you go into a tight loop from which there is no exit. In either case the wound must be self inflicted.

So why is there no reference to pin 15 in your code?

Alec_t

Joined Sep 17, 2013
13,326
If you're only getting 4.3V from a 5V regulator with at least the minimum recommended load there is something wrong with your power supply.

akimata

Joined Mar 6, 2016
9
Yeah sorry , i'm using arduino to put code into atmega. 15 leg is digital pin 9 and i'm using it as INPUT

vw_set_tx_pin(9);

It's much better now because voltage is not jumping , it's stable.
Any idea why transmitter stops trasmitting when i hold a wire?

Papabravo

Joined Feb 24, 2006
19,846
If you're only getting 4.3V from a 5V regulator with at least the minimum recommended load there is something wrong with your power supply.
I agree. I also note from the datasheet that the part will operate with any Vcc from 1.8V to 5.5V so operating a 3VDC should not be a problem. But whatever voltage you operate at should be stable and regulated. Why can't we see a schematic -- why?

Papabravo

Joined Feb 24, 2006
19,846
Yeah sorry , i'm using arduino to put code into atmega. 15 leg is digital pin 9 and i'm using it as INPUT

vw_set_tx_pin(9);

It's much better now because voltage is not jumping , it's stable.
Any idea why transmitter stops trasmitting when i hold a wire?
Without a picture I can only guess what you are talking about.
To answer your question. Yes -- something is wrong with the way you've hooked things up. Show us how you did that and we might have a chance to help you. Drag your feet on generating a schematic and we'll go around in circles till the universe cools to absolute zero.

nerdegutta

Joined Dec 15, 2009
2,684
I don't think this is part of the problem, but what exactly does this line:

C:
Serial.print(9600);

akimata

Joined Mar 6, 2016
9
2 capacitor near crystal are 22pF also i've got 1 capasitor near VCC

Moderators note: changed white balance of image to have more contrast and inserted as full image

Last edited by a moderator:

djsfantasi

Joined Apr 11, 2010
8,783
I don't think this is part of the problem, but what exactly does this line:

C:
Serial.print(9600);
Initializes the Arduino built-in serial port to operate at a speed of 9600bps.

nerdegutta

Joined Dec 15, 2009
2,684
Initializes the Arduino built-in serial port to operate at a speed of 9600bps.
And what does this line:
C:
Serial.begin(9600);

djsfantasi

Joined Apr 11, 2010
8,783
Arghh. I saw what I wanted to see.

The correct answer to your first question is that Serial.print(9600); transmits the number 9600 in ASCII to the output pin.

nerdegutta

Joined Dec 15, 2009
2,684
Arghh. I saw what I wanted to see.

The correct answer to your first question is that Serial.print(9600); transmits the number 9600 in ASCII to the output pin.
That's what I thought. I wonder why the TS want to transmit that number...?

Papabravo

Joined Feb 24, 2006
19,846
2 capacitor near crystal are 22pF also i've got 1 capasitor near VCC

View attachment 101993

Moderators note: changed white balance of image to have more contrast and inserted as full image
1. You show only 8 out of 28 pins connected; what about the other 20?
2. Did you seriously leave those other 20 pins floating?
3. Don't you think you should provide something for the RESET(pin 1)?
4. What is pin 15 doing?
5. There are no bypass capacitors anywhere on the schematic. If they are there then draw them. Their presence is a critical piece of information.
6. Why is pin 6 grounded? It is PD4/PCINT20/XCK/T0 -- Right?
7. Which pin goes to the RF transmitter? I hope it is pin 3 (TXD), and that it is properly configured.
8. What is the frequency of the crystal?
Completeness and precision are everything in this business. You can't expect good results if you rely on sloppy and incomplete schematics. I don't mean to be harsh, but you have to understand that effective debugging absolutely requires adequate documentation of what you have done and what design decisions you have made and more importantly NOT MADE.

Last edited:

akimata

Joined Mar 6, 2016
9
1. Not connected, what should i do with them? all to GND?Waht's the point for that? No matters what state 5V or GND i have there when i'm not using them. If not correct me
2. Looks like
3. Yeah i know i should put 10k Ohm resistor to 5V but i didn't experienced random resets yet, the problem is somewhere else
4. 15 pin is sending some kind of signal to transmitter, no idea how it works exactly
5. I've got 1 capacitor close to VCC and GND near atmega
6. if(digitalRead (guzik)==LOW){msg="on";}, so i need to put GND to it to let it work
7. It's 15
8. 16Mhz
As i said it's working after i change the way i send the signal from "sensor", now voltage is not droping and maybe that was leading atmega to stop working.

Alec_t

Joined Sep 17, 2013
13,326
Not connected, what should i do with them?
What does the datasheet tell you? Floating pins are likely to cause all sorts of unpredictable behaviour of the IC.