# Wisdom

Quite a while ago (in the last century nonetheless) my idea of a productive day entailed writing a lot of code, measured by size in any suitable metric.

Lately I’ve been writing less in volume but I realize that I spend a greater time thinking about the problem at hand as a whole and that it happens mostly in the background while I’m doing something else. By the time I’m again at the workstation everything falls into place.

Also, when stepping aside and contemplating whatever I engineered I can’t help to feel anything but pride. Perhaps except for the documentation I build things from the get go thinking of what I would like to have were I a library user, on terms of building blocks.

During the last two weeks I built a library to parse a protocol called LX200 used to control telescopes and I can’t be happier with the result (for now it’s at https://github.com/telescopio-montemayor/python-lx200 ). The first one was a roller coaster, due to some other issues I went back to a night owl schedule and I can’t remember when was the last time I had such prolonged and intense periods of flow. I also taught myself asyncio.

It’s terse, concise, and (mostly) well structured. My former self would’ve made a mess of a state machine tied together with pages of if statements that worked, for sure, but was a pain to extend or correct. Of course looking down the path and leveraging years of experience this things seem obvious now.

Coincidentally, the other day Eric wrote about the advantage of declarative/table driven approaches.

# Sunday work log

Today I worked mostly on that remote control for our transmitter and on a simple pulse conditioner for a clock distribution system on our university.

We have a central clock reference used to synchronize experiments among various buildings. It’s not always spot on frequency but most of the time what matters is that its phase is continuous. There’s a network of underground cables that take that signal wherever is needed. Some of them are good despite their age (the youngest being around 10 years old) but others are crumbling and drowned.

On the seismograph building there’s a clock slaved to that signal and sometimes it looses track of it and lags as many as half an hour. Just as an experiment we decided to use the PPS signal out of a small uBlox GPS. A friend made a small module with the gps and an arduino to initialize it and display some ancillary status and I built a simple level shifter that makes a ~12V pulse out of that 3v logic output.

I also worked on the housing for the remote control. I’m using a weather proof junction box. After a bit of fumbling I had all the holes to mount the boards, connectors, indicators and cable glands done.

Then I finished a couple of details on the boards and hooked up everything for a trial run. The buttons and rf sense worked fine. But when I tried the dtmf audio input I got data on the digit outputs but nothing on the interrupt pin.

At first I thought that the module was bad (I accidentally fed it with 12V for a brief moment) and I swapped another with the same result.

I moved both of them on the breadboard and they worked fine. I inserted a bare wire on the socket and every time I touched GND with it I got an interrupt. But when installing the module that pin was stuck low. Which is quite odd.

I probed with the adjacent pins and all appeared open as they should. But there’s an unconnected pad on the other side, and there was a dead short to that. I used a scribing tool to clean up but the short persisted. That other pad, while not connected to anything on my board, was part of the dtmf module and when tied to the interrupt output it loaded it to the point of not being useful anymore.

When etching the board I used some fine steel wool and a strand perhaps stuck on the top side between the socket pins. After unseating the module, arduino and other connectors I charged a cap (around 3300uF) and applied it between the pair of shorted pins. Surely enough there was a spark.

And from then on everything worked as intended.

# Evil eye

Today I walked back from the uni at a slow pace with my termo under my arm and the path led me to the corner of 3 and 67 where there’s a kiosk.

It’s run by a friend of mine, we attended to school together. We chatted for a while and then an old woman, queer mixture of a Gypsy and La Nona made her way inside and started to empty her bag.

She tried to sell us some flowers made of what looked like papier-mâché, asking $150 for each one. We refused and I politely tried to help her anyways with what I had on my wallet (a bit less than$50).

That moment she transformed and with an elevated and angry tone accused us of having that amount of money and not wanting to buy, which was completely true, as I had no use for such an item.

We argued back and forth for a while until she said now with a darker and more calm voice, “you are evil, evil persons”, gave us a deep stare and disappeared on the street.

# It gets better

I spent most of the last weekend studying and a bit sick.

When not reading for the Uni I binge watched a lot of talks from previous editions of the CppCon, because that’s obviously what only a sick person would do.

And after not being on that scene for quite a while I found that, like for some wines, the time made it nicer.

The use of auto variables when iterating containers, lambdas, parallelization and inclusion of atomic operations (albeit I believe they are insufficiently documented and will bite a lot of people) are just some of the things that surprised me in a good way. There’s a host of cool stuff under <algorithm> and the new optimizations (like the ones carried for constexpr ) are incredible.

Coincidentally, Bert Hubert started a series of posts with the good parts of C++ that actually makes me want to code something in it again.

# Walk or Ride

(Take the easy way you know that you want to)

As part of my health and lifestyle changes I set up the goal to walk at least an hour a day. This is good as I normally don’t walk very much and with the bike the cold wind stabs deep inside me and I end up with my head aching even if I wear lots of protective clothing on it.

This morning wasn’t as cold as others so I left a bit earlier for uni and went there walking instead of cycling.
It took me more than double the usual time but the morning was lovely. About mid journey I found a lemon on the verge of an abandoned house. I carried it with me, smelling from time to time and capturing odd looks and a handful of smiles.

On my way back home a young lady stopped by my side to ask for the time. It was very strange that she didn’t have a cellphone but after catering to her request we started to walk together and talk, mostly about our whereabouts and her career as English teacher. We parted ways a few blocks from my home.

I don’t remember when was the last time I had that careless feeling of easiness around someone new, in general and for making conversation out of the blue. Perhaps the surprise was the difference.

Today I walked a tad more than hour and half. So far the week started very good.

# Get up off your lazy bum.

For the most part of last week I felt like catching a cold but not quite.
My body and joints ached and was in this general state of drowsiness.

This morning was humid but not cold. I gathered all my willpower and hoped into the bike instead of taking the bus to the uni.

I arrived exhausted and sweaty.
As it happens at these stages the classes are very small. Today it was only me and the professor. We stood up side by side in front of the whiteboard discussing for about an hour.
A very productive morning.

Back at home I felt terrible but empowered.

Later I went to do some errands.
I took a rest on the sidewalk and the neighbors cat brushes me, asking for petting.

We sat there for a while, attracting odd looks from the passerby people.

# Low level fun.

As a wise man said, “low level is easy”.

There aren’t that many things below that can break except for hardware (and compiler!) bugs, they are becoming increasingly common but still the level of pressure and control to keep quality up on processors are orders of magnitude greater than those on the stacks above the OS.

A minor update of Ruby broke everything? The layout is totally wrong when a browser locale is set to Spanish but no in English? Who’s to blame for that? Even if we have most of the sources fixing the problem for everyone but ourselves isn’t that easy.

The other Monday I went to the Uni to take an exam on digital circuits (graded with 9/10) and oh boy, programming in assembler again was refreshing.

The tooling is just as awful as the last time I took that course (not as bad as the first versions of mplab but the assembler is still dumb when it comes to parsing spaces and the integrated editor is notepad in disguise) but the difference is that now they allowed us to use our own notebooks. The only saving grace is that the assembler, debugger and simulator are different executables, they accept a sane set of command line parameters and they run fine under wine.

So I was able to use vim and a simple makefile to streamline the process and finish in almost no time. Sadly the bar to pass has declined a lot in the last years.

# When I’m say I’m alright

… don’t look in my eyes ’cause you’ll see I’m not alright.

But I’m trying.

About a month and half ago I snapped and couldn’t take it anymore. I sought professional help and got myself a Real Shrink and a Therapist (both extremely good and expensive). And I’m on meds now.

For the most part of the last three to four years what I described as “happy” or “fine” was actually different shades of miserable. I had my moments of truly happiness, but those were really few. And there was always that tiny rainy cloud looming above me.

I had a breakdown like this back in 2015 and I almost wanted to give up and get away from programming (I kinda did, I biked many times to the countryside trying to look for a quiet spot).

This time it’s not so bad on its own but compounded with other things happening in my life (one of the biggest is leaving Berisso) it totally wrecked me. The difference now it’s that I asked for help. I still run away from the civilization to take day long bike rides and reflex but I’m trying to get a grip on the problem and fix myself.

Lately I’ve lost interest in most of what my life is/was centered about (technology, engineering) and that bothers me a lot. Not completely, I have many drafts and toy projects that prove otherwise.

The knack it’s there but the thrill is gone. At least for a while.

As Dave Thomas put it, this is supposed to be fun. And it stopped being such for me, instead of an almost daily stream of marvel it gradually turned into a grind with an occasional touch of enjoyment, and not always at work.

I believe that we are defined by what we do (more than what we think / believe), work being a significant part of that. On that reference frame, this is a very tough situation.

So what now? I’m going to spend all the time I need to get better and take care of myself. I’m taking a bit of time off work and going back to uni for real, coming clean of my schedule to not rush things pretending I’m doing something when I’m not (attending lectures and using slack on the phone is awful). I’m saying no instead of hesitating. I’m not committing to do things just to please someone. I take a break when I feel I need it.

I know this stuff (antidepressants) takes time to make effect and it’s not a silver bullet that somehow will make everything fine overnight but I’m anxious, waiting for something to happen.

On a totally unrelated thing, the quote from the beginning is from a Storm Large song (it can be found here). I really miss her days with The Balls, the energy and vocal range from that era reminds me a lot to Skunk Anansie. But her smooth side of nowadays is gorgeous.

# Carpooling.

Around March I was waiting for the bus and it was late for the normal schedule.

I had a very important appointment so I decided to ride a cab instead. There was this quiet woman at the stop with me, out of curiosity I asked her if she wanted to come with me, I could drop her near La Plata.

She said yes, we had a very nice trip talking about Middle Age history and art, her sons and life in general (we both were on our ways to take exams at the uni). She even volunteered to pay half the fare. (I was going to pay it anyway, so I didn’t even thought of asking).

I’m sorry that I forgot your name, but thanks for a nice ride.

# A statistical insight

I’ve been working during the weekends on an instrumentation frontend to precisely measure the resistance of an RTD sensor using a ratiometric approach.

After building it and waiting a prudential time to let it warm I saved an hour of samples (3600) and fired Octave.

The mean and standard deviation looked ok and while a plot showed a bit of noise it was well within reasonable limits.

Just for the sake of it I did a histogram and, oh the horror:

This is clearly not OK. It should be more like a Gaussian (the real formula is quite daunting but still retains symmetry) and that looks a lot like a bimodal distribution. Changing the number of bins does not help.

The ADC I used does not have a reference input so I make two differential reads and then take the quotient (I know… but it was the only one available when started).

Perhaps the input multiplexer is at fault? (the unused channels are grounded, so I discarded that as a cause). I repeated the experiment but this time doing a full run on each channel instead of switching them and this is the result:

Well, both are skewed so there’s something else going on.

Scoping at the inputs shows what seems to be AM at around 70MHz even without power applied (that’s on the tv broadcast band here) and it kind of makes sense because I didn’t use a shield. Head bangs on the desk.

Anyways, using a quick digital filter makes everything look nicer but I’ll still have to shield this:

The transient at the beginning is not going to be an issue, as in real life I don’t expect such a step change (from 0 to ~3k) and in any case the antialias filter will get rid of it.

On a second thought, those chunks skewed up are really interesting and I should spotted that as a failure symptom earlier.

# (trying to) Measure temperature

In a while I’ll need to characterize an oven and perhaps build a new one.
Just to start I have to apply a power step and measure how the internal temperature evolves.

In order to save time I searched my local distributors and bought a K type thermocouple with amplifier and cold junction compensation. It is not the most accurate but it is more than enough for now. There are a couple of ics available that give a direct digital output but the work needed to breadboard them and have a meaningful reading is beyond the scope at this stage.

This is what I bought:

Appears on many places as a “Grove High Temperature Sensor”. It sports an OPA333 precision opamp and a CJ432 adjusted to provide a 1.5V reference. The rest of the circuit is nothing special, except that the manufacturer called the thermistor “light”. It can be consulted here.

### First ligths

While I have more capable hardware at hand I grabbed an Arduino Nano and the official library from https://github.com/Seeed-Studio/Grove_HighTemp_Sensor and lo and behold I had it streaming temperature to my terminal.

### Let’s get graphical

I cooked a simple gui on python using Qt and Qwt while listening to Olivia Newton.
It is pretty barebones, only has facilities to export into csv, a couple of tracking cursors and gracefully handles device disconnections (say, I yank the cable). I expect to post process the data using QtiPlot or Kst.

### Tweaking

One of the first things I noted was that the measured temperature jumped in big steps of about 2°C.
Using the default setup with a 5V “reference” and considering the amplifier gain every adc bit amounts to:

$Vbit = \frac{5000mV}{1023*54.16} = 0.09024 mV$

Looking at the polynomial coefficients used by the library (ITS90) and taking a first order approximation one bit corresponds to a 2.26°C step and it grows bigger with the measured temperature as other terms start to influence the result. Even tough the output is low pass filtered at about 1.6KHz and it is averaged over 32 points there’s still noise.

Changing the reference to use the regulated 3.3V makes it about 1.5°C but even if it is more than enough for what I need it can be better.

With a couple of bits more I can achieve better resolution. Instead of using an external adc I took advantage of the inherent noise on the reference and output and chose to apply a 16 times oversample in order to have 12 bits out of the 10 bit adc. Application note AVR121 explains that nicely. Now I am limited (in theory…) to 0.37°C steps and I can average on top of that to further reduce variations.

The last source of error (besides not knowing for sure the “real” value of the references) is that the library assumes a fixed 350mV output, the circuit ideally floats the amplified thermocouple voltage around that. In order to measure it I added a small relay from my stash (TQ2SA-5V) to short the input. It is not meant to be used as a dry relay but does fine so far.
Upon startup it reads 348 mV; while a 2mV difference may not seem that big it turns out to be at least 185m°C. Anyway the main sources of error now are the thermocouple and adc reference.

# Back to basics.

For a course I’m taking at the uni I spent the last weeks programming entirely in assembler for a not very small micro.

Last time I did that for real work was about 12 years ago, dinosaurs roamed the Earth and the 16F84A was popular among my friends here.

It felt quite refreshing but the compiler sometimes behaved like a real jerk.

For instance this was flagged as invalid:

label   db $BA,$DC, $0E But trimming the spaces made it happy: label db$BA,$DC,$0E

(and I spent my weekly cursing budget chasing it)

Fortunately it runs fine under Wine, can be called from a makefile and the debugger/simulator works.

# Cosas que se al pedo

-(oído al pasar) ¿ Cuál es esa función que crece muy rápido?

– (me meto donde no me llaman) Ackermann…

– Esa misma , gracias.

En media hora de ver un documental reconocí dos temas de Moloko (no precisamente muy famosos) y uno de Piero Umiliani.

Todos estaban enfocados en la muchacha sin ropa y yo viendo el rig de la iluminación en el reflejo de los ojos.

El título vino gracias a, como no podía ser de otra forma, http://www.cosasquesealpedo.com.ar/