Turn-key PCB assembly services in prototype quantities or low-volume to mid-volume production runs

Building and installing USBASP-USB programmer of AVR microcontrollers

USBASP is well-known USB programmer for Atmel AVR microcontrollers initially supported by  Thomas Fischl. USBasp flash uploader is made of an Atmega8 or Atmega88 and few other components including resistors, capacitors, LEDs, and connectors. The adapter works on a firmware driver, which gives a room for customization, and new chips updates. The USBasp programmer has been so famous for a long time. It has been supported by avrdude – an open source programming software, which runs on multiple platforms like Windows, Linux, or Mac. Since Arduino popularity has skyrocketed, the need for such tools has diminished, and so the support has been stopped. I can assure you, that USBasp still works and there is no problem to run it on Windows 10. USBasp circuit diagram Let us see what is this adapter is made off and how to set it up to run on Windows 10. You can find the original circuit in the author’s site: http://www.fischl.de/usbasp/. There you will also find several third-party PCB examples to choose. The core of USBasp adapter is Atmega8 (or Atmega88) microcontroller clocked with 12MHz crystal. The assembled PCB is ready to be connected via simple USB B type cable (PC side needs A…

Continue reading

Interfacing rotary encoder to AVR microcontroller

Recently I was working on a project where I used a rotary encoder. I thought I could share some thoughts on how rotary encoder should be interfaced to AVR MCU and how to write a code to read its value. It is relatively easy to connect and program rotary encoders – only three wires are required to connect to the microcontroller (two for signal quadrature outputs) and one for reference GND). When encoder knob is turned in either direction, it generates a Grey code on the outputs which allows tracking turn speed and direction. Rotary encoder allows including a convenient user interface option with a single knob. Many rotary encoders also come with an integrated button on the knob itself – so menu navigation becomes even more comfortable. In our example project, we are going to use a 12-step mechanical rotary encoder from SparkFun. It is interfaced to ATMega32 board with graphical LCD.

Continue reading

Control AVR 8 bit Timer-Counter0 using AVR-GCC

Timers are an essential part of embedded systems. They make your life much more comfortable if used properly. Timers run independently to main program flow, so they can do job individually without disturbing precious calculations done by CPU. You just set up the timer and let it run while your main program performs other tasks. Timers are easy to set up. In this post, an example is made for Atmega8 timers. Other AVR microcontroller models and even different brand chips have similar timers. Atmega8 has two 8 bit timers/counters and one 16-bit timer counter with many abilities. Standard 8-bit Timer/Counter0 features are: Single channel counter; Frequency generator; External Event counter; 10 – bit clock prescaler. TCNT0 is an 8-bit timer counter register which keeps the current count number. Timer counter can be clocked by an external clock through pin T0 or from internal via pre-scaler. Timer counter is incrementing (MAX value is 0xFF) and then restarts from BOTTOM=0x00. After timer Overflows, the flag TOV0 is written to 1, and if TOIE0 bit in SREG is set, and then timer overflow interrupt is executed. TOV0 acts as a ninth bit of counter register that is only set but not cleared. When…

Continue reading

Example of enumeration c in microcontroller programming

Enumeration allows defining a user data types in C language. For this purpose a #define pre-processor is used which allows describing a set of constants. They allow reading and understanding program code much easier as you may define human readable types. For instance, using pre-processor we can define a simple numbers to be as follows: #define zero 0#define one 1#define two 3 Define is powerful tool for doing many different definitions in pre-processing stage of source code, but in C language there is an alternative way of defining a user data types –  enumerating using keyword enum: enum (zero=0,one, two); //zero=0, one=1; two=2 By default, enumeration assigns values from zero and up. You can use enumeration of new types as in following example: int n;enum (zero=0,one, two);n=one; //n=1 Also you can use enum  to assign special characters to meaningful words like this: enum escapes { BELL = ‘\a’, BACKSPACE = ‘\b’, HTAB = ‘\t’,RETURN = ‘\r’, NEWLINE = ‘\n’, VTAB = ‘\v’ };or enum boolean { FALSE = 0, TRUE }; An advantage of enum over #define is that it has scope, what means that the variable (just like any other) is only visible within the block it was declared.…

Continue reading

Choosing right programmer for AVR microcontrollers

Once you start building something with microcontrollers, one thing you need to take into account is a programming adapter. This is a device which allows uploading compiled code into the chip. I don’t know if this is still fun to build your DIY programming adapter which is not guaranteed to support all chips nor it will be safe and reliable. AVR microcontroller niche is one of the most interesting when talking about programmers. If you take a look at the AVRDUDE configuration file, you will find that there is about 50 of them. Many of them are DIY while others are official. When I started with microcontrollers I also was looking for cheap and easy to build programming adapter. So I have built several if few years.

Continue reading

Using analog joystick in AVR projects


In many cases joystick manipulator is best choice for user input. Whether it is a game, robot or flying machine – joystick is most intuitive way of controlling them. You can actually find them in gaming controllers like PlayStation or XBOX. The one we are going to interface is Thumb Joystick I purchased some time ago from SparkFun. They are really cheap and as users report it is practically same as in XBOX 360 which can be replaces if one is broken. I didn’t bother making a PCB for it – just used a breakout board for it which also can be found on SparkFun. Simply speaking this joystick is nothing more than two potentiometers and one pushbutton. It is designed so that potentiometers are oriented perpendicular and thus moving stick you can have X and Y axis control. Push button is simply action button which can be activated by pressing joystick down. So controlling joystick is a matter of analog read of both potentiometers with microcontroller ADC inputs.

Continue reading

Interrupt driven AVR USART communication

avr usart

Simple USART routines are not always practical because waiting transmitting buffer to be ready in a simple loop occupies processor resources. If we do not know when data will be received, we are just wasting resources inside waiting loop. Another issue arises when multiple data bytes has to be sent/received. In this case, we have to write complex code to deal with data flow. Since microcontroller speciality are interrupts, it is better to use them to handle communications and this way improve overall performance and energy saving. Instead, of continuously checking if there new data received in the UDR register or checking if send buffer is free, lets us write more effective USAR communication code with a guardian which would wake the MCU if it have received a byte via USART. In other hand, Interrupt mode allows to perform other tasks at full capacity while waiting for USART interrupt. Let us implement interrupt driven AVR USART communication example. For this we will need to include the interrupt library: Then we will have to enable USART Receive Complete Interrupt (USART_RXC_vect) and enable global interrupts. Then write interrupt service routine ISR(USART_RXC_vect). Let us write simple bounce program – USART sends back incremented…

Continue reading