Close

It's the clock that's the problem, or is it? (yet another followup on the servo issue)

A project log for T85 Target

A mini Attiny85 target dev board

mcunerdmcu_nerd 02/08/2018 at 22:590 Comments

Up until yesterday, I thought the issue with trying to control the MG90S servo was the internal accuracy of the Attiny85 rc oscillator being too poor.  

Yesterday, I was trying to control the same MG90S servo with a board that I'm developing.  That particular board, unlike the T85 target board has the option to add an external crystal (which I used.)  Had the exact same problem! It was not working at all/unstable.  I then tried to control the servo with my Arduino Uno, and it worked perfectly fine.  

I initially blamed the the cheap Ebay crystal when according to the frequency measurement function of my EX330, it appeared that the accuracy of the crystal was worse than the Arduino Uno that uses a resonator (the mulimeter's frequency measurement function really isn't accurate enough for the task, but it was all I had/still have.) I managed to find some crystals that I ordered from Mouser some time ago and used one of those.  Same issue.  I compared my board to the Arduino Uno and noticed that the Uno has some electrolytic caps on it's 5V rail.  This had me thinking. Could it be a frequency accuracy issue, or is it really a power/noise related issue?

I decided to try my revised hypothesis by bodging in two 47 uF caps in parallel, and servo control was working much better with some occasional glitches.  I then decided to hook up the servo more directly to the power supply and it works flawlessly!  A little bit ago I decided to try the solution on my T85 board and the servo also works fine.  

So the problem appears to be that unlike my other servo, the MG90S must draw more current thus creating a greater voltage sag, thus crashing the mcu, resulting in having issues controlling the servo (found out that the servo was causing the mcu to crash after a bit of probing with my mulimeter.)  The solution is to give it a more direct connection to the power supply vs using the servo header.  A large enough electrolytic capacitor on the board should also fix things.

Other interesting bits:

I noticed that with the board I"m developing the servo would often crash the mcu in various interesting ways.  Sometimes the 50Hz signal would go completely missing.  Other times the duty cycle would remain static.  The most interesting failure mode was when the duty-cycle output became inverted.  I did try using a watchdog timer to reset the mcu after it crashed, but even that wouldn't work (even after I removed the servo.)

TL,DR

It has nothing to do with the accuracy of the 50Hz signal, it was simply drawing enough current to cause a voltage sag that made everything unstable.  Solution:hook it's power pins more directly to the power supply vs using the servo header.  A large enough electrolytic capacitor on the board should also fix things.

Discussions