Electronics - Software and Digital

Created; 05/02/2015, Changed; 13/01/2024, 11/01/2024

Previous Page; Tools measurement and tolerances

It is partly a personal thing how you model a design, and that may depend on the tools available.  For software, I have different advice, than for electronics design.  Software and digital electronics is less art, but it is mostly logical in that you read the datasheet or solve the problem, and you get what you expected, or you get rubbish if you did not listen to the requirement.  Use C rather than assembler and use PC-Lint from the outset, it will criticise you relentlessly unless you behave and write good, clear C.  There are easier tools to use which have a subset of PC-lint testing. 

Buster Keaton stands in one place briefly and the side of a building falls on him, but fortunately he is standing where there is a window, so he is fine.  There are a number of clever stunts in this film, but in this particular case the building weighs 2 tons in order to make the scene look realistic.  PCB and analogue electronics design, are still an art enhanced by good CAD.  But humans with CAD do better design of all types than machines, which organise and put function blocks together well.  All the same children are less likely to have been brought up hands on making and repairing things that gives that extra feel that we associate with child musicians are known for.

Steam Boat Bill Junior is one of Buster Keaton's many films, which are all less violent than much of the comedy at the time.  Not that humans are kinder now, we are not.  But the way we exploit and take from others, is different and war industry is environmentally very dirty.   The amount of waste we create is much more, and there is conflict in making new, needing paid work and avoiding the lie of greenwash about it.

Write software in a way that is readable

Put all your constants and switches in the headers.  If you want to change anything, use those switches.  If you need to add features also add more switches to include those features if they are optional.

Use a good Compiler I found Cosmic C, for Motorola microprocessors, to be excellent.  This complier has always been code efficient and very robust, but had only been available for Freescale's microprocessors originally.

It used to be that using a propriety microcontroller would have fewer erratas, Freescale (Motorola) particularly work on eliminating all erratas on the propriety products.  But this has changed, and generic processors like ARM are cheap, well merged with manufacture's features and goodBy comparison in its time, the 1990s, PowerPC remained with many erratas when it was completed. 

Avoid writing anything in assembler, you should not need to.  Optimiser within Cosmic-C, which is normally selected, is impressive on code speed, modest code size and compliance with standards.   Microcontrollers have very much more code space and using C++ maybe a better option, I believe there is more precise control over data types in order to avoid mistakes more provided the different features of C++ are used.

Use PC-Lint to check the readability and function of your code. Don't be put off because it is the oldest software tool you will ever come across on the web, and quite cheap.  I think it is the by far the best, subset includes MISRA used by the motor industry.  SP-Lint is the free version, which I found difficult to use, but it is worth buying PC-Lint. 

They will tell you to lint everything before you try running the code it will pick up, or make it plain to you what is unclear and could be wrong.  You will find that after sorting out what arises your program will probably run, importantly it will do what you would expect of it.  Of course, if you are unsure what you wanted, you will still be unsure what you get, but you will get there, feel good about it and understand what you have got eventually.

If there is a disparity between the compiler, PC-Lint and the outcome you are certain of that, then suspect the compiler and report the problem to its maker.

In writing C write your code to be reusable with switches defined locally and globally.

I have nested C code for a serial port within another file written in C, in this way the same core code can be RS232, RS485 with turn round control, have Xon/Xoff flow control, and have modem controls.  In addition, the same core code can be serial port 1, 2 or 3 for example. As far as I can tell this is not recommended, but even so, I do recommend doing this because it makes all the code in all the projects you are running feel the same.

There is more to design than meeting the specification - The old film The Medicine Man is about a shop owner who beats his kids, but they run off with the medicine man.  There are other threads in the story, the two card sharps who take money off people as easily as picking plumbs, the two nosey old ladies who interference resulting in the two kids getting another undeserved beating.  In the end there is a sort of rough justice for the girl and boy, the shop owner and the card sharps.  This film seems particularly good for its age, meeting more than the description (specification).  Many early films of the books by HG Wells I found were a sequence of events as in the book, but not good story telling.  Very many modern films and TV shows rarely do better than this - A simple human story told in a traditional story telling way.  A side note, these old films love showing feeble girls or younger women needing to be carried about.

Control loops in software;

To follow on from the previous pages - they are quite easy in software, and you can control each variable separately by comparison.  The simplest is to;

1. At precise time intervals; (point 4 but another way) 

2. Measure the error, 

3. Apply that error as a correction (Proportion - in this case 100% or better if the correction is slightly less than 100%) to the driven level (Integral), 

4. Wait until the loop has stabilised, then do it again (there will be almost nothing to do). 

The refinement is not to wait for stabilisation [4] but to apply a smaller corrects more frequently, though still at precise time intervals.  Using this method, control can be quicker and lower noise than in one or very few step method (general case).  There is an optimum.  This is P.I control, but commonly known as nudge up nudge down control. 

A differential term would give be to see the way things are going a give the driven level another push in that direction. 

The Daleks were controlled by an animal in combination with a politronic (machine) brain.  A warning in fiction in the 1960s, still of concern with AI now.


"Break the line and change the sign" -  Squibb's Law.  This is a tip from my time at college provided by an old tutor named Sid Squibb was this phrase, it is not a law but a phrase that helps a student solve logic equations;

This equation can be changed from Or (+) logic to And (.) logic

 C = A or B 

First double negate the equation; This does nothing, although two inversions have been added.  (the dotted line and the line spacing to the equation they are over, are not intended but was the way I found to create a reasonable double line).


 C = A or B

Now apply the law; Break the line and change the sign; The function is now implemented with inversions using And logic.


C = A and B

See De Morgan's Law - http://en.wikibooks.org/wiki/Digital_Circuits/Logic_Operations

Useful links;

Cybermen - subtly sinister, more so with their balaclava covered heads.  The human inside's brain was modified to remove empathy and conscience.   Otherwise, it had many machine enhancements.   Since the 1960s, we have many more prosthetic implants for humans.  The first time we see Cybermen on TV in Doctor Who.