Wednesday, 12 July 2017

How do Electronic Systems Communicate ?

One of the many things that get thrown upon you while learning about embedded systems is communication protocols.  Now unlike humans, computers are dumb (always remember that!). The way we convey messages by speaking, writing and even gestures is intrinsic and is often taken for granted. On the other hand machines have to be given a complete set of instructions about how to talk. They have to be told what to say and when to speak. But, before talking about I must first digress to something more basic.



Computers only work on the basis of 0’s and 1’s. Where a ‘0’ means ‘OFF’ and a ‘1’ means ‘ON’. But, what do they turn ON and OFF? All microcontrollers have I/O PORTS which as you can see are used for providing output and to receive input signals. Each PORT generally consists of 8 pins which are connected to internal transistors-acting as switches, these can be turned ON and OFF like a switch. In software terms each PORT is of 1 Byte where each bit is individually addressable. We use 0’s and 1’s to switch these pins ON and OFF to control various devices like LEDs and Motors.

Now consider that we want to display certain text on an LCD. Say we want to display ‘ABCD’. But, computers have no intrinsic way of knowing how to display or write these letters. To a computer A-B-C-D are just names of certain values which are designated using a certain code. For example ‘A’ is the name of the value ‘65’ in ASCII code which is 01000001 in binary that is in terms of 0’s and 1’s. Each LCD module has 4 pins called data lines through which the message to be displayed is transferred. So the binary code 0100-0001 is sent 4 bits at a time. Now this was pretty easy up till now. We give a message to our microcontroller, which is converted to binary and sent across data lines to the LCD module which also has a microcontroller on its side. This controller converts the binary back to English and displays it. At this point I would like to return back to the point where I said computers are dumb. And here are some issues which strengthen my case.

1. The LCD Module doesn’t know when the message starts and when does it end.

2. The microcontroller and the LCD may be operating at different clock speeds, someone has to tell them that and make them agree on a common clock speed.

3. Messages are transmitted across wires, in the form of currents and voltages. Each 0 and 1 represents a voltage. What value voltage will that be?

4. What if an error creeps into the message? Because believe me the LCD will display it.

5. What if the LCD wants to send a message back across the data lines? Which fortunately it doesn’t, but say some other similar device wants to reply. They might end up talking at the same time and distort each other’s messages.

To help computers jump these and other hurdles, engineers developed protocols or rules. There are many such protocols like Serial Communication, SPI-Serial Peripheral Interface, I2C, USB, Ethernet and many more. In the coming articles I will not discuss them in detail, because it has been done. You will find excellent links below to study about them. In the next article I will discuss about a relatively unknown standard because it is not used in commercial systems. This standard is the MIL-STD-1553 a communication protocol used to connect electronic devices in planes, tanks and even spaceships. Using this as an example I will explain how various standards are created.

Until next time,

Abhijeet Dutt Srivastava   

P.S Here are the links

Saturday, 25 March 2017

How is Arduino different ?

Lately, I have been dabbling with AVR programming. In the process I am beginning to understand the differences between the Arduino method and for the lack of a better term the real world method. Arduino is a great device when it comes to introduction to microprocessors and controllers. And its the way I started, but Arduino is like training wheels on a bicycle you need to remove them at some point.

So what did I learn ?

First, burning code into an Arduino is simpler compared to the way its done normally. Arduino uses a small program known as bootloader. The bootloader is a small piece of software that enables code to be loaded directly into the controller without using any external hardware programmers like a USBasp. The downside is that it eats precious flash memory of your controller. The USBasp is an ICSP (Incircuit Serial Programmer) which is used to transfer the code to the non-volatile memory of the microcontroller. The device that I am using in the picture is connected to the computer by a USB. The compiled code comes to the USBasp and is sent to the controller by using a SPI interface. So it is a fairly complicated task compared to the programming method used in Arduinos. But, this is all just to save memory which is quite low in microcontrollers.

Second in the Arduino programming language the pinMode( ) and digitalWrite( ) functions are fairly easy to understand. In AVR programming in place of these functions hardware registers are used. Now this is a fairly cryptic, so let me explain.

In Atmel microcontrollers the GPIOs (General Purpose Input Output) pins are divided into ports of 8 bits or pins which are individually addressable. These ports are labelled B,C,D (Look up Atmega328p pinout) .The pinMode( ) function decides whether a pin acts as input or output.How it actually works is that a register of 8 bits on the controller's RAM is hardwired to the 8-pins of the port. Now say we want the pin 0 of port B to act as an output we give this register known as DDR( Data Direction Register ) the value 00000001. It looks something like this-

DDRB = 0b00000001 ;

(where 0b means binary)

The pins 1-7 are made input and pin 0 is output.

 How is this better ? you might ask. Well its not. But its certainly faster. The Arduino uses a software command defined in a library which needs to be referred to before execution occurs. While the DDRx is integral to the hardware.

In a similar fashion the digitalWrite( ) function which toggles the output pin HIGH or LOW value is actually a function referring to a register known as PORT in AVR programming. If we want to toggle the pin 0 of port B high (5v) we write,

PORTB = 0b00000001 ;

Now some terms that I have used here maybe new to beginners and believe me I know. What I do to understand them is look them up on wikipedia and write them down and when I come across them again, I refer to what I wrote and make changes if necessary. By doing this I slowly understand what they do. Hope that helps.

until next time,

Abhijeet Dutt Srivastava




  

Saturday, 2 July 2016

Avionics and more specifically the HUD

I am currently in the heart (or kidney which ever you prefer) of India's aerospace industry - Bangalore (That's right). The energy surrounding the HAL and ADA campuses is almost tangible. I have come here to learn about avionics which is a portmanteau of Aviation and Electronics. This field covers all the electronic requirements of a plane. Of course these requirements are different for civil airplanes, fighter airplanes and everything in between. But, mostly avionics is used for flight information display, flight stability, communication, navigation, fly by wire and so much that I don't even know.

At the moment I have been introduced to flight information displays such as, 

HUD Head Up Display
MFD Multi Function Display
HMD Helmet Mounted Display
SSDU Smart Standby Display Unit

Now these are the various displays used by the pilot to view important flight data. These are designed to improve the ergonomics of the cockpit. Modern planes use what is known as the Glass Cockpit. In this all the round dialled electro-mechanical instruments have been replaced by digital displays(MFDs).  In these the pilot can change modes to view data such as altitude, air speed, angle of attack, artificial horizon, etc. Data from various sensors are collected by a mission computer which displays it on the various display units.

 An HUD can be described as a glass screen through which the pilot can see the surroundings as well as important data relevant to the pilot. The image is produced at infinity and is superimposed on the pilot's view. As a result he doesn't have to change his line of sight or make unnecessary head movement, thus improving his reaction time. 

Its interesting to note that the HUD is not an electronic marvel, the cross hairs used to aim and fire weapons in old world war planes were also a type of HUD.



                                                                  F-18 Hornet, HUD


The basic principle is this, data is produced on a CRT. The image on the CRT is collimated using a convex lens with focal length at infinity, this image is then passed through a flat glass which acts as a combiner. The combiner is coated with a thin filter layer which blocks green light and lets all other light pass through.

Till next time,

Abhijeet Dutt Srivastava

Tuesday, 20 October 2015

A brief history of electronics time

The time_t is a C function which represents time as an integer. This function measures time from 1st January 1970 also known as the 'Unix Time' or 'Epoch Time'. I learnt about this when I was trying to display the date on an LCD using my Arduino UNO.

As I read further; I learnt that the time_t function represents the time since Unix Epoch as a 32 bit binary number which has maximum possible combinations of 4294967296 (2^32). 

This is a limited capacity and it will finish. In binary it will look like this,

1111 1111 1111 1111 1111 1111 1111 1111 
(19.January.2038/03:14:07 UTC)

  
When you add one more bit this to represent the next second it becomes this, 

000 0000 0000 0000 0000 0000 0000 0000 
(13.December.1901/20:45:52)

Which is seemingly innocuous, but see that 0 at the beginning of this number-it means that the number is negative ,which means it will represent a date before 1st Jan 1970. This occurred due to a small mathematical problem known as Integer Overflow. 
While I cannot possibly predict the problems that might be caused due to this, one of the only possible solution to this is to switch to 64 bit architectures which will put the limit of time since Unix Epoch to approx (1.84 * 10^19) or approx 292 billion years .

A problem analogous to this was the year 2000 or Y2K problem. This had occurred due the old age practice of representing years by their last two digits, 1989 was represented as 89 and when the year 2000 came 00 came to represent 1900 or in some cases 19100. 

With this wary note, 

Abhijeet Dutt Srivastava  






Tuesday, 29 September 2015

My very own power supply

I wanted to run a servo motor using an Arduino UNO. I had the code and the necessary inventory;nothing could go wrong. 

On uploading the code the servo did run but in spurts and my laptop which was providing the 5 volts needed via USB started making the noise you get when you unplug a device from your computer. 

I was stumped.

 After reading various articles on the internet I discovered that a motor should not be connected to the Arduino UNO power supply. Motors produce a high back emf due to some sort of induction effect in the coils present in them which might burn a circuit if it can't withstand it.So in such cases an external power supply should be used.

I knew the basic electronics theory behind a typical power supply or a mobile charger,but knowing and doing are two different things So I found the schematics for a 5 V power supply and got the necessary parts and after spending a few hours on my workbench.

As you can see I still did not get an exact 5 V but for my purposes its okay because max power supply for my servo is 6 V.



This is the solder work behind the scene.

 I used schematics and help from 

and

Until next time,

Abhijeet 






Monday, 22 June 2015

Number Systems in retrospect.

In the previous article I talked about different types of number systems. Here I want to talk about how they might have come into existence. As Clive Maxfield pointed out in his excellent book Bebop to the Boolean Boogie the Decimal system owes its existence to our ten fingers. Some lesser known civilizations used a system called the Duo-Decimal system: it had a base of 12. Perhaps they counted along the joints of their fingers.

Another Old but still in use system is the Quinary system where the base is of five. Merchants in Mumbai are known to use this. You may have encountered this during your childhood when the teachers made you count stuff using four vertical lines and a slash across them.
 
Octal and hexadecimal is used as representation of the abstract binary code by electronics engineers as numbers with bases 4,8,16 can be easily converted to binary and back.

Communication theory tells us that a Tertiary system (base 3) would be more more efficient in place of the Binary code used in digital electronics. This system would handle outputs of ON,OFF and a MAYBE. While this sounds great on paper in reality this would be very difficult to implement use transistors.

Until next time

Abhijeet  

Saturday, 20 June 2015

Electronics and Number Systems.

In this article I am going to present two types of number systems.

Number systems can be largely classified as position weighted systems and non-position weighted systems. 

The numbers we use in daily life from 0-9 are called decimal number systems and they have a base or a radix of 10. As you may have studied earlier each position in this has a weight i.e 1,10,100,1000 and so on. Similarly Quinary,Hexadecimal, Octal and Binary are types of position weighted systems. 

Take for instance octal which is a base-8 number system in which numbers from 0 to 7 are used and instead of the 1,10,100.. 1,8,64,512 are used. so for example 17 in octal would be 21.

17  =  (2 * 8)+(1*1) 

Similarly hexadecimal has 16 numbers which contains numbers from 0-9 and the rest up to 15 are represented by letters from A up to E.

Another important position weighted system is the binary system, the binary code gained importance with logic gates and Boolean algebra. It basically uses two numbers 0 and 1. The positions are weighted according to 1,2,4,8,16. Take a number 1101 in binary in decimal it can be shown by 

(1*8)+(1*4)+(0*1)+(1*1) = 13

The arithmetic practices for Binary coding are a a little different than decimal not conceptually, but in implementation. For example a negative number in Decimal is just -256 or -537,but the negative sign lacks logical representation in Binary coding. What we do is find the complement of the number which means we express the number in a form which conveys that it is negative. So if we are performing subtraction in Binary we simple add the number we want to subtract from, to the complement of the number we wish to subtract.   
Now I don't wish go on lengths about this, but if you want deeper knowledge of Binary coding I suggest Digital Electronics by Mano Morris.

Non-position weighted systems include codes such as Gray code,Excess-3,Hamming code,Reed Muller code and many others. Here I will explain the Gray Code and the Excess 3. 

The Gray code is a binary code. But it differs from simple Binary in several aspects, the following list will help clarify.

Binary Code
Gray Code
0000
0000
0001
0001
0010
0011
0011
0010
0100
0110
0101
0111
0110
0101

The list contains Binary and Gray representation of numbers 0 to 6. The shrewd ones among you must have noticed that as the number progresses in Gray there is a difference of only one digit between each successive number. This is why Gray is so important in digital electronics. Logic circuits can have a large number of inputs but it is not possible to ensure that each input reach the circuit at the same time this results in error. But in Gray since only one digit changes at a time this problem does not arise. Gray code is also used in analog to digital conversion when each sample has to be converted to Binary it is actually Gray to which it is being converted. 

Gray code is also used for making angular measurements. A good understanding of Gray is essential as another very important application is in Karnaugh Maps or K-Maps, the K-Map is a logic minimization tool for reducing the number of logic gates required in a digital circuit. 

The Excess 3 is another another Binary code which is converted from Binary by simply adding the Binary code of 3 i.e 0011 to the Binary code you wish to convert. The main property of Excess 3 is that the complement of any Excess 3 number is the Excess 3 representation of the 9's complement of the same number. This is useful when it comes to Binary subtraction in computers. Again the complementary method is something you can read up on, or I'll explain if you ask me nicely.

Cheers, 

Abhijeet