Peek Into The Compiler’s Code — Lots Of Compilers

We don’t know what normal people argue about, but we know we spend a lot of time arguing about the best microcontroller, which editor is the best, and what language or compiler does the best job. The problem with all those compilers is getting them loaded and digging into the generated code. If you too spend your time thinking about those things, you ought to have a look at [Matt Godbolt’s] Compiler Explorer. We know that hosting an IDE-like web page and compiling code is old hat — although [Matt’s] site has been around quite some time. But [Matt’s] doing it differently. The code you build on the left hand pane shows up as assembly language on the right hand side.

There are plenty of options, too. For example, here’s a bit of C code from the site’s example:

int square(int num) {
   return num * num;
}

Here’s the corresponding assembly from gcc 9.2 for x86-64:

square:
  push rbp
  mov rbp, rsp
  mov DWORD PTR [rbp-4], edi
  mov eax, DWORD PTR [rbp-4]
  imul eax, eax
  pop rbp
  ret

Continue reading “Peek Into The Compiler’s Code — Lots Of Compilers”

Frequency Counting A Different Way

Counting frequency is one of those tasks that seems simple on the face of it, but actually has quite a bit of nuance. There are two obvious methods, of which the first is to count zero crossings for some period. If that period is one second you are done, otherwise it’s a simple enough case of doing the math. That is, if you count for half a second, multiply the result by 2, or if you count for 10 seconds, divide by 10. The other obvious method is to measure the period of a single cycle as accurately as you can. Then there’s this third method.from [WilkoL], which simultaneously counts a known reference clock alongside the frequency to be measured.  You can see the result in the video, below.

The first method is easy but the lower the frequency you want to measure, the longer you have to count to get any real resolution. Also, you need the time base to be exact. For the second method, you need to be able to make a highly precise measurement. The reason [WikolL] chose the third method is that it doesn’t require a very precise time base — a moderately accurate reference oscillator will do. The instrument gets good resolution quickly at both high and low frequencies.  Continue reading “Frequency Counting A Different Way”

Lambdas For C — Sort Of

A lot of programming languages these days feature lambda functions, or what I would be just as happy to call anonymous functions. Some people make a big deal out of these but the core idea is very simple. Sometimes you need a little snippet of code that you only need in one place — most commonly, as a callback function to pass another function — so why bother giving it a name? Depending on the language, there can be more to it that, especially if you get into closures and currying.

For example, in Python, the map function takes a function as an argument. Suppose you have a list and you want to capitalize each word in the list. A Python string has a capitalize method and you could write a loop to apply it to each element in the list. However, map and a lambda can do it more concisely:

map(lambda x: x.capitalize(), ['madam','im','adam'])

The anonymous function here takes an argument x and calls the capitalize method on it. The map call ensures that the anonymous function is called once for each item.

Modern C++ has lambda expressions. However, in C you have to define a function by name and pass a pointer — not a huge problem, but it can get messy if you have a lot of callback functions that you use only one time. It’s just hard to think up that many disposable function names. However, if you use gcc, there are some nonstandard C features you can use to get most of what you want out of lambda expressions.

Continue reading “Lambdas For C — Sort Of”

Does Your Home Assistant Know When You Are Sleeping?

It always gives us a sense of wonder when we realize that what would be a simple task for a human child is a big deal for a computer. For example, if you asked someone if you or someone else was in bed, that’s a pretty simple thing to check. For you, that is. For a computer, it requires some sort of sensor. [Lewis] used load cells to tell if someone is in a particular bed or not. He uses Home Assistant and has a great post about how he created and interfaced the sensors. Of course, the sensors really only tell you if something heavy is in the bed. It doesn’t know who it is or even that it isn’t an overstuffed suitcase.

Load cells aren’t exactly high tech. There are several different types that use hydraulic pressure or pneumatics to measure force. However, the most common that we encounter use strain gauges. A strain gauge is a resistor that changes value when it deformed and a load cell usually has several strain gauges wired in a bridge configuration so that small forces create larger output changes.

Continue reading “Does Your Home Assistant Know When You Are Sleeping?”

Learn Morse Code, Clockwork Orange Style

You might have to provide your own wrist straps and eye clamps, but if you want to learn Morse code, [Seth] has a web site for you. You can get code practice using the Farnsworth method and each letter is flashed before you as it is sent, which we assume will burn it into your brain.

Why learn Morse code now? Just about all countries now have at least some no code ham licenses and many have taken code off the tests completely. However, there are still many hams that use the code even today. Why? The personal challenge is part of it and perhaps nostalgia. However, it is also true that Morse code transmitters and receivers are dead simple to build and can get through where other simple radios can’t.

Continue reading “Learn Morse Code, Clockwork Orange Style”

BST-863 Hot Air Rework Station Teardown

[Voltlog] has had a 952 hot air rework station for a long time. You’ll recognize it when you see it — they are the ubiquitous soldering iron and hot air gun combination from China sold under numerous brand names. He didn’t think the old station was as good as some of the newer devices available, and did a teardown and review of the BST-863 station that can be had for well under $200. You can see the video below.

He was impressed with the build quality of the workpiece holder. It lets you store the hot air gun and keep it in standby mode. He liked the touchscreen, too, although the beeping seemed a bit annoying. However, in general, the operating noise was less than the older unit it replaced.

Continue reading “BST-863 Hot Air Rework Station Teardown”

How’s That 2.5D Printer Working For You?

We’ve noticed a trend lately that advanced 3D printing people are calling their normal print setup as 2.5D, not 3D. The idea is that while the machine has 3 axes, the actual geometry generation is typically only in the X and Y axis. The Z axis simply lifts up to the next layer unless you are working in vase mode. [Teaching Tech] wanted to experiment with real 3D printing where the Z axis actually helps build the shape of the printed object, not just advancing with each step.

As it turns out his first investigation linked back to one of our early posts on the topic. There’s been more recent work though, and he found that too. It took a little surgery to get more Z clearance, but nothing too serious — just a movement of a fan.

Continue reading “How’s That 2.5D Printer Working For You?”