The GNU tools must be configured, built, and installed on the system. This chapter presents a simple example of using the GNU tools in an AVR project. After reviewing this chapter, users should gain a better understanding of how these tools are utilized and how a Makefile can be configured. The project involves using pulse-width modulation (PWM) to ramp an LED on and off every two seconds, with the AT90S2313 processor serving as the controller. The circuit for this demonstration is depicted in the schematic diagram. If a development kit is available, it can be used instead of building the circuit. The AT90S2313 has become obsolete; therefore, either its successor, the ATtiny2313, or the ATmega8 or its successors (ATmega48/88/168), which have gained popularity since the original demo project was established, should be used for the project. For these modern devices, an external crystal for clocking is no longer necessary, as they come with the internal 1 MHz oscillator enabled, allowing the omission of components C1, C2, and Q1. Typically, the external circuitry on /RESET (R1, C3) can also be omitted, leaving only the AVR, the LED, the bypass capacitor C4, and possibly R2. For the ATmega8/48/88/168, PB1 (pin 15 in the DIP-28 package) should be used to connect the LED. This demo has been adapted for various other AVRs, with the location of the respective OC pin differing among them, as dictated by the AVR hardware. The source code is provided in demo.c. A file named demo.c should be created to contain this source code. Notable parts of the code include that while the AVR microcontroller series has evolved over the years with new features, the fundamental concepts of timer/counter1 remain consistent with those from early 2001 when this demo was initially written. However, register and bit names have been slightly modified to reflect new features, and the port and pin mapping of the output compare match 1A (or 1 for older devices) used to control the LED varies among different AVRs. The file iocompat.h addresses these differences using preprocessor #ifdef statements, allowing the actual program to operate on a common set of symbolic names. The macros defined in that file include TIMER1_CLOCKSOURCE, which sets the clock bits in the control register to initiate the PWM timer, typically running at full CPU clock for 10-bit PWMs and on a prescaled clock for 8-bit PWMs. ISR() is a macro that designates the function as an interrupt routine, which will be invoked when timer 1 overflows. Setting up interrupts is elaborated on in <avr/interrupt.h>: Interrupts. The main loop of the program remains inactive, with all operations conducted by the interrupt routine. The sleep_mode() function places the processor into sleep mode until the next interrupt to conserve power; however, this may not be noticeable as the LED is still being driven, but it is mentioned here to illustrate the basic principle. Early AVR devices saturate their outputs at relatively low currents when sourcing current, allowing the LED to be connected directly, resulting in approximately 15 mA through the LED. For modern parts, such as the ATmega 128, Atmel has significantly increased the I/O source capability, necessitating R2 with a value of about 150 Ohms when operating at 5 V Vcc. However, when operating the circuit at 3 V, R2 can still be omitted.
The schematic for this project involves a simple circuit where the ATmega microcontroller controls an LED using PWM. The ATmega8 or its successors can be used as the central processing unit, connected to the LED through PB1. The circuit design should incorporate a bypass capacitor (C4) to stabilize the power supply to the microcontroller, ensuring reliable operation. Resistor R2 serves to limit the current flowing through the LED, which is critical for preventing damage to both the LED and the microcontroller's output pin. The PWM signal generated by the microcontroller will determine the brightness of the LED, creating a visual effect as it ramps on and off every two seconds.
The software component of the project is encapsulated in the demo.c file, which contains the necessary code to configure the timer and handle the PWM output. The use of the iocompat.h file allows for compatibility across various AVR devices by abstracting the differences in register names and configurations. This modular approach simplifies the code and enhances its portability. The interrupt service routine (ISR) is crucial for managing the timing of the PWM signal, allowing the microcontroller to enter a low-power sleep mode between interrupts, thereby optimizing power consumption.
In summary, this project serves as an excellent introduction to using GNU tools for AVR programming, demonstrating the integration of hardware and software to achieve a practical application of pulse-width modulation with an LED display.You should have the GNU tools configured, built, and installed on your system. In this chapter, we present a simple example of using the GNU tools in an AVR project. After reading this chapter, you should have a better feel as to how the tools are used and how a Makefile can be configured. This project will use the pulse-width modul ator (PWM) to ramp an LED on and off every two seconds. An AT90S2313 processor will be used as the controller. The circuit for this demonstration is shown in the schematic diagram. If you have a development kit, you should be able to use it, rather than build the circuit, for this project. Meanwhile, the AT90S2313 became obsolete. Either use its successor, the (pin-compatible) ATtiny2313 for the project, or perhaps the ATmega8 or one of its successors (ATmega48/88/168) which have become quite popular since the original demo project had been established.
For all these more modern devices, it is no longer necessary to use an external crystal for clocking as they ship with the internal 1 MHz oscillator enabled, so C1, C2, and Q1 can be omitted. Normally, for this experiment, the external circuitry on /RESET (R1, C3) can be omitted as well, leaving only the AVR, the LED, the bypass capacitor C4, and perhaps R2.
For the ATmega8/48/88/168, use PB1 (pin 15 at the DIP-28 package) to connect the LED to. Additionally, this demo has been ported to many different other AVRs. The location of the respective OC pin varies between different AVRs, and it is mandated by the AVR hardware. The source code is given in demo. c. For the sake of this example, create a file called demo. c containing this source code. Some of the more important parts of the code are: As the AVR microcontroller series has been developed during the past years, new features have been added over time.
Even though the basic concepts of the timer/counter1 are still the same as they used to be back in early 2001 when this simple demo was written initially, the names of registers and bits have been changed slightly to reflect the new features. Also, the port and pin mapping of the output compare match 1A (or 1 for older devices) pin which is used to control the LED varies between different AVRs.
The file iocompat. h tries to abstract between all this differences using some preprocessor #ifdef statements, so the actual program itself can operate on a common set of symbolic names. The macros defined by that file are: TIMER1_CLOCKSOURCE the clock bits to set in the respective control register to start the PWM timer; usually the timer runs at full CPU clock for 10-bit PWMs, while it runs on a prescaled clock for 8-bit PWMs ISR() is a macro that marks the function as an interrupt routine.
In this case, the function will get called when timer 1 overflows. Setting up interrupts is explained in greater detail in : Interrupts. The main loop of the program does nothing - all the work is done by the interrupt routine! The sleep_mode() puts the processor on sleep until the next interrupt, to conserve power. Of course, that probably won`t be noticable as we are still driving a LED, it is merely mentioned here to demonstrate the basic principle. Early AVR devices saturate their outputs at rather low currents when sourcing current, so the LED can be connected directly, the resulting current through the LED will be about 15 mA.
For modern parts (at least for the ATmega 128), however Atmel has drastically increased the IO source capability, so when operating at 5 V Vcc, R2 is needed. Its value should be about 150 Ohms. When operating the circuit at 3 V, it can still be omitted though. /* * - * "THE BEER-WARE LICENSE" (Revision 42): * wrote this file. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return. Joerg Wunsch * - * * Simple 🔗 External reference
When connecting a microcontroller project to a COM port on a PC, an RS-232 converter is required. Various chips can accomplish this task, such as the MAX232 and DS275. However, for a simple and cost-effective RS-232 converter, the following...
The microcontroller (MCU) is responsible for sending variable voltages over time, similar to a traditional Low-Frequency Oscillator (LFO), to an effect that can be modulated by voltage or a potentiometer on a conventional analog effect that can be replaced...
This AM receiver is working perfectly without the need of coils or even a variable capacitor. The LF356 is the basic component. P1 and P2 are the frequency selectors. Use a small telescopic antenna. The stations selectivity is not...
Communication with the MCP3028 ADC chip is achieved through a straightforward serial interface that adheres to the SPI protocol. The PIC16F84 or PIC16F628 does not possess a hardware SPI peripheral. However, a software-implemented SPI protocol can facilitate communication with...
This project meets a specific need by utilizing a frequency counter built with basic TTL chips, predating the availability of CMOS HC versions. The design incorporates four chips: three HC TTLs and an Atmel AT90S2313 microcontroller. It features a...
A board is to be designed with a single input of 120 volts and 600 watts, which will provide more than three outputs, each rated at 120 volts and 200 watts. These outputs will be designated as A, B,...
We use cookies to enhance your experience, analyze traffic, and serve personalized ads.
By clicking "Accept", you agree to our use of cookies.
Learn more