Showing posts with label Quick Tip. Show all posts
Showing posts with label Quick Tip. Show all posts

Friday, March 31, 2017

Arduino (ATmega328) Direct Register Manipulation for Custom PWM Output (ex: 1us HIGH followed by 99us LOW --> 1% Duty Cycle at 10kHz)


Subscribe by Email!
Here's a quick example of how to make a hardware-based 1us HIGH pulse followed by a 99us LOW pulse (ie: 100us period, or 10kHz, PWM with a 1% duty cycle), via direct timer register manipulation. I've left ample comments for you to read and follow. This example below is therefore quite easy to follow and learn from, but just as it took me dozens of hours originally to learn how to do all this stuff from scratch--and to learn about all the different PWM modes possible as described in the datasheet and elsewhere, expect to spend at least a few hours if you are truly going to read the references and dig into it enough to understand it yourself. Good luck and have fun!

References to Study:
  1. Secrets of Arduino PWM, by Ken Shirriff
  2. ATmega328 Datasheet (660 pg version from 11/2015)
  3. ATmega168/328-Arduino Pin Mapping

Here's some oscilloscope screenshots of the output on Pin 3 produced by an Arduino Nano running the code below.

Rising edge to rising edge: Δx = 100us


***Subscribe by Email!***

Tuesday, November 8, 2016

Eagle PCB CAD - How to copy a part from one schematic to another


Subscribe by Email!
Gabriel Staples
8 Nov 2016

Learning EagleCAD? Here's how to copy a part from one schematic or board layout to another.
  1. Open up an Eagle Control Panel, and the board and schematic you are working on.
  2. Open up a *second* Eagle Control Panel, and the board and schematic you want to copy from.
  3. Use the group tool to make a selection of a part to copy.
  4. Click the copy tool, then ctrl + right click to copy the *grouped* selection to the clipboard. Press Esc now to not paste it anywhere in this project. 
    1. Note that you *must* use the group tool followed by ctrl + right click even if only copying a single object, since that's the only way to get it to your PC's clipboard.
  5. Go back to the schematic you'd like to paste into, and click the "paste" tool. Left-click anywhere to paste what's in the clipboard. 

Done!

Helpful References:
...among many others.





***Subscribe by Email!***

Thursday, June 11, 2015

100+V Arduino/AVR Microcontroller Input/Output (I/O) Pin Over-Voltage Protection Using a *Single* Resistor!


Subscribe by Email!
By Gabriel Staples
Written: 11 June 2015
Last Updated: 2 Sept. 2015
Update History (newest on top):
-Added "Upfront Caveat", 2 Sept. 2015
-Added lots of extra info, & the Figures, 21 July 2015

Related Articles:

Here I present a pin protection method for very high and low input voltages that I learned from Atmel themselves, in their Application Note "AVR182: Zero Cross Detector."

If you've read my article titled "Arduino Power, Current, and Voltage Limitations" you know that the pin input voltage limits are as follows:
Maximum Input Voltage: Vcc + 0.5V, or +5.5V for a 5V Arduino
Minimum Input Voltage: -0.5V

However, if you simply add a single resistor in series with any input pin, you can protect it against higher or lower input voltages, with some caveats!

Ex: simply by placing a 10k resistor in series on an input pin, you get input voltage protection up to +15.5VDC and down to -10.5VDC. With a 100k resistor you get input voltage protection up to +105.5VDC, and down to -100.5VDC. Keep reading to learn more.

WARNING: 
-FOR YOUR PERSONAL SAFETY, WHEN USING THIS TECHNIQUE, I RECOMMEND THAT YOU DO NOT WORK WITH INPUT VOLTAGES GREATER THAN APPROXIMATELY 100VDC OR 20VAC UNLESS YOU KNOW WHAT YOU ARE DOING AND HAVE READ ALL OF MY WARNINGS HEREIN, INCLUDING THE ADDENDUM AT THE END OF THIS ARTICLE. 
-REGARDLESS OF WHAT INPUT VOLTAGES YOU ARE USING, YOU AND ONLY YOU ARE RESPONSIBLE FOR YOUR PERSONAL EXPERIMENTS, PRODUCTS, DESIGN DECISIONS, AND THE SAFETY OF YOU AND YOUR CUSTOMERS.

Upfront Caveat:
Though this technique may work, and be good for home-projects or quick prototyping, better techniques are recommended, especially if you are producing a commercial product. Redundancy is your friend. Using external, rated clipping diodes is certainly a better option than relying on the internal, integrated and unrated ones. For better protection techniques, including using *external* clipping diodes for redundancy, and adding transient voltage suppression, read more here: Science Prog: Using current limiting resistors on AVR I/O pins. Also see the AVR182 Application Note for references to additional sources to read in order to add extra pin protection.

Background & Concept:

***Subscribe by Email!***

Saturday, May 9, 2015

Quick Tip: A Comprehensive List of Helpful Arduino Learning Links


Subscribe by Email!
By Gabriel Staples Written: 9 May 2015
Last Updated: 9 May 2015

Related Articles:

Over the past couple years I have been compiling the Arduino learning links, reference pages, and resources, that I have found the most useful for my learning. I keep this list updated, and regularly add to it. The list is found at the bottom of my article titled "The Power of Arduino." Go there, scroll to the bottom, and you'll find the list.

It currently contains the following sections:


***Subscribe by Email!***