Author Topic: Can the Spark lose its program code?  (Read 9351 times)

Shaker

  • Newbie
  • *
  • Posts: 23
Can the Spark lose its program code?
« on: February 14, 2017, 02:28:44 pm »
Hello.

I have finished a project in which the Digispark is in a plastic case that's in another case mounted in the engine bay of my car. It should not get too hot in that particular place, especially these days in winter.

Today the thing stopped working (after about 2 days). I believed in a hardware error. Some transistor that possibly burned. But when I analysed it, it turned out that reprogramming brought it back to life.

Can the Spark lose its sketch code without being connected via USB?? It seemed to be running setup(), but not really running loop(). I pull PIN4 high in setup(), that's why I think, at least this part of the code was still alive.

Can anyone explain, what might have happened and why?

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Can the Spark lose its program code?
« Reply #1 on: February 14, 2017, 03:38:41 pm »
No, it shouldn't lose its program when not plugged in - the memory on the Attiny85 is nonvoliative flash memory, which doesn't need power to retain data - think like a usb flash drive. I can't tell you why it behaved that way... other than a program error. Maybe someone else with have some ideas.

Shaker

  • Newbie
  • *
  • Posts: 23
Re: Can the Spark lose its program code?
« Reply #2 on: February 15, 2017, 04:31:57 am »
That's possible. But I wonder, why it didn't start the sketch after unplugging and re-plugging power. I tried this more than once. PIN 4 was high. Would the bootloader set PIN4 to high? I don't think so. Pulling PIN4 to high is part of my setup()... At the setup() time, the bootloader is shut down already, right?

Then when I connected it with my Laptop, the bootloader came up directly, the (same) sketch uplaoded and the whole thing started working again.

Shaker

  • Newbie
  • *
  • Posts: 23
Re: Can the Spark lose its program code?
« Reply #3 on: February 15, 2017, 08:57:06 am »
Setting PIN4 to high is no fun? That's some news to me ;D

No, for real - I know, that 3+4 are used for USB, but PIN3 is not connected to anything.
PIN4 has a resistor followed by the "Base" of a NPN transistor. The Emitter is on gruond and on the collector there's the "exit" of a reed relais waiting. I don't know, what sould be causing signals here, especially - what could have caused a permanent damage to the memory content?

What I wanted to say is, it was not only my code that pulls PIN4 to high in therory, it actually was high. I could tell, because the relais was activated. So it must already have been partially executing my code. But not all of it, since I was waiting for PIN0 to turn high, which it didn't.
Flashed it and everything worked again.  :-\

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Can the Spark lose its program code?
« Reply #4 on: February 16, 2017, 02:28:01 am »
PIN4? I thought it was P3 that had the pullup resistor???

Shaker

  • Newbie
  • *
  • Posts: 23
Re: Can the Spark lose its program code?
« Reply #5 on: February 16, 2017, 02:39:26 am »
Yes, it's PIN3 that has the pullup resistor, which is why I chose PIN4 for this purpose ;)
I know that it is working (when everything is ok), because until setup() is executed the transistor and the relais are not active.

Shaker

  • Newbie
  • *
  • Posts: 23
Re: Can the Spark lose its program code?
« Reply #6 on: February 22, 2017, 01:25:03 pm »
So then... My problem persists... The thing seems to lock up after some time. Unless I unplug it from power, it doesn't seemm to  execute loop() anymore. That's a second problem, or they are linked. Cause now, unplugging doesn't help anymore. Now it does not startup anymore. I believe, I have to reprogram it again. I haven't tried yet.

I have 2 more questions, please:
1) I have a 14V power source, that connects to PIN1 over a 4K7 resistor. No voltage divider, just one resistor. Is that a possible problem? Is it a problem for the board, if it gets 14V on PIN1, even though the current is restricted? Can all the strange things happen because of this?

2) Are there fake boards around that have a poor quality? I bought mine on ebay for like 5 bucks. It doesn't have this typical USB A connector, but a micro USB jack on it, which I like in fact better. Are there original Digistump boards with micro USB jack? Where can I get an original one? Or are the fake ones as good as the original ones?

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Can the Spark lose its program code?
« Reply #7 on: February 22, 2017, 10:42:39 pm »
Er... yes, connecting P1 to 14v can be causing problems... even with the resistor. That will only limit the current, not the voltage. Maximum voltage any I/O pin should see is VCC + 0.5v, so 5.5v. I'm actually surprised your digispark is still working at all!!

I can't comment on the quality of the fakes or non-genuine boards. The Digispark has only ever come with a PCB USB 'plug', and the Digispark Pro has a microUSB socket. However, there really isn't much to the hardware on the digispark... so it's likely that that will be an issue... as long as it worked the first time you plugged it in! ;)


Shaker

  • Newbie
  • *
  • Posts: 23
Re: Can the Spark lose its program code?
« Reply #8 on: February 22, 2017, 11:53:21 pm »
Damn... Ok, I will try to fit another resistor to ground on my little board then  :-X Thank you!
On another pin (PIN2), that I use to measure some voltage I took care of this. Later it turned out, the maximum voltage to measure is 5V  ::)
But on PIN1 ... somehow... well, alright.

Another question: How trustworthy do you think is the onboard voltage regulator, considering an operation in a car (14V regulator)? I cannot put more components (external regulator + capacitor etc.) on that board to make it fit in the case I chose  :(
« Last Edit: February 23, 2017, 04:39:25 am by Shaker »

Shaker

  • Newbie
  • *
  • Posts: 23
Re: Can the Spark lose its program code?
« Reply #9 on: February 23, 2017, 04:50:24 am »
I understand! Very interesting!
I definitely will add a resistor to have a proper divider there... Poor Digispark board :P
In my case it cannot happen, that the overvoltage of PIN1 is powering the Digispark, because coincidently this is the line that also goes to VIN. My sketch detects power on PIN1. There also is another power source that's able to keep the Digispark running, that's why.
It really would be best to see everything, you're right.

It's kind of "my baby", but I'll never make profit out of it, so I think, it's ok posting it on the internet ;)

12V (batt.) are permanently powered from the car battery.
12V (key) is powered by the key lock.
NTC+ comes from a temperature sensor.
With PIN4 activating the relay RE1 the Digispark is able to power itself for a programmed time.
JP1 is for disconnecting PIN4 in case USB is connected.

Here's what I made out of it: http://satria.de/scripts/ImageBrowser.php?image=/200SX/KITT3/E-Fan2%2008.jpg&filter=E-Fan2&parent=/200SX/200SXs5.3.php?page=200SXs5.3-E-Fan.php
« Last Edit: February 23, 2017, 05:13:23 am by Shaker »

Shaker

  • Newbie
  • *
  • Posts: 23
Re: Can the Spark lose its program code?
« Reply #10 on: February 23, 2017, 05:44:22 pm »
Haha, ich hab auch überlegt, ob du Deutsch sein könntest ;) Ja, ölig sind sie auch hin und wieder. Bleibt nicht aus. Eigentlich bin ich aber IT-ler.

Back to topic: I added a 2K7 resistor from PIN1 to ground, which should result in a voltage of around 5V on PIN1. But I measured something, and this is something I do not understand in general:
When it comes to voltage dividers in front of a Digispark pin - isn't it important to know the impedance of that pin? When connecting the pin, the whole voltage divider changes and so does the voltage.
Without the additional resistor to ground, I measured 3.5V on PIN1. Not 12V. Wouldn't that be ok then, since it is below 5V?
Now, with that proper divider I measured 2,7V on PIN1. Sounds like hardly enough to switch the pin to HIGH at all.

Or is it like this: The voltage must be below 5V when disconnected, even if it drops further when connected? If you put it this way: If I provide a 1MOhm resistor in front of PIN1, the current can never exceed 1mA, altough the disconnected voltage is the operating voltage.

The more you learn the less you understand sometimes :D

Shaker

  • Newbie
  • *
  • Posts: 23
Re: Can the Spark lose its program code?
« Reply #11 on: February 24, 2017, 04:15:32 am »
I don't know exactly what you mean - I can't say, if the input draws current. I was just saying that I measured 3.5V on PIN1 and this is strange, since I had no divider in front, just 1 resistor. Now with the divider, the voltage is even less. That's why I was wondering about the impedance of an input pin, and if you have to take this impedance into account when setting up the divider. Obviously being high impedance, you don't have to. And so the question about the 3.5V remains. :D

Assuming I killed it - then why does it work again now after another re-programming? It behaves completely logically, just as I designed both hardware and sketch. But it doesn't do it for long.
So there is surely no mistake from the schematic to the board either.

An example: I re-programmed it (uploaded the sketch) tried some use cases: Changed the voltage on NTC+, watched the OUT - completely fine. Disconnected 12V (key) and depending on my software logic, PIN4 kept the board running or not. Complete power off, power on again, similar tests, everything fine.

This morning I installed it in the car again, drove 20 minutes to work, waited for the temperature to rise above my configured threshold - fan came on. Went off below the other threshold. Totally fine.

I'm waiting now for the day, it stops working again. ;D

// EDIT:
About the capacitors: I will give them a try, but they won't fit in my sweet case nicely...
About the heat - I measured the Digispark board when out of the case. The chip itself was at 50°C max. The regulator was not hot at all. But I would have to verify this, if it gets important.
« Last Edit: February 24, 2017, 04:29:44 am by Shaker »

Shaker

  • Newbie
  • *
  • Posts: 23
Re: Can the Spark lose its program code?
« Reply #12 on: February 24, 2017, 05:43:52 am »
So, when you attach a resistor to the input pin and feed it with 14V, you should expect 5.5V at the input pin. When it is only 3.5V, the input has become a resistor, providing a voltage divider. There is current flowing into it.
Alright, so this already is an indicator that I broke it :-\

Guess, I have to break a few until I know, how to treat them well :P

I've ordererd new ones and will check on them, how they behave when I provide real 5V from a didiver. Also double-check the temperatures then.

THANK YOU ! I learned quite something!
« Last Edit: February 24, 2017, 06:11:40 am by Shaker »

Shaker

  • Newbie
  • *
  • Posts: 23
Re: Can the Spark lose its program code?
« Reply #13 on: March 03, 2017, 04:33:22 am »
Status of yesterday evening: Still working! 8)

So, it's been an entire week without failure now. The added resistor to ground really made a difference.

I haven't checked the new boards and besides I would not be able to replace the current one, because the pins of Vin, GND and 5V have moved by 1 pin on these boards :-\

old:
Code: [Select]
--------

o 5V
o Gnd
o Vin

  o o o o o o
  0 1 2 3 4 5
--------

new:
Code: [Select]
--------
o 5V
o Gnd
o Vin


  o o o o o o
  0 1 2 3 4 5
--------
« Last Edit: March 03, 2017, 04:51:54 am by Shaker »

dontz125

  • Newbie
  • *
  • Posts: 5
Re: Can the Spark lose its program code?
« Reply #14 on: May 14, 2017, 11:58:40 pm »
If you decide to redesign your unit, I would suggest adding anti-reverse and TVS diodes to the poewr supply. I would also add flyback diodes to your relays across the armature coil pointing towards 12v. Those transistors have a pretty good voltage rating, but it's not uncommon for relay coils to put out spikes pushing 100v. If you can't easily place a diode across the fan relay coil, at least put one across K2 and K5.