keskiviikko 28. joulukuuta 2016

Travelling ...


I know, my writing pace has slowed down significantly. Like I previously said, I've been way too busy with mundane day-to-day stuff to make anything interesting, meaning that I just don't have that much to say. I'd rather not write completely pointless texts, so I choose to lessen my pace. Now, whether this qualifies as pointless text, that's up to you...


I might have said this before, but it is my firm opinion that travelling sucks.

Sorry, let me rephrase that, it's the travelling, being "on the road", part that sucks. I've never been the kind of person that enjoys the journey itself. However, being there part varies from being a chore to being simply glorious - and everything in between.

That's me in the hammock there, in a small village of Kep in Cambodia, 2007. Getting there involved total of around 40 hours of travelling - but this isn't really being fair since this was extended trip and we stopped in many many locations, before and after this specific point.
 
Longest single trip at that point (during that excursion and from point A to point B) had been about 24 hours. Mostly via planes and airports. Cheap air travel doesn't usually be via quickest possible route. That is the part that sucks - cheapest or not. Be it via planes, trains or automobiles, it all sucks equally. Getting from point A to point B takes often so long time, and while there might be some interesting stops on the way, more than often there is not, or you are now aware of them. Or can't be bothered to stop there. Or are just too tired to.

Recently I took a short business trip; just 14 hours total, just to be in a few meetings with total of maybe two hours. All the rest was travelling around or waiting. Can you guess already why I am not a fan of business travel? But really, sometimes you have to do things that aren't the most fun.

Again, I may be repeating myself from earlier post but maybe 20 years ago I read an opinion piece in a local newspaper, saying that business travel should be taxable benefit. Really, that person travelling for work should be taxed for being able to enjoy benefits of travelling for business.

Listen here, bud. You might want to try that for a while first, your opinion is very likely to change.

But, nevertheless, when everything goes better than expected and you find yourself having an extra day with no work to do (having finished early) - well, that one day might be worth all the trouble.

Assuming, of course, that you aren't in middle of nowhere, with nothing but (unfinished) factory and few personnel barracks around you...



tiistai 20. joulukuuta 2016

Completely useless firmware


Not much blog activity lately, sorry about that, I just am swamped with work right now (uninteresting for readers) so I don't have anything new to post.

But I have to vent some frustration here.

Previously I dabbled with USB HID system with STM32F429 MCU, working fine, sources and all published earlier. I've since tried to get same code working with STM32F469, with no success. Couldn't figure out what was wrong (and I might have burned out one test board in process, oops - 5v tolerant like isn't very tolerant if rest of the board is unpowered...), so I wanted to try newer version of their library, maybe code for older processor isn't working because something in newer MCU had changed.

I want peripheral library to be essentially "drag and drop". Get source file (or directory for more complex subsystems like USB) and drop it in my project directory, change few lines at top of header and done.

This library from STMicro isn't like that. USB  system had been splintered in tiny pieces, thrown liberally around in dozen or so directories with pretty much no logic whatsoever (one file each, of course) in different places of messy directory structure, and with configuration thrown around, piece by piece, in those files. Very opposite of user friendly.

It's almost like they want to force people to use Expensive (with huge capital E) development systems for tasks that should be trivial...


perjantai 25. marraskuuta 2016

C: sizeof(pointer) is ...?


Pointers in C are one of the biggest traps for programmers, novices and experienced alike. If you are working with modern PCs they are fairly simple to use - a linear 32- or 64-bit address, handily the same size of native word size of architecture so you "can" cast it to integer and do other things with it (but you really shouldn't, unless you really, really know what you are doing).

Too often people seem to make assumption that sizeof(int*) == sizeof (int). For many architectures this is so - but not for all, and not even for all x86-based architectures. Because of this you really shouldn't do that casting thing I mentioned above (for example, for backwards compatibility 64-bit linux [amd64 ABI] has 32-bit int.)

And when you get to older architectures it gets even weirder.

Let's take original 16-bit x86 for example. It was, of course, 16-bit architecture, but with 1MB of memory total. Memory was addressed with segment:offset system; both being 16-bit values, the pointer total was 32 bits (I won't go into the actual addressing details here as it's irrelevant for the discussion.)
But wait, there's more! This was the "far" pointer, that could point to any address of the system (no memory protection back then.)  Then there was also "near" pointer that could only access memory within a segment with only the 16-bit offset value. And then there was apparently "huge" pointer which I've never encountered myself.

So here even sizeof(int*) isn't necessarily sizeof(int*), if those happen to be "near" and "far" respectively. Confusing already?

How about embedded world then?

I used to work with C51-based devices. This is old architecture, introduced back in early 80s, but is still going strong as modern variants. Different variants are easily and cheaply available from several manufacturers, and many (old-school) programmers are familiar with it, so they are very popular in embedded world.
These devices are 8-bit MCUs (int typically is 16-bit) and have four different memory access modes (and three completely separate memories);
  • DATA, directly accessible RAM, 128 bytes.  
  • IDATA, indirectly accessible RAM, 256 bytes total. This overlaps DATA for first 128 bytes.
  • XDATA, external RAM, up to 64kbytes. These days this is not really external but built in the chip itself. Being external there is no overlap with DATA or IDATA.
  • CODE, being code memory, I've used devices with up to 8kbytes of flash built in.
So here pointer must identify which memory is accessed *and* up to 16-bit address within it. So commonly pointer is three bytes; one byte to specify which memory is accessed, and two to specify offset (and yes, other compilers may have used other methods, this is one I am familiar with.)

Separate memory spaces for code and data is known as Harvard architecture, and it is common even these days; many Atmel chips use it - and my extension, many Arduino devices. I am not familar with those (aside the code/data separation) and how C compilers there handle pointers, but I wouldn't be surprised if similar methods as with C51 would apply.

C is full of traps, especially when you start mixing several architectures in same project, and it's kinda okay to play fast and loose iff you know damn well what you are doing. If you don't (even I don't, not always), one should play safe. Don't assume you know sizes, and don't do any wild castings. It'll come back to bite you.

I should know, I've been there, many, many times over the years.






maanantai 14. marraskuuta 2016

Voltage detector - with a leak within


Some time ago I bought a cheap contactless voltage tester. This is a device that indicates presence of high voltages (AC mains mainly) near the probe with a sound and is powered with two AAA batteries.

I do not need it often, but like so many devices, when I do need it it is really useful for diagnosing power faults (for example: this device seems to be receiving mains voltage so fault very likely is inside it.)  And just as a reminder: even if these don't indicate voltage presence, you should always treat mains wiring as it were powered!

Now, this specific device unfortunately does not have any kind of power switch for detection (it has a flashlight at the other end which does have button, yes, but that does not turn the voltage detection off). And since it takes only one time forgetting to remote the batteries, the end result is inevitable:


No, despite colors this device has nothing to do with Fluke.

Surprisingly, it still worked when in this condition, both detection and LED flashlight. The physical damage to the battery from trying to remove it forcefully - other battery is still deep inside and I don't even bother trying to get it out. I only noticed the situation since there was this white crap around the battery cap.

As my personal tool-buying rules say, I've bought cheap, found it useful, so now it is time to get a better one. And this time it absolutely must have a physical power switch.




torstai 10. marraskuuta 2016

Intermission: Culture and politics


Now that a bit of time has passed, I'll open up my previous short post a bit. Just politics here so if you don't want to read about that, move on.


Back in 80s, when I was growing up, USA seemed like a heaven based on everything I heard from there. Cheap soda, cheaper gas, advanced technology, rich people, good food, space exploration, world leader, etc etc.

As time as passed the reality has crept in (and maybe I've grown older and maybe a bit more world-wiser too), piece by piece, and the more I hear about conditions in the USA the less I nowadays want to live there. Two big things being political system and medical care. Both of which are so important for people and so horribly broken and there is (at the moment) no hope of either being ever fixed.

These days I've given up of even visiting the country as a tourist since border control seems to have taken openly hostile attitude towards anyone (their own citizen included) entering the country. As long as the situation remains like this I take my tourism money elsewhere. Like Colombia (not very likely, but they certainly are at the moment way above USA on my mental list of countries I'd like to visit some time.)

But back to today's main topic. Let's get real now - when electing the president, if your only real choices are "completely horrible person A" and "totally horrible person B", something is seriously fucked up somewhere. And this election was exactly like that. But hey, "Don't blame me, I voted for Kodos." Right?

I do hope that Trump will turn out to be something else than what he has presented himself to be during the campaign. But I won't be holding my breath in the meantime. 


maanantai 31. lokakuuta 2016

Function generator repair


I have TTi TG330 function generator that I use every now and then. It is fairly nice device, capable to frequencies from 0.003 Hz to 3 MHz in sinusoidal, trapezoid or square waveforms, including sweeps and 120MHz counter. I do not need it every day or even every week but when I do, it is worth every single cent of its price.

Unfortunately it broke a while back. Turning it on did absolutely nothing. I checked the main fuse but no, it was okay. So time to take it apart and see what is going on then.


Its a bit difficult to tell from the picture but the top cover has turned slightly yellowish near rear. Generator is fairly warm during use so that isn't exactly surprising.



Covers are held by simple plastic locking tabs instead of screws. Take these off from corners and cover comes handily off.

The insides. Note that generator is shown here upside down; the board seen on bottom is actually towards the top of the cover in normal orientation. I'm not exactly happy about that large and heavy transformer hanging in there during normal use.


All the capacitors seem to be okay, so it was time to start probing the board. It did not take long to find out that fuses, circled in picture below (marked FS1 and FS2) both seem to be blown. Weird, considering that main fuse (earlier in power supply chain) was intact.

These fuses are on secondary side of transformer so there should not be any (very) high voltages there, but one still must be very very careful when probing around these devices. Even when powered off there might be dangerous voltages around.


I could not find schematic for this model, but I did find schematic for model 550 which, while different, suggested that these fuses might be 500mA (if my memory serves, this was few weeks back now). Not something I had handy, but a quick trip to Sp-Elektroniikka (local parts store) I was able to acquire suitable SMD replacements. The space is a bit cramped but I was still able to replace these fuses with little trouble.

Since the original fuses were both blown I was a bit suspicious if this would work; if there is some issue further down the chain, new fuses might blow again immediately.

They didn't, and generator seems to be working fine again.

So I put it back together and it is serving me well again. No idea why those fuses have blown, but as long as it doesn't happen again I am happy. Although I do not keep the generator on 24/7 anymore.