Attiny85 Keeps failing - Help

Hi guys I am running this code on an Attiny85 but it keeps failing after a week or so. Sometimes it can be re-programmed but sometimes it fails altogether and requires replacement.

This is the code which works perfectly:

`Use code tags to format code for the forum`// Attiny85 program for power reduction of electromagnetic motor brakes.
// See http://tvdr.de/sim/3/brakes.htm.
// Provided as is, without any warranty. Free as in beer.
// Author: Klaus.Schmidinger@tvdr.de.

// I/O pins:

#define pCtl PB0 // connects to the control line of the M4S controller
#define pLed PB1 // controls the onboard LED (on if M4S control is low)
#define pPwr PB2 // connects to IN1+IN2 of the relais board
#define pXcg PB4 // connects to IN3+IN4 of the relais board

// Timing:

#define ReleaseTime 1000 // ms

// Globals:

bool BrakesReleased = false;
bool PowerReduced = false;
unsigned long ReleaseStart = 0;

void RelaseBrakes(void)
{
  digitalWrite(pPwr, LOW);
  digitalWrite(pXcg, LOW);
  BrakesReleased = true;
  PowerReduced = false;
}

void EngageBrakes(void)
{
  digitalWrite(pPwr, HIGH);
  digitalWrite(pXcg, HIGH);
  BrakesReleased = false;
}

void ReducePower(void)
{
  digitalWrite(pXcg, HIGH);
  PowerReduced = true;
}

void setup()
{
  // I/O pins:
  pinMode(pCtl, INPUT_PULLUP);
  pinMode(pLed, OUTPUT);
  pinMode(pPwr, OUTPUT);
  pinMode(pXcg, OUTPUT);
  digitalWrite(pLed, LOW);
  digitalWrite(pPwr, HIGH);
  digitalWrite(pXcg, HIGH);
}

void loop()
{
  if (digitalRead(pCtl) == HIGH) {
     digitalWrite(pLed, LOW);
     EngageBrakes();
     }
  else if (!BrakesReleased) {
     digitalWrite(pLed, HIGH);
     RelaseBrakes();
     ReleaseStart = millis();
     }
  else if (!PowerReduced) {
     if (millis() - ReleaseStart > ReleaseTime) {
        ReducePower();
        }
     }
}

 Any idea why it keeps failing?

Please correct your post and add code tags around your code.

There is a small pencil image below your existing posts.

  • click on this pencil ➜ that will let you edit your post.
  • Select the part of the text that corresponds to the code
  • Click on the <code/> icon in the toolbar to indicate that it is code
  • click image Save Edit

(Also make sure to properly indent the code in the IDE before copying and pasting it here. This can be done by pressing ctrlT on a PC or cmdT on a Mac)


Tell us about your circuit, power etc.. The code you shared is straightforward and would not damage the chip by itself. The issue is almost certainly electrical or hardware-related.

➜ relay board does not have proper flyback diodes ?
➜ weak regulator, insufficient decoupling, or long wires with power supply to the ATtiny85 which dips or spikes when the relay engages ?
➜ relay module inputs expecting a heavy sink/source current (some boards need >20 mA on each input), overstressing the MCU's pins ?
...

Hi, @spuidley
Welcome to the forum.

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

What does your project do?
How does it fail?

Tom.... :smiley: :+1: :coffee: :australia:

Hi Tom it switches relays on and off

It fails because it doesn't switch the relays and then it cant be programmed again. 3 have failed so far.

Hi, @spuidley
Thanks for the diagram.

How have you got the project powered on the 5V side?

Can you post some images of your project?
So we can see your component layout.

Tom.... :smiley: :+1: :coffee: :australia:

Do you have flyback diodes on brakes?
What is extra1?

Place 100uF and 0.1uF capacitors in parallel across the 5V and gnd at the Attiny85 PCB.

Tom.... :smiley: :+1: :coffee: :australia:

I had the same problem a few months ago , Atiny85 would even stop programming while connected to my PC.

After 4 failed within 2 weeks I gave up.

Took me some time to get plan B , I then programmed all 4 via ISP using a UNO.

Not one ever failed again

Yes here is an image

No I don't have flyback diodes on the brakes I understood the relays had optical separation here is the link 1-5PCS 4 Channel Relay Board AVR 51 PIC 5V 12V 4-Channel Relay Module with Optocoupler Relay 4 Way Relay Module for Arduino - AliExpress 502

Extra 1 is the signal high from the m4s controller

Does that mean fit the capacitors between the live and neutral as in green on this picture?

Post one still looks ugly…. Please help us maintain the forum tidy and neat… add code tags please.

Thanks, could you point me in the right direction to do that, My Attiny85 has a USB C connector

Thx

Sorry, first time here, I think I have edited it correctly

Where does the 5V on the Atiny come from?

Since there is no feedback diodes on the brakes the Atinys might be damadged.

Is the Atiny chips hot when power?

To program with an UNO just google there is lots of tutorials.

Replying from my phone , cannot attach any pic's.

You should use them.
And the way you power the relay doesn't take advantage of the optocouplers.

The 5 v comes from usb power through the M4s controller from the pc.

I have not noticed the chip getting hot.

It never fails during use, its always next time I turn on the pc and brake circuit.

I don't know anything about feedback diodes but I will learn.

Thanks