Tuesday, January 15, 2019

Job attitude

Recently some novice engineers complained about their work, saying that it was boring. My own attitude towards my work is first and foremost "am I useful, do I add value". If I am not able to answer that question with a resounding yes, I have to find ways to make myself useful. Only after I that do I allow myself to ask for more.

If you take initiative instead of complaining, you will go a long way, especially in fast growing environments, where there are many new challenges whose solutions nobody knows yet.

Similarly, if someone outside my workplace asks for my services, my first question is never "how much will you pay me" but "how can I be of help to you, is this problem worth solving".

As long as you keep on adding value, responsibility, respect and money will follow.

Sunday, January 13, 2019

Refactoring legacy embedded code

Recently we had to add new functionality to existing embedded software. When we analyzed the code, in many cases there were little to no documentation and code smells were all over the place. It was difficult to use existing functionality because it was very hard to understand. But replacing them with new clean code was not an option becaue the functions were used in many places. We would have to repeat costly HWIL and field tests, setting us back for months.

We decided to leave the existing functions but added comments about our suspicions, mark them as "deprecation candidate", write new ones that were only called from new code. We also heavily documented our additions. This approach is similar to changing public APIs: You rarely delete, you usually add and mark old code as deprecated so that existing software continues to function with the new API version.

Friday, January 11, 2019

Operational Amplifiers

Op-amps are used to amplify analog signals. By signal it is usually meant voltage, not current. So, op-amps amplify voltage. Their output current is low, on the order of mA.

In a control system, we usually want to drive a high current device like a motor or an electromagnet according to analog sensor (e.g. 49E) readings. Sensors output low voltage values which are amplified by an op-amp. In order to drive high current devices, we feed the op-amp output to a transistor that can handle higher currents. The reason we can't completely replace the op-amp with the transistor is that a transistor usually expects larger voltages at it's base (low current is not a problem) which the sensor cannot provide.

If your sensor output is not analog but digital (e.g. MPU6050 which has I2C output), you have to feed the output to a microcontroller which than can produce a PWM signal fed to the transistor, i.e. there is no op-amp in the digital sensor case.

Wednesday, December 26, 2018

Enabling technologies for IoT development

Small scale / hobby IoT development has become much easier due to the following:
  • It is possible to buy electronic components in small numbers cheaply and reliably from China. It is a miracle of logistics that I get a couple of transistors for a couple of bucks, shipped to my doorstep from the other side of the world in two weeks!
  • Arduino, it's IDE and tons of libraries for all sorts of devices saves you from dealing with details of device drivers. 
  • Cheap and reliable web services like AWS.
  • Easy to use server environments like NodeJS.
  • Last but not least, YouTube gets you up and running quickly.
We live in amazing times where everyone can tinker with electronics because the barriers to entry are so low now. Even my father who is 73 years old asked me the other day where he can get some breadboards! Imagine what the youngsters of today will come up with in the future.

Wednesday, December 05, 2018


Differences between NPN & PNP Transistors: "...an NPN transistor turns on when the current flows through  the base of the transistor... A PNP transistor turns on when there is no current at the base of the transistor [i.e. the base is connected to the ground]." Usually, the middle pin (#2) is the base but there are transistors like the TIP120 whose base is pin 1, check the datasheet.

You can connect transistors in parallel to handle currents that a single transistor can't.

Friday, November 30, 2018

PWM of a signal

Pulse Width Modulation can be used to convert an analog signal to digital or mimic an analog signal with digital (e.g. Arduino's analogWrite()). PWM basically converts the signal sample values into pulse width values (amplitude of pulses is constant). Below is a Matlab script that demonstrates PWM of a sine wave.

Thursday, November 29, 2018

Software bug target

Any complex software will have bugs in it, no matter how hard you try to fix them all. When testing software, aim for bug free operation in 95% of all operational cases. Note that I say "all operational cases" and not "all possible cases" because possbilities might be infinite due to combinatorial explosion and 95% of inifinity still infinity!

Users / domain experts can tell you realistic edge cases. If you don't constrain your bug target this way, you might spend a lot of time on fixing bugs/optimizing of unimportant scenarios. That is why having a freqent iteration development methodology (e.g. agile) and lots of tests with real users is very important in building a reliable product.