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

Running multiple FreeRTOS tasks on AVR

In the previous post, we just run a single task. Running RTOS with a single task has no meaning at all. This can be quickly done with a conventional program. But what if we need to have more separate functions. To execute them at exact timing would require a separate timer or interrupt. But microcontroller cannot guarantee an interruption for every task. This way, it is hard to make code modular, and testing can be painful. Using RTOS solves this kind of problem. It allows programming each task as an endless loop. Kernel scheduler takes care of assuring each task gets its chunk of processing time. Additionally, it does bearing the priority systems – more critical tasks are executed before less important ones. Let us go further with our example code and add more tasks to our FreeRTOS engine. We already have an LED flashing task that toggles LED every second. Additionally, we are going to create another task that checks the button state. Also, we are going to send some information to the LCD. As always, let’s take care of drivers for all of them.

Continue reading

Using FreeRTOS kernel in AVR projects

FreeRTOS is known as Real-Time Operating System. It would probably be too dare to call it real-time-os, preferably a real-time scheduler where applications can be split into independent tasks that share complete processor resources by switching them rapidly. It. It looks like all functions are executed in parallel. This feature is called multitasking. There are many debates on using RTOS on AVR microcontrollers as they are arguably too small for the running scheduler. The main limitation is a small amount of ram and increased power usage. If you use lots of tasks in the application, you will probably run out of RAM to save context when switching between tasks. Consider FreeRTOS only if you use larger scale AVRs like Atmega128 or Atmega256. Indeed you can find smaller schedulers that are specially designed for smaller microcontrollers, even tiny series. On the other hand, if you master FreeRTOS, it can be used with multiple microcontrollers like ARM Cortex, PIC, and various compilers, including IAR, GCC, and Keil Rowley, Attolic. And the main reason to keep an eye on it – it is free. Probably it would take lots of time and space to go through RTOS theory. Some great information can be…

Continue reading

How to drive servo motor control with AVR microcontroller

Servo motors are so-called “closed feedback” systems. This means that the motor comes with a control circuit inside, which senses if the motor mechanism is in the desired position. If not, it continuously corrects an error until the motor reaches the angle. Servo motors are widely used in robotics, remote-controlled planes, vehicles, and many other industrial machines. They come in many shapes and sizes, but they all operate in almost the same way. Usually, servo motors are controlled by a computer, microcontroller, or even a simple timer circuit. How Servo Motor Control Works Usually, servo motors are put in the plastic box, but inside there is a whole system: motor itself, gears, and motor driving and control circuit. The gears reduce motor speed but increase torque. As we mentioned, servos work with a closed feedback loop when the potentiometer is connected to a mechanical shaft and senses the angle of turn. The potentiometer voltage directly indicates the grade of twist. The potentiometer signal goes to a digital controller of the motor, which powers the motor until the potentiometer reaches the desired angle, then the logic circuit shuts the motor.

Continue reading

How to write an LCD menu for AVR in C

Let us write a simple LCD menu for AVR. I am using four buttons: 2 for menu scrolling up and down and two for changing submenu parameters. As the output indicator, I am using three LEDs that flash according to the menu’s parameters. Button states are captured by using timer0 overflow interrupts. The circuit is elementary:  I have excluded the power circuit for simplicity, just left the main parts: LCD, LEDs, and buttons. This circuit works well with the Proteus simulator as it is. The Proteus circuit is attached to the project archive. My idea is to store menu strings in Flash memory without occupying MCU RAM. This way, menu items are limited only by Flash memory, not by RAM.

Continue reading

AVR-GCC 4-bit and 8-bit LCD library

Earlier I have used 4-bit and 8-bit LCD libraries in various projects. It was hard to maintain and update. Now they are merged into one library where the simple logic structure is implemented to select a 4-bit or 8-bit LCD library just by modifying only three code lines. In the library header file there is line added: //Uncomment this is LCD 4 bit interface isused //****************************************** #define LCD_4bit //****************************************** You can select different LCD modes by commenting and uncommenting this line. Also, don’t forget to select proper ports and pins where the LCD is connected:

Continue reading

Adding external memory to Atmega128

Atmega128 is equipped with internal 4Kbytes of SRAM memory. Is it enough? Well, it depends on what project it’s going to hold. If your project must deal with loads of data or run more extensive RTOS code, you will run out of RAM pretty soon. Atmega128 microcontroller has an external memory interface built-in, which allows expansion of RAM up to 64 Kbytes. With that, you could do much more. I used the Piconomic Atmega128 development board to test things out, which has an XMEM interface header brought out. All we need is to make an XMEM expansion board with some SRAM memory. I’ve chosen a standard 8Kx8 (8Kbytes) memory chip from Alliance Memory Inc. I could use 64Kx8, but this is what I had at the moment. To drive the memory chip, I’ve used a 74HC573 non-inverting latch. As you may know, the latch is used for pins that share the same pins for address and data buses. To access SRAM contents, we need to select a 16-bit address pointing to an 8-bit data cell in the chip. As we are using an 8Kx8 memory chip, we are going to use only 13Address lines. The microcontroller has dedicated pins for…

Continue reading

Running TX433 and RX433 RF modules with AVR microcontrollers

Sometimes in embedded design, you may want to go wireless. Maybe you will want to log readings of remotely placed sensors, or build a remote control for a robot or design an alarm system. Radio communications between two AVR microcontrollers can be easily set up with specialized modules. Let us try to run very well-known RF modules TX433 and RX433 (or similar) that can be found almost in every electronics shop. The pair of them cost less than 15 bucks. Transmitter and receiver modules are tuned together to work correctly at the exact 433.92MHz. The transmitter can be powered from a 3 to 12V power supply while the receiver accepts 5V. The 5V is standard for AVR microcontrollers, ideal for 5V devices. Modules do not require additional components – apply power and connect a single data line to transmit data.

Continue reading

Setup AVR Eclipse plugin to work with WinAVR

Probably many of you (including me) are using Programmers Notepad or AVR Studio to set up AVR projects. Each of them has advantages and disadvantages. For instance, Programmers, Notepad is a great GUI, but there are many manual routines required to start compiling projects – like setting up makefile, creating file dependencies, etc. AVR Studio is a great solution that generates makefiles automatically, and it has a great simulator for immediate debugging. So why would we need another IDE? Actually, Eclipse IDE is one of the best open-source tools that programmers widely use – so it is optimized for managing projects, code writing with auto-complete functionality. So why not give it a try. So let’s set up an Eclipse environment to work with AVR. First of all, let’s download Eclipse from https://www.eclipse.org/downloads/ site. Choose Eclipse IDE for C/C++ Developers as we want to program AVR in C. Open it (no need to install), then go to HELP->Install New Software… Click Add… and in the Add Site dialogue box, enter the URL where the AVR Eclipse plugin is located (https://avr-eclipse.sourceforge.net/updatesite/ )

Continue reading

Yet Another Simple AVR ISP cable

Probably this programmer cable can be found on every AVR fan website. It is straightforward and easy to build. You need a few passive components that can be packed inside the LPT connector. From my perspective, I wouldn’t recommend using this one ISP programmer if you are more serious about microcontroller projects because it has poor computer port protection. It connects directly to the LPT port without precautions. I recommend using a similar ISP circuit with buffer IC between LPT and target board. But let’s don’t pretend like we are brilliant. The whole beauty is in its simplicity. This thing does its job perfectly as long as the target board power supply is OK.

Continue reading

USB bootloaders for AVR microcontrollers

Probably the most proper microcontroller programming method is using a bootloader program. Because you don’t need any special programming adapters or special knowledge – you need to connect a standard cable from your PC to the target board and run a special program on the PC which communicates with the MCU bootloader program. The idea is simple: If the microcontroller is preconfigured, then after reset, it starts running not from the start memory location, which is usually at 0x0000 address, but at some specific location, where usually bootloader lies.

Continue reading