background preloader

Secrets of Arduino PWM

Secrets of Arduino PWM
Pulse-width modulation (PWM) can be implemented on the Arduino in several ways. This article explains simple PWM techniques, as well as how to use the PWM registers directly for more control over the duty cycle and frequency. This article focuses on the Arduino Diecimila and Duemilanove models, which use the ATmega168 or ATmega328. If you're unfamiliar with Pulse Width Modulation, see the tutorial. Briefly, a PWM signal is a digital square wave, where the frequency is constant, but that fraction of the time the signal is on (the duty cycle) can be varied between 0 and 100%. PWM has several uses: Dimming an LED Providing an analog output; if the digital output is filtered, it will provide an analog voltage between 0% and 100% . Simple Pulse Width Modulation with analogWrite The Arduino's programming language makes PWM easy to use; simply call analogWrite(pin, dutyCycle), where dutyCycle is a value from 0 to 255, and pin is one of the PWM pins (3, 5, 6, 9, 10, or 11). Timer Registers Fast PWM

Related:  Voice Synthesis in Arduino

How to Configure Arduino Timer 2 Registers to Drive an Ultrasonic Transducer with a Square Wave  The Arduino IDE has many built-in commands to produce PWM outputs but directly setting the timer registers gives you much more flexibility and power. Below I show how to configure the 8-bit Timer/Counter2 on the ATmega328 (Ardunio UNO) to generate a 40 kHz square wave on Arduino digital pin 11. Why 40 kHz? PulseIn Reference Language | Libraries | Comparison | Changes Description Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, pulseIn() waits for the pin to go HIGH, starts timing, then waits for the pin to go LOW and stops timing. Blog : Hacromatic: Electronics kits and projects worldwide I couldn’t find much information about how to use the Arduino motor shield (as of late 2012), so I thought I’d show how to set up the connections for both stepper motors (4, 5, 6, and 8 wires) and DC motors, along with some basic sketches to drive them. Stepper Motors Steppers can be broadly classified as 2/4-phase or 5-phase. This breakdown covers the vast majority of stepper motors you’re likely to encounter. 5-phase motors typically provide lower vibration and smaller stepping angles than 2 and 4 phase motors, but they are less common and won’t work with the Arduino motor shield, so I’m not going to talk about those here.

Z-80 The 8-bit Z-80 processor was very popular in the late 1970s and early 1980s, powering many personal computers such as the Osborne 1, TRS-80, and Sinclair ZX Spectrum. It has a 16-bit incrementer/decrementer that efficiently updates the program counter and stack pointer, as well as supporting several 16-bit instructions and memory refresh. By reverse engineering detailed die photographs of the Z-80, we can see exactly how this increment/decrement circuit works and discover the interesting optimizations it uses for efficiency. The Z-80 microprocessor die, showing the main components of the chip. The increment/decrement circuit in the lower left corner of the chip photograph above. This circuit takes up a significant amount of space on the chip, illustrating its complexity.

Simple Arduino audio samples This tutorial explains how to do simple playback of short (~4 second), low-bitrate (8 KHz) audio samples from Arduino using only a speaker. It’s based on the PCMAudio code by Michael Smith. Pre-Requisites You’ll need: An Arduino Uno or Duemilanove A speaker with wires soldered to it. (Note that a piezo probably won’t work.)

Arduino Projects: Telescope Control with GOTO Why make your own Arduino control system? After completing my homemade telescope mount it was powered by a Meade DS motor kit. This system was extremely slow, underpowered and unreliable. It was also impossible for me to change the programming or maintain the system. I decided to make my own telescope control system from the ground up and the Arduino platform seemed the obvious choice. This project needed a wide range of inputs and outputs, so has been done using an Arduino Mega 1280 board, although a Mega 2560 would do just as well.

Oric Atmos on Pipistrello - Pipistrello - Gadget Factory Forum Following in the trails of ZX Spectrum on Pipistrello I present you with... Oric Atmos on Pipistrello. The Atmos is dear to my heart as it is my first personal computer I used when I was young. While all my friends were playing games on their Spectrums and Commodores I was bucking the trend spending countless hours with my Oric, my soldering iron and my Oric bible, the "Oric Advanced User Guide" writing 6502 machine code (back in those days we didn't have assemblers and compilers The only reason this is "for the Pipistrello" is because the Papilio Pro is one RAMB block short of being able to fit the design.

PWM - an overview PWM sometimes seems to be a misunderstood and complicated topic. This tutorial will cover the basics of what PWM is, what it can be used for, and how to use the AVR controllers to generate PWM. PWM stands for Pulse Width Modulation. This means that we can generate a pulse whose width (ie duration) can be altered. The digital world Since microcontrollers live in a digital world then their output pins can be either low (0v) or high (5v).

Humidity and temperature measurements with Sensirion’s SHT1x/SHT7x sensors (Part 2) In Part 1 of this tutorial, we discussed about Sensirion’s SHT1x and SHT7x series of humidity sensors, their interface specifications, the communication protocol used for transferring data in and out of the sensor, and the equations to convert their digital outputs to actual physical quantities. These sensors are capable of measuring temperature along with relative humidity and provide outputs in fully-calibrated digital words. We will now see how a PIC microcontroller can be programmed to communicate with these sensors, read the temperature and relative humidity data, and display the information on a character LCD. Circuit setup on breadboard Circuit Diagram We will be interfacing the SHT11 and SHT75 sensors simultaneously to different port pins of PIC18F2550 and display the measured values of relative humidity and temperature from both on a 16×2 character LCD.