RS232 interface standard overview

This is a pretty old standard but still widely used in embedded systems. Using the RS232 interface standard, the data is sent bit by bit. Usually, first comes LSB. The receiver receives data by knowing the position of each data piece and delay. To ensure the quality of data transmission, we need to control the start of transmission. The acknowledgment procedure does this. Let’s take the asymmetrical type of interface RS232-C. The transmitter sends RTC (request to send) signal to the receiver. On the other hand, the receiver detects this signal, finishes the previous operation, and then sends to receiver CTS (clear to send) signal, which means that receiver is ready to accept data. Without CTS transmitter cannot start data transmission. Note: In the RS232 interface, logical “1” corresponds to voltages from -3V to -12V, and logical “0” corresponds to voltages from +3V to +12V. The logical level in the interval -3V to +3V is undefined.

Continue reading

AVR watchdog reset timer-practical approach

This is a continuing thread. Why use a watchdog variable timer. This post is about how the watchdog timer on the AVR microcontroller works and how to control it. As we mentioned earlier, the watchdog timer is a distinct timer counter, which generates a reset signal when it fills up. After the watchdog timer counts up to maximum, it generates a short pulse duration of 1 clock cycle. This pulse triggers an internal reset timer counting up to tout.

Continue reading

Why use watchdog variable timer

Most of the embedded microcontrollers contain watchdog timers. The watchdog variable timer is literally watchdog. The watchdog timer continuously inspects the program flow. Basically, if the microcontroller program hangs, then the watchdog timer resets it and brings the embedded system back to life. The idea is elementary. Let’s say, you know, that your program has to be executed during 20ms. And you know that the worst-case scenario is 30ms. Then you set the watchdog variable timer connected to the highest priority interrupt RESET. Once the Watchdog timer is triggered, the timer counts up to the time you set, and then it resets the MCU. The only way to avoid resetting is to send a command to the watchdog timer to start counting. Technically watchdog variable timer is nothing more than a retriggerable one-shot multivibrator.

Continue reading

How to use inline ASM using WinAVR

I have been working on the optimization of one of my C codes. I needed one function to be as optimal as possible. I decided to use inline ASM to achieve this. I decided to write a few lines about this. There are a few rules that are necessary to follow. Each ASM statement is divided by colons into 3(up to four parts): Assembler instructions part; A list of output operands (comma separated); A list of input operands (comma separated); Clobbered register – usually left empty.

Continue reading

Marking of AVR microcontrollers

There is quite a big variety of AVR microcontrollers that ATMEL company produces. This article is about how to Extract information about the AVR microcontroller using its marking on the package. Each microcontroller has its own mark on the package: numbers and letters. The first is the microcontroller type. After follows, a suffix of three fields. The first field is one or two digits, which indicate maximal operation frequency MHz. The second field is a letter showing the package type. And the third field shows the temperature range of the working environment. There are a couple more marking letters “L” and “V” after the microcontroller type. This means that the microcontroller operates at low or very low voltages (and frequencies, of course).

Continue reading

AVR controlled DDS generator software writing

During my spare time, I am developing the program for the AVR controlled DDS generator. I decided to write software using the WinAVR tool-set. How far ahead I have moved with this? I have implemented: Menu system; Reading previous generator configuration from EEPROM; Setting signal mode; Storing last generator configuration to EEPROM to be loaded after reset; Four types of signal output (square, sawtooth, triangle, and sine wave); Things I still need to do: Ability to change signal frequency; Implement other signals (listed below); Make program clean-up;

Continue reading

Reading AVR button status using WinAVR

If you want to bring some interactivity to your embedded projects, one option is to add buttons. This allows you to control program flow, set parameters, and much more. Few words about AVR ports. AVR Port pins can be configured as input or output. See table for all general pin configurations: DDRx register is the so-called direction register; PORTx – is port output register; PINx – is pin input register;

Continue reading

Simple routine how to store data in microcontroller flash and read from it using WinAVR

I’ve been asked about how to store data tables in flash memory using the avr-GCC toolset. I decided to post an answer here. Might be someone who find this useful. To demonstrate this I have set up a project using the VMLAB simulator. The files you can download from here: Small project using VMLAB simulator So I created a project in VMLAB. It will help if you read my previous article ho to do this: Using VMLAB as a virtual oscilloscope In project window I have connected 8 LED’s to port D by typing this: D1 VDD PD0 D2 VDD PD1 D3 VDD PD2 D4 VDD PD3 D5 VDD PD4 D6 VDD PD5 D7 VDD PD6 D8 VDD PD7 Then I wrote a simple C program: In program you see, that data can be stored in flash memory using data describing sentence: To make PROGMEM macro work you have to include library pgmspace.h. Bellow you see result of simulation in VMLAB environment:

Continue reading

Internal microcontroller ADC

Many microcontrollers contain internal on-chip ADC. Typical devices would be Atmel Atmega series microcontrollers like Atmega8 and further. Internal ADC is a successive way to integrate the analog world into your embedded systems using only one microcontroller die. Many applications don’t require high speed or high accuracy ADC conversions; thus, on-chip ADC is the best choice. Let’s look at Atmega8. It contains a 10-bit approximation ADC with an analog input multiplexer of 8-single-ended input voltage (refers to 0V) channels.

Continue reading

How to measure wind direction

I found this wind direction measurement circuit simple and interesting. If you are doing some home automation project, this might be another sensor included in your project. For Wind direction measurement, you will need a circle from some material (you might even use a CD.) Then stick an arrow on top. One end of the arrow should have a fin. Another end of the arrow should have a piece of magnet. Then put eight magnetic sensors around the circle in the magnet’s way. See drawing:

Continue reading