Samstag, 12. Januar 2013

Mostly delays: What VHDL is all about

Last week I once more realized, that a big chunk of my daily work consists of finding the right places for the needed FlipFlops.

Until you get in contact with reality, you might think, that the implementation of some simple arithmetic is merely a task of rewriting it in another language (as in Java, Perl ...).
And - you aren't really wrong - you get a running solution.
The problem occurs, when it is synthesized in hardware and you find out that you can clock your completely combinatorical circuits with 2 MHz only...

That's the point where you start thinking about pipeline stages and registering of intermediate results.
And pipelined thinking is nothing that comes naturally to the human mind.
When you don't spend close attention to it, the simple task of summing up two signals becomes an exciting source of surprises: The place where you insert the pipeline register isn't the source of errors - it's the rest of the signals, you have to postpone accordingly, when you want to continue to work with the result.

Sounds strange - sounds uncalled-for - sounds familiar

  • Placing flipflops "manually" sounds a bit like the first PONG implementation
  • Of course, there is always a more comfortable way: Mathlab and Simulink for example - there even seems to be some more open alternatives, by now.
  • The problem with this cross-language-access might be in the less optimal resource usage and some missing configuration options (bitwidth, pixels/clock ...) that are hard to express in an abstract language (even though I regret to say, that I haven't given them a honest try).
  • It's a bit like people using pointer arithmetics in C. They know, it might be dangerous and a pain in the ... on the other hand, it just is as fast as it can get - and sometimes that's what counts.

Okay. Here's the problem...

  • Eventually you succeed in placing the logic and pipeline registers together and everything works.
  • After some months, you just want to make a little addition to the circuit and bring in a register stage at some point.
  • Now you have to check and adjust all the rest of the signals once more ... and after some months, the code might look quite new to you ;-)
  • Therefore the little change gets a big change and bares the risk of something going wrong along its implementation - something hard to explain to "normal" programmers.

Staying in VHDL but trying to make one's life easier

  • So the idea popped up to let the computer find out on its own how long the delay lines for the signals should be.
  • Being quite paranoid about automatisms that you cannot check transparently, I considered a external program that parsed the code, filled in the registers on its own and writes the extended code back to the same file.
  • The adjustments would be in commentary brackets - just like GUI code in the good old times of the MFC (/** DONT TOUCH THE FOLLOWING CODE. I - BILL GATES - HAVE FILLED IT IN **/) and the Visual Studio did some magic to it in the background...
  • That way, the resulting file would be self-sufficient and would run with all other software (Simulation, SOPC-Generator, ...) and, when changes to the register stages were needed, they would also turn up in the source file.

Shrinking the solution, hoping to get it done

  • Writing a full-fledged VHDL parser isn't that easy and so I already though about some code style rules, that would just have to be obeyed when you wanted support for the register stages.
  • The connection where the N register stages might turn up could be marked using special postfixes like some_signal__ac (for auto-connect) where it should be used and the signal some_signal where it is declared and passed a value...
  • The input signals and derived signals would have to be marked to fill them into groups that are synchronous to each other. And for synchronous signals that have entered an entity together, the parser can watch their delays ...

Shrinking the hopes

  • The first candidate for this automatism was the one that started the whole thought.
  • Therefore I didn't see it coming that after an hour of rewriting I voluntarily just quit.
  • There were signals that would have been unnecessarily delayed (since they only change every millionth clock and _then_ in an uncritical time span) ... and you would surely get register stages for them even though they aren't needed at all.
  • There were entities that brought in additional delays -  which would have to be described in handish and formal parser commentaries, so the automatism knows what to do with this.
  • There were edge-detections of signals (were you looked at the state of a signal now and a clock before) which broke the synchrony completely.
  • You might place the edge-detection into a sub-entity (with a correspondent commentary for its delay) to circumvent the last problem.
  • .... but I'm sure, there will be other problems that are as bad or worse...

Back to the roots - Back to "paper"

  • Up above I wrote "Eventually you succeed in placing the logic...".
  • Normally this involved a big sheet of paper were you sketched the signals and the flip flops to see, where you have missed one.
  • After some months this sheet of paper is normally lost and you have to start anew
  • To make life at least a little bit better, I switched to Graphviz for the sketches
  • The sketch can be checked in alongside.
  • You don't start to cry when you have to smush some more logic into the completed sketch.
  • The signals that belong to the same clock cycle can be grouped using subgraph s
As an example, I've got a first example here

digraph G {
DELAY_0 [ label="Delay by 2 clocks" shape="rectangle" ];
DELAY_1 [ label="Delay by 2 clocks" shape="rectangle" ];
SubEntity_0 [ label="SubEntity with 2 clks delay" shape="rectangle" ];
SubEntity_1 [ label="SubEntity with 2 clks delay" shape="rectangle" ];
STATE_M_0 [ label="Statemachine registered" ];   
subgraph cluster_0 {
style=filled;
color=lightgrey;
node [style=filled,color=white];
input_pixel;
input_pixel_padded;
input_ddr_content;
arithemetics1;
good_pixel_at_start;
label = "clock cycle 0";
}
subgraph cluster_1 {
style=filled;
color=lightgrey;
node [style=filled,color=white];
input_is_good_enough;
good;
bad;
label = "clock cycle 1";
}
subgraph cluster_2 {
style=filled;
color=lightgrey;
node [style=filled,color=white];
output_ddr_state;
input_ddr_content_reg2;
keep_ddr_content;
changed_pixel;
use_changed_4_ddr_content;
org_after_arithmetic;
label = "clock cycle 2";
}
subgraph cluster_4 {
style=filled;
color=lightgrey;
node [style=filled,color=white];
output_ddr_content;
result_pixel_14b;
result_pixel;
label = "clock cycle 4";
}
changed_pixel        -> SubEntity_1;
        org_after_arithmetic -> SubEntity_1;
        SubEntity_1         -> result_pixel_14b;
result_pixel_14b      -> result_pixel;
input_pixel           -> input_pixel_padded;
        input_ddr_content     -> SubEntity_0;
        input_pixel_padded    -> SubEntity_0        ;
SubEntity_0          -> changed_pixel ;
input_ddr_content -> input_ddr_content_reg2 [ label="2xReg" ]
input_is_good_enough  -> use_changed_4_ddr_content [ label="1xReg" ];
good                  -> STATE_M_0  ;
bad                   -> STATE_M_0  ;
input_ddr_content     -> STATE_M_0  [ label="1xReg" ] ;
STATE_M_0             -> output_ddr_state;
STATE_M_0             -> keep_ddr_content;
use_changed_4_ddr_content -> output_ddr_content_comb;
keep_ddr_content          -> output_ddr_content_comb;
output_ddr_state          -> output_ddr_content_comb;
changed_pixel             -> output_ddr_content_comb;
input_ddr_content_reg2    -> output_ddr_content_comb;
org_after_arithmetic      -> output_ddr_content_comb;
output_ddr_content_comb -> DELAY_1;
DELAY_1 -> output_ddr_content;
input_ddr_content     -> arithemetics1       ;
input_pixel_padded    -> arithemetics1       ;
arithemetics1            -> good_pixel_at_start;
good_pixel_at_start   -> input_is_good_enough [ label="1xReg" ];
input_is_good_enough  -> good;
input_is_good_enough  -> bad;
input_pixel_padded -> DELAY_0 ;
        DELAY_0            -> org_after_arithmetic;
}

leads to


The Plea

.... when there is somebody out there who knows an easier way to do this, please tell me.

Montag, 7. Januar 2013

Mostly holes - part 1 : Having the guts for big tasks

This might become an episodic post, ending with

  • episode 17 (rough guess)
  • me - having the feeling to have told everything at least twice and
  • you - waiting for the connections between all the funny bits and loose ends
  • some big embarassment since it doesn't work out at all - not even in my dreams

Gut feelings

Being an engineer for several years, you learn some old and valuable truths - the normal way - the hard way.

  • There is always some detail, you have missed
  • It's never that easy
  • When it goes bad, you surely had a bad feeling about it in the first place
The last point is quite critical, since the mind tends to play tricks on us most of the time.
But if you are really questioning about your "gut feeling" or you have even made some notes, you might discover one of the most precious tools, mother nature has given us - a "brain" between the place where sience and women would locate it.

Normally guts tend to be quite monosyllabic, with something like "Oh, oh", "6 months at the very least" or "Not again ....". But sometimes it goes off on its own and babbles on and on and on...

Hey brain, 
Hey you - are you listening?
I've got this thingy about language and such - you know?
It's really important, so listen closely:
There are computers you know - and hey - wow - they do all crazy sorts of things.
And there are babys and they spend most of their time eating and crying.
And after two or three years they just talk - so how hard can it be?
Maybe these computational linguists just make too much fuss about it ...
It surely is just a bit of database filling and once the words are in place the talking comes on its own.
Ooooh - let's just start the coding, and you will see, the rest falls into place.

I hope, you have spared yourself the last lines since they don't really make much sense.
That's the problem with gut feelings:
There aren't really any good points and arguments present but you somehow feel, there is something to it and you shouldn't ignore the message.

The message

  • It's a shame that "AI development" and "teaching computers our language" isn't one of the main tasks for "us" (software engineers and alike) anymore
  • Since so many people have already thought about these topics since the 80th, you cannot run along the same trodden paths when you want to get other results
  • You must try to keep the amount of necessary work for yourself to a minimum or you will never finish 
  • The advantage you have - when you start out now - is that the freaks of the 80th had LISP and we have the internet - millions of people doing Farmville.
  • When you have a running system and you can make it more exciting to help teach the net some language than to water virtual cabbage, you should have won!

Flicks of details without much connection

  • Traditional knowledge bases were quite statical, hierarchical systems that had to get everything right from the start - just like a house of cards
  • There are always many ways to explain something - a tree is "many leafes in the sky with a trunk going down to the roots" or "a giant root system that's powered by some leafes up above"
  • It shouldn't make a mess to have concurrent statements, meaning the same and it shouldn't make things much slower
  • The database should be easy to administer, to extend and should scale up nicely.
  • You might even use something strange as the DNS system to store the data since it covers some of the requirements above quite well (CNames, Subdomains, Caching) - and isn't that hostile to funny new applications
  • It's might not be necessary to make the teaching of sentences that formal - it should start of like baby talk
  • You shouldn't expect too much from the system in the first time
  • The Thing (whatever it might turn into) should therefore be at least "cuddly" from the start - otherwise the people will continue to tend to their cabbage... No kidding

Mittwoch, 2. Januar 2013

Java versus C


  • ... is a really redundant topic!
  • There is even a Wikipedia page telling all about the differences between the two programming languages.
  • So - I will only place some links to the gory, technical details and write some prose about life in general.
Reason for this post
  • Smartphones and tablets with Android OS are omnipresent and likely processors find their way into our daily work.
  • In every Android OS, the apps are mostly written in Java and work beautifully
  • The comparisons tell us that with new Just-In-Time-Compilers and the Dalvik VM, Java hasn't got any real performance penalties anymore
  • So it makes you wonder, if Java will eventually replace C in most devices - even if it is just a small microcontroller.
Why Java can't rule alone
  • There are still many systems out there that are just too small (code footprint < C64) for Java
  • The boot time for Java based systems is much higher - and many low power applications boot every few seconds and are asleep for 99.9 percent of the time.
  • Java can't access the hardware ... and shouldn't, since it's such a niiiice language ... it shouldn't get its hands dirty ;-)
Watching the PROs
  • When you watch the success stories closely you see, that All isn't Java that glitters
  • The Android systems are basically Linux systems - but they do good, not to tell anyone
  • Linux has been around a long time but few have the nerves to cope with it
  • Inside the Android OS, all the drivers are implemented in C and probably some more low level stuff is implemented in C.
  • The user / app writer however gets a nice clean interface and can forget about the rest.
And can you also make _a_call_ with your smartphone?

  • The tablets were the first "phones" that couldn't ring anybody anymore
  • Samsung has brought out the next step
  • GoogleTV will bring the apps to the television
  • It might not take too long until we see more industrial applications that incorporate the Android OS - just to get the interface right
  • ... and the application programmers will thank them.


Rio revival - a toddler game (to be verified)

I've got a two-year-old son, who has gotten his first board game for christmas.
Luckily he seems to like games as much as his father (which is quite an ambiguous statement, but I don't know how to put it otherwise).
So - after several rounds of "Mein erster Obstgarten""My first orchard", I am looking for some diversion.

  • When I was a kid, I was quite addicted to a game called "Rio".
  • Thinking about it now, it's quite dumb since you cannot decide very much... but my memory (and the comments in the link) tell me, that for the right age, it's a cool game.
Building it

  • In the original, you had to throw the dice and understand the numbers on the board
  • that's more than I want to demand from him, so the numbers "1", "2" ... "6" have to go and will be replaced by dice images
  • The sticks are nice but I'd prefer coins since he should't play with matches yet
  • Print out the right version
  • Color it the way you like (and better than me, please)
  • Glue it on a card board 
  • cover it in transparent film (if your child gets teeth at the moment and everything in his vicinity is soggy...)
  • Cut it out along with the round holes next to the dice
  • Glue it on another card board so the holes get a backside
  • Cut out the slot for the "6" after the glue has hardened.
Rules of the game

  • Every player gets 6 coins, you have to get rid off to win the game
  • You have to roll the dice and
  • ... when the correspondent field is empty, you can place a coin there
  • ... when the correspondent field is not empty, you have to take the coin
  • As long as you can place coins, you can continue to roll the dice
  • In the first round, you can only roll it once
  • When you roll a "6", the coin disappears through the slot, which is always a good thing...

Since I have surely forgotten half of the rules, here's a link to the  german description.

crashcam app

The Idea

  • Since smartphones are often used as car navigation systems, you might benefit from their universality.
  • They are normally placed at the windscreen and look at the streets by accident
  • In the unpleasant event of an accident, they could have taken a video or pictures of the event... when they had known before ...
  • The crashcam app would therefore take pictures all the time and when the accelerometer tells the app that it might have experienced a crash, it saves these pictures away...
  • It is questionable, if the recorded pictures can be evaluated as forensical proof, but they can at least give the owner and eye witness a clue what has happened and boost his sureness about the event.
Implementation

  • The best (straight-forward) implementation would be the integration into the navigation software
  • Information like the gps coordinates (that are already evaluated by the navigation software) would also be available and help to form a good picture of the situation (speed).
  • The pictures might be saved raw to ram (in 800x600 this would be 0.5 MB per frame)
  • When you make one frame per second and you grab 100 MB of the RAM, you can save 3 minutes of  footage in a cyclic memory that always overwrites the oldest data
  • In the event of a car crash, the data should be written to the SD card. Writing to it all the time would lead to a reduced lifetime of the card ... but it would increase the chances of having the data after the crash.
  • A second app (which might not have to be implemented as will) could start the crashcam app every time, the navigation software is started and shut it down once the navigation software is closed.
  • The smartphone is normally placed in a recharge-station, so the increased battery usage shouldn't be a big problem
Already doubts

  • Will a smartphone at the windshield survive a normal car crash? I would give it a chance of 50%
  • Will the battery stay in the phone? Should depend on the phone...

Readme.txt

Why English?

  • When you fear that the thing you want to say aren't that interesting, you should at least maximize the number of people, who could read it.
  • As an engineer, I have to read English quite often. But I don't have to write it. So - besides the content - this is also a kind of exercise for me.
  • Since my English will surely be riddled with mistakes (grammar, vocabulary etc.) I'm looking forward to find myself corrected by people who know it better.
  • I won't write every post in English - long posts without much hope of being read will stay in german.

Hoping for feedback to the mostly_s:

  • I would be happy when people pointed out, that the idea has been already implemented and - if possible - comment it with a link. That way, the topic is closed and nothing more has to be said about it.
  • Please feel free to question thoughts, statements and ... everything. I often realize that many obvious flaws in the plan only pop up when you look at it from another perspective - or when you have already started working on it.
  • ... and if you think "Hey, good idea, new idea, let's get started", I will surely hop along and help with the implementation.

Labels

  • I will probably ponder on a handfull of topics that aren't connected at all.
  • To save the reader all the scrolling over posts he isn't interested in at all, I plan to use the same labels for these topics, so you can filter out more easily.