Accelerometer Interfacing with AVR

ADXL335 size

The article covers how to interface an accelerometer with the atmega32/atmega16. Before proceeding, the user must know the basics of ADC (Analogy to digital converter) of the AVR. An accelerometer is an electromechanical device that measures acceleration forces. These forces may be static, like the constant force of gravity pulling at your feet, or they could be dynamic – caused by moving or vibrating the accelerometer. Accelerometers are of two types Analog and Digital. In this post, we will be discussing Analog accelerometers. They give voltage as output which is proportional to acceleration. The digital one gives the PWM output or direct binary digital data

Continue reading

All you need to know about AVR fuses

avr crystal oscillator

AVR lock bits and fuses are one of the topics that may cause some confusion. If you missed something or set one bit wrong, it may lead to failure – bricking the whole AVR chip. So it is important to understand once and do things right. Even though datasheets give enough information about AVR fuses, many times, we feel somewhat unsure before executing the write command. Let us go through the main features of AVR fuses and lock bits so next time we would feel safe and get the expected results.

Continue reading

Serial peripheral interface in AVR microcontrollers

Serial Peripheral Interface (SPI) is the fastest synchronous communication interface allowing data transfer speeds up to half of the core clock. If the AVR microcontroller is clocked at 16MHz, then the SPI clock may reach 8MHz in master mode. SPI communication interface is a standard way to talk to other peripherals around MCU like a flash, EEPROM, sensors, and even other microcontrollers. Generally speaking, devices communicate over the SPI interface using four wires MISO (Master In Slave Out), MOSI (Master Out Slave In), SCK (synchronization clock), and SS (Slave Select). Usually, if only one slave device is used, the SS line is omitted while the slave chip select pin is connected to the GND. However, this is a particular case. In all other cases SS pin has to be controlled manually in software – this isn’t handled automatically. If more slaves are connected to the SPI interface, there are options in selecting the suitable slave device: one is to use dedicated SS pins for each slave, or if the slave supports this, use the address byte in data packets to…

Continue reading

ADC on Atmega328. Part 2

After we’ve learned how to perform simple ADC conversions on AVR microcontroller we can move forward with more complex tasks. AVR ADC module has many valuable features that make conversions more robust without occupying MCU resources. Imagine that we need to sample analog waveform or audio signal. It has to be done precisely at defined sampling frequency like 20kHz. The only way to do this correct is to use auto-triggering with exact time intervals. Why not pass counting task to a timer? Let’s write Timer0 auto-triggered ADC conversions with ADC complete interrupt service routine.

Continue reading