How do the Active High and Active Low signal work in Embedded Systems?

This is about how micro controllers work in general..

The programming that we do is converted into 1's and 0's by the compiler and these machine understandable code are then loaded to the microcontroller..

How does the microcontroller respond to this.. I mean are these 1's and 0's converted into corresponding logic voltage (5v and 0) by DAC? If its like that, how does this small piece of silicon decide what to do with these various combinations of 5v and 0v?

I understand that every single IC is made of logic gates and these gates are composed of transistors.. So how does these transistors respond to various combinations of 5v and 0v?

What makes them look for these logics.. I mean how they monitor these instructions when they are powered on?

So certainly there got to be an Operating System loaded into the mcu that tells it to process and how to process these instructions, isn't?..

Next thing is.. consider a timer.. it is simply a register that increments by one after each clock cycle.. Isn't the OS again that instructs the mcu to increment after each clock? Am I right? In that case, in what language, all the code for a operating system is written?

I can just proceed my work with programming the mcu for different tasks but today I was interested to know how my code is understood by this machine..

• I suppose people will have these sort of questions during the start of their career.. – V V Rao Oct 30 '10 at 10:56
• deleted message felt bad – Rick_2047 Feb 13 '11 at 6:53

There is no need to use a DAC. Voltages are used to represent 1's and 0's by the convention that anything under 0.8V (AKA 'low') is a zero, and anything over 2.4V (AKA 'high') is a one. It's relatively simple to construct circuits that perform logic on these representative voltages.

For example, a circuit can output something in the 2.4V to 5V range to represent '1' if either input is over 2.4V, or something less than 0.8V otherwise, and you have an OR gate. If it requires both inputs representing 1 in order to output 2.4V, you have an AND gate. An inverter just outputs a high when the input is low, and vice-versa. You can build simple gates like these with just a very few transistors, and perform combinatorial boolean logic. By using groups of bits to represent numbers, you can even build circuits to add numbers with combinatorial logic, no software required.

Once you are working with gates, you can construct flip flops, and from them, registers and counters. Flip-flops allow you to store 1's and 0's from one point in time and use them later on. Registers and counters are circuits that perform functions on groups of bits that represent numbers. A register holds a number until you load a new number into it. A counter is like a register, but has another input that causes the stored number to increment. (Decrement is possible too). This puts you in the realm of state machines and sequential logic, still, no software required.

Memory systems are a way to store massive numbers of bits. At a component level, some memory is built like a huge collection of flip-flops, but more commonly there is another technology (DRAM) that, while not exactly a flip flop, does the same thing.

As a further step, you can build a system of sequential and combinatorial logic that can carry out operations depending on the bits stored in a memory system, including writing back new values to that memory system. Now you've arrived at the level of the processor, and everything the processor does, is just hardware carrying out lots of simple tasks. (microprogrammed cores notwithstanding). At this point, the particular combinations of bits that you put in the memory system can be considered machine language software.

• Now I have understood that Transistors are the base on which processors are created i.e with a gate like nand, we can create flipflops, registers, counters, alu and all these together make the computing system. Transistors input can be high or low(over2.4v 0r under0.8v).. My question is, what is the device that interprets 1 and 0 from the Compiler as corresponding logic to these transistors if no DAC is used? – V V Rao Nov 22 '10 at 7:34
• @Vicky Rao - I think what's confusing you is that you're mixing levels of abstraction. Nothing is required to convert compiler output to logic levels for transistors, because software 1's and 0's, and hardware 1's and 0's, are just different views of the same physical reality. What at one level looks like millions of transistors changing states, at another level looks like a processor running software. – JustJeff Nov 23 '10 at 0:10

Get the book "Code: The Hidden Language of Computer Hardware and Software" by Charles Petzold. It is awesome, easy to read, and will answser many of those questions.

If you can't afford Petzold's book, then check out "How Computers Work" by Roger Young. It covers much of the same stuff, and the HTML and PDF versions are free.

• Also a nice book would be The Elements of Computing systems. – Rick_2047 Feb 13 '11 at 6:51

Consider an NPN BJT; a transistor. One of the first discovered.

Now you wire it up such that the collector is connected to a variable logic input, and the emitter is connected to another logic input, with a resistor in series. Then, a resistor from the emitter to ground.

               logic
|
10k   |/
logic --/\/\/--|  NPN
|>
+-- output
|
/
\ 10k
/
|
---
-


You have just constructed an AND gate. The output is only high when both inputs are high. It's not perfect by any means as it depends on the input to the collector, and because it doesn't fan out well, but it gives you an idea on how transistors can be used to compute a function.

Then, you can also construct a NOT gate;

                5V
|
/
\  10k
/
+-- output
|
10k   |/
logic --/\/\/--|  NPN
|>
|
---
-


Adding this on to the output of the AND gate just built gives us a NAND gate, and you might know that with a NAND gate you can construct any form of logic. It also has the advantage that the signal is buffered, increasing the fan out and chaining capability.

Real processors rarely use BJT's, but instead CMOS logic, but the same principles apply.

• You could use FETs instead of NPNs :) – endolith Oct 30 '10 at 13:25
• That's why I added this: "Real processors rarely use BJT's, but instead CMOS logic, but the same principles apply." n-JFETs and n-MOSFET's would probably work as well as more estoric forms like valves. – Thomas O Oct 30 '10 at 18:18
• You could also use a PNP to do a NOT in the same fashion as the AND with the NPN – Matt Williamson Feb 14 '11 at 5:45

Maybe you should look up some digital systems references or look into stuff like VHDL. An MCU is basically designed with building blocks, which can be a variety of logic gates and (smaller) building blocks. Ultimately it all goes down to logic gates which are indeed composed with transistors. A typical simple MCU like a PIC18F or something doesn't run an operating system. The program you load into it are a bunch of machine instructions that the PIC runs continuously. All of the proccesing is done by hardware.

A general proccesor usually has an ALU (computes the result of a certain instruction) and a more blocks around it that loads instructions, manages stack and manages the memory. The proccesor has a few registers to work with it itself, mainly to load inputs and store results in. You might not see much of this in C or another language but a lot of it in assembly.

The ALU handles instructions with certain operation codes and inputs. For example, a typical instruction could be ADD 12 1 , which means 12+1 = 13. The result is stored in a register on the proccesor itself.

Depending on the architecture, the ALU is for example 8 bits wide. A simple 8 bit adder can be made of 8x 1-bit adders tied together (using blocks to build a bigger block). A 1-bit adder can be easily written down to logic gates using boolean algebra. Writing down a whole 8-bit adder manually with only using logic gates would be an insane amount of work. That's like writing a program without having the ability to use any function or subroutines at all.

To make the digital systems work correctly , most blocks are designed to clock based. Every digital system has a certain amount of time required to reach it's end state. This is due to switching delays in transistors and states influencing other states. The clock signal is something you should be familiar with, the speed the proccesor runs on. A timer could be a really simple device that has a little adder block and increments by 1 every time it gets a clock tick.

This is a big topic and I can't give a simple answer but...

You can get a little closer to this answer by doing some divided and conquer, and since the other answer tries to attack this problem from a hw point of view I will try from a high level SW view.

If you write some software in let's say c code (a very high level of abstraction), you do not really see what is happening not really understand all of the lover stuff that you are asking about.

But let's begin there anyway.

A simple program that just inc a variable.

int main(void)
{
int i=0;
while(1) {
i++;
}
}


Then we need to get the assembler code so we can understand what is going on. This step can be done on what ever platform you use, but to keep it simple I use gcc on a pc (but it does not matter...)

gcc -O0 -S main.c -o main.lst


Then we end up with something like this:

    .file   "main.c"
.text
.globl main
.type   main, @function
main:
pushl   %ebp
movl    %esp, %ebp
subl    $16, %esp movl$0, -4(%ebp)
.L2:
addl    $1, -4(%ebp) jmp .L2 .size main, .-main .ident "GCC: (Ubuntu 4.4.3-4ubuntu5) 4.4.3" .section .note.GNU-stack,"",@progbits  Then you try to understand every line of code and what it does. And then you start to look into how every instruction is implemented... For example the subl  subl$16, %esp


At this point it is different on different architectures and x86, arm, pic is kind of different... But since my example was x86.

And at this level when you read the copy most of actions will look like you are just moving numbers around, and in some sense this is what is happening. We have a predefine program that we step trough, this program is store in a some kind of flash memory that is usually some kind of electronic logic that will trap one logic level.

If you see some kind of "Flip-flop" for every bit then you are kind of close, and then we needs a lot of those. Here we start to find your ones and zeros.

Then in order for some action to occur we add some cool logic that can transform one number into another number (the CPU it self).

And then we follow the program one step at a time, and to know where we are we have a program counter (PC). And move numbers back and fourth and storing those in another memory that is also kind of a grid with flip-flops.

But let's go back into some specific example again, in order to understand the CPU a little better we can have a look at the ALU and this simplified picture. Where you can see that when we move data into this logic block and do select some operation with the OP pins, we will get a new result at the output. That we in turn can move back into some place in memory.

And of curse your ALU in your CPU part of your MCU is way more complex that this one, but it operates with the same basic principle.

At this point we kind of can see some logic circuit that does the "work" on one side, and some storage on the other side. And the storage has two parts, one for the program and one for the data. But how does we actually "move" then, those must be connected in some way...

And this is where we connect those parts with some a bus.

A bus is just some wires that connects the different parts together, and then the control logic tells the memory what data to send onto this bus, and what part of the CPU that should listen to this data that was sent. And this is done with some parallel control lines that will enable/disable the different parts.

...

So if you take your mcu of choice and dissect a very small program, and as long as you do not understand what is happening you dissect it even more until you have a nice little puzzle that can be used to create a "mcu".

And don't forget to read the datasheet for your mcu and look into what kind of parts it was made with, like what kind of memory, alu, busses etc etc.

Hope this helps a little ???

Good luck

• your strategy of explaining it by splitting the instructions made it really easy.. thanks.. – V V Rao Nov 1 '10 at 4:48

You don't really need to know these things unless you are about to design CPUs yourself, but it all comes down to a huge state-machine implemented in hardware.

The biggest problem with this sort of question is that the answer is huge and takes up several years of University courses, so any answer you get here is only going to scratch the surface.

If you really want to know what goes into a CPU take a look at the vhdl/verilog source code on: http://opencores.org/projects

Just learning vhdl and verilog is going to be a large'ish task on it's own, so you are in for a long read:)

• "huge stage-machine" - that sounds like a Broadway production. – OIO Oct 30 '10 at 12:13
• Fortunately, the answers that these people had given doesn't make me scratch the surface as you mentioned, instead made it crystal clear.. Anyways, thanks pal.. – V V Rao Nov 1 '10 at 5:35

I mean are these 1's and 0's converted into corresponding logic voltage (5v and 0) by DAC?

No, not a DAC. The 1s and 0s never really exist. They're just a mathematical abstraction we use to make programming easier. The actual digital voltages might be 5 V, or 3.3 V, or 1 V, depending on the hardware. Ultimately a computer is just digital logic. The memory stores the 1s and 0s as digital logic, a digital logic circuit transfers them from memory to the processor, the processor is a digital logic circuit that can add, subtract, or compare binary numbers, etc.

how does this small piece of silica

Silica is glass, a mixture of silicon and oxygen. Chips are made from pure silicon, with impurities added in specific places to make all the transistors.

I understand that every single IC is made of logic gates

Digital ICs are made from logic gates, not analog ICs.

So how does these transistors respond to various combinations of 5v and 0v?

Read up on the simplest example, the CMOS inverter.

• You have explained that DAC is not used, 1 and 0 are just mathematical abstraction we use to make programming easier. Can you add little more detail on this with reference to "Compiler"? the compiler converts high level language to 1 and 0. You said that these 1 and 0 are stored in memory as digital logic, a digital logic circuit transfers them from memory to the processor.. What is the name of the device that does this function? And again, the processor's input will be 5v or 0v. So what device converts the 1 and 0 from memory(actually from the compiler) into 5v and 0v? – V V Rao Nov 22 '10 at 7:18
• @Vicky: There is no conversion from "1" to 5 V. "1" and "0" are just labels we give to high and low voltages when doing math with binary numbers. For simple low-level logic that's not operating on binary numbers, it's more common to call them "H" (high) and "L" (low). – endolith Nov 22 '10 at 16:00