# 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/

# Cómo estudiar.

Eso mismo me pregunto yo ahora.

Cómo hacer a estudiar con personas en el cuarto de al lado viendo el TC que solo conocen dos estados para la tv, apagada y con el volumen al tope de su capacidad. En el otro cuarto dos personas copulando de una forma tal que enmudecería al mismísimo Ron Harris, teniendo a diez minutos de caminata el hotel mas barato de toda Buenos Aires (y sorprendentemente limpio para lo que vale la hora) o la casa de ella libre todo el finde.

# 12 Easy steps

Desde hace unas semanas estoy tratando de volverme mas diurno, o por lo menos rendir un poquito, sólo un poquito mas durante horarios “normales”.  Es algo complicado porque en tres o cuatro horitas durante la noche hago mucho mas que en un día completo de estudio.

A partir de las seis de la tarde nada de mate o estimulantes. Mejor dicho, nada de mate con yerba nueva. A las siete ya no tiene gusto a nada pero no me siento tan perdido como si lo suspendiera directamente. Un par de conocidos que usan vapeadores pasan por algo parecido, cuesta perder la costumbre.

Está funcionando de a poco, por lo menos ahora a eso de las doce ya tengo sueñito y no me cuesta levantarme temprano (para valores razonables de temprano) aunque no progreso mucho en cuanto a rendimiento.

Hoy todo estaba saliendo genial hasta que Loli decidió a eso de las cinco de la mañana que era mi obligación entretenerla y alimentarla. Y me lo comunicó como solo ella sabe hacerlo: tiró absolutamente todo lo que había en el escritorio y cuando se aburrió empezó a morderme los pies.

Arghh…. a las seis estaba nuevamente en la camuchi con sueño y malhumorado, sólo para dormir (mal) hasta las ocho.

Tan bien venía…

# Nerd weekends rock

Would you rather spend the weekend partying with amusing strangers or doing geeky stuff? Happy as never with my shiny new and photocopied books (Principles of Communications by Ziemer being the most notable and a bunch of theses) I chose the latter. Also I played with some brushless motors and field oriented control.

To make things worse (?) every single attendant to the party confirmed that my weekend was funnier than theirs.

# “Not for student use”

Third time in less than a hour I see this in datasheets and other technical documents. Funny thing is that different manufacturers of the same part disagree about whether we students should use their information.

# Noisy neighbour

Fuck it. I’m gonna play baroque music with the flute ’till your head explodes, my lips sore and Bach rises from his grave asking for mercy. Then I’ll crank the bass amp all way up to 11 while playing some candombe as if I were Seppälä. Even better, i’ll put some records of the original, hope you don’t mind the noise. It’s really fun when you try to study or sleep and you people are constantly shouting with ‘La Champions’ at full blast, as if it was enough to cover up your fights. I swear if it wasn’t for the rain and the fact that I can barely keep the balance at this hour I’d cut your connection to the power grid.