Wednesday, April 29, 2020

fopen() - Text or Binary?

Its often convenient to control an embedded system remotely via some sort of communications protocol. In the good ole days, I'd devise some sort of homebrew communications protocol that was specific to my application's needs and I'd bash some data in and out of the serial port. Having grown up on 8-bit micros with limited RAM, every byte was valuable so there was a strong inclination to pack things tightly into binary streams, but the problem with that is how to test it... and before you know it I'm being drag into an endless rabbit hole of development on the PC side just so I could conveniently communicate with the embedded app.
Embedded processors have come a long way and right now, I'm getting up close and personal with some pretty nifty STM32 processor boards - this one in particular that I sourced from Banggood: https://sea.banggood.com/STM32F407VET6-Development-Board-Cortex-M4-STM32-Small-System-ARM-Learning-Core-Module-p-1460490.html

Compared with an 8051, these ARM devices are a beast; and the development boards are so cheap! It's time to cast off the constraints of decades past and update my comms routines... enter JSON.
JSON is sooo simple even I can wrap my head around it; it's text based which means testing it with my embedded app is simply a case of sending text files through a PuTTY terminal. Furthermore, because JSON is used so widely across the winternet, I'm pretty confident I'll be able to keep using it even if I upgrade my comms to Etherweb.
I dug around and quickly settled on a relatively compact JSON interpreter (called JSMN) from Serge Zaitsev (kudos @zsergo): https://zserge.com/jsmn/. It comes packaged as a single C header file which feels a little hacky but its nonetheless effective and I was able to get a basic command interpreter up and running on my target board pretty quickly.
At that point, I started thinking more about what sort of commands I might want to exchange and it became pretty clear that I was going to need some sort of generic command interpreter that was easy to abstract and extend.  That's going to be a work in progress but the relevance to today's discussion is how it drove me back to establishing a parallel development platform that would allow me to develop and test code on my PC rather than needing to run everything from my target (ARM) platform, and how I bumped into a nasty little PITA on how Windows processes text files.
I'm not going to post my original code because some dufuss will blindly cut and past it into their application and wonder why it doesn't work.. instead I'll post the working code:

 ============================================================================
 Name        : main.c
 Author      : Marty Hauff
 Version     :
 Copyright   : Use at own risk
 Description : Test scaffold for reading a file and processing...
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>
#include <limits.h> //PATH_MAX
#include <unistd.h> //getcwd()
#include <sys/stat.h> //struct stat
#include <string.h> //strlen()

#define MAX_TOKENS 256

int main(void) {
FILE* fp;
char* Filename;
struct stat st;
char cwd[PATH_MAX];
char* json_string = {0};

printf ("\nJSON Test\n");
getcwd(cwd, sizeof(cwd));
if (cwd != NULL) {
printf ("Current working dir: %s", cwd);
} else {
perror("getcwd() error");
return EXIT_FAILURE;
}

Filename = "JSON Examples/JSON_2.json";
fp = fopen(Filename, "rb"); //MUST use binary mode otherwise \r\n sequences get messed up!!
if (fp == NULL)
{
printf ("\nFailed to open %s", Filename);
return EXIT_FAILURE;
}

printf ("\n\"%s\" opened successfully", Filename);
stat(Filename, &amp;st);
printf ("\nStat Size: %ld", st.st_size);
fseek(fp, 0, SEEK_END);
printf ("\nfseek Size: %ld", ftell(fp));
fseek(fp, 0, SEEK_SET);

json_string = malloc(st.st_size+1);
fread(json_string, st.st_size, 1, fp);
fclose(fp);

json_string[st.st_size] = '\0';
printf ("\nstrlen Size: %d", strlen(json_string));
printf ("\n%s",json_string);

jsmn_parser p;
jsmntok_t tkns[MAX_TOKENS];
int nodes = 0;

jsmn_init(&amp;p);
nodes = jsmn_parse(&amp;p, json_string, strlen(json_string), tkns, MAX_TOKENS);
printf ("\nFound %d nodes", nodes);

free(json_string);
return EXIT_SUCCESS;
}

The thing that got me stuck for a day was that pesky little 'b' character in the fopen command. Here's what the output looked like without it (I'm using some test JSON from: https://json.org/example.html):

JSON Test
Current working dir: C:\Users\user\Documents\Projects\WinTest
"JSON Examples/JSON_2.json" opened successfully
Stat Size: 253
fseek Size: 253
strlen Size: 253
{"menu": {
  "id": "file",
  "value": "File",
  "popup": {
    "menuitem": [
      {"value": "New", "onclick": "CreateNewDoc()"},
      {"value": "Open", "onclick": "OpenDoc()"},
      {"value": "Close", "onclick": "CloseDoc()"}
    ]
  }
}}
âãäåæçèéêëì
Found -2 nodes

I couldn't work out what was causing the garbage at the end of the stream (second last line) and why jsmn was subsequently failing to parse the file. The clue is that there are the same number of garbage characters as there are lines in the JSON string. Take a look at a hex dump of the JSON file:
Take note of the 0D 0A sequence. Also take a look at these settings in Notepad++

Without the 'b' in the fopen() call, the file is opened as a text file and Windows strips out all the CR (0x0D '\r') characters when its reading the contents into a buffer. As a result, the string stored in memory is actually shorter than the number of characters read from disk.
Now look at the output when the 'b' is included in the fopen() call (i.e. as per the code listing above):
JSON Test
Current working dir: C:\Users\user\Documents\Projects\WinTest
"JSON Examples/JSON_2.json" opened successfully
Stat Size: 253
fseek Size: 253
strlen Size: 253
{"menu": {
  "id": "file",
  "value": "File",
  "popup": {
    "menuitem": [
      {"value": "New", "onclick": "CreateNewDoc()"},
      {"value": "Open", "onclick": "OpenDoc()"},
      {"value": "Close", "onclick": "CloseDoc()"}
    ]
  }
}}
Found 26 nodes

The CR character remains in the text stream so the console output (on Eclipse) double spaces each line, but take note that we no longer get the garbage at the end of the stream; AND jsmn has managed to parse the file correctly.

Take note of the moral of the story - consider reading a file in binary mode even if you know the contents are text.

Now to work out how to build a generic JSON command interpreter.

Return from hiatus

After almost 10 years since my last blog, I've decided it's about time I started writing up a few things again. It's been an eventful 10 years... not the least of which was living in China for almost 8 of them. The great firewall of China blocks this blogger site so it was increasingly difficult to make entries and, for the most part, I was so busy doing life that finding time to update this blog just became one of those things that fell off the priority list.
In any case, kids are now living their own independent lives back in Australia and a year ago wifey and I moved to Singapore and I've got a lot more control over my time.  And with this Covid-19 shenanigans I've been recently put out of (working for the man) work and so I've got plenty of time to pursue some projects of my own. Over the past couple of years, I've also bought some reasonably good test equpment (DSO, PSup, Sig Gen & Desktop Multimeter) so I'm pretty well equipped to do development at home. One of these days I'll do a writeup of my lab setup.
For now, this is a quick hello to the world and I hope to be keeping this site much better fed.

Friday, April 15, 2011

Using Competitors as Suppliers

Not that long ago, a PCB designer posted an interesting question on one of the LinkedIn discussion groups. The question was this:

"How do you feel about using a fabricator that also offers design services?"

I responded to the discussion directly but for the benefit of those who may not be members of the group, I wanted to share my thoughts more broadly because it shows how building connected devices can actually help defend against suppliers who might also be competitors.

It's a really interesting question that you are posing but I think it points to a bigger issue.
I use a mechanic in my local area to service my car. The service he offers (in terms of tuning my car up and changing the oil) can not be differentiated from any other mechanic I might choose to use, but over time, I have become loyal to this one mechanic because the service he offers goes beyond the oil he puts in my car. Sitting at the back of our transactions is a relationship and the history of that relationship is not something that a competitor could replace by simply undercutting the price.
So when it comes to creating an electronics product, I think designers really need to ask themselves whether the sole basis of their business is built on the secret sauce they add to their boards in the form of IP, or does it extend to an ongoing relationship.
I know the Apple example is overused but it really highlights the point. They don't make the cheapest MP3 players, but they have changed the game so that it's actually not an MP3 player that I'm buying from Apple; its a relationship and ability to seamlessly connect into their eco-system of content. In effect, the player is almost ancillary to my real requirement which is to have good quality music / entertainment on the run.
So the best defence against would-be IP thieves is to build products that develop an ongoing relationship and provide a reason for customers to remain connected to you... and then service those customers as if your life depended on it (because it does)!

Wednesday, April 13, 2011

China, here we come

It seems ironic that my last post dealt with the issues that foreigners have in grasping command of the English language. And now, it seems, I am to become a foreigner too.
I haven't been on the air much over the past 6 months because I've been backwards and forwards to China several times while working pretty solidly on the launch of a brand new training facility at our office in Shanghai. I'm thrilled with what has come together around that project and the fact that this week marks the launch of our first public course.
While "paid for" training might be a relatively new thing in China, the appetite is very high for quality courses that lift designers to a new level of skill and provide them with a deeper understanding of the methodology driving the creation of Altium's solutions. Our new facility will allow us to help customers better than ever before while also feeding the huge demand for skilled electronics designers as China continues on its massive growth surge.

In other news, you no doubt would have read the news that Altium is relocating its headquarters to Shanghai, China. This has been met with a huge range of responses from customers and industry commentators. Some have suggested that it makes perfect logical sense given the huge investment being made in China in technology areas that are in absolute alignment with Altium's vision to create a "copper to cloud" design tool. But others have been slightly less rational. At the extreme end they've insinuated that Altium's move can only mean that we have lost our way and have been hijacked by Communist antagonists who are planning on overthrowing Western military installations by using Altium Designer as a back door window into the inner sanctums of top-secret design houses.
In all honesty, I've got little time for xenophobic tirades but I do understand the depth of emotion that news such as this can evoke. It is very hard for designers in the West to not feel threatened by Altium's decision. Western designers have been the fortunate benefactors of over a century of manufacturing fueled growth that has led to great relative prosperity. But Altium's decision to locate its headquarters in Shanghai rather than Silicon Valley makes a very strong statement about where it sees the next wave of prosperity coming from. And that statement challenges several assumptions that many in the West have become accustomed to making. But on reflection, do we really believe that the West has some sort of monopoly on innovative design and quality? Do we really believe that our political system somehow gives us the absolute right to create better products?
Now before anyone starts sending volleys of political abuse at me, please take a moment to consider what I'm saying. The way I see it is this: when 1.4 billion people start becoming upwardly mobile, you can choose to stand at the shore and yell at the encroaching tide. Or you can jump right in and ride the wave of your life.
I, for one, am a surfer and my family and I are currently preparing for a move to China.

Tuesday, September 21, 2010

Thank goodness English is hard to master

I took a moment the other day to clean out my email spam folder and was amazed again at some of the crap that is out there and circulating. Frankly I pity the mums and dads, grandmas and grandpas who are still getting a handle on internet communications and are forced to wade through the mountains of spam content that spews from lowlife individuals trying to gain a dishonest buck.
No I don't want $US1,000,000 dollars deposited into my bank account from the estate of some poor soul who's only crime was to die in an African country that I've never heard of before and whose name I can't pronounce. I don't want to increase the size of my ... (and frankly I'm offended at the suggestion that I need any further augmentation), and I'm not in any way your acquaintance so don't address me as "Dear Friend".
But as good as my spam filter is, and as thankful as I am for it performing the job of raking through the rubbish that skates across the internet, I'm actually most thankful that English is a difficult language to master. It is that fact that provides us with the single biggest identifier of spam emails and allows us to differentiate them from their legitimate counterparts. Take this latest email as an example:

Dear Friend
I am Mr Ailudiko Razak working with Islamic Development Bank(ISDB)Ouagadougou Burkina Faso. I want to inquire from you if you can handle this transaction for mutual benefits/life opportunity for you and me.The transaction is about seeking your consent to present you as the next of kin/ beneficiary To our late customer over his fund US$25,Million dollars.
He died with his family during their vacation journey. I am waiting for your response for more details. The fund is going to be share at the ratio of 60/30.30% for you and 60% for i and my family which we are going to use for investment.and 10% for outstanding expenses.
Mr Ailudiko Razak


What self-respecting bank would ever communicate using such a poor command of the English language? Even if my spam filter had allowed this one to slip through the cracks, I'd have every opportunity to detect its stench simply from the malformed sentence structures and incorrect use of words.
So while the English language is the bastard child of centuries of conquerors arriving on the shores of the UK, it is now the greatest asset I have to protect me against cyber criminals.

Thursday, September 16, 2010

Altium Morfik acquisition

At last I can finally share with you some commentary about what has been rattling around the corridors here at Altium HQ for some time. We've just formally announced our intention to acquire Morfik and it's very exciting.

Picture this. You're an electronics designer and you've got a great idea for a new gadget. You've got all the skills necessary to design a PCB with some smarts in it and you can even program those smarts yourself. But then you come to adding some connectivity to the internet. You add an ethernet interface, update your smarts, and now you're ready to do the cloud stuff .... and you hit a brick wall. All that stuff about PHP and SQL and internet servers and SOAP and HTML and XML and Java and Ajax and ... It's a whole 'nother world!

So what do you do? As an electronics designer, you know about bits and bytes and if you were ever pushed on the point, you could probably even design the hardware for a web server. But when it comes to writing applications that exist in the cloud, where do you start?

Put simply, the Altium Morfik acquisition is all about giving you that starting point right out of the box. The philosophy is that pretty soon, every little device will need to be somehow connected to the cloud to maintain its relevance and appeal. And when it comes to designing those little neddies, you've got to start thinking about how and what you're going to connect it to. How will you pass data between your device and the cloud? Will it be via email posts, a simple Web server running inside the device, or will it be some other technique?

The cool thing about what Altium is up to is that pretty soon you won't need to worry about the implementation specifics of all that sort of stuff. Using Morfik's technology (which lets you write applications on a PC and deploy them into the cloud), and Altium's unified design strategy, you'll be able to co-develop new devices AND the cloud-based eco-systems that they plug into. So adding cloud connectivity and applications will be just as accessible to you as an electronics designer as it is to all those geeky CS dudes ;)

Hopefully it won't be long before I'll get to show you how this stuff works in practice with some real demos, but for the time being, I suggest you take a look at the videos on Morfik's website. We'll be adding more and more of this stuff under the Altium banner over time but take it from me, this is a state changer.

If you thought that Altium was a little out there as an EDA company, now we're off in the cloud!

Thursday, August 26, 2010

Who cares about inefficient code

At the risk of stirring up a hornets nest, I'm getting really tired of the naysayers who quickly play the "it's not as efficient as hand-crafted code" card when a new, high-level programming or design technique comes along. They just don't seem to get it that the question of 'efficiency' extends well beyond the run time of the application. In the real world of commercial pressures, making successful products is not just about the performance of the end product. It's also about your ability to develop, deploy and maintain that product within the window of opportunity given to you by the market.
This little rant of mine was provoked again after I read a recent FPGA Journal article 'Drag and Drop vs HDL?' by Dick Selwood. It was a well-written and informative article about National Instrument's continued push into FPGA design with their drag and drop design environment. But all three reader comments (as of today) focus around the efficiency of the code produced by GUI based design approaches. Now come on guys. Surely you can try a bit harder. Of course hand crafted code is going to be more efficient than GUI-based stuff. But that only matters when it matters! To write off the whole GUI-based approach on account of the few situations when it isn't suitable is way to short-sighted. And it's not like NI is taking away the ability to use hand-crafted code. They are simply giving you the choice.
The real problem with the "it's not as efficient as hand crafted code" argument is that although it sounds rational, it places us in a very dangerous position of being dismissive of the whole technique without giving further thought to whether that technique will be disruptive. If you ever get the chance to read "The Innovator's Dilemma" by Clayton M. Christensen then I highly recommend you do. It gives some really strong reasons why it can be suicidal to ignore new technologies on the basis of how well they fit current market demands. Technology doesn't stand still. It continues to push on at a break neck pace. If we dismiss a technology today because it appears to be inefficient compared with established techniques, we run the risk of being blind-sided when technological advances suddenly make the inefficiencies irrelevant. By that time, it is too late to reposition ourselves around the new way of doing things. As the book puts it, the real question is not about efficiency, it is about how disruptive the 'new thing' will be.
So here are my rules:
1) If something looks slow, technology will make it fast.
2) If a new design technique raises the abstraction level, gets you to market faster, or allows broader access to growth technologies (i.e. disruptive), it will supplant other techniques.
3) There will always be a need for hand-crafted solutions. But the proportion of products that must be hand-crafted will decrease.

Monday, August 23, 2010

The difference between Vias and Pads

A recent post on one of Altium's forums related to the fundamental difference between pads and vias. So because I thought it was an interesting question, I figured it was worth posting a blog entry about it.

Pads are the connection point between copper on the PCB and leads on the component. They are a common part of component footprints and they can be through hole or surface mount. When they are through hole, they are virtually always drilled completely through the board. When they are surface mount, they only exist on either the top or bottom layer. Pads can have virtually any arbitrary shape however round, rectangular, and rounded rectangular are most common.

Vias, on the other hand, are the means by which an electrical connection is routed between two layers. As such, they are part of the track net and not usually tied to the component footprint. They are always drilled and always round. The depth of a via can vary depending on whether it needs to pass between the outside layers of the PCB, an outside and inside layer (blind), or two inside layers (buried).

So the big question is, "Are these two primitives similar enough to be merged as one?"
The short answer is No. And the reasons are multiple:
1) Pads make their connection to component leads by being soldered. This means that the properties of the pad must have consideration for the soldering process being used. Solder mask pullback, pad surfacing, size and shape are all dictated by the soldering process and the physical properties of the component lead being connected.
2) Pads need to support multiple sizes and shapes due to both the properties of the leads of components connected to them, and any heatsinking effects needed as part of the component's cooling.
3) The pads of low pin count surface mount components need to be thermally balanced to avoid any ill effects caused by different cooling rates. For instance, a pad on one end of a two lead component (such as a resistor) that cools faster then the pad at the other end can cause the component to stand on its head (tombstone) as the solder contracts.
4) Unless you are dealing with embedded passives (i.e. components that are placed within the layers of the PCB), it makes little sense to have buried pads. Blind pads could be argued for some leaded components but that would make the board very dependant on very accurate lead lengths being maintained by the component vendor. This is probably an unnecessary risk as component leads that are too long will cause the components to stand off from the PCB. In some instances this may be desirable but I suspect it would be more hassle than it's worth.
5) Pads must have a designation to indicate how component pins and pads must be aligned.
6) The primary conduction path of a via is through the hole barrel. The copper donut area on top and bottom of the via is simply there to provide a solid connection between the hole barrel and the top / bottom connecting tracks. Without this, the connecting track could be torn off when the via barrel is drilled during manufacture.
7) Because vias don't require solder to fulfill their purpose, vias can be tented (covered with solder mask) to ensure that no copper is exposed to the outside world. This limits the risk of oxidisation of the via copper.
8) Vias offer a path between layers and so it is meaningless to use anything other than round, donut-shaped entry/exit points.
9) Vias need not have any designation since they are unreleated to components. However some form of unique ID would be helpful when devising design rules intended only for specific vias (of specific nets).

So in summary, Vias and Pads might appear similar but their functions are quite separate. And in my view, they should remain as separate primitives. Comments?

Wednesday, May 19, 2010

Schoolies week in India

This morning I had the opportunity to catch up with a valued colleague and friend Emma LoRusso. One of the things I really value about Emma is her ability to see the way forward and devise the strategies to get there. Over some scrambled eggs and coffee, she helped calibrate and clarify a few thoughts I’ve been having and as a consequence, I want to share with you an idea and passion that I want to pursue.

In 1999, I ventured on my first, short-term missionary trip to India. It changed my world. Having grown up in one of the most privileged countries in the world, I had never seen poverty like what I saw in India. So many people; so little material wealth.

But even more confronting was the slow realization that maybe I was the one who was impoverished. In spite of all my material wealth and good fortune, maybe I was the one who had the greater need.

The defining moment came for me when I shared a meal with an Indian family in a village whose name I could never pronounce. From a woodfire that had been cut into the earthen floor of what would otherwise be the verandah, the mother of the house served a bowl of rice with chicken curry that was so heavily spiced that it made my hands burn. And as I sat on the edge of the bed that doubled as their couch and begin eating with bare hands, it was as if my eyes had suddenly gained their vision for the first time. With the material facade pulled away I could see the world in a new light, and that the essence of living ran much deeper than my material possessions would have me believe.

This epiphany was profound but no amount of words would allow me to convey it to you in all its richness; you must experience it for yourself. Somehow, I must take you there.

And so I want to create a ‘Schoolies week in India’ program that gives you that opportunity. I want to take you out of your comfort zone and show you places and people that will change your world. And I want you to take that experience as a young adult and combine it with your passions so that you can know what to do with your future. This is my passion.

Monday, May 10, 2010

Why Government grants don't work

Having purchased a house around 8 months ago and now having experienced 6 interest rate rises in that time, I find it interesting to hear the ongoing debate about the rising cost of housing in Australia followed by demands for the government to "do something about it!" In typical political fashion, the Australian Government has been throwing money at new home buyers to help them live the Australian dream as well as stimulate the economy throughout this Global Financial Crisis. But I seriously doubt that this has been a useful exercise. In essence I believe it has actually hurt those people that it was intended to help.
For starters, housing affordability is driven by two forces; the first is the size of the deposit and the second is loan serviceability. Throwing money in the form of a one-off grant to first home buyers certainly helps them with their deposit but it does nothing to help with loan serviceability. And to make matters worse, because so many new home buyers have been clambering over the top of each other to get into the market and access their government grants, it has artificially inflated new homes by an amount roughly equal to the grant. In effect, the grant has passed straight through the hands of the borrowers and into the hands of the developer.
Solving the affordability problem is going to take a lot more than new home-buyer grants. The problem has to do with supply and demand. Everyone wants to live in a nice suburb and have access to good services. But that is an infrastructure issue as much as anything else. You can't create more land, all you can do is make better use of the land you have. And that's not something I hear the government doing anything about.
Why do we all feel we have to live close to the major capital cities? - So we can access good employment opportunities and education for our kids. Why do we want good employment opportunities? - So we can afford a nice house that's close to the city. And so the cycle goes.
So in my view, the only way to resolve the housing crisis is to provide incentives for industries to establish themselves in under developed areas of Australia. Rather than hand outs to new home buyers, why not invest in some real infrastructure and designate satellite cities that offer tax breaks to companies to establish there. Why not start building hospitals and schools before people live there rather than waiting until they have to fight for it?
I met a lady the other day who was selling up from her Northern Beaches property in Sydney and moving to the country. With the proceeds of her suburban house sale she was buying a 7-acre allotment with a large house and 'plenty of room for her daughters to own and ride horses'. The family opportunities in the country were so much greater than what could be afforded in the city.
So perhaps a little more lateral thinking around the problem would see us making better use of this land that we have rather than having us all feel like we have to cram into shoe boxes just so we can be close to the big cities.

Thursday, April 29, 2010

Socially Connected Devices

There's no shortage of people shouting about 50 billion devices being connected by 2020 but frankly I find all these futuristic discussions a bit shallow and without any real insight. People talk about everything being connected to everything and how your refrigerator will be able to order more milk when you run out (or something like that). But their arguments all seem to be built on an evolutionary model of connectivity expansion rather than a revolutionary one; there doesn't seem to be state change in how devices will communicate, just a whole lot more of them. So let me share with you where I think it is all going.

1st Generation Internet: All about getting big ugly machines to be able to transfer data between one another where the nature of the data was only meaningful to the computers at each end of the communication pipe.

2nd Generation Internet: People start getting involved and applications such as email allow people to start communicating with other people across the internet. The internet begins its amazing growth phase and websites designed for human interaction emerge.

3rd Generation Internet: Social Networking. Broadcast and community-based forms of communication emerge. Instead of using point to point emails to talk to the world, people broadcast their status using sites such as YouTube, Facebook, Twitter and Blogs.

OK, so hopefully you are still with me because here's where it gets interesting. We are currently in the 3rd Generation phase but the most interesting part is where its going from here. If we think that 50 billion devices are all going to start talking to one another, then what will they be saying? What will be the style of their communication?

4th Generation Internet: Socially Connected Devices.
By combining concepts related to the previous generations, 4th generation internet devices will communicate with one another in much the same way as humans interact on social networks; a device will broadcast its status / opinion / desire for information, etc to the 'cloud' and let other devices on that cloud respond in a manner similar to human social networks. Devices would comment on the status or opinion expressed by the original device; I agree, I disagree, I have a similar idea but my information is based on different inputs, etc. and they would adjust their own operation (opinion / status) based on the information they receive. They could supply information according to the original broadcaster's request, or they could attempt to open up a point to point communications channel with the original broadcaster in order to resolve, clarify or expand on the original topic of discussion.The point here is that (unlike the 1st & 2nd generation internet) communication is rarely point to point. It is far more communal in nature and provides all members of the device's social community an opportunity to engage further. Devices are no longer dumb robots that happen to be connected to the internet, they are intelligent and capable of forming 'opinions' as they communicate with other Socially Connected Devices.

To illustrate the concept, consider an example: On a hot day in summer, all the air-conditioners across the city are running flat out to keep homes and buildings cool. To help with their efficiency they monitor the open air humidity, temperature and sun load, and they broadcast this information to the cloud along with their location. As a cool change arrives and begins to travel across town, a sudden drop in temperature and sun load is measured by outlier buildings and they report this news to the cloud. Over time, more and more buildings report this change in temperature and a trend of information begins to emerge. Buildings that are yet to be hit by the cool change take note of the trend and check the local weather site to see where the prevailing winds are coming from. They quickly deduce that they are in the path of a cool change and so rather than continuing to listen to their own sensors that are telling them the sun load is still quite high, they listen to the outside opinions of other devices that are telling them that a cool change is on its way. With knowledge of the thermal mass of their building and an estimate of when the cool change will arrive at their specific location, they adjust the cooling output of their chillers at just the right time to ensure a more consistent temperature is maintained within the building and power is not wasted. And in the background of all of this, the power station throttles its output to manage the requirements of the network.

Maybe it all sounds a bit futuristic but the technology to do it is all here today. So very soon I expect to see my smart house Tweeting its status to a whole cloud of socially connected devices.

Thursday, December 31, 2009

Are you still alive?

Well it's been way too long since my last post and if you've read some of the user comments on previous postings, the last thing I want you to think is that I've somehow been shut down. Nothing could be further from the truth! But I have been very busy.
My wife and I bought a house back in September and it seems that every spare moment in the 6 weeks prior to that and since has been taken up with moving preparations, the actual move, and then renovations. So far we've managed to repaint all the bedrooms but the next job is to remove a wall in the main living area and then remodel the kitchen and lounge area. On top of that we need to remove all the carpets and sand the wooden floor boards back. I'm exhausted just thinking about it.
Our house is in Warriewood which is about half way up the Northern Beaches region of Sydney. It's a great location and we are only about 1km from the beach (around a 10 minute walk). I really want to be well connected with my local community and so on top of all the moving and renovating, I also did the Surf Bronze Medallion qualification which lets me volunteer as a Surf Lifesaver at my local beach - Warriewood SLSC. Hopefully this will also come in handy with some other things I'm involved in such as Surf For Life.
On the professional front, the major landmarks were a trip to the US for a week to discuss some higher level opportunities (still hush hush), an editorial webcast discussing the impact of high level software on embedded design, a webinar discussing how ECAD and MCAD design processes can merge, sponsorship and attendance at FPT'09, and creating a wacky NB3000 based Christmas Light Display.
So as 2009 draws to a close, I can definitely say that it has been a very full year and yes, I am very much alive. There are some very exciting opportunities emerging for 2010 that I hope to share with you soon so stay tuned.
Happy New Year.
Marty

Friday, October 2, 2009

You get what you pay for

The other week I was passing one of my local car dealerships and I noticed a car brand that I hadn’t seen before. It was a Chinese manufactured 4x4 and it was listed at about $20K less than a similar 4x4 that I’ve had my eye on for awhile. Of course my initial reaction was it couldn’t be all that good but in spite of that, I took one for a test drive.

To my surprise, I can honestly say that it wasn’t an entirely horrible experience and I was seriously considering my options. There were a few niggling things such as very heavy suspension and a driver’s side mirror that didn’t fold out far enough but overall it felt like a pretty solid vehicle. When I returned it and started talking turkey with the salesman, I asked him about the extra options. I wanted tinted windows, a tub-liner and canopy for the rear tray, and a towbar. As expected, they were all additional options that pushed the price up by about $3000 but hey, you get what you pay for right?

Ok, I agree. For most things you do in fact get what you pay for. But does that also mean that if I want less, I can expect to pay less? Altium Designer is a unified design tool that includes (amongst other things) PCB, FPGA, CAM, Simulation, and Embedded Software development capabilities. So should I expect to pay less if I don’t want the FPGA bits? Or maybe I don’t want the embedded software stuff; can I pay less if I leave that out?

How you respond to this question really depends on your philosophical position. If you think FPGA or Embedded Software is an optional extra, then you’d rightly expect to not have to pay for it if you didn’t want it. But what if it isn’t? What if FPGA and Embedded Software development is a necessary part of sustainable product development? Surely it should always be included as part of the ‘base model’.

Put another way, what if I wanted to buy a Volvo without airbags? Will they sell it cheaper? What if I only want two forward gears, can I remove the top three gears and get a discount? Of course not. The reality is that these features are so much a part of the complete product that it doesn’t make much sense to try to remove them.

In the same vain, Altium views FPGA and Embedded design capabilities as being so fundamental to the future of electronics product development that it makes no sense to treat them as optional extras or ‘delete items’ that you can take off the price. We are all heading towards a future built on smarter products that continue to increase their reliance on functionality defined in the soft realm, and whether today’s customers choose to use these capabilities or not will not change the inevitability of that future.

Maybe you do get what you pay for, but maybe you need more than you realize.

Monday, July 27, 2009

Being free to succeed

As a subscriber to Seth Godin's blog, I was reading a recent post on The reason riding a unicycle is difficult. As it just so happens, I taught myself to ride a unicycle a couple of years ago (some brief footage here) and what Seth mentions about falling is quite true. To ride a unicycle, you actually need to sit up straight and lean forward as if you're about to fall. But to save yourself, you pedal to catch up and before you know it, you're riding. So the key to riding a unicycle is finding that knife edge between falling flat on your face and moving forwards.
A few years ago, some friend's kids came away with us on holidays and I promised them I would teach them to ride. Their names were T. and D. and they were about 6 & 5 respectively. T., being the boy, was right into it and took off like a flash. After barely an hour of running behind him, he was off like a pro. But D. took a bit more work. After the first fall or two, she was ready to give up. It seemed that everytime she got going, she fell off. To her, riding was pain and not something worth pursuing. I could see that I needed to change my approach.
So instead of teaching her to ride, I started teaching her to stop. We did a few practice stops where I held her on the bike and without it moving forwards, I got her to take her foot off the pedals and place it on the ground as the bike fell to the side. Once she mastered that simple skill, integrating it with moving forward was just a matter of practice. After a day, she was up and doing laps alongside her brother. By taking the fear out of the fall, she was suddenly free to succeed.

Wednesday, July 15, 2009

Avoiding conflict with customer service

With the kids on school holidays and in another city with my parents, it was high time my wife and I got away for a weekend together. We found a hotel/resort online, phoned ahead to make a booking, and leisurely drove down to the NSW south coast.
At the time of making the booking, I had requested a dinner reservation for 7:30pm. When we arrived however, the hotel reception informed us that a reservation had been made for 7pm. Later, when we fronted at the restaurant at 7pm, we were told that the reservation had, in fact, been made for 8pm and that a table would not be available until that time. Slightly inconvenienced, we went back to our rooms with the prospects of our stomachs churning over for another hour. But at 7:30, I received a call from the restaurant to inform me that a table had now become available and we could begin our dining immediately if we so desired.
So in the end, we got the dinner reservation at the time we originally requested but not without some mucking around. I noted all of this on the hotel feedback form when we checked out. The hotel receptionist was very pleasant and smiled warmly as she finalized the invoice. "Did you consume anything from the minibar?, No? Well that's all paid up then. Did you enjoy your stay?"
I hesitated for a moment. Do I tell her that we had been stuffed around by the dinner reservation? Or do I simply return her smile and not mention it?
I chose the latter after convincing myself that I had written all my grievances in the hotel feedback form and that there was no need to make a scene by going over old ground. But as I walked back to my car and drove off, I pondered this interaction.
I've done enough customer service stuff to know that for every 1 person who complains about something, there are at least 10x that many people who have probably felt similarly but have chosen not to say anything for fear of 'making a scene'. So when someone does indicate that their expectations have not been met, it is well worth the effort to resolve things both for them and to ensure the same thing doesn't happen again. But for me, telling the hotel receptionist that I had felt let down by the restaurant booking would have created a position of potential conflict between the two of us and that really wasn't something that I wanted to come between my weekend away with my wife. It was just easier to avoid the conflict altogether and move on.
But in doing this, I had let an opportunity for improvement pass by the hotel.
I started thinking if there was a better question that the receptionist could have asked that would have solicited my feedback without creating a sense of conflict between us. I concluded that a better question might be, "Is there any feedback that you would like me to pass on to management for you?" All of a sudden, the receptionist is no longer my adversary but is now my advocate. My grievance was not between me and her. It was with a faceless hotel reception system that had mucked my dinner plans around. And yes, that IS something that I would like passed onto 'management'.
By asking this slightly better directed question, the receptionist would have created the opportunity for much better feedback without creating a position of confrontation between us. By introducing 'management' as a third party into the discussion, she would invite me into her confidence and create an atmosphere of much better customer service. So while I honestly did enjoy my stay, the hotel is much more likely to receive the valuable feedback it needs through a better framed question.

Monday, June 29, 2009

Avoiding Premature Evaluation

I was recently part of some discussions with company 'NoName' who had been evaluating Altium Designer. They knew a thing or two about FPGAs and so that's where they had headed first. When they found the schematic editor and the library of FPGA-specific components, they figured they understood what Altium Designer was all about and formed the (premature) conclusion that it was just another schematic-based FPGA design system.
When I questioned 'NoName' about their conclusion, they revealed, "We evaluated the design tool in line with how we felt a design tool should work." It's hard to argue with that logic and the reality is that their conclusion wasn't actually wrong - Altium Designer does allow you to do FPGA design using a schematic-based workflow. But it offers so much more than that and it was my job to help them see that.
Given that we all live in such an information rich environment, most of us have developed sophisticated filtering systems that allow us to order the information we we receive each day into nicely contained buckets. This works really well with well-behaved information that conforms with our pre-existing classification system. But what about the other things? How do we handle that?
That depends on whether we think the information is likely to be well-behaved or not. If we think it is well-behaved, then we will probably try to stuff the new information into one of our existing buckets. If we think it isn't well-behaved then we may try to put it into a couple of buckets. And in very rare circumstances, we may even consider making a paradigm shift and changing our entire bucketing strategy.
The problem with paradigm shifts is that we don't always know when we need to make one. Because we spend most of our time packing new information into existing buckets, our brains get very used to that sort of routine. So when something comes along that would warrant a paradigm shift, we may overlook it in our haste to stuff it into a pre-existing bucket.
That is how I would describe 'NoName's' initial reaction to Altium Designer. They thought they knew what they were looking at, they confirmed their ideas through some initial investigations, and once the classification process had concluded, they saw little reason to reconsider their conclusion. But to their credit, 'NoName' proved extremely open-minded and allowed me to discuss Altium Designer further with them. As a result, I was able to show them the features beyond the schematic entry capabilities and the overall exchange of information was quite valuable.
So if you're suffering from premature evaluation too, then maybe its time we talked about it.

Wednesday, May 20, 2009

The Best Switch Debounce Routine Ever

Switch debouncing is the process of filtering out the mechanical chatter that comes from switches (and relays) when their contacts touch or release. The duration of the chatter depends on the physical properties of the contacts but can last for as long as several tens of milliseconds. A comprehensive backgrounder to switch debouncing can be found here so I won’t repeat that content here. But I want to share with you an effective software debounce routine that is elegant in its simplicity, efficient and perfectly scalable.

Consider the following ‘bouncy’ signal.

Up until t=3, the input signal is in a low state. At t=3, some EMI induces some spurious noise on the wire that we want to reject. At t=5, the switch is in a bouncy state as a result of being activated. And at t=6 and beyond, the switch is in a stable high state.

The goal of the debounce routine is to reject spurious signals such as those found at t=3 while still reporting a valid transition within a timely fashion. This can be done by taking periodic samples of the signal and reporting an update once several samples agree with one another. The exact number of samples and periodicity will depend on the environment that your application will be used in and the immediacy that you need to report an update.

So let:
A = Current Switch Sample (T=0)
B = Previous Switch Sample (T=-1)
C = Sample taken prior to B (T=-2)
Z = Last reported debounce value
Z’ = New debounce value

If (A = B = C) then
Z’ = A
Else
Z’ = Z
EndIf

We can create a karnaugh map for Z’ using the inputs A, B, C and Z.

There are a number of benefits to this routine over other routines I've seen:

  1. It works for debouncing an entire input port as well as individual bits.
  2. It doesn’t consume any timer resources other than those required to periodically call the routine.
  3. It can be readily implemented in programmable hardware, and
  4. It is perfectly scalable. So you can expand the number of samples without modifying the basic algorithm. For instance, the equation for debouncing across 4 samples is:
    Z’ = Z(A+B+C+D)+A.B.C.D
    And the equation for sampling across 5 samples would be:
    Z’ = Z(A+B+C+D+E)+A.B.C.D.E

A sample C routine is listed below (please excuse the formatting):
int debounce(int SampleA)
{
static int SampleB = 0;
static int SampleC = 0;
static int LastDebounceResult = 0;

LastDebounceResult = LastDebounceResult & (SampleA | SampleB | SampleC)
| (SampleA & SampleB & SampleC);
SampleC = SampleB;
SampleB = SampleA;
return LastDebounceResult;
}

Thursday, April 30, 2009

What is your sense of entitlement?

In my last post I mentioned that Altium have stirred the pot with their new pricing model. Well now they've gone even further with a web-based advirtising campaign and billboard promotion. The text is a little hard to see in the photo so I've included it here:

1,000,000 people overseas can do your job
What makes YOU so special?
Altium. Next generation electronics design solutions.

Not surprisingly, its caused a rise out of more than a few people with one person stating that Altium should sack their ad agency and the foolish executives who approved this indignity. It is certainly a stark departure from the "You're so special" sort of advirtising that we're used to seeing.
But it has got me thinking about the sense of entitlement that we have around our work, our skills and our job. What is at the core of our indignation over someone overseas taking our job?
Karl Faase, a regular "life moments" radio presenter, recently had this to say on one of the local community radio stations:

The present generation has grown up believing that every child needs good self esteem. Every child needs to believe in themselves and their ability. But is there a potential down side to this attitude? Over the past 20 years American children have grown up being told they are special and can achieve anything and now there seems to be a growing gap between American kids’ self esteem and their abilities.
In a study of maths skills tests among students in eight nations, Americans ranked lowest in overall competence and Koreans highest, but when researchers asked the students how good they thought they were, the results were exactly opposite; Americans highest, Koreans lowest.
We need to be realistic about our abilities. As writer Steve Salerno says “In the grand scheme of things, knowing one's limitations may be even more important than knowing one's talents.”

When it comes to designing electronics products, the days are gone when our value was implicit in the degree or qualifications we had earned. We have jobs for the simple reason that we add value to the companies that employ us.  It is an issue of economics and not entitlement. The only defence is continuous innovation.

Monday, April 27, 2009

Altium's new pricing model

I can hardly believe it's been over a month since my last post.
Things are progressing nicely on our target project but it has taken quite a few twists and turns over the past 6 weeks as has the focus of the objective.  I can't say too much at this point 'cause it aint public yet but all will be revealed soon (very exciting!).
Last week we released new pricing for Altium Designer. It's been really interesting to see the user response to it on the forum.  A number of people have reacted to the fact that our huge reduction in price has severly depreciated their purchase. Others have just been happy that Altium tools will be more accessible to the broadest possible range of designers.  Yet others have taken the synical view that it is simply a grab for cash in tough economic times. From the inside though, I can honestly say that I am excited about the pricing decision as I know it will help a lot of struggling engineers and companies out there and it will ensure that price is much less of a barrier.
So let me know what you think.  Is it still too much? Or is it too little - i.e. will the "you get what you pay for" adage work against it?

Friday, March 13, 2009

Fail fast, fail cheap

Often when we try to build something, the very last thing we consider is failure.  But it is actually through our failures that we learn the most and find the path towards true innovation. So rather than avoiding failure, we should focus on sandboxing our thoughts in a way that captures failure early and cheaply.
Let me offer a recent example.  You've heard me talk about the new design that I'm working on for an upcoming training program we are running at Altium.  Well I thought we were going to go ahead with the Natural Disaster Management System but that got canned because we didn't want users to pay several hundred $$$'s in weather measuring equipment in order to replicate the project.
So the new project is a moving light system. Basically it involves mounting a high powered LED onto a pan-tilt head (something like this) and creating a moving light show that can be controlled from a myriad of sources.
According to info I found on the web, driving R/C servo motors is pretty easy.  So I thought getting one to work would be a piece of cake.  In actual fact it was pretty easy but after connecting up the first servo, its range was only about 90 degrees.  I needed at least 180. No problem, tweak the driving circuit a bit and before you know it I had it driving across the full 180.  As it happens, the generic servo drive specs didn't seem to match up with the servos I bought and I had to spread the signal out a bit to get the full range.
So in a word, my first attempt failed, but that's what lead me to the second attempt and a greater understanding of what I am working with.  I now know that I need to leave provision in the application code so that I can calibrate for any servo to ensure I get the full range out.
So fail fast, fail cheap, and move on to the real innovation.