Bad things happen when programmer finds a soldering iron

AuxPower1U: Power Supply Selection

This is post 5 in the series (next: Cooling, previous: Dell Trigger).


When it comes to power supplies for embedded electronics, it’s really hard to beat Meanwell. They are easily available, they have a wide selection, and they are reasonably priced. Thus, my search for power supply started with the first Meanwell catalog I found.

After testing the Dell trigger board, my power supply setup crystallized to 48/55V (for my routers), 15/20V for computers, and lastly (optionally) 12V for a modem. Why do I say “optionally”? Well, the option of using a buck regulator for the modem is always open. Since I have my case dimensions predetermined, the choice on whether to use 2 or 3 power supplies will be mostly driven by their dimensions.

As 1U severely restricts the height, my choice fell onto four power supply families:

I wanted to get as small as possible (can I fit 3?), a reasonable amount of power at each voltage (100W+, especially for 15V needed by computers), a reasonably small ripple (less than 200mA, if possible), tight voltage tolerance (1%, ideally), high efficiency (90%+ desired), and lastly robust overload controls (ideally with auto-recovery). Looking at the catalog, I placed the following power supplies on the short list:

ModelOutputPowerTolRippleEffDimensions
LRS-35-1212 V 3.0 A35 W±1%120 mV86%99 x 82 x 30
LRS-50-1212 V 4.2 A50 W±1%120 mV86%99 x 82 x 30
LRS-100-1515 V 7.0 A105 W±1%120 mV90%129 x 97 x 30
LRS-100-4848 V 2.3 A100 W±1%200 mV91%129 x 97 x 30
LRS-150-2424 V 6.5 A150 W±1%200 mV89%159 x 97 x 30
LRS-150-4848 V 3.3 A150 W±1%200 mV90%159 x 97 x 30
RS-50-1212 V 4.2 A50 W±1%120 mV84%99 x 97 x 36
RSP-150-2424 V 6.3 A150 W±1%150 mV89%199 x 99 x 30
RSP-150-4848 V 3.2 A150 W±1%250 mV90%199 x 99 x 30
RSP-320-4848 V 6.7 A320 W±1%240 mV90%215 x 115 x 30
UHP-200-1212 V 16.7 A200 W±1%240 mV93%194 x 55 x 26
UHP-200-1515 V 13.4 A200 W±1%240 mV94%194 x 55 x 26
UHP-200-2424 V 8.4 A200 W±1%240 mV94%194 x 55 x 26
UHP-200-4848 V 4.2 A200 W±1%240 mV94%194 x 55 x 26

ModelInputC OverloadV OverloadPFCFanCost
LRS-35-1285-264 VacY (auto)Y (repower)NN$13
LRS-50-1285-264 VacY (auto)Y (repower)NN$14
LRS-100-1585-264 VacY (auto)Y (repower)NN$17
LRS-100-4885-264 VacY (auto)Y (repower)NN$19
LRS-150-2485-264 VacY (auto)Y (repower)NN$19
LRS-150-4885-264 VacY (auto)Y (repower)NN$25
RS-50-1288-264 VacY (auto)Y (auto)NN$19
RSP-150-2485-264 VacY (auto)Y (repower)YN$39
RSP-150-4885-264 VacY (auto)Y (repower)YN$43
RSP-320-4888-264 VacY (auto)Y (repower)YY$54
UHP-200-1290-264 VacY (auto)Y (repower)YN$58
UHP-200-1590-264 VacY (auto)Y (repower)YN$54
UHP-200-2490-264 VacY (auto)Y (repower)YN$57
UHP-200-4890-264 VacY (auto)Y (repower)YN$59

After tinkering with a couple of combinations, including using power supplies from different families, I decided on a homogenous UHP-200-XX setup. They have ridiculously low profile, high power, and high efficiency. On the downside, they do have a bit of a ripple and their cost is quite a hit.

Another setup I could go with would still have UHP-200-15, but combined with LRS-50-12 and LRS-100-48. The downside of this approach would be a bit of a crowded central setup and less robust power supply.

The three power supplies I ended up with are UHP-200-12, UHP-200-15, and UHP-200-55. While the last one might be a surprise since I was leaning more toward 48V, the 55V version has unusually wide adjustment range (45-58V). This means it covers both 48V and 55V thus allowing me some flexibility.

If you look into their datasheet carefully, one will notice that these power supplies require quite a big heatsink. But alas, we cannot solve everything today; there needs to be something for a future me to deal with too. For now, I need to order these three before I change my mind again.

AuxPower1U: Triggering Dell

This is post 4 in the series (next: Power Supply Selection, previous: Case Selection).


Illustration

One action item mentioned way back in the first post, was discovering if a Dell Optiplex 3050 Micro can handle voltages lower than its specified 19.5V. However, you cannot just check that by plugging in any old power supply. No Sir, you need to have a 19V charger blessed by gods and naked virgins who dedicated their life to making sure your Dell equipment is not using impure power like those other peasant computers do.

However, since I am unworthy of such service, I decided to see about bypassing the same for three reasons. The firs2024t one is that it makes my life so much easier if I can use any old charger in case my current charger dies. Secondly, it really messes with my goal of consolidating power supplies if I need to take special care of Dell.

Before I went onto deciphering the charger protocol myself, I decided to check if someone had already done the work. And, wouldn’t you believe it, someone did. Even better, the author provided all the information one might need. The only thing I had to do was to make a PCB. So make a PCB I did.

The final board consists just of a resistor in series with the EEPROM data line and a zener diode for overvoltage protection between the data and ground. The value of the resistor is not really important but original charger uses 330 so that’s what I went with. Zener is also not critical so I went with 5.1V one I had laying around - go, mini-MELF, go!

The main part is a 1-wire EEPROM memory, either DS2501 or DS2502. And yes, you can program that EEPROM yourself, but there is actually a source of preprogrammed memory on AliExpress. That is way easier than dealing with 12V pulses programming this memory requires. There are some reports suggesting you can use DS2431 (with much simpler programming model) but buying preprogrammed stuff was easier.

As for the Dell connector, I was originally planning to cut the existing cable but Amazon had some pigtails available so I opted to use them and keep my original charger for emergencies. On the barrel connector side I found that a DC 2.1x5.5mm connector intended for panel mounting has spacing that fits a 1.6mm PCB perfectly.

With PCB and all parts ordered, the only remaining work was to assemble, wrap it in heat shrink, and finally test whether 3050 is properly charging at 15V. Will it? Well, it will!

Based on the old method of “try and see what happens”, I could power on my Dell starting as low as 13V. While that was the lowest voltage it booted on but I found it would ocassionally “stutter” a bit. However, when I bumped it to 14V, all looked the same as when running at the official 19.5V. For all practical purposes, you can view the Dell Optiplex 3050 Micro voltage range as 14-20V.

And yes, all standard disclaimers apply, especially given that it’s a test sample of one. For this use case, I only care about my setup, so this is sufficient. However, I am willing to bet that pretty much all other similar Dell machines behave the same.

In any case, this smalll board enables me to emulate Dell charger at lower voltage, thus allowing use of 15V power supply. This gives me access to a more common voltage in embeeded electronics (way more common than 20V that’s usual for laptops) and it also proves that both my NUC and Dell can both drink power from the same faucet.

AuxPower1U: Case Selection

This is post 3 in the series (next: Dell Trigger, previous: Features).


Quite often, I like to start my projects with a case selection. Since I have quite a few hardware projects under my belt, I also have a fair idea of how much space things are going to take. Despite this, in reality, I sort-of overlap the selection of case with the selection of the largest components; in this case, power supplies. I will cover power supplies in a future blog post; suffice it to say that I determined 200 mm of case depth would suffice.

Based on that, I wanted a 19" 1U rack case with a depth of 200-250mm. The width and height were fully determined by the 1U factor, while the depth was selected as not to interfere with other components. For power supply health, I also wanted to have some cooling slots.

Representative of a cheap case was AliExpress Lang Lang coming in at only $32. It’s made of aluminium, has slots, and gets offered in depths of 200mm (1), 250mm (4), and 300mm (3). However, the specification is a bit unclear as to the rear panel. One picture makes it seem as though it’s predrilled, but on another, it seems to be one-piece. I find this case to be as close as it gets match to my requirements.

Even cheaper variant is AliExpress Tokban at $28. It has no slots, but that’s not an issue since drilling aluminium is not an issue. And it already has power supply input cutout, so that’s a bonus. On the negative side, its dimensions seem to be higher than 1U would allow. There is a high possibility this is just a typo. Also, considering I need 2 AC inputs, I’m missing a second cutout.

All other cases I found on AliExpress were just a variant of these two.

My other source is always DigiKey and I started my search by filtering on basic case properties.

The cheapest case I found comes at $34 in form of Bud Industries PRM-14460. This one is 200 mm deep and already has some mounting options inside. I am not as worried about structural stability since it will sit on top of UPS, but structural supports inside do fragment the internal space a bit.

Another interesting case is Hammond RM1U1908VBK, but I try not to even look at it too hard due to its high price of $158. Yes, it’s built better than any other case in this list, but the premium cost doesn’t justify it for this project. That said, for some other projects, this might be a really nice option, so I’m placing it as an alternative here.

At this time, I am leaning toward a plastic option with Bud Industries PRM-14460 since plastic seems the most promising material to mount an OLED screen. If mounting stuff inside proves to be much of a challenge, my backup option is AliExpress Lang Lang since it allows for more freedom when it comes to mounting and it also has a deeper 250mm option.

AuxPower1U: Features

This is post 2 in the series (next: Case Selection, previous: Requirements).


In my previous post, I split all my desires into two categories: requirements and features; requirements being something mandatory while features being something that is nice to have. In reality, the line between them isn’t really as clear so you can view this just as an addition to the first post.

When it comes to features, the main externally visible functionality of my consolidated power supply box will be the ability to reset devices from the front as I currently have with ResetBox.

While this is a requirement, the exact button count is a bit more flexible since the primary function of them is to provide a quick reset of the Internet for my family when I’m not around. Considering that, the minimum would be something like this:

  • Button 1: Arris SURFboard Modem
  • Button 2: Mikrotik hAP ac, Mikrotik Audience, and Mikrotik hAP ax3

However, while I have other means of resetting devices, I also like buttons so my desired setup might be something like this:

  • Button 1: Arris SURFboard Modem
  • Button 2: Mikrotik hAP ac, Mikrotik Audience, and Mikrotik hAP ax3
  • Button 3: Dell OptiPlex 3050 Micro
  • Button 4: Intel NUC

Let’s add one more button to account for possible future needs, and this brings us up to a total of 5. Please note there is no requirement that the button count matches the physical layout (i.e., one button could reset two different outputs), but I like to have it setup like that nonetheless. It just simplifies configuration immensely if I keep that link.

Functionality of buttons is to remain the same as it is for ResetBox; i.e., they should handle brief touches without any action, and reset should be “hidden” behind a longer press. Also, if one keps pressing button for a long duration (e.g., more than 10 seconds), the reset should be cancelled.

I might as well try to include some monitoring for both voltage and current. This is easy enough to implement, and it would be a shame to miss such opportunity. As not to go overboard, just monitoring output lines will be sufficient since I can already see that monitoring both input and output would take a lot of board space.

In order to display that data, I would definitely like to go with OLED, albeit I can already see mounting it on the front will be a challenge no matter which case I select. Thus, I might not bother making it user-visible, but I would still like to have it on board so my development and troubleshooting can benefit from it. I trust 128x32 will do.

For real-time monitoring, I would like to have either UART, RS-232, RS-485, or CAN-bus output. Since each of those requires different components, I would need to make that decision eventually but not necessarily now. I am tentatively leaning toward CAN-bus due to its resilience; but let’s hold the final decision for now.

Lastly, having an idea of the temperature might be beneficial. While precision is not really important, there should be a sensor somewhere on the board that will give us a ballpark figure of how hot we’re running.

That’s all I really want from this project. Now, onto figuring out the details.

AuxPower1U: Requirements

This is post 1 in the series (next: Features).


As part of my home server setup, I have a few devices that have “free-floating” power supplies. For example, my modem, my wireless PoE adapters, and a few test boxes all have their power supply pushed into rack’s nooks and crannies. Even worse, since I want to have the capability to reset them, they are connected via ResetBox (or its type-C variant) making cable situation even messier. It’s way beyond time to sort that out!

In this blog series, I will go over what’s needed to design a nice 1U box that can fit all (or as many as I can) different power supplies togethe. Their outputs should be resettable by physical buttons on the device’s front. Since I actually didn’t finish the project as I’m typing this, expect the series not only to last a few months while I gather all necessary equipment but also for my “specifications” to shift slightly as I discover new things or rethink my old ways.

At first, let’s look at what power supplies we have currently:

  • 12V 25W: Arris SURFboard Modem
  • 22V-57V 20W: Mikrotik hAP ac
  • 24-57V 30W: Mikrotik Audience
  • 12-28V 40W: Mikrotik hAP ax3
  • 19.5V 65W: Dell OptiPlex 3050 Micro
  • 12-19V 65W: Intel NUC
  • 54V 15W: Netgear GS305EPP (150W max)

If I squint hard enough, there are three distinct power supplies to use there; the first one being a simple 12V power supply for modem. Power usage will be really low on this one, so any hardware we place will run from it too.

To the second power supply, I had to give a bit more thought. Without question, it has to run of the UPS but its target voltage is a bit of an unknown. Currently, I am running my hAP ac and Audience from a 20V type-C power supply, and Audience doesn’t seem to love it as any minor transient causes reset. And yes, officially Audience doesn’t run that low, but I got lucky, I guess. Previously, I was running my WiFi routers on 48V and both were fine with that; so there are my two daya points. Considering other devices, I was leaning toward selecting 24V as a second power supply.

However, that leaves my NetGear PoE switch a bit of a loner and outside of The Box. For it, I would need to provide a proper 55V PoE power supply or at least 48V if stars align. The downside of this approach is that it leaves my Mikrotik hAP ax3 either on 12V or for the last, non-UPS power supply. But the upside is that it allows for a bit of future-proofing.

That leaves 2 non-UPS computers. Why are they not using UPS? Well, in my setup, UPS power is really limited and is reserved for only two categories: my main server and my Internet delivery devices (modem, router, WiFi APs). Anything else just needs to handle a power loss. These two computers fall into “anything else” category.

Intel NUC, we can already see, is flexible with a power supply specification. When it comes to standard industrial voltages, it can handle both 12V and 15V inputs. However, it Dell bretheren officially are not that flexible. While there is a possibility my 3050 micro would work on 15V, anything higher is a no-go. And since Dell authenticates its chargers, to figure this out, I’d need to trick it first into accepting such voltage - all of which smells like another sub-project. :)

If Dell doesn’t want to cooperate, the only way forward would be to use one of many buck modules intended for RVs that brings 24V to 19V. I would really like to avoid this, if possible, because the last thing I need is yet another power supply. However, it’s good to have options. And yes, ideally, I would find a 19V power supply; but I have a feeling that finding one that can be properly mounted inside a 1U case is not going to happen.

This brings us to the following rough power supply distribution (with a bit of derating on power specification):

  • 12V 150W (100W if I kick out Mikrotik hAP ax3 from my network):

    • 25W: Arris SURFboard Modem
    • 25W: Control boards
    • 40W: Mikrotik hAP ax3
  • 15V/19V/24V 200W (150W should be realistically more than fine):

    • 65W: Dell OptiPlex 3050 Micro
    • 65W: Intel NUC
  • 48V/55V 100W (going higher than this might be good for the future PoE devices):

    • 20W: Mikrotik hAP ac
    • 30W: Mikrotik Audience
    • 15W: Netgear GS30s5EPP

There is an alternative at a bit lower voltage:

  • 12V 75W

    • 25W: Arris SURFboard Modem
    • 25W: Control boards
  • 15V/19V/24V 200W (150W should be realistically more than fine):

    • 65W: Dell OptiPlex 3050 Micro
    • 65W: Intel NUC
  • 24V 150W

    • 20W: Mikrotik hAP ac
    • 30W: Mikrotik Audience
    • 40W: Mikrotik hAP ax3
  • Out-of-scope

    • 15W: Netgear GS30s5EPP

I am strongly leaning toward option 1, but option 2 is a good alternative. And yes, Mikrotik is not as power hungry as it seems above; I’ve never seen it reach its maximum power usage. However, since I really love my network, I use those numbers to bring an additional margin to the dimensioning process. If I find a nice power supply that’s slightly below what I need, I will get it and not worry about it. But, before I get to that, this fudged accounting provides more visibility into what brings the most value.

For various protection circuits, I’, going to rely onto power supplies to protect themselves. Thus, at minimum, I expect any selected power supply to have over-voltage, over-current, short-circuit, and over-temperature protection built-in.

When it comes to controlling this, I would say that ability to reset my Modem and WiFi is a must. And these can be two buttons as I want to be able to separately restart modem. For the hAP ax3, I don’t care as much since it has “under test” status in my network at this time. But let’s argue that it needs to be a separate button. At this time, I do control each of my computers inside the rack via smart plug so moving them into The Box, I might want to see a button for each, but I wouldn’t really mind if both go down at the same time. This brings the total number of reset buttons to somewhere between a minimum of three and a maximum of seven.

Lastly, this blog post leaves us with the following action items I will probably get around to solving:

  • Chck can Netgear GS305EPP work on 48V
  • Make trigger board for Dell
  • Check does Dell Optiplex 3050 Micro work on 15V

Powering External Devices while Protected

Illustration

I have designed a few framework expansion cards already, but I tried to keep them data-only interface. That is, I avoided providing power as much as possible. And, in my opinion, that’s the proper way of doing it. However, what if I occasionally want to provide some power too? Can it be done (reasonably) safely?

Considering my intentions of using an expansion card, and thus sourcing power directly from the laptop, my goals were to avoid the two most common issues: current backflow and current limiting.

While using fuses for current limiting is a traditionally accepted method, it’s neither precise nor fast enough to protect a laptop. Fortunately, there are load switches that allow for not only precise current limiting but also for fast response.

My choice fell onto AP22652Wx family. These devices allow for quite precise current limiting using external resistor, short-circuit and reverse voltage/current blocking. All that in a small SOT26 (aka SOT23-6) package.

As it often goes, we do need a few external components too - at least one resistor (to limit current) and at least 100 nF decoupling capacitor. Realistically, if you’re not sure what gets connected on the other side, you need a few more capacitors. I usually opt for 100 nF/10 μF combo on both input and output. And here is the biggest disadvantage of using load switch - quite a lot of PCB real estate.

Second issue I mentioned (current “backflow”) is also known as reverse current. This happens when one accidentally connect a positive voltage to a power output. As often in life, bigger force “wins” and thus current will start flowing into the output pin. When that device is a framework expansion card powered by laptop itself, this is definitely not the most comfortable situation.

Load switch I selected does offer basic reverse-current protection, but I wanted a bit of a foolproof solution and that comes in the form of a humble diode. Such forward biased diode will allow current to flow towards output but it will stop conducting if output voltage goes higher than that. And yes, that comes at a cost of voltage drop. However, if you keep current low, voltage drop is still within a few hundred millivolts.

In my case I decided to limit current to 400 mA and thus CUS08F30 I selected has not only healthy headroom with current but it would drop under 400 mV at a full load. Yes, there are diodes that have even better characteristics but this one comes in quite a small package and I already had it lying around.

With theory solved, it was time to test it. For that purpose I’ve created a new Power framework expansion card https://github.com/Medo64/PowerFEC. I used PIC16F1454 to interface it to USB, small ZXCT1009 to measure current, in addition to load switch and diode described above.

PCBs were manufactured courtesy of PCBWay. When it comes to framework expansion cards, they became my go-to manufacturer for two reasons. The first one is their standard routing bit seems to be much smaller than the one used by competition. This is important when it comes to the Type-C edge connector which requires a really small feature that large routing bits will mangle. The second nice thing is that PCBWay doesn’t use break-away connections, opting instead for V-groove. This means the edge is as perfect as it gets, saving me from manual sanding.

And yes, they’re not perfect. They still put their screen markings (you can pay extra to keep it clean). They still use leaded HASL (you can pay extra for non-leaded or ENIG). And sometimes waiting for somebody to manually check PCBs really clashes with my habit of finishing PCBs just before my bedtime thus forcing me to wait (albeit never too long).

But, all in all, those are all things that are minor enough not to bother me too much. I haven’t had bad PCBs from them in ages. Quite often with small PCBs I would get a few more than I ordered. And HASL is fine for pretty much all my use cases. While this PCB was sponsored, I used PCBWay on my own dime without complaint.

In order to make it all work, I decided to reuse my old code and make device behave as a serial port. It will output voltage and current in addition to allowing for a few basic commands (e.g., enable and disable).

After messing with it quite a while, I found protection working pretty much perfectly, thus expect a few updated expansion card designs in store.

As always, hardware and software are available on GitHub

Rendering KiCAD PCB to PNG

Illustration

I have pretty much automated creation of KiCAD export files thanks to its command line interfacehttps://docs.kicad.org/8.0/en/cli/cli.html). However, there was always one thing missing - image for each PCB. Yes, not really necessary for manufacturing but it’s really handy when you want to just quickly check things without starting KiCAD and/or for any inventory system.

Before KiCAD 8, getting a PCB image required exporting to .step file and then converting stuff around. It got complicated enough with all the prerequisites that I have essentially given up. Fortunately, that’s not true anymore, and now we can get .wrl files that can be often used directly.

kicad-cli pcb export vrml --output "board.wrl" "board.kicad_pcb"

While exported files don’t include lights, this usually doesn’t matter to viewers who add their own. However, for our processing, we want to add light that is just slightly to the top-left (at 0.1 -0.1 -1) of the camera (at 0 0 -1).

head -1 "board.wrl" > "board.front.wrl"
cat <<EOF >> "board.front.wrl"
Transform {
    children [
        DirectionalLight {
            on TRUE
            intensity 0.63
            ambientIntensity 0.21
            color 1.0 1.0 1.0
            direction 0.1 -0.1 -1
        }
EOF
cat "board.wrl" >> "board.front.wrl"
echo "] }" >> "board.front.wrl"

And yes, this method is a bit crude but it does work.

In order to reduce this 3D model into 2D image, ray tracing comes in handy. However, for that we need an external tool. I found that RayHunter worked great from the command line. While you only need that tool, you might want to check Castle Model Viewer as it can show you parameters in a bit more interactive way. Please note you also need libpng-dev package for PNG output.

cd ~/Downloads
wget https://master.dl.sourceforge.net/project/castle-engine/rayhunter/rayhunter-1.3.4-linux-x86_64.tar.gz
tar xzvf rayhunter-1.3.4-linux-x86_64.tar.gz
sudo install -m 0755 ~/Downloads/rayhunter/rayhunter /usr/local/bin/rayhunter

sudo apt install --yes libpng-dev

With prerequisites out of way, now we can finally export our board, looking directly at its front side. Camera position is a bit further away than I usually need it for my board but resolution of 4320x4320 pixels is large enough to then later crop the unneeded pixels.

rayhunter classic 7 \
    4320 4320 \
    "board.front.wrl" \
    "board.front.png" \
    --camera-pos 0 0 6 \
    --camera-dir 0 0 -1 \
    --scene-bg-color 1 1 1

You can see what each parameter does in rayhunter documentation

If all went fine, this will give you PCB board nicely rendered but with quite a lot of whitespace. In order to remove those extra pixels, I like to use ImageMagick.

sudo apt install -y imagemagick

Using convert command I trim all the whitespace, resize it to 1060x1060 pixels, add 10 pixels boarder on each side, and finally extend it to the full 1080x1080 size.

convert \
    "board.front.png" \
    -trim \
    -resize 1060x1060 -normalize -density 600 \
    -bordercolor white -border 10 \
    -gravity center -extent 1080x1080 \
    "board.front.png"

Congrats, your PCB image should be looking good just about now.


PS: You can do this from any PCB orientation by just adjusting camera and light position.

Pulling Rotary Encoder State

Illustration

When it comes to microcontrollers reading a rotary encoder, I often see it being done using interrupts. While that is not necessarily the wrong thing to do, it can crowd the interrupt handler with something that’s not really critical functionality, especially if microcontroller can handle it within its base loop just as effectively.

To start with, the code is available here and consists of two exported functions:

void rotary_init(void);
enum ROTARY_DIRECTION rotary_getDirection(void);

If we disregards rotary_init which just initializes a few variables, all the significant code is in rotary_getDirection function. To use it, simply call this function once in a while from the main loop, and it will return one of three values (ROTARY_DIRECTION_NONE, ROTARY_DIRECTION_LEFT, or ROTARY_DIRECTION_RIGHT) corresponding to the detected movement.

The heart of the functionality is in the following code:

    uint8_t currRotState = getRotaryState();
    if (currRotState != lastRotState) {
        histRotState = (uint8_t)(histRotState << 2) | currRotState;
        lastRotState = currRotState;
        uint8_t filteredRotState = histRotState & 0x3F;
        if (filteredRotState == 0x07) { return ROTARY_DIRECTION_LEFT; }
        if (filteredRotState == 0x0B) { return ROTARY_DIRECTION_RIGHT; }
    }
    return ROTARY_DIRECTION_NONE;

First, we get the state in binary for each of the 2 contacts available. Thus, the output can be either 0x00, 0x01, 0b10, or 0b11, depending on which contacts are closed. If the state has changed compared to the previous reading, we append it to the variable used to store previous states. As each state is 2 bits long, this means we can easily fit all 4 states in a single 8-bit value by shifting it 2 bits at a time.

If your switch is new and shiny, this miis where you might stop. However, in the real world, switches are dirty and thus can skip a state or two. For example, one of my rotary encoders would skip a state every once in a while. This means that a proper code would simply make experience worse as time goes by.

However, due to redundancies in how the encoder functions, detecting three neighboring states still gives you plenty of information to go by without misidentifying the direction of scrolling. In my code, detection starts when both encoder contacts are active (i.e. 0b11 state). On all encoders I worked with (admitely, mostly PEC12R series from Bourns), this actually nicely aligns with steps and almost perfectly filters wear-induced noise.

And yes, you can adjust the code slightly to make it run in an interrupt routine if you are so inclined.

Driving the Plunger (part 3)

This is part 3 out of 3 in the series (see part 1 or 2).


Well, if after reading previous posts you were curious as to how it all looks, wait no more. Below is a quick video showing its usage. And yes, it was a minimum effort video so sound is not there.

First is the mounting method. Just place syringe around the plunger and rotate to fix in place. If you used another syringe before this, you might need to move the plunger ahead until it makes contact. In the video, you can see that I reverse it a bit and then I move it forward just to illustrate this point.

After dealing with the initial paste surge, you get to control the syringe using either the button in the top-left corner or the foot pedal. As I use a foot pedal, you won’t directly see my presses, but you’ll notice the LCD flashes.

As you can see in the video, this thing actually works. However, it’s not without its issues. The most noticeable one is speed and drooping. Every push creates pressure and, no matter how many pull-back tricks I’ve tried, it will not squirt paste fast and without excess. Each profile was essentially a balancing act between how much paste I push and how quickly.

Firmware development for this was actually quite easy and really depended on two programming exercises I already had made from before: OLED and rotary button. The rest of the firmware was just reading the button status and pushing text to an OLED. You can check how I did it on GitHub but I will probably also make a separate post on each.

Would I use it? Well, maybe. While it actually does what I intended to do, the whole process is just too slow. I can do non-paste soldering much faster. Also, different paste will react differently and will need adjustments.

It’s not great for regular work but it’s actually quite okay if you need repeatable solder paste dispensing for special components.

Driving the Plunger (part 2)

This is part 2 out of 3 in the series (see part 1 or 3).


So, we’re continuing on PlungerDriver development. If you’re not up-to-date, do check part 1.

For electronics, I decided early to keep it rather simple and use only components I had lying around. I mean, I was waiting for motors but there was no reason why I couldn’t just cobble something up.

The first decision I almost always like to make is how I will control the darn thing. In this case I saw myself using combination of a rotary button and a small OLED screen.

Illustration

The rotary button I had was the one I used for a few projects in the past, which was Bourns PEC12R, more precisely its PEC12R-4220F-S0024 variant. It’s 12mm square, has detents (which I love), and you can also press it to get button functionality. Essentially, you have left/right/button controls. Ideal for something like this.

The screen I also had decided early on. Small 128x64 I2C OLEDs are easy to obtain and easy to drive. Even better, I had quite a few of different ones laying around from previous projects (e.g., USB OLED).

Input-wise, I wanted to connect it all via just a standard 3.81 mm Phoenix-style MC connector. These are really easy to work with, available from multiple manufacturers, and I have a load of these always in my storage.

For output, I decided to use JST XH connector. Using a different connector here was just to make it really clear what goes where. If I can do it, I always try to do different connectors for each functionality board might have. Makes mistake a lot less likely to happen.

As a trigger for paste dispensing, I decided to use both an on-board button and an external connector. While having a button on board was a handy thing to have during the testing, I really wanted an external connection for a foot pedal. Not only are they easy and cheap to get, but they’re the only practical way to trigger something while keeping both of your hands free. And yes, in order to avoid potential errors, I used a JST PH connector here.

The last selection was a PIC microcontroller. And yes, I knew it would be a PIC since those are the only ones I have in my storage. I did play with some other microcontrollers out there, but my pipeline and knowledge are so heavily skewed toward PIC that I always select it for projects like this. And here I opted for PIC16F1454. While many other Microchip devices would work equally well, I had a load of PIC16F1454 in my storage.

Illustration

PCBs were made by PCBWay and provided to me for free. While they do sponsor me occasionally, I actually did quite a few orders with them where I paid my own money to get stuff made. They were fast (well, much faster than me doing my part) and boards ended up being exactly what I ordered. Unfortunately, that meant they had a few errors - none of which were PCBWay’s fault.

The first issue I noticed was actually reaching programming ICSP header. OLED simply didn’t leave enough space to reach the darn thing. Fortunately, I use Pogo pins with my PICkit so I could reach the header from the bottom. Had I been using just a standard header, it would have been really a deal breaker.

Second, a more serious issue was with the motor driver simply not working. All voltages were just fine when the motor was not connected. However, connect the motor and it would go nowhere. It took me a bit of troubleshooting to notice I messed up Vref voltage divider and that was causing any load to trip the current limit function on my motor driver.

As I already soldered the whole board, I had to unsolder the OLED to reach resistors underneath and place a bodge wire. Since I use lead-free solder, it took a considerable amount of heat to fix that and the board survived that without any issues. The same couldn’t be said for my OLED display which didn’t work after I placed it back. So I had to unsolder it again in order to solder a replacement.

Why I mention this? Well, playing with higher temperature quite often damages the soldermask. And I had that experience with many PCB manufacturers, including PCBWay. However, either PCBWay changed their soldermask formulation to handle the higher temperature or this red soldermask I selected is a bit more resilient as after cleaning it with alcohol, I couldn’t even tell it was ever worked on.

And that’s all for this installment of the project. See you next time when I get the firmware running and see how this works in practice.