Disassemble the electric toothbrush and use 3 IO ports to control 6 LED lights. How to do it? Charlie reuse!

260da7eb5b4366388931ad01a0d6fe86.png

▲ The circuit to be analyzed in this article

This is how it started.

I bought an electric toothbrush, which cost a few dozen yuan:

2a9de5abebc9a0dab6510ae5e1db57f0.jpeg

The actual item received looks like this:

896150072cdb3a3f1aaf73debe157e47.jpeg

There is 1 button and 6 LED lights on the toothbrush handle:

e9353d2ccadfb60c11ae6cc3d70b74ff.jpeg

Take a look at the circuit board:

425ba5672205286e56138355206bc3da.jpeg

It can be seen that the microcontroller used on the circuit board only has 8 pins, but it has to control 1 button, 6 LED lights, and 1 vibrating motor:

78a431cbfebbab4e2d541d66da44b9db.jpeg

At first glance, the GPIO should not be enough.

The microcontroller removes the power pin (positive pole) and GND pin (negative pole), leaving only up to 6 GPIO pins.

So how do you make it enough?

It turns out that through clever circuit design, this electric toothbrush uses 3 GPIOs to control 6 LED lights, saving GPIO.

b278989e18f2236c702aee8d16138dbe.jpeg

This clever circuit is as follows:

9c46015d6c0680b2bfd72e47fe535497.png

The 6 LED lights are of the same model. For easy viewing, red and green colors are used to distinguish two different directions.

1. Principle analysis

This circuit uses three states of the microcontroller GPIO:

  • high level

  • low level

  • High resistance state

The so-called "high resistance state" means that the GPIO shows great resistance to the external circuit. Because the impedance is very large, it hardly draws in current and does not output current to the outside world.

Each LED light lights up individually and is divided into six situations.

1. When only LED1 lights up, the status of each GPIO of the microcontroller is as follows: (The red line with an arrow is the current loop)

6ef4018bb7a9bbed8dd5b262e9d38586.png

2. When only LED2 lights up, the status of each GPIO of the microcontroller is as follows:

e8b6b608c2851a43fca41f4d3f46d94e.png

3. When only LED3 lights up, the status of each GPIO of the microcontroller is as follows:

024b4fe0c5abaa62268224b3c057dacb.png

4. When only LED4 is on, the status of each GPIO of the microcontroller is as follows:

42fc2e0ca230c0205b0dcef3acd7ccba.png

5. When only LED5 is on, the status of each GPIO of the microcontroller is as follows:

c1baf01aa8eaaa69c3444a4606934ab8.png

6. When only LED6 lights up, the status of each GPIO of the microcontroller is as follows:

2bf413ca7fddd3a4e296e57b90160ed6.png

It is organized as follows:

1c452e77250972386109b6b1a7b2ffa5.png

It's that simple!

2. Summary and improvement

The above actually uses a method called "Charlieplex".

Why is it called Charlie multiplexing?

c76010034f6dddf9d4cc031dfc384800.jpeg

It's very simple, because this method comes from Charlie Allen, an engineer at Maxim Semiconductor Company.

b58477a2a5d4f5bfedd5b4e01192b920.gif

Charlie multiplexing is a method that can effectively save GPIO when driving LEDs, especially when driving a large number of LEDs.

Using this method, n GPIOs can drive n*(n-1) LEDs, so:

  • You can drive 2 LEDs using 2 GPIOs.

  • 6 LEDs can be driven using 3 GPIOs.

  • 12 LEDs can be driven using 4 GPIOs.

  • And so on.

The basis for this method to be realized is:

  • The three states of the microcontroller GPIO: high level, low level, and high resistance state.

  • LED has unidirectional conductivity.

Charlie’s approach to reusing designs:

  • Two LEDs are connected in series between any two GPIO pins. The two LEDs are connected in parallel and the LED directions are opposite.

  • When you want to light up a specific LED, set the GPIO pins connected to both ends to high level and low level respectively, and set the remaining GPIO pins to high impedance.

  • The circuit of the 6 LED lights in the electric toothbrush above is designed in this way.

Let's start with the simplest one and experience the circuit design of Charlie multiplexing step by step.

1. It is easiest to use 2 GPIOs:

a31ed0a83d7c2865f1ea83c0255cb0dc.png

When LED1 is on:

8b81ecefb863ab6d0bfca0c5436181e2.png

When LED2 is on:

d5fc3b3c70b5902dfad058fed75cd781.png

Only the high-level and low-level states are used here, and there is no need to use the high-impedance state.

2. When using 3 GPIOs, it has been analyzed before:

2f704c7067f22f4d26ce1c6aeea36306.png

It can be equivalent to the following figure:

ba981b30c276051ef2b66ac756851f73.png

It can be seen that there are indeed two parallel LEDs connected in series between any two GPIOs, and the LED directions are opposite.

3. The same principle, when using 4 GPIOs:

3f823dacf5b7a893654cb974e89ad17c.png

When LED1 is lit:

646d79eccf312517ffd8953dfaf5c6e5.png

The situations in which other LEDs light up are no longer listed.

Charlie's reuse of such a circuit connection will also cause some problems.

First of all, when the LED lights up, the current is completely output by the GPIO of the microcontroller, so there are certain requirements for the current driving capability of the GPIO. When designing a circuit, you should pay attention to check the current driving capability of the MCU you are using. The following figure is an explanation of the GPIO current driving capability in the STM32 microcontroller:

9a56bef0ea3475d92686e744ddc69f36.png

Secondly, if an LED is open-circuited or short-circuited, the flow of current will be disrupted, and the logic of the LED lighting up will become confusing. In the worst case, the circuit will demand a large current from the GPIO, causing damage to the microcontroller. The figure below assumes that LED1 is short-circuited. When LED5 is lit, LED3 will also light up:

f8c1d1ec40c6e029c4387f68f26bba49.png

3. Continue to advance

What should I do if I want to light up more than two LEDs at the same time?

Just light them up alternately. As long as the switching speed is fast enough, due to the persistence of vision effect of the human eye, they will appear to light up at the same time.

It is worth mentioning that if there are many LEDs that are to be lit at the same time, such as a large-scale LED dot matrix, then there are some new issues that need to be paid attention to, and there are quite a few tricks.

This article will not be expanded upon. Interested readers can inquire and practice by themselves and continue to advance.

4. Finally

I want to thank this electric toothbrush for giving me the opportunity to write "Charlie Reuse".

It’s just that updates have slowed down again recently. After all, I don’t make money writing public accounts, so I still work hard and try to buy an expensive electric toothbrush!

ad10a331042ba5b379814645c4ac5f6a.jpeg

Recommended in the past

9dc6f64ba344465263d2374c20c57d71.jpeg

Disassemble the old rice cooker temperature limiter and verify its principle

9a976acbfb0362f7623df01ce896a7c9.jpeg

Disassemble an old Panasonic cassette recorder from Japan and experience the circuit design from 50 years ago, which is full of history.

e95d3b30e0980e5fad1c7dabc6d08df0.jpeg

[ Teardown ] A platform’s 19 yuan children’s phone watch. How does it work?

2bd444f98445752e45547be57ea55caf.jpeg

[ Teardown ] Alipay box, Alipay received 1 million!

Guess you like

Origin blog.csdn.net/karaxiaoyu/article/details/133286781