Trinket M0 freeze

Adafruit's tiny microcontroller platform. Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
thefwguy
 
Posts: 19
Joined: Wed Apr 25, 2018 12:24 pm

Trinket M0 freeze

Post by thefwguy »

Hi ! I have a question.
I have a simple project using a Trinket M0 that more or less randomly freeze.
I tested it for long time but not on the final place and never experienced any problem. Now on the final place, it randomly freeze, I have to reset it to have the code restarted.
The code is based on Arduino, not CircuitPython and I suspect the freeze come from electric noise that somehow reach the micro.
The power supply (5V) is applied to the BAT pin and "supposedly" is filtered, i.e. is coming from an AC/DC step down converter. Is quite hard to do measurement on the final place so I can't see if actually there are strange spikes around, however knowing there is a motor involved and that the freeze happens randomly only when the motor is running, I would say is the most probable cause. It could be maybe induced on the line or even as magnetic field (some wires are close to the Trinket).
To solve the problem I was considering to place some small capacitor on the micro board, I did assume exists some filters there but probably is better to have something more.
Any suggestion about how to filter ? I was thinking about a .1 uF between BAT and GND
Thanks

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Trinket M0 freeze

Post by mikeysklar »

If you want to post a photo of your circuit that might help.

Have you tried adding some print statements and watching the Arduino Console to see where the freeze is occurring?

Can you test the circuit without the motor connected to see if the hang still occurs?

Does the same hang occur when powered from a USB source instead of from the BAT pin?

User avatar
thefwguy
 
Posts: 19
Joined: Wed Apr 25, 2018 12:24 pm

Re: Trinket M0 freeze

Post by thefwguy »

Schematic_bathFan_2021-11-20.png
Schematic_bathFan_2021-11-20.png (60.24 KiB) Viewed 199 times
Hi !
Thanks for the answer, let see

The circuit right now is in a wall and thus is not connected via USB to a computer, aka I can't see any log nor I can plan to do so unless doing heavy works on the wall :)
So no, I can't debug traditionally, I have to theorize and try in different way.
Actually I'm planning to build another circuit identical (I made a PCB to host the Trinket) and try to reproduce more or less the same conditions, like grabbing a motor and having it close to the Trinket.

Without the motor I don't have any problem, I did test the circuit for more than a month, never had a single freeze.
And I didn't try to power from the USB pin .. mmm this in interesting, need to check the differences on the Trinket schematic, thanks for the idea !

I also will try to add the watchdog, at least I will not have to manually restart the circuit (I don't press the reset button, I turn off and then back on).

Attached the schematic :
Schematic_bathFan_2021-11-20.png
Schematic_bathFan_2021-11-20.png (60.24 KiB) Viewed 199 times
Thanks !
Steve

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Trinket M0 freeze

Post by mikeysklar »

Thank you for the schematic.

Since the circuit runs well without the motor that is likely the culprit and you should focus on that part of the circuit.

I see you are using a relay which shows a protection diode. Is that all in the real circuit? Is the protection diode large enough for the kickback as that also seems like the most likely culprit for resetting the controller.

User avatar
thefwguy
 
Posts: 19
Joined: Wed Apr 25, 2018 12:24 pm

Re: Trinket M0 freeze

Post by thefwguy »

Hi

Yes, I think the problem comes somehow from the motor.
Could be maybe the wire that bring power to the motor (coming from the relay) that creates EMI maybe because very close to the electronics, or maybe a return over the hot that somehow pass the AC/DC step down converter.

To answer your questions, yes, everything you see on the schematic is on the real circuit and for the diode I used a 1N4001 I had around, hope to don't have to use a Schottky but I think anyway the spikes could come from the contacts or the motor rather than the control.
Attached a picture of the circuit when was under tests outside the wall.
Do you think a small capacitor between BAT and GND (maybe a ceramic .1 uF) could help ?

Thanks
Attachments
2022-01-04 16.07.32-small.jpg
2022-01-04 16.07.32-small.jpg (240.49 KiB) Viewed 196 times

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Trinket M0 freeze

Post by mikeysklar »

Nice combo of custom board and 3D print.

I could not see the diode in your photo.

The .1uF cap for power filtering is fine to add, but I doubt will make a difference.

Try running some test code that triggers than fan more frequently. Does it hang sooner (more frequent)?

User avatar
thefwguy
 
Posts: 19
Joined: Wed Apr 25, 2018 12:24 pm

Re: Trinket M0 freeze

Post by thefwguy »

Hi !

The diode is barely visible in the photo but is there :)
Is the small black spot close to the relay, on the top.

I did try to run some tests to see if there is some trigger pattern but so far I have to say seems totally random.
I can manually trigger the fan and sometime no crash, I can turn on and off the fan without problems.
Other times the crash happens after few seconds the fan starts, other times after minutes.
It appears to be a very random event.
I hope this week end to have time to build a second unit, find a motor somewhere and start to see if I can duplicate the problem.
Since the unit is placed in a box in a wall the problem could be triggered by the position of the wires connecting the fan to the circuit.

So I will try to duplicate the system and run experiments, then I'll try to add some ceramic capacitor as filters but also switch the power supply from BAT to USB.
On the duplicate I should be able to do some measurements and see if the power supply (https://www.diymore.cc/products/ac-dc-5 ... or-arduino) is affected by the fan, supplying a noisy 5V.

Thanks
STeve

User avatar
thefwguy
 
Posts: 19
Joined: Wed Apr 25, 2018 12:24 pm

Re: Trinket M0 freeze

Post by thefwguy »

Quick update.

I did build a second unit and assembled a test bench with a motor similar to the one in the bathroom.
So far the tests I was able to run and the measurements done, confirms that the problem IS the motor, or better, the spike generated on the AC line when the motor starts.
When this happens it can have devastating effects on the Trinket via the AC/DC step-down converter.
Depending when the motor starts, probably in relation with the phase, a spike (about 200 uS) is generated and propagated to the AC/DC step-down converter.
When this happens, due the spike, the AC/DC step-down converter drops the power from 5 V to 2 V for at least 50 ms !!
Clearly this is something the Trinket doesn't like and in fact triggers the watchdog now present in the code.

So clearly the .1uF capacitor on the 5V would do nothing, the problem is the AC/DC converter I choose that acts badly in front of spikes on the AC.
The 470uF capacitor I put initially after the AC/DC is not enough to reduce the 50 ms powering down, not sure if is making sense to try with bigger capacitors.
I need to explore to use different power supply for the circuit, less affected by AC noise due to inductive loads.

I improved the code activating a 8 seconds watch dog but is really not a solution. On my bench I experienced consecutive resets every time the motor was starting.
Because on the test bench the motor is very close to the circuit of course the effects are amplified and what I see happening random on the circuit, is quite consistent on the bench (that's good :) ).
Attached some pictures, the bench and the power glitch when the motor starts
Any suggestion is usually more than welcome !

For example, anybody has suggestions for a small yet robust AC/DC step-down converter ?
Need to go from 110V to 5V at least 500mA

Or maybe a way to filter the AC from spikes ?

Thanks
Steve
Attachments
spike_on power.jpg
spike_on power.jpg (305.79 KiB) Viewed 166 times
initial_spike_over_DC.jpg
initial_spike_over_DC.jpg (290.82 KiB) Viewed 166 times
test_bench.jpg
test_bench.jpg (244.61 KiB) Viewed 166 times

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Trinket M0 freeze

Post by mikeysklar »

Good job isolating the motor and nice shot of your setup.

What does the fan require for current / voltage (as shown on its label)?

What are the specs on the AC/DC converter you are using?

I feel like I've cheated these kind of situation on the past by using a battery to power the Trinket thus isolating the circuit from the AC load.

User avatar
thefwguy
 
Posts: 19
Joined: Wed Apr 25, 2018 12:24 pm

Re: Trinket M0 freeze

Post by thefwguy »

Hi, thanks !

Well, the motor is an unknown exhaust fan, embedded in the ceiling of a bathroom, I know only is a 110 V one and very probably old :)
The only way to see some characteristics would be dismantle the bathroom,
The one I'm using for tests (in the test bench picture) was around in my junk box :) I think was coming from some kind of fan for something.
No brand, only a P/N 001-02082-006, year 2005 and anyway is a 110V of course.
So no really motor specifications. I'm sure that the bathroom fan cause little bit less spike because the greater distance from the AC/DC stepdown converter.
The one on the test bench being so close generates a much stronger noise.

The AC/DC stepdown is a diymore AC/DC 5V stepdown (https://www.diymore.cc/products/ac-dc-5 ... or-arduino)

Yeah I hear you, dealing with AC noise is not fun :) I hope to be able to find a solution, I could add a charger and a battery, it should limit the problem but I will have to redesign everything with a price increase. True, I'm not doing a production but still would be overkill.
I'll try to increase the capacitor on board, maybe that alone will relieve the drop enough to don't cause problems to the micro.

Thanks !!
Steve

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Trinket M0 freeze

Post by mikeysklar »

Steve,

Have you considered swapping the relay for a SCR or solid state triac over a relay which has the kickback? I know that can help in specific AC loads.

User avatar
thefwguy
 
Posts: 19
Joined: Wed Apr 25, 2018 12:24 pm

Re: Trinket M0 freeze

Post by thefwguy »

Hi Mike !

Actually yes, I did consider to redesign the circuit using a Triac to control the fan, however doing so imply to redesign everything and re-do the PCB.

I did some other tests and I think the "problem" is the doubt quality of the AC/DC step-down unit.
From some measurements on the system, there is nothing that justify the drop from 5V to 2V for 50 ms when the fan starts.
I did order other AC/DC modules and some EMI filters and will run some tests, if still the problem will exists I'll try to use a Triac instead a rele'.

I'm waiting the arrival of the ordered material, hope they'll arrive soon.

Thanks
Steve

User avatar
thefwguy
 
Posts: 19
Joined: Wed Apr 25, 2018 12:24 pm

Re: Trinket M0 freeze

Post by thefwguy »

Quick update
I did receive today two new AC/DC step-down converter, one 700mA, similar to the one used so far, and one 2 A.
Did try the 700 mA and already saw a huge improvement !
Still random there are Trinket freezing, but at least I don't see anymore the voltage dropping.
What I see now is a random narrow spike when the fan start or stop, but most of the time the circuit works as designed.

So that is the confirm that the problem is the AC/DC step-down unable to filter properly spikes on the AC due to the motor.
I'm still waiting for an EMI filter to see if it improve the situation and I will try to test now the AC/DC step-down with 2A, just looking at it seems much well fitted for filtering out noise.
Attached the three converter, on the top the original one, the worse, in the middle the "new" 700 mA version and on the bottom the 2A version.

Already with the new 700 mA and the watchdog enabled on the Trinket the system is surely more usable.
I have to design an enclosure for the new AC-DC converter and will try on the final place, so far I did tests only on the test bench.

Will post an update after all the tests, including using the EMI filter and on the final place.

Thanks
Steve
Attachments
ac-dc-step-down.jpg
ac-dc-step-down.jpg (140.2 KiB) Viewed 153 times

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Trinket M0 freeze

Post by mikeysklar »

Cool. Nice to see progress with the 700mA already showing improvements. Maybe 2A will just resolve it? Following.

User avatar
thefwguy
 
Posts: 19
Joined: Wed Apr 25, 2018 12:24 pm

Re: Trinket M0 freeze

Post by thefwguy »

Hi, yes, definitively changing the AC/DC step-down alone, improved the reliability up to the 90% !
Now I have only to deal with some spikes that still can make the Trinket go berserk, I did ordered some 5V diodes suppressor, we'll see soon if that put the word End on this :)
The spikes are about 200 uS over the 5V rail, about 14V spikes.
Not long enough to damage the Trinket (at least I hope so) but strong enough to trigger a crash but quite random.
As said, now the reliability on my test bench is about 90%, with the older AC/D was probably around 20-30%.

The bottom line is, never underestimate the impact of the power supply on a project !

However I will have to deal with another problem.
I use a DHT-22 to read humidity and temperature. Sometime, instead to have the Trinket crash, it become impossible to read the sensor.
I did try to force a Trinket reset but has no effect, sometime it restore alone after random time (seconds to minutes) but sometime remains stuck forever.
The only way to restore is to detach the power supply from the sensor.

So would be nice to have an extra I/O pin to power supply the sensor when reading it and remove the power after that.
But I don't have a free I/O on the Trinket M0. However I did some quick test.
I'm using a neopixel bar and I saw that I can still control manually the SDA signal without causing problems to the rest of the code.
The maximum time spent to send data to the neopixel is around 250 uS.
So I could set up a circuit that monitor the SDA signal for the neopixel and if there is a signal stable for more than 500 uS, give power to the DHT-22.
Since I have a state machine that control everything, there is no conflict to use the SDA in this dual mode, i.e. signal for the neopixel and signal for powering up the sensor.

Any idea how to set up such circuit ?
Wonder if somebody else had this problem before.

If I can pull up this, I will redesign everything at this point, even integrating the new AC/DC step-down in my PCB.

Once again, thanks for the discussion, so far I had lot of fun and learned something new :)

Steve

Locked
Please be positive and constructive with your questions and comments.

Return to “Trinket ATTiny, Trinket M0”