The programming language “immediate C” or iC is a declarative, event-driven extension of the procedural language C – useful for machine control, robotics and for dealing with events generated in a GUI.
iC utilizes the syntax of C to give meaning to statements that have no semantic support in C. In addition to standard variables, which are modified by the flow of instructions, iC provides so-called ‘immediate‘ variables, whose values are updated, whenever a change of input calls for an immediate change in output. An efficient Data Flow technique implements this strategy.
iC provides programmers with built-in operators, whose function is closely modelled on integrated circuits. The name iC is a reminder of this fact. Logical AND, OR, EXCLUSIVE-OR and NOT as well as D flip-flops, SR flip-flops, shift registers and many others are implemented in such a way, that their use in iC follows the same design rules, which apply to their hardware counterparts. These rules have led to a well-developed hardware technology, whose effectiveness is demonstrated by the success of today’s complex computer hardware. Particularly the concept of clocked functions plays an important role in the language iC. It gives the same protection against timing races in iC programs, as it provides for hardware IC designs. But iC is not a hardware description language nor a simulation language – it provides the functionality and some of the speed of field-programmable gate arrays with a language, which is pre-compiled into straight C code, which is portable and produces efficient machine code.
Writing programs in the language iC has the added quality, that many simple ideas and relationships, which should result in direct actions, can be written down immediately in one line. The coding of call back routines and other overhead is not required. It was this thought, which also prompted the name “immediate C“. The following is a fully working iC program. The output message is triggered by the external switch IX0.0.
if (IX0.0) { printf(“hello, world\n”); }
The design of immediate C was very much influenced by thinking about biological neural networks in the brain. How is it possible that such relatively slow chemical components as neurons and synapses can process such vast amounts of information at the speed that they do? The algorithms at the heart of the iC system are based directly on synapses and biological neural networks – not for artificial learning, but simply to gain speed.
An iC program consists mostly of a series of logical and arithmetic expressions, each expression declaring the relationship between some external inputs and/or intermediate variables on either another intermediate variable or on an external output. This type of program and functionality is very similar to that of an industrial “Programmable Logic Controller (PLC)”. In iC, these expressions are not executed in sequence as is the case for all instruction flow languages, including PLCs, but only when an input to one of the expressions changes. This feature makes immediate C a ‘declarative’ computer language and is the basis of its event-driven strategy. The fundamental assumption for iC is, that the output of an expression does not change if none of its inputs has changed and therefore does not need to be executed until one of its inputs does change – but then it should be executed immediately (at least as soon as possible). This event-driven strategy gives iC an enormous speed advantage over PLC’s, which execute every instruction in the program over and over sequentially – independent of whether the instruction causes a change or not.
Here is an example of a simple iC control program for a water heater with external inputs on, waterLevel, temperature; intermediate variables waterLo, tempLo and external outputs fill, heat, ready:
imm bit on; // & is AND, ~ is NOT in iC imm int waterLevel, temperature; imm bit waterLo = waterLevel < 90; imm bit tempLo = temperature < 98; imm bit fill = on & waterLo; imm bit heat = on & ~waterLo & tempLo; imm bit ready = on & ~tempLo;
If these expressions were placed in an instruction flow environment, each of the expressions would have to be executed over and over at regular intervals, because that is the only way to catch a change in any of the inputs to an expression. This is what an industrial Programmable Logic Controller (PLC) does. The polling interval determines the maximum response time of the controller. But this response time must always be a compromise between the total number of control expressions, an acceptable response time and an acceptable CPU loading. For PLC’s the CPU is 100% compute-bound and even then there is a limit to the number of expressions that can be tolerated before such a controller becomes too slow.
Each of the above variables in the iC environment is an immediate variable. bit and int immediate variables are objects, which have a value, but each such variable also has a list of pointers to those expressions in which the variable occurs. Each of these variables, which have one assignment expression to determine their value or are an external interrupt input, is called a Node and the pointers associated with each immediate variable Node object link these nodes into a network, much like a neural network, where the expression nodes are the synapses and the pointers to other expression nodes are the dendrites. This forward action of signals from one expression node to the next constitutes the basic data flow strategy of the iC system, which was copied from biological neural networks.
The Analogy to neural networks is even closer. Synapses fire when a certain input threshold is exceeded at which time signals flow through dendrites to other synapses. Each AND or OR bit expression in iC is implemented by majority logic in which the number of hi inputs are counted. When the number of hi inputs reaches a threshold (just like in a synapse) the expression node fires, at which point it executes a similar action in all the expression nodes on which it acts (in which it is an input). The only difference between an AND majority node and an OR majority node is the threshold, which is set once at the initialisation of the system. The threshold for an OR expression node is 1 – only 1 input hi fires the node. The threshold for an AND node is the number n of its inputs. All n inputs of an AND node must be hi for it to fire. It only takes a few machine instructions to execute this algorithm. The upshot is, that the internal response time of the iC system to one change is in the order of nanoseconds for modern CPU’s, even for control programs with thousands of immediate expressions. Most of the real response time is in the drivers, getting inputs and outputs from and to their electronic connections. The CPU loading is generally well under 1%.
Another way to view the run-time model for iC is to think of expression nodes as digital or analog IC components, interconnected by their forward pointers. Keeping this view in mind may make programming iC easier. Even such concepts as Large Scale Integration (LSI) are catered for with so-called ‘function blocks’, which allow the programming of groups of interconnected expression nodes into a sub-assembly with a list of parameters for connecting to the rest of the iC program. Such function blocks look very similar to C functions, but their execution is very different. C functions execute their instructions each time they are called. iC function blocks are templates, which are cloned for every instance in which the function block is used (not called). Each instance has its own internal expression nodes which only execute when one of their inputs changes.
A full Integrated Development Environment (IDE) called iClive, with a full editor with emacs bindings, buttons to build iC programs and run one or more of them in parallel as well as debugging facilities, is included in the distribution. A special debugging facility called ‘Live display’ shows the state of iC variables of a running program by changing the colour of those variables in the program text. (This facility is standard for PLC’s and factory personnel would be very familiar with it). Another debugging facility is Watchpoints, which stop execution when any marked immediate variable changes or reaches a certain value and the ability to single-step the code a single change at a time. This is more common for instruction flow language debuggers with Breakpoints, but the ability to freeze an iC program and look at its state while things are not changing makes testing iC code much easier.
The Header picture of this post shows iClive loaded with a simple program andOrXor.ic and running it in ‘Live’ mode, showing some values Hi (yellow/red) and some values LO (green/black). I/O is taken from a separate virtual app iCbox (shown on the left of the Header picture).
iCbox allows the generation of inputs and the display of outputs while an application is running. The screen hardcopy on the right shows the iCbox window for the sample program demo.ic, which is written in the iC language and which is part of the software distribution. To start the program simply type “iClive demo.ic” and click “Build”, “Run” and “Live”. The documentation contains full instructions on how to install and use the software.
iClive is both a text editor and an online debugger, which can display the live state of variables as an iC program is running. This is shown on the right using the same demo.ic program as above, with different variables changing from LO (green/black) to HI (yellow/red).
To start with immediate C, have a look at the immediate C Programming Manual in the Books section of this site, which starts with a tutorial introduction of the language in the style of the K&R C Programming Language, building up from there discussing all the features added to C. The immediate C Reference Manual describes the iC language and its built-in function blocks in detail. Several small but important features have been added to the language in the last year and both manuals reflect these changes.
On a Linux system and particularly on a Raspberry Pi you can clone the whole GIT repository from https://github.com/JohnWulff/immediatec.git or download the ZIP file of the latest release from the same GitHub site and try your own iC code very quickly.
immediate C is built with the usual configure – make – make test – make install commands. The README explains the details and how to make, run and debug iC apps.
immediate C can execute direct Input/Output on a Raspberry Pi computer. Drivers are included for digital I/O on GPIO’s and PiFace cards as well as a driver for PWM analog output on GPIO’s and analog input from an MCP3008 A/D converter. See README.RPi for details.
A number of interesting machine control projects have been realised with Raspberry Pi’s and their associated peripherals. The most realistic was a one metre high Meccano model of a lift system built by Keith Burston. This lift services four floors with a moving cage and counterweight driven by an electric motor and motor-driven inside doors, which mechanically engage with the outside doors at each floor to open both together. It has outside floor buttons and a box with inside floor buttons as well as floor indicators. Keith Burston’s original controller was made from miniature relays and a rotating sequencer.
Keith built an electronic interface to his lift based on PiFace hardware. The iC control program kbLift.ic uses iCpiFace as a driver. It does proper queuing of floor requests from both outside and inside the lift and follows a regular sequence of up and down movements to the nearest floor in the current direction, which is not necessarily the sequence in which floor request buttons were pressed.
To run the lift control program without the Meccano model, I have a virtual lift system based on a GUI called iClift, generated with a Perl/Tk canvas. It has a simulated cage and doors and all the right buttons. The GUI simply communicates with the iC control program with the same message protocol as all other iC drivers like iCpiFace for connection to real I/O or iCbox, which is a virtual I/O.
The screen below shows iClift with all its controls and an iClive screen showing the “request floor” logic.
The full video of the virtual lift with sound can be shown from here.
All iC support programs, such as iCmake and the iC pre-compiler immcc, iClive, iCbox, iCserver as well as drivers iCpiFace and iCpiPWM and even iClift have man pages, which can be shown with the standard Linux program ‘man‘. A good way to show man pages is the man page viewer iCman, which is part of the immediate C distribution. This image shows the man page for iClive displayed by iCman with the search word ‘Text’ highlighted.
You really make it seem really easy along with your presentation having said that i
find this topic to become actually something that I feel I would personally never understand.
It appears to be too complicated and very broad to me.
I’m anticipating for your post, I’ll try to have the hang of this!
I am currently writing a Programming Manual, called the “iC PROGRAMMING LANGUAGE”, based on the style of Kernighan and Ritchie’s “C PROGRAMMING LANGUAGE”, with a similar easy Tutorial Introduction. The work embodied in “immediate C” covers 60 years of experience as a design engineer, starting in the telephone industry, working with electro-mechanical relays followed by switching systems using vacuum tubes, transistors, DTL, TTL etc integrated circuits followed by computer automation systems using home grown real time operating systems from the late 60’s onwards.
I have included different aspects of all the different hardwares I have used over the years, crystallising them into am EASY TO USE computer application. The basic principles must be understood and are, I believe, quite simple. There is plenty of extra functionality in the system to allow engineers and programmers to do amazing things with the iC system. I have recently implemented a control system for a mechanical model of an elevator system built from Meccano parts by a friend. I will be posting pictures and a YouTube film of that shortly.
That exercise proved to be quite challenging for me, although I wrote the system. There is a big difference between theory and doing. We all have to learn new Programming Systems by DOING. Hopefully you will find it enjoyable and not too frustrating. I have made a big effort to provide useful error messages to help you.
Thank you for providing an exceptional opportunity to check tips using this site. It really is excellent and also brimming with fun for me personally in addition to my office colleagues to visit your site at least 3 times in 7 days to study the fresh advice you have. Two tips on this page are the most beneficial we have all ever had.
Please let me know which two tips were most beneficial to you. That would really help me to provide better content.
I am now not positive where you are getting your information, however good topic. I must spend some time learning much more or figuring out more. Thanks for great information I used to be looking for this information for my mission.
60 years of experience as a working hardware and software design engineer. I am happy to answer specific questions.
Wonderful blog! I discovered it while surfing around on Yahoo News.
Have you got any tips on how to get indexed in Yahoo News? I’ve been trying for some
time but I never appear to arrive there! Appreciate it
Sorry – do not know how I got on Yahoo News. Please let me know at what URL I can see that
Fine means of telling, and nice post to obtain facts
concerning my presentation subject, which i am going to deliver in college.
Good luck with your presentation. I would appreciate if you sent me a copy of your presentation as an email attachment. BTW I speak fluent German.
Pretty section of content. I just stumbled upon your weblog and in accession capital to
assert that I get actually enjoyed account your blog posts.
Anyway I’ll be subscribing to your augment and
even I achievement you access consistently rapidly.
Keep on writing, great job!
I’ve been surfing online a lot more than 2 hours today, yet I never found any interesting article like yours.
It’s pretty worth enough in my opinion. In my opinion, if all site owners and bloggers made good content as you may did, the internet will be far more useful than before.
Simply want to say your article is amazing. The clarity in your post is just spectacular and i can assume you
are an expert on this subject.
Thanks a million and please continue the rewarding work.
Wow, that’s what I was exploring for, what a data!
existing here at this web site, thanks admin of this web
page.
Pretty! This has been an incredibly wonderful post. Many
thanks for supplying this info.
Good day! This post could not be written any better! Reading through this post
reminds me of my old room mate! He always kept chatting about this.
I will forward this article to him. Pretty sure he will
have a good read. Thanks for sharing!
wonderful issues altogether, you just received a new reader.
What may you suggest in regards to your post that you
just made a few days ago? Any certain?
Interesting. I have developed something similar using the Observer Pattern, but using old VB6. The overall performance is simply great: the time involved in the propagation is marginal compared to the time involved in computions of complex algorithms.
I will give a try.
Well done.
When you say “the time involved in the propagation is marginal compared to the time involved in computations of complex algorithms” I assume you mean that event driven execution is much much faster than using algorithmic approaches to handling external and internal actions (events) for control purposes. That is undoubtedly the case.
Please drop me a line by a comment here or email of your experience with immediate C.
I think this is one of the most important information for me.
And i am glad reading your article. But wanna remark on few general things, The web site style is perfect, the articles is really great : D.
Good job, cheers
I’m not that much of a online reader to be honest but your sites
really nice, keep it up! I’ll go ahead and bookmark your website to come back later on. Cheers
Nice blog right here! Additionally your web site a lot
up fast! What host are you the use of? Can I get your associate link for your host?
I desire my web site loaded up as quickly as yours lol
I’m truly enjoying the design and layout of your website.
It’s a very easy on the eyes which makes it much more pleasant
for me to come here and visit more often. Did you hire out a designer to create
your theme? Excellent work!
The design and layout was theme “Twenty Sixteen” directly from WordPress. I only entered text and organised menus.
Thanks very interesting blog!
I am truly pleased to glance at this webpage posts which contains plenty of valuable data,
thanks for providing these kinds of data.
Thanks on your marvelous posting! I truly enjoyed reading it, you can be a great
author.I will ensure that I bookmark your blog and will come back in the foreseeable future.
I want to encourage you continue your great writing, have a nice evening!
Hi friends, pleasant article and pleasant urging commented at this place, I am actually
enjoying by these.
Excellent site. Lots of helpful info here. I’m sending it to a few
pals ans also sharing in delicious. And of course, thank you
in your effort!
We are a group of volunteers and opening a new scheme in our community.
Your site offered us with valuable info to work on. You’ve done an impressive job and
our whole community will be grateful to you.
asmr 0mniartist