Interfacing PC keyboard to AVR microcontroller

Properties: Interface AVR to standard PC AT keyboard; Only two I/O lines used. One line is also connected to external interrupt pin of AVR; No external components is needed for interface; Included C source reads from keyboard interface and converts to serial In many situations you need some kind of human interface to your microcontroller project. In this example is interfacing AVR microcontroller to standard PC AT keyboard described. Physically interface looks as in picture bellow: In a keyboard interface signal lines are open collector with pull-up resistors. Keyboard cable connectors can be DIN or Mini DIN (We are not talking about USB interface): According to keyboard timing diagram in bellow picture the keyboard transfers data to host AVR microcontroller. The protocol is: one start bit (always 0), eight data bits, one odd parity bit and one stop bit (always 1). The data is validated during the low period of clock pulse. Clock signal is generated by keyboard and pulses are about 30-50us low and high. The keyboard has a scan code associated with each key. When key is presse – the code is transmitted. If key is is hol down for a while the code is transmitted repeatedly (about…

Continue reading

Clockless CPU design

Clockless CPUs are so called asynchronous CPUs where are not clock generator needed which clocks every synchronous operation. Asynchronous processors gives results not after defined number of clocks, but after it finishes operations. This is a key of effective usage of energy and asynchronous processors generates less noise than synchronous. Asynchronous processors have couple advantages against synchronous: Components can run in different speeds inside clockless CPU while clocked CPU components are tied to clock generator. Clockless CPU operation stages doesn’t depend on clocks and can be finished faster than normal and there is no time gap between stages as there is no need to wait for next clock cycle. For instance in it can show results of operation rather than waiting for next clock cycle like it is in sychronous CPU. So why asynchronous processors aren’t so popular? There are many factors but I think the biggest is historical, because instead asynchronous technology engineers of middle of nineteenth century decided to develop synchronous technology as they looked potentially more productive, reliable and there were easier to project them. So now there is a lack of professionals in this area. In other hand it is problematically to match synchronous and asynchronous…

Continue reading

Embedded RTOS System

RTOS – Real Time Operating system is a program environment which interfaces hardware and desired tasks. RTOS usually has built in set of services (interfaces and functions) which allow to interact between tasks and hardware. Because most low level functions are performed by RTOS realisation of programs becomes much easier. What is difference between Embedded RTOS System and regular OS (Operating System)? The main difference is that RTOS performs tasks according to reaction time on one or another event. Many microcontrollers have ability to support one or another Real Time Operating System. According to this we can say, that RTOS is a background application which controls multiple tasks and alleviates managing those tasks. Note that Operational system is able to perform multiple tasks at one time. This is called multitasking. We all know that microcontroller can perform only one task at one time, but if we cut time in to small pieces and perform all tasks in row for a bit time, then we achieve multitasking. This like illusion of performing tasks at one time. If you are familiar with system programming of PC, then you should know what is processes and flow and about planning of tasks (including real…

Continue reading

Connect 6 LEDs using 3 microcontroller pins

Sometimes you need more than you have. I am talking about microcontroller pins. Lets say, you have to connect 6 LED diodes but you have only 3 microcontroller pins available. To use other microcontroller isn’t always a solution using decoder circuitry isn’t necessary as well. There is a simple hint on how to do this: Connect diodes to microcontroller as follows: < p align=”left” style=”margin-bottom: 0cm”> Now look – if you set one pin to “1” and second to “0” (leave third pin high state – as input pin) then only one led lights on. You can light two LEDs at one time as well by setting third pin as output and state “1” or “0” depends on which LED you want additionally to light on. If you need to light all LEDs at one time then you need to change states of microcontroller pins at some desired frequency to avoid visible blinking. Using this method you can connect twelve LEDs using only 4 pins. This is convenient method of expanding when using dual colour LEDs, when two LEDs are packed in one case but in different directions. There is an example of AVR-GCC C code how to control LEDs.…

Continue reading

Testing Your Embedded System

Every time you are making some circuit or more complex system, you always do some testing to make sure that your electronic “baby” is working properly and you can expose it to publicity. Lets say you are constructing some kind of robot. Then typical list of testing task may be as follows: Stability tests using various working modes and critical supply voltages (like 4,75 and 5,25V); Start up testing – purpose is to check system readiness to accept commands after power up; Checking correctness of executed commands; Checking correctness of sensors; sometimes you will need to prepare good documentation where every node reliability is calculated. Also testing methods of each nodes may be included in documentation. Of course many devices may work in wider range of supply voltages, but there are always some electronic components that needs more than 5% stability. If your system is bigger and may be dangerous to your health or to itself. For instance if it is a robotic system, then you should know, that it can brake itself in some obstacles. In this case should include some blockage of tires in case if you loose control of your robot. When testing electronic circuit there is…

Continue reading

Choose right electronic components for your projects

Every time you start your project one of the most important things is to thinking about what electronic components you will choose. There might be a series of questions you might have to answer for yourself. Lets say you will construct some robotic or other sensor related system based on microcontroller. Then questions might be as follows: What type of microcontroller to use for your project? What type of clock generator to use? What type of power source to use? What type of sensors will be used for gathering of information? What will be output devices (motors, displays)? Will you need some kind of memory excluding internal microcontroller memory? Can all required components be found without problems? And the last question you will need to ask yourself is: Can other amateurs repeat your project on your component base? Lets say you will make your system using some exotic electronic components or programming environment then it can be difficult to replicate your system. Of course if you are making it only for your needs and you are not going to document it, then there is no problem. But in other situations first thing in your project is accessibility of electronic components.…

Continue reading

Microcontroller Brown-out detection

Mostly all microcontrollers have built-in Brown-out detection (BOD) circuit, which monitors supply voltage level during operation. BOD circuit is nothing more than the comparator, which compares supply voltage to a fixed trigger level. If microcontroller doesn’t have On-Chip Brown-Out detector, then there can be external circuit used : The image above there is a discrete brown-out detector circuit. In a real word, there are particular IC where additional delay circuitry and hysteresis used as normalizing of supply voltage may take some time. Such IC’s are cheaper than one built from discrete components. Brown-out meaning Brownout is an important safety feature in electronics and microcontrollers. There are two main tasks of brown-out function in microcontroller – hardware and software. Hardware brown-out feature resets the microcontroller and keeps it until the power supply is returned to operating range. This ensures that all parts of the circuit work correctly. Software brown-out part – an interrupt based functionality which detects falling voltage, which allows the software to take care of critical components like saving vital information to non-volatile memory before resetting. What causes a brown-out As an example, let us see how Atmega128 microcontroller, which has an On-chip Brown-Out detector reacts to the brown-out…

Continue reading