Did I permanently damage my Mega2560?

I believe I damaged my Mega, however more concerning to me is that I don't know how it happened and I'm hoping that those of you more experienced may be able to speculate as to how.

Yesterday I used a few of the different frequency modules (
<FreqMeasure.h> and
https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/arduino-pwm-frequency-library/Arduino%20PWM%20Frequency%20Library%20v_05.zip and
Gammon Forum : Electronics : Microprocessors : Timers and counters)
and I noticed that after I uploaded frequency code (I'm not sure which module this started with) that my A1 and A2 stopped working and now they output 2.8v as pinMode(A1, INPUT_PULLUP); and 1.8 as pinMode(A2, INPUT_PULLUP);, as well as 2.53v as pinMode(A1, OUTPUT); and 0.47v as pinMode(A2, OUTPUT); . I believe that test confirms that A1 and A2 are hosed, correct? Is there any sort of firmware reset I can try?

I'm confused as to what could have caused this, I did not knowingly change anything with those pins and the hardware has remained the same for at least a week. My Arduino was supposed to be well protected using the circuit below and A3, which is using a duplicate of A1 and A2 (and even resides on the same breadboard) is still functioning correctly? To be more descriptive I have 3 replications of the below circuit on the same breadboard, all using the same supply voltage source. The Arduino is powered by my laptop and there were no storms or anything recently. VCC is 4.72 and the output from the circuits to A1 and A2 are 4.7x, down to 0.3 when the momentary contact button is pressed.

Someone explained that with freqmeasure, you lose pwm functionality with pins 6, 7 and 8. I'm wondering if any of those modules could have affected the functionality of any of the analog in pins? I was also under the impression that with the circuit below, my Arduino pins were well protected?

[edit]
Could this have happened because I left that circuitry connected and uploaded a frequency test sketch that did not have those pins configured as inputs/anything at all?

// testing code
void setup() 
{
  // put your setup code here, to run once:
    Serial.begin(9600);
    pinMode(A1, OUTPUT);
    //pinMode(A1, INPUT_PULLUP);
    pinMode(A2, OUTPUT);
    //pinMode(A2, INPUT_PULLUP);
}

void loop() 
{
  // put your main code here, to run repeatedly:

    Serial.println("Looping");
    delay(3000);
}

The die of the ATmega2560 chip has the analog section separated from the rest to reduce noise.
It is possible to damage only the analog section of the chip, while the rest seems to run normally.

Remove everything from the Mega board, and check once again that the analog pins are bad. If they are, then gid rid of the Mega board. Don't use it, because you don't know what else is damaged.

Using a library or timers or a sketch can not damage the analog pins.

I would use 1N4148 diodes, because the Schottky diodes have leakage current. The 1µF is large, I would use 1nF or 10nF.
I like the double safety of the circuit, but something went wrong there. A breadboard can have bad contacts and jumper wires can be broken. If something is not connected properly, then it is not so safe anymore.

I don't believe that it is only 15V. Can it have a peak of 300V ? For example if the grounds are not connected.
I'm not talking about the 15V, I'm taking about the voltage between the 15V output and the Arduino GND. Can it be 300V if a ground wire has bad contact in the breadboard ? It depends on how the Arduino and the ECU are connected to the mains, but I think it is possible.
You should not destroy one Mega board after another. Try something else.
How much current can the 15V give ? Is there enough current for a optocoupler ? There are optocouplers that need only 1mA.

[ADDED] Which ECU is it ? Are there large motors with large current or is it inside a car ?

Hi, thank you for the reply. It appears that only A1 and A2 are damaged, I ran the below 3 sketches/scenarios with everything disconnected, 5v was 4.76, Vin was 4.23.

I forgot that the diagram mentioned ECU on it. You are correct to infer that this is for an automotive application and I was actually excited to put it into the vehicle for testing for the first time this weekend, however this happening has delayed that. That being said, this has all happened on the bench. I have the Arduino powered by my laptop currently and an external power supply (grounds linked together) that provides 15v to the circuit to simulate automotive voltage and benchtop switches to simulate the switches in the car. The 15v power supply can provide up to 3A, however it should be no more than 0.05mA with the resistance values, correct? I just received some PC817 opto couplers and some 74HC14 Schmitt Triggers today and I'd like to make changes so that overall the circuitry is more bullet proof, as most likely I caused this even though I'm not sure how. Let me know about your opinion on those components and the testing results.

With scenario 1 pinMode(Ax, INPUT_PULLUP); aside from A1 (2.67v) and A2 (1.526v), A0 through A15 were all at 4.68v except for A0 which was 4.57v .

With scenario 2 pinMode(Ax, OUTPUT); analogWrite(Ax, 0); aside from A1 (2.48v) and A2 (0.336v), A0 through A15 were all between 10 and 40 millivolts.

With scenario 3 pinMode(Ax, OUTPUT); analogWrite(Ax, 0); aside from A1 (3.29v) and A2 (3.81v), A0 through A15 were all 4.59v

Scenario 1


void setup() 
{
   Serial.begin(9600);
   
    pinMode(A0, INPUT_PULLUP);
    pinMode(A1, INPUT_PULLUP);
    pinMode(A2, INPUT_PULLUP);
    pinMode(A3, INPUT_PULLUP);
    pinMode(A4, INPUT_PULLUP);
    pinMode(A5, INPUT_PULLUP);
    pinMode(A6, INPUT_PULLUP);
    pinMode(A7, INPUT_PULLUP);
    pinMode(A8, INPUT_PULLUP);
    pinMode(A9, INPUT_PULLUP);
    pinMode(A10, INPUT_PULLUP);
    pinMode(A11, INPUT_PULLUP);
    pinMode(A12, INPUT_PULLUP);
    pinMode(A13, INPUT_PULLUP);
    pinMode(A14, INPUT_PULLUP);
    pinMode(A15, INPUT_PULLUP);
    
}

void loop() 
{
  // put your main code here, to run repeatedly:

    Serial.println("Looping");
    delay(3000);
}

Scenario 2

void setup() 
{
  // put your setup code here, to run once:
    Serial.begin(9600);

    pinMode(A0, OUTPUT);
    pinMode(A1, OUTPUT);
    pinMode(A2, OUTPUT);
    pinMode(A3, OUTPUT);
    pinMode(A4, OUTPUT);
    pinMode(A5, OUTPUT);
    pinMode(A6, OUTPUT);
    pinMode(A7, OUTPUT);
    pinMode(A8, OUTPUT);
    pinMode(A9, OUTPUT);
    pinMode(A10, OUTPUT);
    pinMode(A11, OUTPUT);
    pinMode(A12, OUTPUT);
    pinMode(A13, OUTPUT);
    pinMode(A14, OUTPUT);
    pinMode(A15, OUTPUT);
    
    int value = 0;

    analogWrite(A0, value);
    analogWrite(A1, value);
    analogWrite(A2, value);
    analogWrite(A3, value);
    analogWrite(A4, value);
    analogWrite(A5, value);
    analogWrite(A6, value);
    analogWrite(A7, value);
    analogWrite(A8, value);
    analogWrite(A9, value);
    analogWrite(A10, value);
    analogWrite(A11, value);
    analogWrite(A12, value);
    analogWrite(A13, value);
    analogWrite(A14, value);
    analogWrite(A15, value);
    
}

void loop() 
{
  // put your main code here, to run repeatedly:

    Serial.println("Looping");
    delay(3000);
}

Scenario 3

void setup() 
{
  // put your setup code here, to run once:
    Serial.begin(9600);

    pinMode(A0, OUTPUT);
    pinMode(A1, OUTPUT);
    pinMode(A2, OUTPUT);
    pinMode(A3, OUTPUT);
    pinMode(A4, OUTPUT);
    pinMode(A5, OUTPUT);
    pinMode(A6, OUTPUT);
    pinMode(A7, OUTPUT);
    pinMode(A8, OUTPUT);
    pinMode(A9, OUTPUT);
    pinMode(A10, OUTPUT);
    pinMode(A11, OUTPUT);
    pinMode(A12, OUTPUT);
    pinMode(A13, OUTPUT);
    pinMode(A14, OUTPUT);
    pinMode(A15, OUTPUT);
    
    int value = 255;

    analogWrite(A0, value);
    analogWrite(A1, value);
    analogWrite(A2, value);
    analogWrite(A3, value);
    analogWrite(A4, value);
    analogWrite(A5, value);
    analogWrite(A6, value);
    analogWrite(A7, value);
    analogWrite(A8, value);
    analogWrite(A9, value);
    analogWrite(A10, value);
    analogWrite(A11, value);
    analogWrite(A12, value);
    analogWrite(A13, value);
    analogWrite(A14, value);
    analogWrite(A15, value);
    
}

void loop() 
{
  // put your main code here, to run repeatedly:

    Serial.println("Looping");
    delay(3000);
}

A1 and A2 are definitely broken, and I'm not sure about A0.
It is better to get rid of that board. If you use it and a problem occurs, than you have to ask yourself every time if it could be caused by the ATmega2560 chip on the Mega board or something else. Perhaps the ATmega2560 chips decides to overheat after a month. It is damaged, get rid of it.
(I don't mind if you use it for testing, but paint a large red cross on it)

The electronics for inside a car should be able to deal with a spike of 120V at a input.
But to damage your A1 and A2 through that circuit, then I'm looking for a spike of 300V.

If the input of the ECU can drive a opto-coupler, then you can read the output of the optocoupler with the Arduino board. Most opto-coupler need 20mA at the input. Is it possible to connect the opto-coupler with a resistor to the 15V and the input, parallel with the internal pullup of the ECU ?
We have to know the specifications of the ECU.

I unfortunately do not have any access to the ECU hardware information. I can make the changes to the circuit that you've suggested (I must state that I've forgotten most of what I learned about hardware and that it was a circuit another forum user was nice enough to provide for me) however I'm uneasy that I still don't know what caused this and how to avoid it happening again. I guess the only thing the Mega is now good for is some sort of long term testing to see if it happens again.

It looks like the PC817 opto coupler I have has IF of 5 mA. The data sheet says

The PC817 contains a light emitting diode optically coupled to a phototransistor.It is a packaged in a 4-pin
DIP package.Input-output isolation voltage is 5000Vrms,Response time,tr,is typically 4μs and minimum
CTR is 50% at input current of 5mA.

The diagram below was suggested by someone on the forum, however I'm not sure of the values for D1 and D2, nor which inverting op amp they're suggesting for X4 and X3 and I've forgotten a lot about them so I'm not sure how to implement it and I don't want to speculate with the unlabeled hardware values. The first circuit I am more comfortable with because it only uses diodes, resistors and capacitors. Are either of the bottom 2 circuits what you had in mind?

15vAdc1

The idea is to separate the 15V ECU from the Arduino. A complete separation. No GND, no 15V, no 5V or whatever that is connected to both.

The input of the optocoupler (with resistor) does not have to be connected to GND. It can be connected to 15V and the input of the ECU. Pressing the button turns on the optocoupler.
No diodes or voltage divider is needed. Only a resistor to the collector output of the optocoupler.

afbeelding

Why is there a resistor of 10Ω or 100Ω in series with the pushbutton ?

:point_right: I was confused by ECU input and thought that it was an output. Sorry. The pushbutton is the part the creates the either 0V or 15V for the ECU input.

@turbosupramk3
Why are you using Analog inputs if the signal is either High or Low?

What I believe the ecu looks for is a pull to near ground for 2 of the inputs and varying voltage decreases for the other 2 inputs. So I have inferred that it has a pull up resistor in the ecu and I've measured a resistance of 10 ohms in the pull down switches for the 2 that pull to near 0 and varying resistance levels in the other 2 switches depending on the selector position.

Since ecu input and ecu 15v are the same signal wire , how does that change the diagram? I also need the Arduino to be able to pull that circuit to ground just like the factory selector does.

That's a great question. I had started emulating the varying voltage switches first and had replicated them for the binary switches. You're correct that at least 2 of them could be digital inputs.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.