Fixing the flicker on the Adafruit Feather M4 Express

Picture of Adafruit Feather M4, plugged into a USB cable, showing the "Charge" LED illuminated.

The Adafruit Feather M4 Express is a lovely piece of kit. It has just one flaw – the yellow “charging” LED flickers constantly whenever the Feather is powered by USB. This is because of the Li/poly charger on board – if you have no battery, the charger attempts to charge the stray capacitance of the board, turning on the “charging LED”; when it reaches the critical voltage (4.2V) it turns off, turning off the LED; once the charge leaks away the charger starts charging again, turning on the LED and restarting the cycle. This is all very sad, and very annoying. Especially since you cannot disable the on-board charger.

I got frustrated by this, and looked up the Feather’s schematic and then the datasheet for the MCP73831/2 charger controller.

The datasheet makes clear that the charger does have battery detection – so why is it attempting to charge even when there is no battery connected to the Feather?

The answer is in section 4.2. The chip sources 6µA on the Vbat pin; if the voltage of that pin goes over the target voltage Vreg (4.2V, see section 1) plus 100mV, the device assumes a battery is not present; if below, a battery is present. But why is this not working?

The schematic shows that the Feather connects the Vbat pin to more than just the battery: in order to monitor the charge of the battery, it connects Vbat to ground via 2 × 100kΩ resistors forming a voltage divider (the midpoint is taken to Ain13 (=A6) on the SAMD51 chip – we assume the sink current here is negligible). That means that at 4.2V we expect a current of 21µA – more than enough to trigger battery detection! Oh dear.

Drastic solutions are possible – e.g., cutting the charge LED resistor R2, or the voltage divider R96. But I’d rather not cut my board.

All we need to ensure is that Vbat is over 4.3V. We can do this with a pull-up resistor from Vbat to Vbus (USB). With Vbus at a nominal 5V, and a current of 21µA, we need a resistor of less than 33kΩ. Since Vbus is likely lower (I measured 4.85V with my setup), we’ll give it a 3× safety margin and use a 10kΩ resistor. At the cost of a leakage current (Vbus to ground) of just 24µA (1/40th of a milliamp), this should disable the charger correctly when no battery is fitted!

DO NOT USE THIS IF A BATTERY IS CONNECTED!
DO NOT USE ANY PULL-UP RESISTOR IF A BATTERY IS CONNECTED!

What will happen if a battery is fitted?

The minimum value of the lowest permitted battery voltage (UVlo) is 3.2V (section 1); with a 10kΩ resistor to 5V we will charge this at a rate of 0.2mA. Even at full charge (4.2V), we will continue to charge at around 0.1mA. Even though this seems like a tiny current, lithium batteries do not saturate and have no safe trickle current – even at 0.1mA, your battery will eventually catch fire and explode. You do not want this to happen. In any case, you don’t need the resistor – if you have a battery fitted, the charge LED will not flicker.

Summary: to stop the flicker when no battery is connected, connect a 10kΩ resistor between the BAT and USB pins. REMOVE THE RESISTOR IF A BATTERY IS CONNECTED, OR YOUR BATTERY WILL EVENTUALLY EXPLODE.

I hope this has been useful! I’d love to hear about your experiences – please comment below.

Things Matthew has two of

The Gospel of Matthew was written to tell the story of Jesus from a Jewish perspective. It recounts many of the same incidents as the other gospels, but it also emphasises how Jesus fulfilled many Old Testament prophecies.

Sometimes though it seems something strange has happened in the retelling: where there was just one thing in the other gospels, now there are two. Is this an attempt to fit the literal sense of an Old Testament passage, or is something else going on?

The triumphal entry: Jesus sits on a donkey and a colt?

This took place to fulfill what was spoken through the prophet:

“Say to Daughter Zion,
    ‘See, your king comes to you,
gentle and riding on a donkey,
    and on a colt, the foal of a donkey.’”

 The disciples went and did as Jesus had instructed them. They brought the donkey and the colt and placed their cloaks on them for Jesus to sit on.

Matthew 21:4-7 (NIV)

The town of Capernaum is in two districts at once?

Leaving Nazareth, he went and lived in Capernaum, which was by the lake in the area of Zebulun and Naphtali— to fulfill what was said through the prophet Isaiah:

“Land of Zebulun and land of Naphtali,
    the Way of the Sea, beyond the Jordan,
    Galilee of the Gentiles—
the people living in darkness
    have seen a great light;
on those living in the land of the shadow of death
    a light has dawned.”

Matthew 4:13-16 (NIV)

In the other gospels there is just one demon-possessed man (called “Legion”) on the other side of Galilee, but here there are two?

When he arrived at the other side in the region of the Gadarenes, two demon-possessed men coming from the tombs met him. They were so violent that no one could pass that way. “What do you want with us, Son of God?” they shouted. “Have you come here to torture us before the appointed time?”

Matthew 8:28-29 (NIV)

In the other gospels there is one blind man who shouts out “have mercy on me, Son of David” – his name is Bartimaeus. But here there are two?

As Jesus went on from there, two blind men followed him, calling out, “Have mercy on us, Son of David!”

When he had gone indoors, the blind men came to him, and he asked them, “Do you believe that I am able to do this?”

“Yes, Lord,” they replied.

Then he touched their eyes and said, “According to your faith let it be done to you”; and their sight was restored. Jesus warned them sternly, “See that no one knows about this.” But they went out and spread the news about him all over that region.

Matthew 9:27-31 (NIV)

Or is it four?

As Jesus and his disciples were leaving Jericho, a large crowd followed him. Two blind men were sitting by the roadside, and when they heard that Jesus was going by, they shouted, “Lord, Son of David, have mercy on us!”

The crowd rebuked them and told them to be quiet, but they shouted all the louder, “Lord, Son of David, have mercy on us!”

Jesus stopped and called them. “What do you want me to do for you?” he asked.

“Lord,” they answered, “we want our sight.”

Jesus had compassion on them and touched their eyes. Immediately they received their sight and followed him.

Matthew 20:29-34 (NIV)

This all seems a bit surprising. I don’t have any explanation, but I’d love to hear your suggestions.

Musicle

I’ve had some fun over the last few days putting together a little toy called Musicle. It helps you understand a bit about how the Western musical scale is put together and why the notes are the way they are, using something called an Euler lattice.

Musicle gives you a screen with middle C in the middle and a grid of notes around it. Notes to the left and right are separated by a perfect fifth (frequency ratio 3/2), and notes above and below are separated by a major third (frequency ratio 5/4). Believe it or not, the usual Western scales and notes are generated simply by powers of 3 and 5 (and 2, for the octave).

Musicle lets you play the notes, on their own or in combination, by clicking on them. Hold Ctrl if you want to play several notes together.

One of the things that becomes apparent when you start exploring is that the notes don’t quite line up with each other the way your musical theory might have led you to expect. Musicle shows the nearest note name to each pitch, but it also shows the distance of that pitch from the “normal” even-tempered pitch, in cents (100ths of a semitone).

To make it easy to explore without odd jumps, I’ve used Shepard tones.  You can turn this off at the bottom if you like, and you can also choose one of a very small number of instruments.

Musicle is mastered on github.

If you want to learn more about all this, take a look at xenharmonic or Kyle Gann or search for Just Intonation.

Comments welcome!

Twenty years ago today!

It’s a pretty big day for me today – in 1997, a brave kid headed out into the unknown and landed on the other side of the world. I left on 6 September, and arrived twenty years ago today with 91kg of luggage and a plan to do a PhD. It’s been a huge and eventful couple of decades and I had no idea of any of it back then!

Thinking back my main memories are people: my friends all gathered in Auckland airport singing “The Lord bless you and keep you” to send me off, my distant relative who helped me with my luggage and found a train that went direct from Haywards Heath to Glasgow without a change in London, my flatmates in Glasgow who knocked off my rough corners and taught me to be a better person. And of course everyone on both sides of the world and in between who has loved me and looked after me and helped me grow over the years. He tangata, he tangata, he tangata.

I found some embarrassing pictures in the attic which you might enjoy. If you want to know how different I was back then (hint: not very!), read my “blog” KeithNet (they hadn’t been named back then, but it was) http://www.lochan.org/2005/keith-cl/news/index.html. And if you’d rather remember other things, there’s always Diana, Mother Teresa, and Cassini.

Thank you so much to all of you!

(originally posted on Facebook – now shared here)

“The Lord bless you and keep you…” Friends farewelling me at Auckland Airport.

Me with mum, dad, and Heather just before I left.

Me with Heather before I left.

Too much luggage! 91kg, if I recall rightly. It was quite a challenge lugging it on my own.

Me in my room in Glasgow (a few weeks later, after my shipping cartons had arrived).

ASCII Knitting

Inspired by Carolyn knitting another decoder hat like the one she made me, I’ve put together a little web app which lets you turn a message into a knitting pattern ready to be decoded by your geek friend! The instructions in the pattern for how to encode the message are quite involved, and I figured the whole process would be much easier if the computer helped out a bit more – after all, what knows codes better than a computer?

Various people have done something similar, often referring to the old essay HEX and BIN meet my friends Knit & Purl (which I had to recover from the Wayback machine!), but I haven’t seen anything that goes quite as far as this.

Enjoy – and share it around if you find it useful!