Electronics - Software and Digital
Created; 05/02/2015, Changed; 24/02/2020, 21/03/2020
Old this webpage; http://ww1.andrew-lohmann.me.uk/engineer/electronics/electronics---software-digital/
updated
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 has an 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. This project on electronics does not be spending much time on this subject.Unlike my advice on simulators for electronics design I make in the previous pages use PCLint at 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 PClint testing.
Write software in a way that is readable
Put all you 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 microprocessor until recently.
Use a propriety micro it will have fewer erratas, Freescale (Motorola) particularly work on eliminating all erratas on the propriety products. Don't expect the same of a generic processors like ARM or PowerPC they may many errata's but are cheap in high volume.
Avoid writing anything in assembler, you should not need to. Optimiser within Cosmic, which is normally selected, is impressive both on speed and code size.
Use PCLint 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 MIRSA used by the motor industry. SPLint is the free version but it is worth buying PCLint.
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 cause if you are unsure what you wanted you will still be unsure what you get.
If there is a disparity between the compiler, PCLint and the outcome you are certain of that, then suspect the compiler and report it.
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%) to the driven level (Integral),
4. Wait until the loop has stabilised then do it again (there should be 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 know 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.
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.
-----------
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;
- PCLint http://www.gimpel.com/html/ - PCLint C programming checker,
- SPLint 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.
To discuss electronics see; Blog page Electronics or https://mewe.com/join/electronics_-_analogue_electronics
Next page; Electronics - Examples of filtering methods