The AT90PWM81 microcontroller can produce pulse signals with varying duty fields called pulse width modulation (PWM) that can be utilized in control systems like motor control, brightness control of lighting, and many others. In this commentary, I aim to give a summary of what PWM involves, the methodology behind it, and how the AT90PWM81 microcontroller can generate PWM signals.
What is Pulse Width Modulation?
Pulse width modulation or PWM is a modulation method of a given message in a pulsing signal. It does so either by modifying the length of the pulse by keeping the pulse repetition frequency fixed or by the rate at which the pulse is being repeated. The width of each pulse is equivalent to a certain value from the message that is being conveyed. In typical applications, the pulses are sent to a system like a motor or light, and the varying pulse widths cause the amount of power delivered to vary accordingly.
For example, in a basic motor speed control application using PWM, a full-width pulse corresponds to full power/speed, while a narrow pulse corresponds to low or no power/speed. By smoothly varying the pulse width from narrow to wide, the motor’s speed can be finely controlled even though it is receiving a series of pulses rather than a smooth analog voltage. The higher the frequency of pulsing, the smoother the perceived variation in power/speed.
PWM works because most electronic systems (motors, lights, etc.) operate by averaging the power delivered over time. With a constant frequency pulsing signal, the longer each pulse is “on”, the more power is delivered on average. By encoding information in the pulse widths, this variation in average power allows precise control to be achieved.
How PWM is Generated
Generating PWM typically involves using a microcontroller’s built-in hardware capabilities. Microcontrollers contain timers/counters that can rapidly count until a pre-set value. The timer is incorporated to specify the PWM frequency in the sense that, it is reset and enabled for counting anew after each pulse. The microcontroller also has pins that can be toggled on and off by software. One pin is configured as the PWM output. When the timer reaches its preset value, the pin is turned on. The software then monitors the timer and turns the pin off once the desired pulse width count is reached. The timer then resets and the cycle repeats.
By quickly changing the pulse width count value, the duty cycle (pulse width as a % of period) can be modulated constantly to generate a PWM signal. Modern microcontrollers like the AT90PWM81 have dedicated PWM modules that take the counting and I/O toggling tasks away from the main processor, allowing reliable high-frequency PWM outputs on multiple pins simultaneously with minimal code.
How the AT90PWM81 Works
As previously indicated, the AT90PWM81 is an 8-bit AVR microcontroller, somewhat unique in that it is especially intended for PWM production. There are 4 separate PWM outputs and these are not linked as none of the PWM channels control the other; all 4 PWM channels can generate their own PWM waveform on a selected pin.
Some key features of the AT90PWM81 that enable precise PWM control include:
- Four 8-bit Phase Correct PWM (PCPWM) modules that can operate independently.
- Each PCPWM module has its frequency and duty cycle registers, compare match registers, and interrupt/overflow flags.
- Duty cycles can be changed on the fly in steps as small as 0.39% for 10-bit resolution.
- PWM frequencies up to 125kHz are achievable on each channel simultaneously.
- Additional pins for complementary (inverted) PWM outputs or dead-time insertion between standard/complementary outputs.
- On-chip analog comparator for feedback control or current sensing without external components.
- Full-featured 8-bit AVR core for programmability including timers, interrupts, ADC, etc.
To generate PWM using the AT90PWM81, the software simply loads the desired frequency divisor into the PCPWM module’s clock register and loads the initial duty cycle value into one of the compare match registers. The hardware then takes over and generates the pulses autonomously according to these values. Duty cycles can be adjusted on the fly by changing the compare match register value.
Example Applications
Some common applications that can benefit from PWM control using the AT90PWM81 include:
- DC motor speed control – Vary motor speed by adjusting the duty cycle of the PWM driving motor’s H-bridge. Closed loop control with feedback.
- LED/lighting dimming – Fade an LED or change light brightness by adjusting the LED’s duty cycle-driven PWM.
- Fan speed control – Change fan RPM by controlling the fan’s PWM-driven motor speed.
- Battery charging – Use duty cycle to precisely control charge/float voltages of battery packs during charge cycles.
- Temperature control – In an oven or incubator, the duty cycle controls power to heating elements to regulate temperature.
- Power supplies – Adjusting PWM duty cycles control the output voltages of switching power supplies.
- Servos – Vary servo position by changing the duty cycle of PWM driving each servo motor.
The high PWM resolution, independent channels, and on-chip support make the AT90PWM81 - well-suited for applications requiring precise, flexible PWM generation across multiple outputs simultaneously – all with minimal additional components.
Software Libraries and Development Tools
To simplify PWM control and application development, many open-source and commercial software libraries exist for the AT90PWM81:
- Atmel Software Framework (ASF) from Microchip provides precompiled drivers, examples and config tools to get started quickly.
- FreeRTOS is an RTOS commonly used that includes PWM driver modules to generate and control outputs.
- AVR-PWM is a standalone C library containing configuration and control functions.
In addition, the low-cost AT90PWM81 breakout boards available include header pins wired to all ports and make prototyping easy.
The standard AVR toolchain (AVR-GCC, AVaRStudio) works with the AT90PWM81 as well. Projects can be compiled from the command line or IDE, then programmed and debugged with a standard in-circuit debugger/programmer.
Open-source code examples are also available on sites like GitHub demonstrating basic and advanced PWM applications. Combined with library support, this lowers development barriers considerably.
Limitations and Alternatives
While very capable for simple PWM tasks, the AT90PWM81 has some limitations to be aware of:
- Only 4 independent PWM channels limit more complex designs needing more outputs.
- The top frequency of 125kHz may be too low for Audi/servo applications needing > 20kHz outputs.
- Lack of higher resolution ADCs limits on-board feedback/sensing in closed-loop control systems.
- Only 8 GPIO pins total hampers integration into systems requiring more digital I/O.
For more demanding applications, alternatives with stronger specs include 32-bit ARM MCUs or microcontrollers from other vendors with dedicated motor control peripherals:
- NXP Kinetis K80 – Up to 16 PWM channels at 160MHz, advanced motor control blocks
- TI Piccolo – Up to 16 channels at 150MHz + sigma-delta ADC, integrated driver support
- STMicro LPC408x – 8/16 channels at 120/105MHz, full-featured MCU with DSP capabilities
- Microchip SAM C21 – Up to 18 channels at 100MHz, integrated LCD/touch/comms peripherals
While more expensive, these bring significantly expanded capabilities for industrial/IoT control applications requiring more precision, channels, or integration.
Conclusion
In summary, the AT90PWM81 is a low-cost yet very capable microcontroller optimized for generating flexible, high-resolution PWM signals on multiple outputs simultaneously.
Its dedicated hardware PWM modules, independent channels, and on-chip support make it well-suited for applications where precise modulation across a few signals is required, from basic motor/light control to battery charging and power supply regulation.
Supported by open-source libraries and examples, developers can quickly prototype PWM designs with the AT90PWM81 on low-cost breakout boards. While limited to more demanding uses, it remains an excellent solution for many basic embedded control tasks requiring flexible, multi-channel PWM generation.
FAQ
Q: What is pulse width modulation (PWM)?
A: Therefore PWM is a way to achieve analog results with digital solutions. It involves generating a digital pulse signal with a fixed frequency but varying pulse width. The ratio of on vs off time (duty cycle) is modulated to encode and control analog properties like motor speed, light brightness, etc.
Q: How many PWM channels does the AT90PWM81 have?
A: The AT90PWM81 has 4 independent PWM channels that can each generate a PWM output signal on its dedicated pin.
Q: What is the maximum PWM frequency?
A: The AT90PWM81 can generate PWM signals at frequencies of up to 125kHz on each channel simultaneously.
Q: What is the PWM resolution?
A: The resolution of the PWM duty cycle can be varied in 0.39% steps, providing up to 10-bit resolution control of the duty cycle.
Q: Can you change the PWM settings dynamically?
A: Yes, the PWM frequency and duty cycle values can be changed on the fly-in software even while the PWM output is active. This allows flexible control of motor speeds, light levels, etc. in real time.
Q: What peripherals does it have besides PWM?
A: The AT90PWM81 is an 8-bit AVR microcontroller, so it includes common peripherals like GPIO pins, timers, interrupts, and an analog comparator to aid applications beyond just PWM generation.
Q: Are there any libraries available to help use the PWM functions?
A: Yes, libraries like ASF, FreeRTOS, and AVR-PWM contain driver code and examples to simplify using the AT90PWM81’s PWM hardware from within C programs on supported MCUs.
Q: What are some common applications for this chip?
A: Some of the areas of applications are for motor control, artificial lighting and dimming, fans, and blower speed regulation, battery charging, temperature control, power supplies, and accurate positioning of servo motors.