Atmega328P stops working

Discussion in 'Embedded Systems and Microcontrollers' started by akimata, Mar 6, 2016.

  1. akimata

    Thread Starter New Member

    Mar 6, 2016
    9
    0
    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
    Only thing what helps for freeze is pull out the plug.

    Hope someone knwos the answer :)
    Sorry for bad english
     
  2. Alec_t

    AAC Fanatic!

    Sep 17, 2013
    7,010
    1,451
    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?
     
  3. akimata

    Thread Starter New Member

    Mar 6, 2016
    9
    0
    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.
     
  4. nerdegutta

    Moderator

    Dec 15, 2009
    2,626
    847
    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. :)
     
  5. Papabravo

    Expert

    Feb 24, 2006
    11,069
    2,152
    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.
     
  6. akimata

    Thread Starter New Member

    Mar 6, 2016
    9
    0
    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

    //Receiver
    Code (C):
    1. #include <VirtualWire.h>
    2. int LED=2;
    3. boolean LEDON=false;
    4. char stan;
    5. void setup()
    6. {
    7.  
    8.   Serial.begin(9600);
    9.   pinMode (LED,OUTPUT);
    10.   vw_setup(2000);
    11.   vw_set_rx_pin(4);
    12.   vw_rx_start();
    13.   Serial.print(9600);
    14. }
    15.  
    16. void loop()
    17. {
    18.     uint8_t buf[VW_MAX_MESSAGE_LEN];
    19.     uint8_t buflen = VW_MAX_MESSAGE_LEN;
    20.  
    21.     if (vw_get_message(buf, &buflen))
    22.     {
    23.     int i;
    24.        String stan;
    25.       for (i = 0; i < buflen; i++)
    26.   {
    27.   stan +=char(buf[I]);
    28.   }
    29.      if ( stan =="on")
    30.      {
    31.  
    32. digitalWrite (LED, HIGH);
    33. Serial.print(stan);
    34. Serial.println("");
    35.   delay(100);
    36.  
    37.    }
    38.    else
    39.    {
    40.     digitalWrite (LED, LOW);
    41.    }
    42.    } }
    43.  
    //Transmitter
    Code (C):
    1.  
    2.  
    3.  
    4. #include <VirtualWire.h>
    5. int guzik=4;
    6. void setup()
    7. {
    8.   pinMode(guzik, INPUT_PULLUP);
    9.   vw_set_tx_pin(9);
    10.     vw_setup(2000);    // Bits per sec
    11. }
    12.  
    13. void loop()
    14. {
    15.   char *msg;
    16.   digitalWrite(13, true);
    17.  
    18. if (digitalRead (guzik)==LOW) {msg="on"; }
    19. else {msg="off"; } ;
    20.  
    21.       vw_send((uint8_t *)msg, strlen(msg));
    22.     vw_wait_tx(); // Wait until the whole message is gone
    23.     digitalWrite(13, false);
    24.     delay(200);
    25. }
    Mod note: Added CODE tags
     
    Last edited by a moderator: Mar 6, 2016
  7. Papabravo

    Expert

    Feb 24, 2006
    11,069
    2,152
    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?
     
  8. Alec_t

    AAC Fanatic!

    Sep 17, 2013
    7,010
    1,451
    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.
     
  9. akimata

    Thread Starter New Member

    Mar 6, 2016
    9
    0
    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?
     
  10. Papabravo

    Expert

    Feb 24, 2006
    11,069
    2,152
    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?
     
  11. Papabravo

    Expert

    Feb 24, 2006
    11,069
    2,152
    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.
     
  12. nerdegutta

    Moderator

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

    Code (C):
    1. Serial.print(9600);
     
  13. akimata

    Thread Starter New Member

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

    akimata_atmega_schematic.jpg

    Moderators note: changed white balance of image to have more contrast and inserted as full image
     
    Last edited by a moderator: Mar 6, 2016
  14. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    3,486
    1,245
    Initializes the Arduino built-in serial port to operate at a speed of 9600bps.
     
  15. nerdegutta

    Moderator

    Dec 15, 2009
    2,626
    847
    And what does this line:
    Code (C):
    1. Serial.begin(9600);
     
  16. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    3,486
    1,245
    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.
     
  17. nerdegutta

    Moderator

    Dec 15, 2009
    2,626
    847
    That's what I thought. I wonder why the TS want to transmit that number...? :confused:
     
  18. Papabravo

    Expert

    Feb 24, 2006
    11,069
    2,152
    Your schematic is incomplete:
    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: Mar 6, 2016
  19. akimata

    Thread Starter New Member

    Mar 6, 2016
    9
    0
    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.
     
  20. Alec_t

    AAC Fanatic!

    Sep 17, 2013
    7,010
    1,451
    What does the datasheet tell you? Floating pins are likely to cause all sorts of unpredictable behaviour of the IC.
     
Loading...