Electronics - Software and Digital
Created; 05/02/2015, Changed; 09/03/2024, 12/04/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.
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.
PCB and circuit design
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.
In my opinion, the electronics designer should do the PCB design. He should add or remove decoupling capacitors and filter chokes. And whilst thinking about the PCB layout, be considering the design.
But in digital design an autoroute will do a good job, though a manual routing using bus routing tools will do a neater looking job. That is because digital signals are immune to noise unless you are running at ECL speeds, then you need to keep the pairs of signals tracked together.
When operating at high frequency avoid blind via holes, kinks and curves and long tracks particularly without pairing negative signal to form a transmission line - which sounds basic, but I have seen it done.
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 good. By 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, there is a GUI you can use with it or another checking tool.
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.
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). This should therefore be on a timer interrupt.
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 for this task to do until the next timer interrupt.
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.
Digital
"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
This allows you to resolve a logic problem in all NAND gates.
Useful links;
PC-Lint https://pclintplus.com/ - PC-Lint C programming checker,
SP-Lint http://www.splint.org/ - Free version is not very usable I found, but is the website puts a compelling case for using such tool. (Virginia State University - you may come across other interesting projects)
Cosmic C http://www.cosmic-software.com/ - A robust C compiler, the best I have used.
ST Microsystems tool set for STM32 microcontrollers (I am evaluating this tool set now)
MCU Finder (This tool is not tied in to the other three tools). - Helps you cross select parts by cost and function.
Cube - Will help you select and configure 32-bit ARM microcontroller. Then give you an outline project.
uVison - Keil tool is an assembler, C complier and linker. This is for any ARM microprocessor, but is licenced for ST.
ST-Link - SWD programming tool used with the debugging tool provided with the evaluation board.
There have been many tools for decades to help get you started. This set of tools should get you going in days, weeks rather than months it took in the past turning into years to develop libraries of headers and program so that you can create a new project in days that it took in the past. ARM core is not necessary the most efficient processor, but the whole uVision Keil package that comes for the ARM gives you results quickly from any maker.
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.
To discuss electronics, see; Blog page Electronics
Next page; Electronics - Examples of filtering methods