Friday, December 18, 2009

Take the time to learn your system

I’ve always been fascinated by microcontroller systems and the process of making them come to life.

It all starts by designing the system, a controller with some peripheral hardware. Once I finally have a prototype of my design the first thing I do is to see if I can talk to the processor. This is always an exciting moment. Will it respond? Will it program?

I prepare a small hello-world type of program and try to load it into the controller (or in its external memory, depending on what I am working on). Suppose all went well and the controller accepted the program (what a deception if it didn’t). Usually the hello-world program is flawed and doesn’t work as intended. Maybe I was too brave and tried to put too much in it, maybe I didn’t understand some functionality? I modify the program and try again, but still nothing. So I hook up the oscilloscope and start probing around. Aha! found a signal, but on the wrong pin. Back to the code, locate the bug this time and now the hello-world program works. Great! Little by little I start adding functions to the code, first to test the peripherals and then to get fancy. And then suddenly it all stops working…

Oops. Now what exactly did I change the last time? Ehmm…

So I start taking bits of code out, but that doesn’t help. I remove more, change this and that, decide that some parts could be coded more elegantly and I end up spending many hours coding without much success.

And then, as suddenly as it stopped working, the program starts working again. Hallelujah! From this moment on, I know from experience, it will never stop working again. No matter what I do, the program will run. There will be a bug every once in a while, but I know I will fix it quickly and I just can’t seem to mess it up anymore. My baby is alive! I master the system without really knowing what went wrong, where and why. Now my prototype can and will grow into a fully functional system.

Fascinating, isn’t it? No? Oh well, I guess you had to be there.

So what’s the point? Well, the fact that I spend many hours fiddling around trying to figure out what and why made me into an expert. The experience gained from debugging and rewriting code helped me understand my system. Since this has happened often to me, I now know that I have to go through this phase to be able to finish the job.

So don’t despair when you can’t find out why your system doesn’t work. Keep patient. You will get there if you are willing to spend the time to learn your system. Once you are the expert, your system will listen to you and obey.

Do you recognise any of this? Let me know how you work, how do you learn your system? Please share your experiences.


  1. Clemens, that process sounds very familiar! What I try to do in a project is to leave a few spare pins on the processor where I can attach a small LCD for diagnostics. That way, I can just print a letter or number when the software takes a particular route through the program.
    Another thing I do is to save the project with a consecutive number, everytime I solve a major problem or finish a functionality. That way, I always have a functional fallback. I also keep notes of the changes from one version to the next. Not as good as a professional version control system, but free!

    Jan Didden
    Linear Audio

  2. Souvenirs, souvenirs, it was in 2003, someone rings at the door.
    I rush to the intercom.
    Me : “yes ?”…
    The intercom loudspeaker :”I am the postman, are you M. Ester ?”
    Me : “Yes !! Yes !!”
    The postman : “I have a package for you”.
    Me : “Yes, yes, I’m on the third floor”

    …From the frame casing of the door, I am watching the opening of the lift’s door, I am hearing the engine lift, the cables tighten, the postman is trapped in this elevator shaft which brings him, inexorably, to me. The lift doors open at last…
    Me : “It’s here”
    The postman :”sign here”
    Me : “I wish you a great day !!”
    The postman : “Thank you, good bye”
    I try hard to open the package…
    Finally, I see two letters “ST”, then a word, “Flash”.. I remove the entire box out of the wrap, at least.
    All of the inscriptions appear clearly : « STK500 AVR STARTER KIT - AVR Flash Microcontrollers ».
    I open the box and I finally discover the development board green/white/green with its sockets, jumpers, connectors, leds, switches, reset button…
    What I had compiled and simulated for days would finally come to life…
    The microcontroller is slotted into its place : ATmega32.
    The LCD 2x16 is ready too.
    The STK500 board is finally connected to power supply. I say “finally” because I checked a thousand times the polarity ; the action on the power button has been done almost slow.
    LED’s begin to shine. The back of my right hand helped me to wipe drops of sweat that reflected an evident stress mixed to the heat of summer.
    I double-click on the icon that start AVR Studio, the microcontroller is well alive !!! It gives me the status of its bits configuration.
    I browse through my files to finally find my compiled program “Hello World !”, ready to be added to my ATmega.
    One more click and life will take shape…
    -click- on the “program” button, the LCD’s screen let appear the display I was waiting for :”Hello World !”.
    There was no rejections, serious things are finally going to start.

    In broken English :-) Grégory Ester