Restructered pre-import

This commit is contained in:
Liz Cray
2024-07-07 13:53:31 -04:00
parent 47996087db
commit cc9e65b5c6
302 changed files with 0 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
A recent and decent looking tutorial posted here for you and whoever
fills out this page!
- [tutorial on
avrfreaks](http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=89843)
[Category:AVR Tutorial](Category:AVR_Tutorial "wikilink")
+116
View File
@@ -0,0 +1,116 @@
Part of the [AVR Tutorial](AVR_Tutorial "wikilink")
## Goals
In this lesson, you'll program the micro-controller version of "hello
world", letting you fire up your programmer, compiler, chip, LED, and
test them all out. You'll learn how to setup and use pins for output,
and along the way get some exposure to AVR-specific coding practice.
## The Circuit
Possibly the simplest circuit you can imagine: plug an LED into pins PB4
and ground. PB4 is going to go the positive leg of the LED to source
current across the LED and light it up.
If you want, you can include a current-limiting resistor inline with the
LED (around 100 ohms is good). I've done it both ways -- the AVR will
drive the LED at ~50mA, which will burn out the LED over the long run,
but for this demo, it'll be fine.
## The Code
<nowiki>
/* Blinker Demo */
#include <avr/io.h> /* Defines pins, ports, etc */
#define F_CPU 1000000UL /* Sets up the chip speed for delay.h -- 1MHz for Tiny13*/
#include <util/delay.h> /* Functions to waste time */
#define LED PB4 /* Defines pin PB4 for the LED. I
often incorporate a bunch of the circuit
info in the defines, which makes
porting the code to another chip
easier and reminds you of how to
hook it up. */
int main(void){
DDRB = _BV(LED); /* Data Direction Register B:
writing a one to the bit
enables output. More on the
_BV() macro in the next
lesson.*/
while(1){ /* the main loop, from which we never return */
PORTB = _BV(LED); /* Turn on the LED bit/pin in PORTB */
_delay_ms(400); /* wait */
PORTB &= ~_BV(LED); /* Turn off the LED bit/pin in PORTB */
_delay_ms(400); /* wait */
}
return(0); /* never reached */
}
</nowiki>
## Discussion
Even though this is a very short program, it provides a sketch of what
most AVR code looks like.
At the top is a bunch of includes, defines, and etc.
**io.h** defines all of the port and pin macros and is linked to the
individual chip's io header during compilation, which allows the same
code to work for different AVR chips. You pretty much always want to
include io.h.
The delay functions in **delay.h** are fairly generic, but depend on
knowing the chip's CPU clock speed to get the timing right. Also note
that the maximum delay you can request also depends on the chip's clock
speed. Read up in delay.h for details if you're interested. Practically
speaking, if you're asking it to delay for 600ms and it's only delaying
for 200ms, try calling the _delay_ms() function three times, each for
200ms.
After the defines and includes we get down to the **main()** function.
Most AVR main()'s have at least an initialization section and an
infinitely-repeating loop where the bulk of the chip's work gets done.
In this example, the **initialization section** just sets up the LED pin
for output by writing a 1 to the relevant bit in the Data Direction
Register for port B. When the chip is reset or powered on, all of the
input/output ports are initialized as inputs (DDRB = 0). We write a one
to the DDR do set it as output. More on the bitwise math in the next
lesson.
The **main loop** of the function then blinks the LED by alternately
driving the output pin high (the supply voltage, VCC) or low (GND, 0v),
and it does this forever, or until the chip is reset or powered off.
(The return(0) line is just there to stop the compiler from warning
about main() functions that don't return -- a requirement of GCC that
isn't really relevant to the AVR, but it doesn't hurt the code either.)
For a lot more examples of what you can do just by toggling one pin, see
the code over at [AVR Noise Toys](AVR_Noise_Toys "wikilink").
## Trouble?
Programmer woes:
Is the LED in the correct polarity? (Positive to pin PB4, negative to
GND).
Is avrdude complaining? Try unplugging and re-plugging your programmer
if it's a USB one. Sometimes it can get out of sync.
If avrdude's not working, you may also be having permissions problems.
Solutions include running giveio.bat for Windows or calling avrdude (or
the make command) with *sudo* for Linux if you didn't set up user
permissions for USB.
[Category:AVR Tutorial](Category:AVR_Tutorial "wikilink")
+123
View File
@@ -0,0 +1,123 @@
The first step is to get set up with all the necessary hardware and
software to start making your controllers do your bidding.
## Programmer
A programmer needn't be super-fancy. In fact, you can get by with five
wires soldered to a parallel port plug if you'd like. [This
Instructable](http://www.instructables.com/id/Ghetto-Programming%3a-Getting-started-with-AVR-micro/)
steps through making a parallel port programmer. I'll probably make up a
cable or two and bring it in to the space if you'd just like to try it
out. Note that if you've got a breadboard, you can skip the step of
making a programming cradle and just plug the wires into the correct
pins on the AVR.
If you're getting a little more serious, spend \$22 and get a [USB-based
programmer from ladyada](http://www.ladyada.net/make/usbtinyisp/) or
make your own [usbtiny SPI
programmer](http://www.xs4all.nl/~dicks/avr/usbtiny/) for maybe
\$10-15ish. If you're making your own, you'll need to flash an AVR with
the supplied firmware, but you can do that with a parallel port
programmer or just ask one of us to hook you up.
This part may seem daunting -- it's not. Dive in or get someone to help
you. The Ladyada kit is a good first/second soldering project.
Indeed, if any of that seems too complicated, just connect some wires
from a parallel port to the right pins on the AVR (perhaps directly onto
your breadboard?) and you're started. There's an adapter for doing just
that floating around the lab somewhere. For more on that style of
programmer, see [AVR Tutorial: Bootstrapping the
AVR](AVR_Tutorial:_Bootstrapping_the_AVR "wikilink")
## Software
The standard toolchain consists of a GCC-based C cross-compiler, the
AVR-libc libraries, and the software to run your programmer: *avrdude.*
Feel free to write the C or assembler code using whatever editor you
like best.
**Windows:** The whole toolchain is put together nicely with
[WinAVR](http://sourceforge.net/projects/winavr). Download and install.
If you're using a parallel port programmer, you'll need to also run the
included *giveio.bat* file to get yourself permissions.
**Linux:** I'm most familiar with Ubuntu these days. As of 2008/04,
"sudo apt-get install avrdude avr-libc binutils-avr gcc-avr" will set
you up. Or fetch tarballs and compile it yourself. (I'll incluce
versions here in a few.)
**MAC:**
Wanted to note something quick about my MAC experience so far (Q): I
haven't really read the link to ada's site about programming AVR for MAC
but 'AVRMacPack' is really cool! In OSX it's a simple .pkg file to
install and drop into /Applications - then as long as you've installed
XCode (that comes with macbook in the 2nd CD 'Developer Tools' section)
they have this great little script in there called 'avr-project'. When
you run this little badass piece of code it creates a DIR for your
project called /FIRMWARE and three things:
`An .xcodeproj file - this is a template (with skeleton code) for writing your program in Xcode`
`Makefile template which ROCKS - all you have to do after is change the DEVICE you're`
`  using along with PROGRAMMER and FUSES. (Will LINK my file here for reference `
` email Q if i forget)`
`main.c file that is just a stupid simple C template to get you started`
In addition to the compiler and programming software, it's nice to have
an [AVR Makefile](AVR_Makefile "wikilink") that automates the
cross-compilation build process. Comment in/out the first few defines to
match your environment.
## Chips
So you're set to program, but you need a couple chips. [This page at
AVRFreaks](http://www.avrfreaks.net/index.php?module=Freaks%20Devices&func=viewDev)
has some of the specs and all the datasheets in one place, but it's a
bit overwhelming.
A shortlist of the coolest chips includes:
**Tiny13** -- Smallest and cheapest. 8 pins, 5 of them useful. 1k
program memory. Goes everywhere. Cheaper and more versatile than a 555
IC. Some hardware SPI/I2C support, but it's a pain to write for.
**Tiny45** -- Another 8-pin, but with a high-speed (64MHz!) PWM clock
and 4k of program memory. ~\$0.75 from Digikey. Can be made to run at
16MHz+ using its internal oscillator, making firmware USB a reality.
Some hardware SPI/I2C support like the Tiny13.
**Tiny2313** -- 20 pins. It's the cheapest/smallest unit with \> 5
usable pins. Hardware USART makes serial communication (e.g. with your
computer) reasonably simple, which can be sweet for debugging or
datalogging.
**Mega 48** -- 28 pins. All of the bells and whistles, with 4k program
memory. 6 ADC channels, buncha timers, SPI/I2C/USART communications.
They'll do what you want.
**Mega 88, 168** and beyond. A lot of power for under \$10. Overkill for
most of my (Elliot's) small projects, but when you need the memory, you
need the memory.
Maybe we could do a few group purchases to get up to Digikey's
price-break minimums. Interested? E-mail Elliot.
And while you're at the AVRFreaks page, download both the long and short
datasheets for whichever chips you end up buying. The short one has a
nice pinout diagram on page two, while the long one explains everything
you'll ever need to know.
## Misc. Extras
You're at least going to need some LED's to go blink. Pushbuttons are
nice for playing around with inputs. Photocells give your creations
sight. Motors and motor drivers give you legs. I'm sure there's more
than enough scrounge around the space to get everyone started.
[This
Instructable](http://www.instructables.com/id/Ghetto-Development-Environment)
details my current setup, and is a good start.
[Category: AVR Tutorial](Category:_AVR_Tutorial "wikilink")
+392
View File
@@ -0,0 +1,392 @@
<nowiki>
# WinAVR Sample makefile written by Eric B. Weddington, J??rg Wunsch, et al.
# Modified (bringing often-changed options to the top) by Elliot Williams
# make all = Make software and program
# make clean = Clean out built project files.
# make program = Download the hex file to the device, using avrdude. Please
# customize the avrdude settings below first!
# Microcontroller Type
MCU = attiny13
# MCU = attiny2313
# MCU = atmega8
# MCU = attiny45
# Target file name (without extension).
TARGET = LED_Demo
# Programming hardware: type avrdude -c ?
# to get a full listing.
# AVRDUDE_PROGRAMMER = dapa
AVRDUDE_PROGRAMMER = usbtiny
# AVRDUDE_PROGRAMMER = dt006
AVRDUDE_PORT = /dev/usb # not really needed for usb
#AVRDUDE_PORT = /dev/parport0 # linux
# AVRDUDE_PORT = lpt1 # windows
############# Don't need to change below here for most purposes (Elliot)
# Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = s
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
# List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c
# If there is more than one source file, append them above, or modify and
# uncomment the following:
#SRC += foo.c bar.c
# You can also wrap lines by appending a backslash to the end of the line:
#SRC += baz.c \
#xyzzy.c
# List Assembler source files here.
# Make them always end in a capital .S. Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC =
# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
EXTRAINCDIRS =
# Optional compiler flags.
# -g: generate debugging information (for GDB, or for COFF conversion)
# -O*: optimization level
# -f...: tuning, see gcc manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlms: create assembler listing
CFLAGS = -g -O$(OPT) \
-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
-Wall -Wstrict-prototypes \
-Wa,-adhlns=$(<:.c=.lst) \
$(patsubst %,-I%,$(EXTRAINCDIRS))
# Set a "language standard" compiler flag.
# Unremark just one line below to set the language standard to use.
# gnu99 = C99 + GNU extensions. See GCC manual for more information.
#CFLAGS += -std=c89
#CFLAGS += -std=gnu89
#CFLAGS += -std=c99
CFLAGS += -std=gnu99
# Optional assembler flags.
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlms: create listing
# -gstabs: have the assembler create line number information; note that
# for use in COFF files, additional information about filenames
# and function names needs to be present in the assembler source
# files -- see avr-libc docs [FIXME: not yet described there]
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
# Optional linker flags.
# -Wl,...: tell GCC to pass this to linker.
# -Map: create map file
# --cref: add cross reference to map file
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
# Additional libraries
# Minimalistic printf version
#LDFLAGS += -Wl,-u,vfprintf -lprintf_min
# Floating point printf version (requires -lm below)
#LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
# -lm = math library
LDFLAGS += -lm
# Programming support using avrdude. Settings and variables.
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
# Uncomment the following if you want avrdude's erase cycle counter.
# Note that this counter needs to be initialized first using -Yn,
# see avrdude manual.
#AVRDUDE_ERASE += -y
# Uncomment the following if you do /not/ wish a verification to be
# performed after programming the device.
#AVRDUDE_FLAGS += -V
# Increase verbosity level. Please use this when submitting bug
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
# to submit bug reports.
#AVRDUDE_FLAGS += -v -v
#Run while cable attached or don't
AVRDUDE_FLAGS += -E reset #keep chip disabled while cable attached
#AVRDUDE_FLAGS += -E noreset
#AVRDUDE_WRITE_FLASH = -U lfuse:w:0x04:m #run with 8 Mhz clock
#AVRDUDE_WRITE_FLASH = -U lfuse:w:0x21:m #run with 1 Mhz clock #default clock mode
#AVRDUDE_WRITE_FLASH = -U lfuse:w:0x01:m #run with 1 Mhz clock no start up time
# ---------------------------------------------------------------------------
# Define directories, if needed.
DIRAVR = c:/winavr
DIRAVRBIN = $(DIRAVR)/bin
DIRAVRUTILS = $(DIRAVR)/utils/bin
DIRINC = .
DIRLIB = $(DIRAVR)/avr/lib
# Define programs and commands.
SHELL = sh
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
# Programming support using avrdude.
AVRDUDE = avrdude
REMOVE = rm -f
COPY = cp
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) -A $(TARGET).elf
# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = -------- end --------
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
MSG_COFF = Converting to AVR COFF:
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
MSG_FLASH = Creating load file for Flash:
MSG_EEPROM = Creating load file for EEPROM:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:
# Define all object files.
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
# Define all listing files.
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
# Default target: make program!
all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
$(TARGET).lss $(TARGET).sym sizeafter finished end
# $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
@echo
@echo $(MSG_BEGIN)
finished:
@echo $(MSG_ERRORS_NONE)
end:
@echo $(MSG_END)
@echo
# Display size of file.
sizebefore:
@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
sizeafter:
@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
# Display compiler version information.
gccversion :
@$(CC) --version
# Convert ELF to COFF for use in debugging / simulating in
# AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000
coff: $(TARGET).elf
@echo
@echo $(MSG_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
extcoff: $(TARGET).elf
@echo
@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
# Program the device.
program: $(TARGET).hex $(TARGET).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
@echo
@echo $(MSG_FLASH) $@
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
%.eep: %.elf
@echo
@echo $(MSG_EEPROM) $@
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
# Create extended listing file from ELF output file.
%.lss: %.elf
@echo
@echo $(MSG_EXTENDED_LISTING) $@
$(OBJDUMP) -h -S $< > $@
# Create a symbol table from ELF output file.
%.sym: %.elf
@echo
@echo $(MSG_SYMBOL_TABLE) $@
avr-nm -n $< > $@
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
# Compile: create object files from C source files.
%.o : %.c
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Compile: create assembler files from C source files.
%.s : %.c
$(CC) -S $(ALL_CFLAGS) $< -o $@
# Assemble: create object files from assembler source files.
%.o : %.S
@echo
@echo $(MSG_ASSEMBLING) $<
$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Target: clean project.
clean: begin clean_list finished end
clean_list :
@echo
@echo $(MSG_CLEANING)
$(REMOVE) $(TARGET).hex
$(REMOVE) $(TARGET).eep
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).cof
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).a90
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lnk
$(REMOVE) $(TARGET).lss
$(REMOVE) $(OBJ)
$(REMOVE) $(LST)
$(REMOVE) $(SRC:.c=.s)
$(REMOVE) $(SRC:.c=.d)
$(REMOVE) *~
# Automatically generate C source code dependencies.
# (Code originally taken from the GNU make user manual and modified
# (See README.txt Credits).)
#
# Note that this will work with sh (bash) and sed that is shipped with WinAVR
# (see the SHELL variable defined above).
# This may not work with other shells or other seds.
#
%.d: %.c
set -e; $(CC) -MM $(ALL_CFLAGS) $< \
| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
[ -s $@ ] || rm -f $@
# Remove the '-' if you want to see the dependency files generated.
-include $(SRC:.c=.d)
# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
clean clean_list program
</nowiki>
[Category: AVR Tutorial](Category:_AVR_Tutorial "wikilink")
+14
View File
@@ -0,0 +1,14 @@
We've had two rounds of the AVR Microcontroller class at HacDC so far.
- If you're looking to learn, see the 2011 class. [AVR Microcontroller
Class 2011](AVR_Microcontroller_Class_2011 "wikilink") (happened in
Feb/March 2011)
<!-- -->
- If you're looking for specific old materials, we're keeping that
online too! [AVR Microcontroller Class
2009](AVR_Microcontroller_Class_2009 "wikilink") (the first run of the
class)
[Category:AVR_Class](Category:AVR_Class "wikilink")
+180
View File
@@ -0,0 +1,180 @@
Syllabus, course material, homeworks, photos, etc from a previous
Introduction to Microcontrollers with AVR chips class can be found here.
For the current class, head on over to [AVR Microcontroller Class
2011](AVR_Microcontroller_Class_2011 "wikilink")
Also see (and contribute to) [Useful AVR
Links](Useful_AVR_Links "wikilink")
## Class 0: Introduction and Setup
What the AVRs are, what all the pins do, what they can do for you. Then
the toolchain: soldering together the programmer kits, getting the
software up and running.
Labs: building the kit and running a test LED flasher. (Almost all lab
today, little talk.)
**Resources**:
- Slides from class: [Media:class0.pdf](Media:class0.pdf "wikilink")
- ATmega48P Datasheets (get both): [ATmega48P Summary
Datasheet](http://www.atmel.com/dyn/resources/prod_documents/8025S.pdf)
and [The Long ATmega48P
Datasheet](http://www.atmel.com/dyn/resources/prod_documents/doc8025.pdf)
- Download the software part of the toolchain: For Mac folks: [AVR Mac
Pack](http://www.obdev.at/products/avrmacpack/index.html). For Windows
folks: [WinAVR](http://winavr.sourceforge.net/) and the Atmel IDE [AVR
Studio](http://www.atmel.com/dyn/products/tools_card.asp?tool_id=2725).
For Ubuntu linux folks: "sudo apt-get install build-essential avr-libc
binutils-avr gcc-avr avrdude"
- Programmer and mega48 pinouts:
![Image:FFVH7HBF5UO1JMR.MEDIUM.jpg](FFVH7HBF5UO1JMR.MEDIUM.jpg "Image:FFVH7HBF5UO1JMR.MEDIUM.jpg")
<img src="Screenshot-ATmega48-88-168.png"
title="Screenshot-ATmega48-88-168.png" width="320"
alt="Screenshot-ATmega48-88-168.png" />
## Class 1: Programmer Hookup and Hello World LED Blinking
Lecture on how the programmer works -- simple serial interface basics.
Some basics on avrdude / GCC tools. Hook up the programming interface
wire-by-wire to the Mega48 chip and flash it with a simple program. Then
hook up an LED to the output port and watch it blink!
**Resources**
- [helloWorld.zip](http://elliotwilliams.org/avrclass/helloWorld.zip)
<!-- -->
- Class notes: [Media:class1.pdf](Media:class1.pdf "wikilink")
<!-- -->
- Wiring Diagram:
<img src="wiring.png" title="wiring.png" width="520" alt="wiring.png" />
**Homeworks**
- Your kit has 10 resistors and 10 LEDs. If you want, you can solder
them together to make \[AVR: LED Blinkenlights\].
<!-- -->
- If you didn't already, make labels for the signal wires. Think of an
easy way to remember which go where (into the 6-pin or 10-pin header).
And/or make permanent programmer "pigtails" by soldering the signal
wires to a 2x3 header in the correct orientation (headers available in
the HacDC hackersmart for pennies).
<!-- -->
- Play around with the delays in the LED_Demo.c code. Make the blinking
faster or slower. Experiment with on time and off time.
## Class 2: Outputs: Bit Math, Cylon Eyes, and PWM Fading
How to make chips speak to the outside world, pin-by-pin. Enough C
bitwise-math operations to make it work. Pulse-width modulation.
Labs: Visualizing bytes, Cylon eyes, and dimming LED's. Extra credit:
cross-fading cylon eyes!
**Resources**
- [registers.zip](http://elliotwilliams.org/avrclass/registers.zip)
- [cylonEyes.zip](http://elliotwilliams.org/avrclass/cylonEyes.zip)
- [introPWM.zip](http://elliotwilliams.org/avrclass/introPWM.zip)
- Class notes: [Media:class2.pdf](Media:class2.pdf "wikilink")
**Homework**
- So you can make various lights blink and/or dim. Now what?
Cross-fading cylon eyes? Patterns? Something groovy?
<!-- -->
- Note that you've got an 8-bit display if you're willing to read out
numbers in binary. Useful for debugging later on, for sure. What else?
Binary clock? Simple upcounter? Display "random" numbers?
<!-- -->
- If you could swing it around, you'd be on your way to a [POV
toy](http://www.ladyada.net/make/minipov3/index.html).
## Class 3: Inputs: Buttons
Gather data from the world. The lecture ended up being just on digital
input.
Labs: One note organ [Media: class3.pdf](Media:_class3.pdf "wikilink")
## Class 4: Inputs: Debouncing and Analog-to-Digital conversion (ADC)
This class, we'll get to debouncing our button input, and reading in
continuous voltages
For more info on ADC stuff, see [this
note](http://www.avrfreaks.net/index.php?module=Freaks%20Files&func=viewFile&id=383&showinfo=1)
Labs: pushbutton organ, light-dependent theremin.
[Media: class4.pdf](Media:_class4.pdf "wikilink")
[Media:
debouncedMusicbox.zip](Media:_debouncedMusicbox.zip "wikilink")
[Media:
lightDependentTheremin.zip](Media:_lightDependentTheremin.zip "wikilink")
## Class 5: Serial I/O and Interrupts I
Laptop, meet AVR. AVR, laptop. Serial communication (plus serial-to-USB
cable) lets you connect your micro to about anything, including your
computer. Interrupts let the hardware (pins, serial port, timers, etc)
call run functions for you, with the main body of your code picking up
where you left off. Combine the two, and you can get pushbutton control
of an AVR from your laptop keyboard.
[Media: helloSerial.zip](Media:_helloSerial.zip "wikilink")
[Media: helloInterrupts.zip](Media:_helloInterrupts.zip "wikilink")
[Media: class5.pdf](Media:_class5.pdf "wikilink")
And as a bonus, if you run Python,
[serialScope.py](http://www.jerkpile.com/serialScope.py) provides a
helpful debugging tool and an example of how simple USB/Serial code can
be on the laptop side. Coupled with on-chip ADC, it's a (low speed,
sideways) serial oscilloscope. Otherwise, a handy debugging aide.
**Homework:** Take the scale.h from last class, and using input from
your laptop, make a full keyboard out of the AVR plus speaker. Or write
a ROT-13 device that takes your input and returns the encoded version.
## Class 6: Timers/Counters and Interrupts II
Timers/counters let you do precision things with time. Fix up that nasty
audio tone from the LDR theremin. Precise timing allows you to use LED's
as light sensors. It's also good for making quality analog output and
for directing servo motors. Interrupts + timers = deluxe PWM. Or give
your AVR a solid internal timebase. (You know you want to.) In this
class, we'll scratch the surface of what you can do with timers.
[Media: timerPWM.zip](Media:_timerPWM.zip "wikilink")
[Media:
timerPWM_ctc_hardware_toggle.c](Media:_timerPWM_ctc_hardware_toggle.c "wikilink")
## Extra Credit: I2C
Talked a bit about the I2C serial protocol -- a light-weight serial
multi-master bus using two wires (plus ground) and capable of addressing
127 different devices. Great for connecting to all sorts of peripherals.
Demoed an \$20 I2C 3-axis accelerometer using bare-minimum I2C code,
with none of the error-checking that the pro's would do. But it works a
charm. That's why it's called hacking, baby!
[Media: i2c_class.pdf](Media:_i2c_class.pdf "wikilink")
[Media: i2c_accelerometer.zip](Media:_i2c_accelerometer.zip "wikilink")
[Category:AVR_Class](Category:AVR_Class "wikilink")
+171
View File
@@ -0,0 +1,171 @@
Syllabus, course material, homeworks, photos, etc from an Introduction
to Microcontrollers with AVR chips class can be found here.
Also see (and contribute to) [Useful AVR
Links](Useful_AVR_Links "wikilink") For info about the kit:
[Avr2011_kit](Avr2011_kit "wikilink") and [Avr2011 Programming The
Kit](Avr2011_Programming_The_Kit "wikilink") Or check out the old
version of the course [AVR Microcontroller Class
2009](AVR_Microcontroller_Class_2009 "wikilink")
## Class 0: Introduction and Setup
Hello World!
**Covers**: What the AVRs are, what all the pins do, what they can do
for you. A brief tour of the toolchain, and getting your firmware up and
running on the chip. Reading the datasheets. How to make chips speak
digital to the outside world, pin-by-pin. Just enough C programming
fundamentals to make it work.
**Slides:**
[Media:avr2011_class0.pdf](Media:avr2011_class0.pdf "wikilink")
**Lab**: Building the kit and running a test LED flasher.
For assembly instructions and more details on the class kit, see
[Avr2011_kit](Avr2011_kit "wikilink"). How to program the class kit, see
[Avr2011 Programming The Kit](Avr2011_Programming_The_Kit "wikilink").
**Demo Code**: [Media: LED_Demo.tgz](Media:_LED_Demo.tgz "wikilink")
**Homework**: More soldering, and Cylon Eyes. Optional extra credit:
Simple POV toy (hint, make the timing around 2ms between updates and
swing your arms). Super bonus points: Make a neat POV toy.
**OPC (Other People's Code)**:
[Media: Pov demo.tar.gz](Media:_Pov_demo.tar.gz "wikilink") An example
POV toy. This contains 4 different patterns; two diamonds, a trapezoid
and a **smiley face**. Also contains examples of using a character array
to drive the POV toy, as well as use of constants to determine how the
program runs. - Will
**Resources**:
- ATmega48P Datasheets (get both): [ATmega48P Summary
Datasheet](http://www.atmel.com/dyn/resources/prod_documents/8025S.pdf)
and [The Long ATmega48P
Datasheet](http://www.atmel.com/dyn/resources/prod_documents/doc8025.pdf)
- Bootloader appnote
[1](http://www.atmel.com/dyn/resources/prod_documents/doc1644.pdf)
- [Installing AVR Toolchain](Installing_AVR_Toolchain "wikilink")
<figure>
<img src="Screenshot-ATmega48-88-168.png"
title="Screenshot-ATmega48-88-168.png" width="500" />
<figcaption>Screenshot-ATmega48-88-168.png</figcaption>
</figure>
## Class 1: Digital and Serial I/O
Interfacing with the real world is the soul of microcontrolling.
**Covers**: Gathering simple data from the world, and learn how to spit
it back out. A serial link with your computer enables all sorts of
tricks, and enables the microcontroller version of printf debugging.
Some boolean logic comes in handy here. Along the way, we'll learn a
bunch about debouncing switches.
**Slides**:
[Media:avr2011_class1.pdf](Media:avr2011_class1.pdf "wikilink")
**Labs**: More Cylon Eyes, All sorts of button-pressing demos,
ASCII-to-binary keymapper, General-purpose serial LED display
**Demo Code**: [Media:
avr2011_class1_demoCode.tgz](Media:_avr2011_class1_demoCode.tgz "wikilink")
**HW**: Ghetto logic probe and analyzer: read input on PORTC, display
values on the LEDs, write out the value of PINC over serial,
interpret/log/whatever using your laptop
**OPC (Other People's Code)**: [microTweeter](microTweeter "wikilink") a
silly little program to interface twitter with a microcontroller. It is
designed to post quotes from a file when a button is pressed on a
microcontroller. This was done as learning experience with python,
serial communications and social media integration. -Will G.
**Resources**:
- More than you ever wanted to know about debouncing: [A Guide to
Debouncing](http://www.ganssle.com/debouncing.htm)
## Class 2: ADC and PWM: "Analog" I/O
**Covers**: Learn about ways to fake analog data into and out of your
microcontroller. We'll learn how to switch logic states fast to emulate
an analog output, and how to use the built-in analog-to-digital
converters to measure the complex real-world.
**Slides**:
[Media:avr2011_class2.pdf](Media:avr2011_class2.pdf "wikilink")
**Demo Code**: [Media:
avr2011_class2_demoCode.tgz](Media:_avr2011_class2_demoCode.tgz "wikilink")
**Labs**: Dimming LEDs, light-level meter, ghetto oscilloscope
**Homework**: Auto-dimming LED or basic light-level data logger
**Resources**: You'll need to solder up the light sensors: [follow these
directions](http://wiki.hacdc.org/index.php/Avr2011_kit#Adding_the_Light_Sensor_for_Class_2_.28ADC.29)
## Class 3: Interrupts
**Covers**: Interrupts call subroutines when certain conditions are
true. They take a lot of the programming burden off your shoulders,
enable the AVR to syncronize to external devices, and are great for
super-fast response applications.
**Slides**: [Media:
avr2011_class3.pdf](Media:_avr2011_class3.pdf "wikilink")
**Demo Code**: [Media:
avr2011_externalInterrupt.tgz](Media:_avr2011_externalInterrupt.tgz "wikilink"),
[Media:
avr2011_serialInterrupt.tgz](Media:_avr2011_serialInterrupt.tgz "wikilink")
**Labs**: Bunch of pushbutton interrupt routines, light/dark transition
sensor, non-blocking serial I/O
**Homework**: Response-time-tester Game or "improved" interrupt-driven
ghetto oscilloscope
**Resources**:
## Class 4: Timers and Counters
**Covers**: Timers and counters let you time and count events! Up until
now, we've been doing a lot with for loops and delays to count the
passing of time. It's much easier and more precise to let the hardware
do the timing. When you add interrupts and timers together, the world
becomes your oyster!
**Slides**: [Media:
avr2011_class4.pdf](Media:_avr2011_class4.pdf "wikilink")
**Demo Code**: [Media:
avr2011_counterClock.tgz](Media:_avr2011_counterClock.tgz "wikilink")
[Media:
avr2011_counterPWM.tgz](Media:_avr2011_counterPWM.tgz "wikilink")
**Labs**:
**Homework**: Response-time-tester Game or tone generator
## Class 5: Flash, EEPROM, I2C, USB, SD Cards, GPS, and Life After AVR Class
**Covers**: First, we'll cover using the internal flash memory and
EEPROM for data storage. Then I'll demo how to use other people's
code/libraries and tie it in to our packages, interfacing with all sorts
of random devices for fun and profit. The final (optional) trick will be
turning your classboard into a standalone AVR programmer so that you can
program raw chips yourself, and outgrow the bootloader.
**Labs**:
**Homework**:
[Category:Microcontrollers](Category:Microcontrollers "wikilink")
[Category:AVR_Class](Category:AVR_Class "wikilink")
+150
View File
@@ -0,0 +1,150 @@
## Noise Toys
To turn a blinky LED program into a simple square-wave synthesizer, plug
a speaker into PB4 and ground (where the LED was before), and turn up
the frequency.
The code is largely the same, just toggling a pin on and off, but now
doing it at different speeds (for different tones) and for differing
time periods (notes duration).
## squareOne.c
<nowiki>
/* Makes a quick square wave for noise-making experimentation. */
#include <inttypes.h>
#include <avr/io.h>
#define F_CPU 16000000L /* really? tested with the scope for Tiny45 */
#include <util/delay.h>
void init(void){
DDRB |= _BV(PB4);
}
int main(void){
uint8_t i, j, k;
uint16_t wavelength;
init();
while(1){
for (k = 10; k > 3; k--){ /* pitch multiplier: makes different notes */
wavelength = 20*k;
for (j=0; j < 200/k; j++){
/* number of cycles at each pitch: controls speed of loop */
PORTB |= _BV(PB4);
for (i=0; i < wavelength; i++) /* on for 20*wavelength microsecs */
_delay_us(20); /* loop needed b/c each call to
the delay function can't
delay all that long before
it overflows */
PORTB &= ~_BV(PB4); /* off for 20*wavelength microsecs */
for (i=0; i < wavelength; i++)
_delay_us(20);
}
}
}
}
</nowiki>
## spacePhaser.c
<nowiki>
/* Starts with a very short pulse (high-frequency) and drops rapidly. */
#include <inttypes.h>
#include <avr/io.h>
#define F_CPU 16000000L /* really? tested with the scope */
#include <util/delay.h>
void init(void){
DDRB |= _BV(PB4);
}
int main(void){
uint8_t i, j, k;
uint16_t wavelength;
init();
while(1){
for (k = 3; k < 120; k++){ /* pitch multiplier: makes different notes */
wavelength = k;
for (j=0; j < 200/k; j++){
/* number of cycles at each pitch: controls speed of loop */
PORTB |= _BV(PB4);
for (i=0; i < wavelength; i++) /* on for 20*wavelength microsecs */
_delay_us(20); /* loop needed b/c each call to
the delay function can't
delay all that long before
it overflows */
PORTB &= ~_BV(PB4); /* off for 20*wavelength microsecs */
for (i=0; i < wavelength; i++)
_delay_us(20);
}
}
for (j=0; j < 60; j++){ /* with delay between shots */
for (i=0; i < 250; i++)
_delay_us(200);
}
}
}
</nowiki>
## chaosEngine.c
<nowiki>
/* Now the frequency of the wave is a crazy function. */
#include <inttypes.h>
#include <avr/io.h>
#define F_CPU 16000000L /* really? tested with the scope */
#include <util/delay.h>
void init(void){
DDRB |= _BV(PB4);
}
int main(void){
uint8_t i, j, k;
uint16_t wavelength;
init();
while(1){
wavelength = (13 * wavelength + 1) % 123 + 100;
for (j=0; j < 30; j++){
/* number of cycles at each pitch */
PORTB |= _BV(PB4);
for (i=0; i < wavelength; i++) /* on for 20*wavelength microsecs */
_delay_us(20); /* loop needed b/c each call to
the delay function can't
delay all that long before
it overflows */
PORTB &= ~_BV(PB4); /* off for 20*wavelength microsecs */
for (i=0; i < wavelength; i++)
_delay_us(20);
}
}
for (j=0; j < 60; j++){ /* longer delay between shots */
for (i=0; i < 250; i++)
_delay_us(200);
}
}
</nowiki>
[Category: AVR Tutorial](Category:_AVR_Tutorial "wikilink")
+71
View File
@@ -0,0 +1,71 @@
Warning: this page is a nearly-completely incomplete skeleton. For the
class (and supporting materials) that actually came to be, see [AVR
Microcontroller Class](AVR_Microcontroller_Class "wikilink"). This
section needs a lot of development, so if you're in the mood please feel
free.
There's a lot of good information out there about programming
micro-controllers, but I couldn't find a good, stepwise, lesson-based
tutorial. Since a bunch of the HacDC folks are just learning their way
around, I thought it'd be fun to put together a mini-course based on the
Atmel AVR platform and GNU-GCC. The idea is to have each lesson doable
in an hour or so
What follows is a mix of how-to and code snippets and peoples'
experience walking through it all. If you're following along and want to
contribute, feel free.
[Useful AVR Links](Useful_AVR_Links "wikilink")
## The Basics (take these in order):
[AVR Lesson: Setup](AVR_Lesson:_Setup "wikilink"): Get a programmer, a
chip, the software, and some parts
[AVR Lesson: Output Pins I](AVR_Lesson:_Output_Pins_I "wikilink"): Basic
output and LED Blinky example
[AVR Lesson: Output Pins II](AVR_Lesson:_Output_Pins_II "wikilink"):
Binary math and Cylon Eyes
[AVR Lesson: Input Pins](AVR_Lesson:_Input_Pins "wikilink"): Debouncing
and Button-triggered Cylon Eyes
[AVR Lesson: Timers](AVR_Lesson:_Timers "wikilink"): Clocks and how to
use them.
[AVR Lesson: Interrupts](AVR_Lesson:_Interrupts "wikilink"):
[AVR Lesson: Pulse-width
Modulation](AVR_Lesson:_Pulse-width_Modulation "wikilink"): An easy way
to get analog outputs. Dimming LEDs or Crossfading Cylon Eyes
[AVR Lesson: Analog-digital
Conversion](AVR_Lesson:_Analog-digital_Conversion "wikilink"):
Automatical Dimming Night Light
## Advanced Material (mix-n-match):
[AVR Lesson: Watchdog Timers](AVR_Lesson:_Watchdog_Timers "wikilink"):
[AVR Lesson: I2C](AVR_Lesson:_I2C "wikilink")
[AVR Lesson: Using Program
Memory](AVR_Lesson:_Using_Program_Memory "wikilink"):
[AVR Lesson: Motor Driving](AVR_Lesson:_Motor_Driving "wikilink"):
[AVR Lesson: Servo Control](AVR_Lesson:_Servo_Control "wikilink"):
[AVR Lesson: State Machines](AVR_Lesson:_State_Machines "wikilink"):
[AVR Lesson: Sound](AVR_Lesson:_Sound "wikilink"):
[AVR Lesson: Serial I/O](AVR_Lesson:_Serial_I/O "wikilink"):
[AVR Lesson: USB](AVR_Lesson:_USB "wikilink"):
[AVR Lesson: Interfacing with External
Memory](AVR_Lesson:_Interfacing_with_External_Memory "wikilink")
[Category: AVR Tutorial](Category:_AVR_Tutorial "wikilink")
@@ -0,0 +1,36 @@
So you want to program an AVR, but you don't have a programmer? Do you
have a parallel port? Then fear not!
The AVR chips are set up to flash their program memory through a serial
connection with the host computer, so programming them is mostly a
matter of getting the right lines to the chip, with the rest taken care
of by the AVRdude software.
The simplest way to get started is with one of the parallel-port
"programmers". The basic procedure is to a) look at the docs for
AVRdude's various parallel port adapters, b) look at the pinouts for the
chip you're using, and c) wire the right pins on the parallel port to
the right pins on your AVR.
For instance, the DAPA (Direct AVR Parallel Access) "programmer" makes
the following connections between the parallel port pins and the AVR:
| Parallel Pin | AVR |
|--------------|-------|
| 1 | SCK |
| 2 | MOSI |
| 11 | MISO |
| 16 | RESET |
| 20 | GND |
| 21 | GND |
Connect the wires and test it out! Type **avrdude -n -v -p tiny13 -c
dapa** and you should see your part recognized and the fuse settings
displayed. (Make sure to substitute your part name for tiny13. Type
**avrdude -p help** to see the list of supported parts.)
For a much more complicated boot strap technique, there is the [secure
bootloader](secure_bootloader "wikilink") that uses AES encrypted
firmware images.
[Category: AVR Tutorial](Category:_AVR_Tutorial "wikilink")
+35
View File
@@ -0,0 +1,35 @@
Cut and paste the following into a file called LED_Demo.c
/* Blinker Demo */
#include <avr/io.h> /* Defines pins, ports, etc */
#define F_CPU 8000000UL /* Sets up the chip speed for delay.h */
#include <util/delay.h> /* Functions to waste time */
#define LED PB0 /* Defines pin PB0 for the LED. I
often include a bunch of the circuit
info in the code this way, which
makes porting the code to another
chip easier and reminds you of how to
hook it up. */
void main(void){
DDRB = _BV(LED); /* Data Direction Register B:
writing a one to the bit
enables output. More on the
_BV() macro in the next
lesson. */
while(1){ /* the main loop, from which we never return */
PORTB = _BV(LED); /* Turn on the LED bit/pin in PORTB */
_delay_ms(400); /* wait */
PORTB = 0; /* Turn off everything(!) on PORTB */
_delay_ms(400); /* wait */
}
}
[Category:Microcontrollers](Category:Microcontrollers "wikilink")
+400
View File
@@ -0,0 +1,400 @@
Cut and paste the following into a file called Makefile in the same
directory as the LED_Demo.c
# WinAVR Sample makefile written by Eric B. Weddington, J??rg Wunsch, et al.
# Modified (bringing often-changed options to the top) by Elliot Williams
# make all = Make software and program
# make clean = Clean out built project files.
# make program = Download the hex file to the device, using avrdude. Please
# customize the avrdude settings below first!
# Microcontroller Type
#MCU = attiny13
# MCU = attiny2313
# MCU = atmega8
# MCU = attiny45
# MCU = atmega88
MCU = atmega88
# Target file name (without extension).
TARGET = LED_Demo
# Programming hardware: type avrdude -c ?
# to get a full listing.
# AVRDUDE_PROGRAMMER = dapa
#AVRDUDE_PROGRAMMER = usbtiny # Note: have to use sudo make for USB
# AVRDUDE_PROGRAMMER = dt006
AVRDUDE_PROGRAMMER = avr109
#AVRDUDE_PORT = /dev/usb # dummy, but it's fun :)
#AVRDUDE_PORT = /dev/parport0 # linux
# AVRDUDE_PORT = lpt1 # windows
AVRDUDE_PORT = /dev/ttyUSB0
BAUD_RATE = 9600
############# Don't need to change below here for most purposes (Elliot)
# Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = s
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
# List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c
# If there is more than one source file, append them above, or modify and
# uncomment the following:
#SRC += foo.c bar.c
# You can also wrap lines by appending a backslash to the end of the line:
#SRC += baz.c \
#xyzzy.c
# List Assembler source files here.
# Make them always end in a capital .S. Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC =
# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
EXTRAINCDIRS =
# Optional compiler flags.
# -g: generate debugging information (for GDB, or for COFF conversion)
# -O*: optimization level
# -f...: tuning, see gcc manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlms: create assembler listing
CFLAGS = -g -O$(OPT) \
-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
-Wall -Wstrict-prototypes \
-Wa,-adhlns=$(<:.c=.lst) \
$(patsubst %,-I%,$(EXTRAINCDIRS))
# Set a "language standard" compiler flag.
# Unremark just one line below to set the language standard to use.
# gnu99 = C99 + GNU extensions. See GCC manual for more information.
#CFLAGS += -std=c89
#CFLAGS += -std=gnu89
#CFLAGS += -std=c99
CFLAGS += -std=gnu99
# Optional assembler flags.
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlms: create listing
# -gstabs: have the assembler create line number information; note that
# for use in COFF files, additional information about filenames
# and function names needs to be present in the assembler source
# files -- see avr-libc docs [FIXME: not yet described there]
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
# Optional linker flags.
# -Wl,...: tell GCC to pass this to linker.
# -Map: create map file
# --cref: add cross reference to map file
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
# Additional libraries
# Minimalistic printf version
#LDFLAGS += -Wl,-u,vfprintf -lprintf_min
# Floating point printf version (requires -lm below)
#LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
# -lm = math library
LDFLAGS += -lm
# Programming support using avrdude. Settings and variables.
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
# Uncomment the following if you want avrdude's erase cycle counter.
# Note that this counter needs to be initialized first using -Yn,
# see avrdude manual.
#AVRDUDE_ERASE += -y
# Uncomment the following if you do /not/ wish a verification to be
# performed after programming the device.
#AVRDUDE_FLAGS += -V
# Increase verbosity level. Please use this when submitting bug
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
# to submit bug reports.
#AVRDUDE_FLAGS += -v -v
#Run while cable attached or don't
AVRDUDE_FLAGS += -F # -E reset #keep chip disabled while cable attached
#AVRDUDE_FLAGS += -E noreset
## For AVR109 Bootload Programmer
AVRDUDE_FLAGS += -b $(BAUD_RATE)
#AVRDUDE_WRITE_FLASH = -U lfuse:w:0x04:m #run with 8 Mhz clock
#AVRDUDE_WRITE_FLASH = -U lfuse:w:0x21:m #run with 1 Mhz clock #default clock mode
#AVRDUDE_WRITE_FLASH = -U lfuse:w:0x01:m #run with 1 Mhz clock no start up time
# ---------------------------------------------------------------------------
# Define directories, if needed.
DIRAVR = c:/winavr
DIRAVRBIN = $(DIRAVR)/bin
DIRAVRUTILS = $(DIRAVR)/utils/bin
DIRINC = .
DIRLIB = $(DIRAVR)/avr/lib
# Define programs and commands.
SHELL = sh
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
# Programming support using avrdude.
AVRDUDE = avrdude
REMOVE = rm -f
COPY = cp
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) -A $(TARGET).elf
# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = -------- end --------
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
MSG_COFF = Converting to AVR COFF:
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
MSG_FLASH = Creating load file for Flash:
MSG_EEPROM = Creating load file for EEPROM:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:
# Define all object files.
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
# Define all listing files.
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
# Default target: make program!
all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
$(TARGET).lss $(TARGET).sym sizeafter finished end
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
@echo
@echo $(MSG_BEGIN)
finished:
@echo $(MSG_ERRORS_NONE)
end:
@echo $(MSG_END)
@echo
# Display size of file.
sizebefore:
@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
sizeafter:
@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
# Display compiler version information.
gccversion :
@$(CC) --version
# Convert ELF to COFF for use in debugging / simulating in
# AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000
coff: $(TARGET).elf
@echo
@echo $(MSG_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
extcoff: $(TARGET).elf
@echo
@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
# Program the device.
program: $(TARGET).hex $(TARGET).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
@echo
@echo $(MSG_FLASH) $@
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
%.eep: %.elf
@echo
@echo $(MSG_EEPROM) $@
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
# Create extended listing file from ELF output file.
%.lss: %.elf
@echo
@echo $(MSG_EXTENDED_LISTING) $@
$(OBJDUMP) -h -S $< > $@
# Create a symbol table from ELF output file.
%.sym: %.elf
@echo
@echo $(MSG_SYMBOL_TABLE) $@
avr-nm -n $< > $@
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
# Compile: create object files from C source files.
%.o : %.c
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Compile: create assembler files from C source files.
%.s : %.c
$(CC) -S $(ALL_CFLAGS) $< -o $@
# Assemble: create object files from assembler source files.
%.o : %.S
@echo
@echo $(MSG_ASSEMBLING) $<
$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Target: clean project.
clean: begin clean_list finished end
clean_list :
@echo
@echo $(MSG_CLEANING)
$(REMOVE) $(TARGET).hex
$(REMOVE) $(TARGET).eep
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).cof
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).a90
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lnk
$(REMOVE) $(TARGET).lss
$(REMOVE) $(OBJ)
$(REMOVE) $(LST)
$(REMOVE) $(SRC:.c=.s)
$(REMOVE) $(SRC:.c=.d)
$(REMOVE) *~
# Automatically generate C source code dependencies.
# (Code originally taken from the GNU make user manual and modified
# (See README.txt Credits).)
#
# Note that this will work with sh (bash) and sed that is shipped with WinAVR
# (see the SHELL variable defined above).
# This may not work with other shells or other seds.
#
%.d: %.c
set -e; $(CC) -MM $(ALL_CFLAGS) $< \
| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
[ -s $@ ] || rm -f $@
# Remove the '-' if you want to see the dependency files generated.
-include $(SRC:.c=.d)
# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
clean clean_list program
[Category:Microcontrollers](Category:Microcontrollers "wikilink")
+105
View File
@@ -0,0 +1,105 @@
# Software:
If you haven't already installed the laptop-side software toolchain, see
[Installing AVR Toolchain](Installing_AVR_Toolchain "wikilink") and come
on back.
# Hookup:
- your laptop
- an FTDI cable
- the classboard, populated with chip and FTDI header
The chips we use in class are pre-flashed with a bootloader, which means
that you can program them over the AVR's serial port.
Plug the FTDI cable into the board -- black wire to GND.
<figure>
<img src="_avr2011_cable_hookup.jpg" title="_avr2011_cable_hookup.jpg"
width="500" />
<figcaption>_avr2011_cable_hookup.jpg</figcaption>
</figure>
# Getting the Board Into Bootloader Mode
When the chip starts up, the bootloader program checks if the "B" button
(connected to PD2) is pressed. If the button is pressed, it sits and
waits for programming data to come in over the serial line. If the
button isn't pressed, it starts your program. So, what you want to do is
reset the chip while the "B" button is pressed.
To get the chip into ready-to-program Bootloader Mode:
- Hold down the "B" button
- Tap the "A" button (RESET)
- Now you can release the "B" button
You can tell you're in bootloader mode because your normal code won't be
running. If you had and LED on or blinking, for instance, it won't be
now.
# Programming the Chip
- Get the chip into bootloader mode
- While you're in the directory with your code and the Makefile, type
"make" or "sudo make" into the terminal
- Your code will compile, and it will upload your code to the chip
- The chip will automatically reset and start running your program
If all is well, you will see
avrdude: erasing chip
avrdude: reading input file "LED_Demo.hex"
avrdude: input file LED_Demo.hex auto detected as Intel Hex
avrdude: writing flash (156 bytes):
Writing | ################################################## | 100% 0.21s
avrdude: 156 bytes of flash written
avrdude: verifying flash memory against LED_Demo.hex:
avrdude: load data flash data from input file LED_Demo.hex:
avrdude: input file LED_Demo.hex auto detected as Intel Hex
avrdude: input file LED_Demo.hex contains 156 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 0.19s
avrdude: verifying ...
avrdude: 156 bytes of flash verified
avrdude: safemode: Fuses OK
avrdude done. Thank you.
# If there are errors...
Common problems and their solutions include:
- Permissions to write to USB port. Solution: keep typing "sudo make" or
add yourself to the USB output group:
Ubuntu: sudo usermod -a -G dialout yourNameHere
<!-- -->
- /dev/ttyUSB0 not found. Is the FTDI cable plugged in? Try "lsusb" to
see if it's there. Try "ls /dev/ttyUSB\*" to see if it's registered as
USB1. Edit Makefile accordingly, and remember that you'll probably
have to change it back later.
<!-- -->
- Bugs in your code -\> failure to compile. If you get something like:
`Compiling: LED_Demo.c`
`LED_Demo.c: In function ???main???:`
`LED_Demo.c:22: error: expected ???;??? before ???while???`
`make: *** [LED_Demo.o] Error 1`
you have an error in your code that's preventing compilation. Read the
error output for hints, tweak your code, and try again. (In this case,
I left out a ';' in line 20.)
[Category:AVR_Class](Category:AVR_Class "wikilink")
+244
View File
@@ -0,0 +1,244 @@
### Kit Contents
You will need:
1\) AVR ATMega microcontroller 2) AVR Classboard printed-circuit-board
3) Eight resistors (~120 ohm) 4) Eight LEDs (I like the small square
ones) 5) 1 uF capacitor 6) 0.1 uF capacitor 7) Two push buttons 8) 6-pin
header to connect the FTDI serial cable 9) A small-signal diode for
backward-power protection (optional, but certainly won't hurt)
<figure>
<img src="_avr2011_kitContents.jpg" title="_avr2011_kitContents.jpg"
width="500" />
<figcaption>_avr2011_kitContents.jpg</figcaption>
</figure>
(D'oh! I left the AVR out of the photo. You should have one.)
### A Brief Tour of the Board
Before you start assembling anything, have a look at the printed circuit
board.
<figure>
<img src="avr2011_pcb.jpg" title="avr2011_pcb.jpg" width="500" />
<figcaption>avr2011_pcb.jpg</figcaption>
</figure>
Big and bold in the center is the location for the AVR chip. Notice the
notch in the silkscreen at one end? That corresponds to a notch on the
top of the AVR chip, and helps you get it in the right orientation when
the time comes.
Just to the outside of the AVR chip itself, you'll see two rows of holes
labelled for the port/pin combinations that appear in the datasheet. For
instance, just below the chip see the two rows labelled PORTD, and PD0
-- PD7. See how there are tiny white lines connecting the two rows of
holes, pairwise? Those indicate that the two holes are electrically
connected to each other. This was a convenience -- you can solder two
things easily to each AVR pin. One side of the chip has PD0-PD7, the
other has PB0-PB7 and PC0-PC6.
Just outside of the AVR connection points, you'll see two more rows of
holes, labelled VCC and GND respectively. GND is connected to the
board's ground plane, and so is at 0V. VCC is connected to the board's
power supply and is whatever voltage you're using to drive the whole
mess -- In class, I'll refer to this as VCC or I usually just call this
5V.
And finally, at the edge of the board is another pair of rows of holes.
These are electrically connected in pairs, and are just there to allow
you to connect things together easily. For the LED array, we'll use
these paired holes to connect the resistor to the positive end of the
LED.
Other stuff:
To the left of the AVR, there are holes for two buttons, a protection
diode, power-supply buffering capacitors, an optional power LED and its
resistor, a 3x2 SPI programming header, and the 6-pin inline FTDI cable.
Below the AVR chip area and to the right, there's more prototyping space
-- just sets of holes electrically connected to each other in ways to
facilitate soldering stuff up.
The power LED and it's associated LED are optional and included for your
creative use/abuse. Everyone should solder the coolest LED they can find
in here, with a 100-1k ohm resistor, depending on how bright you want
it.
And those white areas? They're for writing your initials on. Or notes.
Tiny, little notes.
### Assembling the Kit
0\) If you're new at soldering (or even if you're not) go spend seven
minutes with [the best soldering video
ever](http://www.youtube.com/watch?v=I_NU2ruzyc4).
1\) To get your feet wet soldering, install the two capacitors. They can
go in either capacitor position, and are non-polarized (can go in either
way). When you clip off the leads from the capacitors, save the wire for
the next step.
2\) Now install the two pushbuttons. They're oblong, but there's no top
or bottom.
3\) Solder in the protection diode. Notice that it's polarized, with a
black band on the diode itself corresponding to the little band in the
silkscreen.
4\) Above the buttons, there are two pairs of holes -- these connect the
button to the pin on the AVR when they're jumpered together. (I did this
for flexibility so that you could connect the buttons up to other pins
later as you wish.) Take two of the leads you saved in step 1) and
connect each pair of holes together.
<figure>
<img src="avr2011_jumpers.jpg" title="avr2011_jumpers.jpg"
width="500" />
<figcaption>avr2011_jumpers.jpg</figcaption>
</figure>
5\) Solder in the 6-pin header for the FTDI cable. Rather than doing it
the way I did (which covers the labels on the circuit board) why not
mount the header on the bottom side like Ed did?
<figure>
<img src="avr2011_ftdiInstall.jpg" title="avr2011_ftdiInstall.jpg"
width="500" />
<figcaption>avr2011_ftdiInstall.jpg</figcaption>
</figure>
6\) Now start on the LEDs -- in PORTB pins PB0 through PB7. They _are_
polarized, and you'll notice that one lead is longer than the other. The
short lead gets connected to ground, while the long lead will eventually
connect through a resistor to the AVR output pins. (Resistors soldered
in next step.) Place the LEDs so that their short leads are in the
ground strip (labelled GND), and the long lead is in one of the outside
rows of hookup holes. Orientation matters here. Double-check it before
soldering?
<figure>
<img src="avr1022_rowLEDs.jpg" title="avr1022_rowLEDs.jpg"
width="500" />
<figcaption>avr1022_rowLEDs.jpg</figcaption>
</figure>
For aligning the LEDs, I had success putting them all face-down on the
table, and using the fact that they have rectangular faces. Pro-tip:
solder one pin on each LED, make sure they're in a nice line, and
re-heat any that you need to wiggle into place. Then solder in the
second pin on each LED.
<figure>
<img src="avr2011_aligningLEDs.jpg" title="avr2011_aligningLEDs.jpg"
width="500" />
<figcaption>avr2011_aligningLEDs.jpg</figcaption>
</figure>
7\) Once you've done the LEDs, you can solder in their resistors. These
fit most easily and cleanly on the underside of the board, so you'll
want to trim off the extra leads from the LEDs before installing. You
want to solder each resistor to the outside strip of holes that
connected to the positive (long) pin of the LEDs, and the other end of
the resistor to the pins of the AVR. Notice that you're working on the
back-side of the board! Double-check that you're not connecting the
resistor to the VCC line that is closest to the LED.
<img src="avr2011_LEDresistors.jpg" title="avr2011_LEDresistors.jpg"
width="300" alt="avr2011_LEDresistors.jpg" />
<img src="avr2011_LEDresistors_top.jpg"
title="avr2011_LEDresistors_top.jpg" width="300"
alt="avr2011_LEDresistors_top.jpg" />
<img src="avr2011_LEDresistors_bottom_done.jpg"
title="avr2011_LEDresistors_bottom_done.jpg" width="300"
alt="avr2011_LEDresistors_bottom_done.jpg" />
8\) At this point, you can install the chip. They come from the factory
with the pins splayed out a little bit -- you can lean the chip into a
tabletop to straighten the pins out. Place the chip with the notch on
the top of the chip corresponding to the notch in the silkscreen.
Double-check. Solder.
<img src="_avr2011_chipBending.jpg" title="_avr2011_chipBending.jpg"
width="400" alt="_avr2011_chipBending.jpg" />
<img src="_avr2011_chipAlignment.jpg" title="_avr2011_chipAlignment.jpg"
width="400" alt="_avr2011_chipAlignment.jpg" />
9\) Optional fun stuff: Feel free to solder in an artistic power LED and
its resistor. (Note the polarization. Short pin downwards, or notice
that there's a flat-spot on the LED flange.) Write your name on it. Wire
up the battery (black wire to GND).
<img src="_avr2011_kitDone.jpg" title="_avr2011_kitDone.jpg" width="400"
alt="_avr2011_kitDone.jpg" />
<img src="_avr2011_kitDone2.jpg" title="_avr2011_kitDone2.jpg"
width="400" alt="_avr2011_kitDone2.jpg" />
10\) You should now be ready to flash in your first program. Hooray.
From here on it's (mostly) firmware!
### Adding the Light Sensor for Class 2 (ADC)
For the light sensor, you're creating a voltage divider with the
photoresistor and two legs of the potentiometer used as a variable
resistor. The photoresistor is connected to VCC and the AVR pin PC0, and
the variable resistor from PC0 to ground.
In the following image, the red pins represent the potentiometer, and
the blue are the leads from the photoresistor.
<figure>
<img src="_avr2011_bare_board_annotated_small.jpg" title="500 px" />
<figcaption>500 px</figcaption>
</figure>
Start out by placing and soldering the potentiometer on the underside of
the board. Make sure that the smaller center pin connects to the ground
lines. Do _NOT_ clip the leads short yet.
<figure>
<img src="_avr2011_board_bottom.jpg" title="500 px" />
<figcaption>500 px</figcaption>
</figure>
Bend one lead on the variable resistor up and over the two other holes
on the board, and plug it into PC0. Solder it in on the top side. Now
soldering the photoresistor in place should be easy.
<figure>
<img src="_avr2011_board_topside_soldered.jpg" title="500 px" />
<figcaption>500 px</figcaption>
</figure>
Flash in the light sensor firmware and turn the potentiometer until it
give you a nice range of values on the LED display. I found that turning
it up to _just_ max out in full light works well -- you'll see that
it'll get down to one or two bars when you cover the cell with your
hand. You're done!
### Schematics, etc
If you'd like to make yourself a class-board, the attached Eagle files
should get you started.
Warning: It's a good idea to socket your AVR in the board so that you
can remove/swap chips when you want to.
Also, the LEDs in port B will over-ride the SPI port. For the class, we
used AVRs with a bootloader already flashed into them, so we didn't use
the SPI most of the time. If you'd like to use the SPI instead, you can
**probably** get away with using large-value (1k Ohm?) resistors for the
LEDs. Best is to omit them if you're going to use the SPI a lot, though.
[Media:
mega_classboard_files.zip](Media:_mega_classboard_files.zip "wikilink")
Finally, if you want something with almost all of the functionality (but
none of the style!), Evil Mad Science sells a nice, very cheap, AVR Mega
breakout board.
[Category:Microcontrollers](Category:Microcontrollers "wikilink")
[Category:AVR_Class](Category:AVR_Class "wikilink")
+182
View File
@@ -0,0 +1,182 @@
`*** See also `[`Suppliers`](Suppliers "wikilink")` ***`
A sizable inventory of electronic components was purchased for
[Hackersmart](Hackersmart "wikilink"), with the goal that the unsold
portion thereof would seed HacDC's electronics lab. This has come to
pass, and the components are arranged on a pegboard by the soldering
desk. This page is to explain what's available, how much it cost, where
to get more, and as a place to request additions.
This list has not been actively maintained in some time. We are not able
to resell items or run a store because that would require us to collect
and pay DC sales tax. So, think of the parts as office supplies that we
have stocked. If you use something, please donate an appropriate amount
to the tip jar.
### Large Parts (Dept 4)
| Item | Supplier | our cost | retail price |
|---------------------------|----------|----------|--------------|
| Arduino with Atamega328 | Adafruit | \$28 | \$35 |
| Boarduino kit w/ USB | Adafruit | \$22 | \$25 |
| USB TTL-232 Cable | Adafruit | \$18 | \$23 |
| Arduino Protoshield Kit | Adafruit | \$14 | \$15 |
| USBtinyISP AVR Programmer | Adafruit | \$20 | \$25 |
| XBee Adapter | Adafruit | \$10 | \$15 |
| XBee Module | Adafruit | \$23 | \$25 |
### Small Parts
| Component | Supplier | partno | our cost | retail price | [department](cash_register "wikilink") |
|------------------------------------------------------|--------------------------------------|----------------------|-----------------------|-----------------|----------------------------------------|
| resistors | Mouser/BG | partno | 1.4c (\$2.95 for 200) | 2c | 6 |
| 100-ohm trim pots | All Electronics | TPK-100 | 10c | 25c | 6 |
| 100k trim pots | All Electronics | TP-100k | 10c | 25c | 6 |
| 0.1uF 'decoupling' caps | Mouser | K104K15X7RF53H5 | 5c | 5c | 6 |
| 4.7uF capacitors | Mouser | 647-UVR1H4R7MDD1TD | 4c | 5c | 6 |
| 47uF capacitors | All Electronics | 47R10 | 4c | 5c | 6 |
| Misc caps (grab box) | Goldmine | G3060 | 1c? | 5c | 6 |
| 56uH inductors | Goldmine | G16521 | 35c | 50c | 6 |
| Red/Grn/Yel 3mm LEDs | MPJA | 15101/15102/15103 OP | 2c | 5c | 6 |
| Red/Grn/Yel 5mm LEDs | MPJA | 15108/15308/15309 OP | 2c | 5c | 6 |
| Aqua LEDs | Goldmine | G16645 | 25c | 50c | 6 |
| Infrared LEDs | supplier | partno | cost | price | 6 |
| Ultraviolet LEDs | supplier | partno | cost | price | 6 |
| 12MHz crystal | Goldmine | G3840 | 1.50 | 2.00 | 6 |
| 1xAA holder | Mouser | 12BH311-GR | 0.69 | 1.00 | 7 |
| 2xAA holder | Mouser | 12BH321D | 0.67 | 1.00 | 7 |
| 4xAA holder | Mouser | 12BH351-R | 0.99 | 1.50? | 7 |
| 9V battery snap | MPJA | 2600BT | 0.29 | 0.50 | 7 |
| SPDT pushbutton PCB mount | Goldmine | G14045 | \$1/5 | 0.25 | 7 |
| SPDT pushbutton panel mount | MPJA | 5019SW | 0.29 | 0.50 | 7 |
| DPDT slide | Goldmine | G1827 | 5/\$1 | 0.25 | 7 |
| DPDT 5v relay | All Electronics | RLY-506 | 0.70 | 1.00 | 7 |
| 2.1mm DC power jack | supplier | partno | cost | price | 7 |
| 2.1mm DC power plug | All Electronics | DCSID | 0.50 | 0.50 | 7 |
| 2.5mm DC power jack | All Electronics | DCJ-6 | 0.20 | 0.25 | 7 |
| 2.5mm DC power plug | supplier | partno | cost | price | 7 |
| 2.5mm (3/32") stereo plug | supplier | partno | cost | price | 7 |
| 3.5mm (1/8") stereo plug | supplier | partno | cost | price | 7 |
| 3.5mm (1/8") stereo jack | Goldmine | GP3 | 50/\$2.49 | 0.25 | 7 |
| USB B jack | Mouser | 649-61729-1010BLF | 0.50 | 1.00 | 7 |
| 8-pin DIP sockets | Digi-Key | 3M5461-ND | 0.156 | 0.25 | 7 |
| 14-pin DIP sockets | Digi-Key | 3M5462-ND | 0.13 | 0.25 | 7 |
| 20-pin DIP sockets | Digi-Key | 3M5465-ND | 0.18 | 0.25 | 7 |
| 28-pin DIP sockets | Digi-Key | 3M5469-ND | 0.23 | 0.50 | 7 |
| 0.100" headers | Goldmine | GP6 | 50/\$2.49 | 0.25 | 7? |
| 830-point breadboard | MPJA | 4443TE | 3.95 in qty 10 | 5.00 | 8 |
| small perfboard | All Electronics | PC-1 | 0.75 | 1.00 | 8 |
| large perfboard | BG Micro | ACS1052 | 1.95 | 3.00? | 8 |
| crappy clipleads | Goldmine | G1498 | 10/\$2 | 25c | 8 |
| Minigrabbers (yellow) | DealExtreme | sku.8391 | 30/\$7.41 | 50c | 8 |
| Micrograbbers (red/black) | DealExtreme | sku.7892 | 20/\$6.10 | 50c | 8 |
| 6 amp Triac 400 PIV | RS | 276-1000 | 0.00 | 0.95 | 9 |
| 7805 regulator | Mouser | 512-LM7805ACT | 0.31 | 0.50 | 9 |
| 78L05 regulator | Mouser | 512-LM78L05ACZX | 0.18 | 0.50 | 9 |
| 7812 regulator | Mouser | 512-LM7812ACT | 0.31 | 0.50 | 9 |
| TL431 adjustible zener regulator | RS | 276-559 | 0.00 | 1.50 | 9 |
| LM317 adj reg | Mouser | 511-LM317MT | 0.30 | 0.50 | 9 |
| 1n914/1n4148 diode | Goldmine | G13807 | 100/\$1 | 5c | 9 |
| 1n4007 diode | MPJA | 5217DI | 0.07 | 0.10 | 9 |
| Zener diodes | BG Micro | partno | 0.12 | 0.25 | 9 |
| 2n4891 UJT Transistor | RS | 276-2029 | 0.00 | 7.08 | 9 |
| 2n3904 NPN transistor | BG Micro | TRN2N3904 | 0.06 | 0.25 | 9 |
| 2n3905 PNP transistor | Goldmine | G43374 | 0.12 | 0.25 | 9 |
| 2SC945 NPN Transistor | RS | 276-2051 | 0.00 | 0.25 | 9 |
| ICL7621 Dual Op Amp Low Power | RS | 276-2331 | 0.00 | 1.07 | 9 |
| LM358 opamp | Mouser | 512-LM358N | 0.25 | 0.50 | 9 |
| LM1458 dual opamp | Mouser | 512-LM1458CN | 0.33 | 0.50 | 9 |
| LM393 dual comparator | All Electronics | LM393 | 0.30 | 0.50 | 9 |
| LM3915N LED bargraph driver | RS | 276-1708 | 0.00 | 2.50 | 9 |
| LM555 timer | Mouser | 512-LM555CN | 0.22 | 0.50 | 9 |
| ADM202 RS232 transceiver | All Electronics | ADM202EAN | 0.75 | 1.00 | 9 |
| 4n33 optoisolator | Mouser | 78-4N33 | 0.32 | 0.50 | 9 |
| LM386 audio amp | Mouser | 513-NJM#386BD | 0.42 | 0.50 | 9 |
| MC34063 switching power supply controller | Mouser | 863-MC34063AP1G | 0.70 | 1.50 | 9 |
| 74HCT573 Octal D-type Latch | RS | CD74HCT573E | 0.00 | 0.85 | 9 |
| 74HCT4020 14 stage binary counter | RS | 74HCT4020N | 0.00 | 1.80 | 9 |
| 74HCT240 Octal Inverting Buffer | RS | 74HCT240N | 0.00 | 0.68 | 9 |
| 74HCT273 Octal D Flip Flop | RS | 74HCT273N | 0.00 | 0.66 | 9 |
| 74HCT393 Dual 4 Bit Binary Counter | RS | 74HCT393E | 0.00 | 0.60 | 9 |
| 74HCT164 8 Bit Serial In Parallel Out Shift Register | RS | 74HCT164N | 0.00 | 0.55 | 9 |
| SN74LVC16245A 16 bit bus transceiver | hamfest | SN74LVC16245A | 0.00 | 1.52 | 9 |
| 74LS244 Octal Noninverting Buffer | RS | SN74LS244N | 0.00 | 0.30 | 9 |
| 74LS373 octal transparent latch | RS | SN74LS373N | 0.00 | 1.39 | 9 |
| 4093 CMOS 2 input NAND Schmitt Trigger | RS | CD4093BCN | 0.00 | 0.55 | 9 |
| AVR microcontrollers | I'm gonna leave this to Elliot or TC | | | | 10 |
| ferrite snap beads | All Electronics | FB-80 | 2.50 | 2.00 + shipping | 10 |
| Hantronix HDM16216H-5-300S 2x16 LCD no backlight | Goldmine | G16717 | 2.95 | 5.00 | 11 |
| 0.6 amp Polyfuse | Mouser | 576-60R065XU | 0.24 | 0.50 | 11 |
| 1.1 amp Polyfuse | Mouser | 576-30R110UU | 0.26 | 0.50 | 11 |
| CF-IDE 44-pin | DealExtreme | sku.10310 | 2.26 | 3.00 | 15 |
| CF-IDE 40-pin male | DealExtreme | sku.10309 | 2.09 | 3.00 | 15 |
| CF-IDE 40-pin female | DealExtreme | sku.2720 | 2.16 | 3.00 | 15 |
| CF-IDE 40-pin male on bracket | DealExtreme | sku.10311 | 3.52 | 5.00 | 15 |
| 2.5-to-3.5-inch IDE adapter | DealExtreme | sku.727 | 1.33 | 2.00 | 15 |
| 2GB CF card | DealExtreme | sku.12352 | 22.12 | 30.00 | 15 |
| 1GB MicroSD (TransFlash) | DealExtreme | sku.1458 | 5.43 | 7.00 | 15 |
| 2GB MicroSD (TransFlash) | DealExtreme | sku.2934 | 9.22 | 12.00 | 15 |
| SDHC-to-USB adapter | DealExtreme | sku.6858 | 2.52 | 3.00 | 15 |
| All-in-one USB memory reader | DealExtreme | sku.2708 | 4.87 | 5.00 | 15 |
| | | | | | |
### Proposed Additional Inventory
| Component | Supplier | partno | our cost | retail price | department | QTY Desired |
|----------------------------------------------------------------------------|-----------------------------|--------------------------------------------------------------------------|------------|--------------|------------|-------------|
| IRFZ20 MOSFET | TBD | | | | | |
| H-Bridges | TBD | (SN754410, aka L293) | | | | |
| piezo elements | TBD | | | | | |
| 22 AWG hookup wire | TBD | | | | | |
| TBD Light Sensor | TBD | | | | | |
| TIP102 Transistor | TBD | | | | | |
| USBtinyISP AVR Programmer Kit | adafruit.com | | \$22 | | | |
| AVR Programming Adapter | Sparkfun.com | BOB-08508 | \$0.99 | | | |
| Infrared Emitters and Detectors | Sparkfun.com | SEN-00241 | \$1.95 | | | |
| 8-Bit Shift w/Latch | Mouser | 595-SN74HC595N | \$0.66 | | | |
| 5.6v Zener Diode | Mouser | 512-1N5232B | \$0.06 | | | |
| 10-pin bussed 10K-100K resistor network | Mouser | 266-100K-RC | \$0.25 | | | |
| L293D Dual H-Bridge | Mouser | 595-L293DNE | \$2.74 | | | |
| 5-position 5.08 terminal block | Mouser | 538-39880-0303 | \$077 | | | |
| 2-position 5.08 terminal block | Mouser | 538-39880-0302 | \$0.46 | | | |
| cisco 48V power supplies | <http://tinyurl.com/6n4z8b> | | \$10ea-ish | | | |
| Darlington array | Mouser | 511-ULN2801A | \$0.91 | | | |
| Opto-Isolator | Mouser | 782-139 | \$1.12 | | | |
| Power Transistor | Mouser | 511-2N3055 | \$1.40 | | | |
| 74C CMOS Logic Hex Schmitt Trigger | Mouser | 512-MM74C14N | \$0.72 | | | |
| LED Assortment | Alan Parakh | <http://alan-parekh.vstore.ca/product_info.php/cPath/4_8/products_id/31> | \$25 | | | |
| IRL3713PBF MOSFET 30V/260A continuous drain current, very low gate voltage | Newark Electronics | <http://www.newark.com/> or Mouser 844-IRL3713PBF | \$4 | | | |
### Suppliers:
[Mouser](http://www.mouser.com) and [Digi-Key](http://www.digikey.com)
are the "big guns" of the hobbyist and small professional electronics
market, with breathtaking inventories, fast order fulfillment, and
sophisticated websites. Digi-Key adds a handling fee to orders under
\$25.
[Marlin P. Jones & Associates](http://www.mpja.com) is a smaller web
retailer specializing in power supplies, but with a fair assortment of
other stuff too. Their prices on breadboards are hard to beat. (Thanks
[Jon](http://serialwombat.com/) for that tip!)
[All Electronics](http://www.allelectronics.com/) has been in the
surplus electronics game for a long time, with a small newsprint catalog
that's a staple in many geeks' bathrooms. As with any surplus dealer,
their inventory is constantly in flux, and sometimes they have really
amazing deals.
[B.G. Micro](http://www.bgmicro.com/) (known pre-9/11 as "The
Electronics Mecca", now calls itself "The Electronics Supplier") is a
small mostly-surplus dealer whose bright yellow catalog offers Texas
humor mixed with eyestrain. Their shopping cart software is chaotic
evil, but they have great prices, particularly on industrial stuff like
thermal fuses and zener diodes.
[Electronics Goldmine](http://www.goldmine-elec-products.com/) has a
better selection of motors, magnets, and boxes than almost anyone else.
They offer "GoldPaks", grab-bags and assortments of surplus (sometimes
take-outs) hardware, some of which are so-so deals and some of which are
simply jawdropping.
[Category:Materiel](Category:Materiel "wikilink")
@@ -0,0 +1,227 @@
This is an attempt to write documentation for the ATmega328P
microcontroller (& learn to use it as I go along). Send corrections,
suggestions, & comments to: gippgig@gmail.com Bobby The ATmega328P
Microcontroller - 1 Setting up the I/O pins - Oct. 3, 2019 version Note:
In the following, the more negative voltage (Gnd) is 0 & the more
positive voltage (Vcc) is 1. Addresses & data are given in hexadecimal.
The ATmega328P is one of a large family of similar 8-bit
microcontrollers and can operate on 1.8 to 5.5 V. The data sheet is
available at
ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061A.pdf
(in the following the section describing an item is often given
afterwards in parentheses, i.e. SREG(7.3.1)); the instruction set manual
for this family is available at
ww1.microchip.com/downloads/en/devicedoc/atmel-0856-avr-instruction-set-manual.pdf
(note that the 328P does not have all of the instructions listed) & also
see en.wikipedia.org/wiki/Atmel_AVR_instruction_set. Other members
differ in various ways; consult their data sheets for details. The
ATmega328P has 32 8-bit general purpose registers (which can also be
addressed as data memory locations 0000-001F), 224 8-bit I/O registers
(which can also be addressed as data memory locations 0020-00FF; note
that 20 must therefore be added to the I/O register number when
addressing it as memory), 2kx8 data RAM(8.3) (data memory locations
0100-08FF), a separate 16kx16 program flash memory(8.2) (note that while
it is an 8-bit chip the instructions are 16 bits), & a separate 1kx8
EEPROM(8.4). The ATmega328P is available as a 28-pin DIP (more exotic
packages are also avilable) with 23 general purpose I/O pins which can
also have specialized functions(14.3.1-14.3.3); in particular, pin 1 is
an external reset(11.4) unless RSTDISBL(28.2) has been programmed to 0.
Altho each pin can be individually controlled, they are grouped into the
8 bit port B (B0-B7), 7 bit port C (C0-C6), & 8 bit port D (D0-D7). 1=C6
B7=10 2=D0 B6=9 3=D1 B5=19 4=D2 B4=18 5=D3 B3=17 6=D4 B2=16 9=B6 B1=15
10=B7 B0=14 11=D5 C6=1 12=D6 C5=28 13=D7 C4=27 14=B0 C3=26 15=B1 C2=25
16=B2 C1=24 17=B3 C0=23 18=B4 D7=13 19=B5 D6=12 23=C0 D5=11 24=C1 D4=6
25=C2 D3=5 26=C3 D2=4 27=C4 D1=3 28=C5 D0=2 There are 3 I/O registers
associated with each port: DDR(14.4.3, 14.4.6, 14.4.9) (data direction
register), PORT(14.4.2, 14.4.5, 1.4.8), & PIN(14.4.4, 14.4.7, 14.4.10).
The DDR determines whether the pins are inputs or outputs; if a bit in
the DDR is 0 the corresponding pin is an input; if 1 it is an output.
When the chip is reset (which happens automatically when power is turned
on) all the DDR & PORT bits are cleared making all pins inputs; bit 6 if
pin 1 is reset & unused bit 7 of DDRC, PORTC, & PINC are always 0. The
PORT register contains the value that is output on the corresponding
pins that are set as outputs. Note that if a bit corresponding to an
input pin is set to 1 an internal "pullup" resistor is connected from
the positve voltage to that pin unless PUD(14.4.1) has been set to 1.
Reading the PIN register gives the value of the corresponding pins
(regardless of whether they are an input or output). Note that
unconnected inputs are not defined and may give erratic values when
read. Unconnected inputs can also cause high power consumption so unused
inputs(14.2.6) should be connected to something; this is easily done by
turning on the pullup resistors. Also note that there is a 1 instruction
delay(14.2.4) between writing data to the PORT and having it appear in
the PIN register. Writing 0 to a PIN bit does nothing but writing a 1
will cause the corresponding bit in PORT to change state(14.2.2) (from 1
to 0 or from 0 to 1). Here are the I/O addresses for the various
registers: 03 PINB 04 DDRB 05 PORTB 06 PINC 07 DDRC 08 PORTC 09 PIND 0A
DDRD 0B PORTD Suppose that pin 1 is reset, 2 is an input with the pullup
resistor on, 3-6 & 9 are outputs with 9 set to 0, 10 is unused, 11-15
are outputs with 11-13 set to 1, 16-19 are unused, & 23-28 are inputs
with the pullups on for 24-25. Also suppose that setting pin 9 to 1
(except under special conditions) could damage the circuit; to reduce
the chance of this happening this output is placed next to Gnd (pin 8),
a resistor (~5k ohms suggested) is connected from the pin to Gnd, & the
other adjacent pin (10) is unused & is connected thru a "pulldown"
resistor (1k suggested) to Gnd instead of using the internal pullup.
Here is the port bit map (the port bit is given first followed by the
corresponding pin, the value of the DDR for that position, the value (if
the value doesn't matter it is generally set to 0 in these examples) of
the PORT for that position, & a description; after the last bit of a
port the hexadecimal value of DDR & PORT is shown): B7 10 0 0 unused,
resistor to Gnd B6 9 1 0 out, =0, cannot be set to 1, resistor to Gnd B5
19 0 1 unused (set PORT to 1 to turn on pullup resistor) B4 18 0 1
unused B3 17 0 1 unused B2 16 0 1 unused B1 15 1 0 out B0 14 1 0 out
DDRB=43 PORTB=3C C6 1 0 0 reset C5 28 0 0 in C4 27 0 0 in C3 26 0 0 in
C2 25 0 1 in, pullup on C1 24 0 1 in, pullup on C0 23 0 0 in DDRC=00
PORTC=06 D7 13 1 1 out, =1 D6 12 1 1 out, =1 D5 11 1 1 out, =1 D4 6 1 0
out D3 5 1 0 out D2 4 1 0 out D1 3 1 0 out D0 2 0 1 in, pullup on
DDRD=FE PORTD=E1 The following code fragment sets up the pins (in all
code examples the program memory address is given first (4 hexadecimal
digits) followed by the opcode (4 digits), the instruction, & an
explanation). When power is turned on the processor resets and starts at
address 0000(11.1) unless BOOTRST(27.6) has been programmed to 0.
However, interrupts can cause execution to start nearby (for example,
INT0 can cause execution to start at 0002(12.4)) so the first
instruction is often a jump to get out of the way. 0000 940C JMP 0001
1000 1000 ... 1000 E423 LDI R18,43 Load value to make pins 9 & 14-15
outputs into arbitrarily chosen temporary register 1001 B924 OUT 04,R18
Store into DDRB 1002 EF6E LDI R22,FE Load value to make pins 3-6 & 11-13
outputs 1003 B96A OUT 0A,R22 Store into DDRD 1004 E31C LDI R17,3C Load
value to turn on pullup resistors for unused pins 16-19 1005 B915 OUT
05,R17 Store into PORTB 1006 EE51 LDI R21,E1 Load value to set pins
11-13 to 1 & turn on pullup for pin 2 1007 B95B OUT 0B,R21 Store into
PORTD 1008 E036 LDI R19,06 Load value to turn on pullups for pins 24-25
1009 B938 OUT 08,R19 Store into PORTC 100A rest of program No need to
load DDRC since it was reset to 00 when power was turned on If possible,
do not connect or disconnect whatever would be damaged if pin 9 was 1 &
connect it to Gnd instead if applicable. Once the rest of the circuit is
built, turn on a voltmeter, set it on DC volts, & select the lowest
range that includes the voltage chosen to power the circuit. Before
connecting power to the circuit turn on the power source, select the
correct voltage, & measure the output. If the voltage is wrong make sure
the power source is plugged into an outlet that has power or test the
batteries & check for corroded battery contacts. If the voltage is
correct verify which connection is positive & which is negative. Turn
off power, connect power to the circuit MAKING SURE THE POSITIVE VOLTAGE
IS CONNECTED TO VCC, turn on power, & measure the voltage at pin 7
(Vcc). If it is negative shut off power (& hope the circuit hasn't blow
out) because the power is somehow connected backwards, if it is 0 check
for a loose connection or short circuit, if it is low check for weak
batteries or a short. If Vcc is correct check the voltage at pin 9. If
it is not 0 find & fix the problem and repeat the check. If it is 0 turn
off power, connect the rest of the circuit, & turn on power. Check pin 9
again; if it is not 0 shut off power, find & fix the problem, & repeat
the check. If it is 0 repeat the check of Vcc. If Vcc is not correct fix
the problem, repeat the check of pin 9, & then test Vcc again. If Vcc is
correct see if the circuit works. The ATmega328P Microcontroller - 2
Adding a self-test - Oct. 21, 2019 version The self-test works by
checking whether the pins have the expected values. Note that the value
of PIN should equal the value of PORT for output pins unless a pin is
heavily loaded (which should generally be avoided and always avoided at
higher Vcc); this is also the case for unused pins with the pullup
enabled & unused pins with the pullup off if pulled down to Gnd (i.e.,
pin 10 below). Unless it would cause something bad to happen to whatever
the microcontroller is controlling, the test should be repeated with
each output pin set to both 0 & 1 to detect excessively low resistance
to either Vcc or Gnd and adjacent pins should have opposite values to
detect shorts between pins. Using the previous example, suppose that pin
1 is reset, 2 is an input with pullup on, 3-6 & 9 are outputs with 9 set
to 0, 10 is unused, 11-16 are outputs with 11-13 set to 1, 17-19 are
unused, & 23-28 are inputs with pullups on for 24-25. Pin 2 should
initially be 0, pin 6 is heavily loaded, pin 9 must not be set to 1 &
has a resistor to Gnd, pin 10 also has a resistor to Gnd, pin 16 is the
self-test output (0=fail, 1=pass), pin 23 is an analog input, pin 24
should initially be 1 & pin 27 0, & pin 28 should be the same as pin 26
until the self-test sets pin 12 to 1. Note that the self-test
momentarily sets pin 16 to 0 so this must not trigger an error response.
Here is the port bit map; 3 values are given for PORTB (the first 2
being the values used for self-testing with the 2nd also being the final
value if the self-test passes (there is no need to change it since pin
16 is already 1 & 14-15 don't need to be set to a particular value)
while the 1st (pin 16 already 0) or 3rd is the final value if the
self-test fails) & 3 values are given for PORTD (the first 2 again being
the values used for self-testing & the 3rd the final value that sets the
outputs to the correct values). B7 10 0 0 0 0 unused, resistor to Gnd B6
9 1 0 0 0 out, =0, cannot be 1, resistor to Gnd B5 19 0 1 1 1 unused B4
18 0 1 1 1 unused B3 17 0 1 1 1 unused B2 16 1 0 1 0 out, self-test B1
15 1 1 0 0 out B0 14 1 0 1 1 out DDRB=47 PORTB=3A,3D,39 C6 1 0 0 reset
C5 28 0 0 in, =C3 until pin 12 is set to 1 C4 27 0 0 in, initially 0 C3
26 0 0 in, =C5 until pin 12 is set to 1 C2 25 0 1 in, pullup on C1 24 0
1 in, pullup on, initially 1 C0 23 0 0 in (analog) DDRC=00 PORTC=06 D7
13 1 1 0 1 out, =1 D6 12 1 0 1 1 out, =1 D5 11 1 1 0 1 out, =1 D4 6 1 0
1 0 out, heavy load D3 5 1 1 0 0 out D2 4 1 0 1 0 out D1 3 1 1 0 0 out
D0 2 0 1 1 1 in, pullup on, initially 0 DDRD=FE PORTD=AB,55,E1 The
following code fragment sets up the pins & does the self-test. 0000 940C
JMP 0001 1000 1000 ... 1000 E427 LDI R18,47 Load value to make pins 9 &
14-16 outputs 1001 B924 OUT 04,R18 Store into DDRB 1002 EF6E LDI R22,FE
Load value to make pins 3-6 & 11-13 outputs 1003 B96A OUT 0A,R22 Store
into DDRD 1004 E31A LDI R17,3A Load value to do 1st B self-test 1005
B915 OUT 05,R17 Store into PORTB 1006 EA5B LDI R21,AB Load value to do
1st D test 1007 B95B OUT 0B,R21 Store into PORTD 1008 E036 LDI R19,06
Load value to turn on pullups for pins 24-25 1009 B938 OUT 08,R19 Store
into PORTC 100A B173 IN R23,03 Load temporary register from PINB 100B
2771 EOR R23,R17 Clear bits where PINB=PORTB (CPI R23,3A is an equally
good alternative) 100C F4D1 BRNE 1A PINB not same as PORTB, self-test
failed, pin 16 already 0, go to 1027 (note that the branch distance is
relative to the following instruction so this jumps ahead 1B) 100D B179
IN R23,09 Load from PIND 100E 7E7F ANDI R23,EF Clear bit D4
corresponding to heavily loaded pin 6 100F 3A7A CPI R23,AA Test for
correct value (note that EOR R23,R21 is not an alternative since PORTD0
is 1 but input pin 2 should be 0 so the result should be 01 not 00) 1010
F4B1 BRNE 16 PIND outputs not same as PORTD besides D4, fail, pin 16
already 0, go to 1027 1011 B176 IN R23,06 Load from PINC 1012 7F7A ANDI
R23,FA Clear unpredictable bits C0 & C2 1013 3072 CPI R23,02 Test for
pass with C3=C5=0 1014 F011 BREQ 02 Pass with C3=C5=0, go to 1017 1015
327A CPI R23,2A Test for pass with C3=C5=1 1016 F481 BRNE 10 PORTC
wrong, fail, pin 16 already 0, go to 1027 1017 E555 LDI R21,55 Load
value to reverse D outputs 1018 B95B OUT 0B,R21 Store into PORTD 1019
E31D LDI R17,3D Load value to reverse B outputs except pin 9 101A B915
OUT 05,R17 Store into PORTB (no need to change PORTC since it has no
outputs) 101B B179 IN R23,09 Load from PIND (note that PINB couldn't be
tested yet because of 1 instruction delay) 101C 7E7F ANDI R23,EF Clear
heavily loaded bit D4 101D 3474 CPI R23,44 Test for correct value 101E
F439 BRNE 07 PIND outputs not same as PORTD besides D4, fail, go to 1026
101F B173 IN R23,03 Load from PINB 1020 2771 EOR R23,R17 Clear bits
where PINB=PORTB 1021 F421 BRNE 04 PINB not same as PORTB, fail, go to
1026 1022 B176 IN R23,06 Load from PINC 1023 7D72 ANDI R23,D2 Clear
unpredictable bits C0,C2-3,C5 1024 3072 CPI R23,02 Test for C1=1 & C4=0
1025 F009 BREQ 01 Self-test passes, pin 16=1, go to 1027 1026 982A CBI
05,2 Set pin 16 to 0 1027 EE51 LDI R21,E1 Load value to set pins 11-13
to 1 & turn on pin 2 pullup 1028 B95B OUT 0B,R21 Store into PORTD
1029... rest of program To turn on an LED if the self-test passes
(recommended because it indicates that the initialization routine
executed) connect the positive LED lead to pin 16 & the negative lead
thru a resistor (the value depends on the voltage used) to Gnd. However,
the LED may be too dim to see if the voltage is under 2V (test by
connecting it directly from Vcc to Gnd (no resistor needed if under
2V)). To do more than just set pin 16 if the self-test fails, add
additional code after 1026 & change the value of BREQ at 1025 to jump
past the end of the added code. For example, this alternate ending will
halt the program at the point the self-test failed to make it easier to
find (as described below) the problem: 1025 F011 BREQ 02 Pass, go to
1028 (increased by 1 since 1 instruction added) 1026 982A CBI 05,2 Set
pin 16 to 0 1027 CFFF RJMP FFF Go to 1027 (halt by going into infinite
loop) 1028 EE51 LDI R21,E1 Load D value 1029 B95B OUT 0B,R21 Store into
PORTD 102A... rest of program In this particular case only, it makes
sense to also change the BRNE at 100C,1010,& 1016 to F7F9 BRNE 7F to
halt the program at those points. After all the tests described
previously pass, if the self-test does not pass measure the voltage at
pin 16; if it is not 0 test the resistor & LED, make sure the LED isn't
backwards, & check for a wiring error. If pin 16 is 0 connect a 2.7k
resistor from pin 16 to Vcc; if it now reads \>1V the pin apparently was
not initialized to an output, check the program for errors (beware
typos) & make sure it was loaded into the microcontroller correctly. If
it still reads 0 the self-test really did fail. Check the voltages on
all of the pins. Suppose that the supply is 2V & the voltages on pins
1-6 are 2,0,2,0,2,1, on 9-19 are 0,0,2,0,0,0,2,0,2,2,2, & 23-28 are
.7,2,2,0,0,0. The odd value at pin 6 is not unexpected because of the
heavy load and pin 23 is an analog input while 9-10 & 14-19 match the
1st test value for port B indicating that the first part of the
self-test (at 100C) passed (but the test failed before PORTB was
reloaded at 101A). Pins 23-28 match the expected value (pin 1 should be
2V because it's reset) for port C. Pins 2-6 & 11-13 match the 1st value
for port D except for pin 13 (D7), which should be 2V but was 0. This
indicates that pin 13 is shorted, check the wiring to that pin. On the
other hand, if pins 12 & 13 were both .9V that would indicate that pins
12 & 13 are shorted together. Fix the problem & try again. If the
self-test passes see if the circuit works.
+81
View File
@@ -0,0 +1,81 @@
## About
Some people have made the mistake of expressing interest in electron
tubes. They're about to learn more than they bargained for.
## News
The first session was a great success. We covered the first item in the
syllabus and part of the second.
The next session will feature a brief review of the first session and
finish covering the second section. I think it should be possible to
reach the section on advanced circuits. during the next session.
I also owe you guys a tube dissection, I'll try to work that into the
next session too.
## Schedule
Next class: Aug 11 at 7:30 PM.
## Silly Bus
- Thermionic emission: From the lightbulb to the pentode.
- Fundamental circuits and coupling
- Push-pull and Phase splitting circuits
- Transformers in single-ended and push-pull.
- Advanced circuits
- Tube failure modes
<!-- -->
- Hands-on experience building a battery-powered single tube filamentary
pentode pre-amp.
<!-- -->
- Power supplies and tweaking.
<!-- -->
- What is the real secret to great sound?
### Laboratory Supplies
[cheap demo
pre-amp](http://www.bottlehead.com/store.php?crn=220&rn=438&action=show_detail)
Go to \[tubedata.info\] and obtain what you think is the most
informative datasheet for the following tubes and print out a copy. --
you need a physical copy.
**filamentary diode** 5U4\* Optional: GZ34 / 5AR4
**canonical triode** 2A3 Optional: 845
**to explore gain versus output** 6SN7\* 6SL7\* or 12AX7 / ECC83
**Pentodes** 6BQ5 / EL84 Optional: KT88, EF86
3S4 \<\<\< absolutely required, this is the tube we're using.
### Suggested Reading
Radiotron Designer's Handbook 4th ed. \[www.pmillett.com\] Might have
one lying around.
Tube Circuits for Audio Amplifiers (1-882580-03-6) features some very
elegant and practical designs.
An Approach To Audio Frequency Amplifier Design. (1-882580-05-2) Has
some good discussions about output transformers and ultralinear design.
Then it starts out with some nice practical amps but, before long at
all, starts talking about 1,100 watt monsters with 2.5KV power supplies.
Building Valve Amplifiers (0-7506-5695-6) is probably too practical to
be enjoyable but I have to deem it essential. His other book is
fantastic, one of the most well worn tomes in my personal library, but
get this one first.
[Category:Classes](Category:Classes "wikilink")
+95
View File
@@ -0,0 +1,95 @@
## Background
[Go](http://en.wikipedia.org/wiki/Go_(board_game)) is a board game of
strategy, like chess, that is around 3000 years old and the most popular
game of it's type in the world. Before going any further, take a look at
the wikipedia page... the short version is that it's an *extremely* easy
game to learn and for every player to date beyond mastery. No computer
or algorithmic approach can beat even a moderately skilled amateur (it's
been in the crosshairs of the AI community since chess, a vastly
inferior pastime, fell with little resistance) but four year olds are
routinely taught to play. Its played on a grid, usually 19x19, but
occasionally bigger and frequently smaller for faster or educational
games (9x9 and 13x13 being the other standard sizes). The object is for
two players to try to surround as much of the board as possible by
placing immovable stones on the intersection points of the grid, the
central caveat being that stones can be captured if totally surrounded
by opposing colored stones. There are maybe two other rules, depending
on how you count, but it's beautifully simple.
Games are played ([illustrative
picture](http://en.wikipedia.org/wiki/Image:Go-Equipment-Narrow-Black.png))
on a board called a Goban, traditionally a very thick slab of wood with
it's own feet that sat directly on the floor, with players on opposing
sides sitting on cushions. These days you're more likely to see a table
board, which is still essentially a slab of wood. The stones range from
traditional (read: expensive) slate and shell to bottlecaps
(glass/plastic coated lead being the most common).
## Concept
Many clients exist to play Go on computers/handheld devices. These are
wonderful in that they can record your game in the SGF format, which is
(near) universally used by players to review their games (an important
part of getting better, often done with a teacher or opponent). They're
also handy when you're moving around, and can't set up a bunch of slick
stones on a slab of wood (trains, planes, automobiles, bicycles). For
casual games, it's nice to be able to stop and resume at any time.
The big downside is face to face interaction. It's simply nowhere near
as enjoyable to play by passing a handheld back and forth or staring at
a computer, the latter not being particularly portable most of the time
anyway.
So the plan would be to build something that's as close to the form
factor of a real goban, but shrunk a bit for portability, and completely
electronic. I'd say about a 30cm square (~1 foot for the unit
challenged) and no thicker than a paperback book would be a good size.
Something you can throw in a bag without hesitation. It should have as
intuitive an interface as possible, the ability to automatically score
the game, and best of all store games and export them to a computer
somehow.
Of course, it should also have some pointless eastereggs built in...
[the game of life](http://en.wikipedia.org/wiki/Conway%27s_game_of_life)
springs to mind.
## Implementation Ideas
Simply but, a big array of multicolor LEDs, each one an "intersection"
on the board. 19^2, 361, of them. A glorious sight to behold. Initially
I thought it would be neat to make each LED a pushbutton, but quickly
realized that multicolor LED pushbuttons are expensive, make the whole
project orders of magnitude more difficult and would be rather fragile
(I'd be delighted if someone showed me otherwise though). So the backup
plan would be to simply have a big old grid of LEDs and a d-pad
(think... nintendo controller) to move around your "stone" on the matrix
before placing it. A five button interface, one on each side. If you use
Red/Green bicolor LEDs you can get three colors (tricky eh?): Red,
Green, and Yellow. I *think*
[these](http://www.superbrightleds.com/TriColor%20LED.htm) are true
tricolor LEDs... in the sense that you have one anode (or cathode, your
choice) per color (unfortunately they cost way too much, we'll see if
they can be found cheaper, something under \$0.30 would be nice). The
stone you're "placing" would be yellow, and upon pressing would turn
your color (based on whose turn it is, obviously). The yellow could also
be used to mark the "edge" when playing on a smaller 9x9 or 13x13 board.
This is a project ideally suited for a microcontroller of some sort.
They're surprisingly cheap (once you factor in how much it costs to get
PIC/AVR prog hardware) and should be very easy to interface to a
computer for game data offload. Also, the algorithms for driving this
thing will be more sophisticated than I'd want to try to implement on a
PIC or AVR. Totally open to ideas here though - I've never done anything
with microcontrollers except some robot programming in C with PICs, and
then only using an existing framework.
Driving a huge multicolor LED matrix will be... interesting. The normal
solution for a monochrome display is, as I understand it, a bunch of
shift registers. I guess for this, if you use "true" tricolor LEDs,
you'd just need twice as many shift registers. If you use bicolor LEDs,
which, as I understand it, achieve the third color by duty cycle
trickery (switching between the two colors very rapidly to blend them)
I'm not sure how you could accomplish this. Advice needed.
[Category:Proposed_Projects](Category:Proposed_Projects "wikilink")
+501
View File
@@ -0,0 +1,501 @@
# Electronics Class
This class is targeted at the beginner who wants to learn electronics.
It would make a fine prerequisite to the [Microcontroller
Course](Microcontroller_Course "wikilink") or the
[HAMClass](HAMClass "wikilink")
### tease
These images form a slide show and a gestalt introduction to
electronics. In which we map the techniques available to hackers and
their surrounding requisite building blocks.
- \[<http://wiki.hacdc.org/images/8/82/Mindmap.jpg%5Dmindmap>
My hacking started with music and production. it wasn't exacly the tech;
more for the ride.
- [1](http://wiki.hacdc.org/images/5/5c/Wmuc_main.jpg) WMUC main studio
Complicated behaviour arises from iteration of simple models. Learning
how to operate something like this is simpler and more subtle than it
looks.
- [2](http://wiki.hacdc.org/images/thumb/9/99/Wheatstone.jpg/800px-Wheatstone.jpg)
wheatstone broadcast console
Easier to see is block diagram form; a gestural view of a complex
system. WMUC recording suites and broadcast control rooms. Computing.
- [3](http://wiki.hacdc.org/images/b/b9/Mixerschem.png) signal diagram
Why study DC/baseband/RF electronics; anachronism?
- [4](http://wiki.hacdc.org/images/a/a3/Roofchill.png) chill on the
roof.
Space shuttle shots; APRS , RACES, field day. Social technical effects
require proficiency.
- [5](http://wiki.hacdc.org/images/e/ea/W3eaxtower.png) W3EAX tower
Small systems scale into big ones. 40,000 people at Operation ceasefire
(united for peace& justice) '05 at the national mall. Standing between
SS, Park police and thousands of protesters.
- [6](http://wiki.hacdc.org/images/d/d7/Ceasefirestage.jpeg) ceasefire
stage
- [7](http://wiki.hacdc.org/images/3/30/Ceasefirecrowd.jpeg) ceasefire
40k
No always smooth sailing.
- [8](http://images.spaceref.com/news/2003/09.06.03.noaa-n.med.jpg) mars
needs bolts
Building whimsey.
- [9](http://wiki.hacdc.org/images/b/bf/Dancepanel.jpeg) lightup dance
floor
Computer control over physical objects. microcontrollers + christmas
tree lights.
- [10](http://wiki.hacdc.org/images/f/f3/Dancectll.jpeg) dance floor
controller
Not always smooth. Electrical compatibility != political compatability
- [11](http://wiki.hacdc.org/images/2/2c/Hhr.png) hhr - phear the
transaxle
More small systems iterated.
- [12](http://wiki.hacdc.org/images/c/cc/Igniterschem.jpeg) fireworks
diagram
DIY Ignition source in Berlin. in a pinch you don't need a parts
catalog.
- [13](http://wiki.hacdc.org/images/9/91/Igniterface.jpeg) igniter
controller
Apologies to Dakami
- [14](http://wiki.hacdc.org/images/d/d1/Fireworkscrates.jpeg) fireworks
crates
Simple systems, RC control, Robots and igniters.
- [15](http://2.bp.blogspot.com/_KqHQ-3WDqyk/SFqH25qqRwI/AAAAAAAAAS0/sJ2S8ppcBWQ/s1600-h/1055943372_295788412e.jpg)
wm greek fire
Recently robotics have become accessible to experimenters. Bluto cuts,
welds and hugs.
- [16](http://wiki.hacdc.org/images/4/47/Cadfab.jpg) Welding robots!
## Required Materials
(see also: our [Suppliers page](Suppliers "wikilink"))
---- <img src="Digital_Multimeter.jpg" title="Digital_Multimeter.jpg"
width="200" alt="Digital_Multimeter.jpg" /><img src="Analog_Multimeter.jpg" title="Analog_Multimeter.jpg"
width="200" alt="Analog_Multimeter.jpg" />
- Multimeter \$4
- [Source: Harbor
Freight](http://www.harborfreight.com/7-function-digital-multimeter-92020.html)
------------------------------------------------------------------------
<figure>
<img src="Soldering_iron.jpg" title="Soldering_iron.jpg" width="200" />
<figcaption>Soldering_iron.jpg</figcaption>
</figure>
- Soldering Iron (25-30w) \$10
- [Source: Harbor
Freight](http://www.harborfreight.com/30-watt-120-volt-soldering-iron-47887.html)
------------------------------------------------------------------------
<figure>
<img src="Solder.jpg" title="Solder.jpg" width="200" />
<figcaption>Solder.jpg</figcaption>
</figure>
- Solder ( 22ga )
- [Source: Harbor
Freight](http://www.harborfreight.com/lead-free-rosin-core-solder-95861.html)
- [Source: Radio
Shack](http://www.radioshack.com/product/index.jsp?productId=2062712)
- Or ANYWHERE, really.
------------------------------------------------------------------------
<figure>
<img src="Breadboard.jpg" title="Breadboard.jpg" width="200" />
<figcaption>Breadboard.jpg</figcaption>
</figure>
- Bread Board ( or [AshClassBoard](AshClassBoard "wikilink") ) \$10
- [Source:
Mouser](http://mouser.com/ProductDetail/BusBoard-Prototype-Systems/BB400/?qs=sGAEpiMZZMskUkxWo/qA8g6E2/%252b0L/2p)
- [Source:
Digi-Key](http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=438-1045-ND)
------------------------------------------------------------------------
- wire 24ga
------------------------------------------------------------------------
- 30ga solid core wire
------------------------------------------------------------------------
- Resistors 10kohm
------------------------------------------------------------------------
- variable resistor 10kohm linear \$1
------------------------------------------------------------------------
- switch
[17](http://www.mouser.com/search/ProductDetail.aspx?qs=JTMHOUw%252b%2fhkyoxmWRloCXw%3d%3d)
------------------------------------------------------------------------
- leds (various)
------------------------------------------------------------------------
- capacitor 470uf (ish)
[18](http://www.mouser.com/Search/ProductDetail.aspx?qs=Dj1PTMaP5uJBsuYHd%252b9oGQ%3d%3d)
------------------------------------------------------------------------
- pn2222 transistor \$.03
------------------------------------------------------------------------
- 1/8 male phono jack
`Read The Fine Data Sheet:  They hide secrets in the documentation.`
## Metering
`There are many like it but this one is mine.`
- Naming of parts
- Should be a VOM - Volt Ohm Meter
- metering modes
- restistance - Ohms of resistance
- voltage - Volts
- Current - Amps/Milliamps - check the leads
- diode check - see \[Diodes\]
- leads - plugged into the right ports?
- Continuity testing
- set the meter to the lowest resistance mode (200ohms or auto
resistance)
- or perhaps Diode check; or even beeping
- reads "off scale" when the leads are unconnected, this is an open
circuit
- firmly touch leads together -loopback test
- reads near 0 if the leads are crossed
- Voltage testing
- set meter to 20Vdc or VautoDC
- touch leads to metered points
- the reading on the meter is the difference in voltages between the
leads
- Try AC mains!! - safety second.
#### SwitchLab
- use the continuity meter to diagram the electrical layout of the
switch.
- solder switch to the board.
- test under power with meter voltage setting
## Relays/Switches
Codespeak
- SPDT - single pole dual throw
- DPST - dual pole single throw
- 4P10T - ???
`- Map this mystery switchLab`
## Wire
The basic wire is a pipe through which electrons can flow from the
lowest voltage side to the highest ([conventional
current](wikipedia:Electric_current#Conventional_current "wikilink")) up
to the physical limits of the wire.
- Condunctor vs. Insulators
- Current limit via wire gauge
[19](http://www.powerstream.com/Wire_Size.htm)
- Voltage limit via insulation.
- Magnetic and Electric fields surround an energized wire (what?!)
- And wire will respond with current when moved through magnetic flux
- bass pickups
- Lentz law
- Siemens, mho, ohms
- strip wire
- and don't nick the conductor
## Electromagnetics
- Einstein's "spukhafte Fernwirkung"
- Quantum Electrodynamics
- Electron and photons interact - somehow
- Gauss, Maxwell and
- Permanent magnets useful - locked domains
- Ferro materials, Ni, Co, Sr, Rb, Nb, Nd, Cr and Fe.
- Except when they aren't - curie temperature.
- Hall effect - sensing - spaceship drives
- Motors, linear, rotary, vibrational, direct ( magnetohydrodynamic)
- Radios
- EM probe demo
- EM spectrum
- DC, ELF, SLF (submarines, blue whales), AF, LF,HF, (Short wave),
VHF, UHF, Microwave, weird stuff, gamma rays (the incredible hulk,
gian ants).
## Soldering
`Hold the cold end.`
Soldering ( for our purposes ) is the process of joining electrical
contacts with a low melting point metal to make a mechanically and
electrically strong connection.
- Restrain long hair/clothing/jewelry.
- Clean both parts of waxes, oils or debris.
- Ethanol/Methanol/SLX
- Flux/Rosin/Dry
- Mechanically fit connections together
- Clean and wet the iron
- Tip should be immaculate and bright
- Heat both parts until hot
- Cheat, use another heating element
- quartz floodlight, sterno, propane or mean stare.
- but not too hot - see blue smoke lab
- Apply just enough solder to wet the contact surfaces
- Wait for the connection to shine smoothly
- remove the iron an test the connection
- yes it's hot stupid.
- the meter should find near 0 ohms of resistance between the two
parts even when mechanically stressed.
- the meter should read "off scale" to everything that should be
isolated
- Splice practice
- Western Union Splice
- Pigtail Splice
## Speakermaking lab
materials:
- junk wire, lots of it
- magnet ( stronger is better )
Test stuff:
- multimeter
- signal generator, (or music source)
- power amp
Construction:
- Make coil of wire 24ga 1" dia, 50-400 turns.
- use a form, marker, tp tube, pvc pipe
- Measure impedance \> 1.5 ohm
- Stick coil of wire to diaphram
- Make stator/armature
- stick magnet to something - not too ferrous
- stick diaphram near armature (correct axis??)
- connect to amplifier; apply Rock!
Exercises for suckers:
- Use the lentz law to calculate the force generated by thingy.
- Why 8ohm speakers in the house?
## Resistor
`Not like the NYC variety`
Resistors impede the flow of electrons across them; usually to protect
components from excessive current.
<figure>
<img src="resistoriv.png" title="Image:resistoriv.png" />
<figcaption>Image:resistoriv.png</figcaption>
</figure>
- [Ohm's law](wikipedia:Ohm's_law "wikilink")
- Diagonal IV curve.
- symmetric
##### ResistorLab
- solder resistors, meter and record;
- compare to ohms law math
##### BlueSmokeLab
`Get this out of the way early (and often)`
- turn off the switch
- Solder the 30ga wire ends on to the lab 0 area
- stow fingers away from wire
- turn on switch
## Power
- Measured in watts (usally)
`* .01w laser pointer`
`* .25w cell phone`
`* 1w `
`* 15w car stereo`
`* 25w soldering iron`
`* 100w light bulb`
`* 1500w hair dryer`
`* 200 horsepower (750w/hp)`
`* 3 tons of Air conditioner capacity (3.5kw/ton)`
- The notion of instant work
- Energy or work is expressed in joules (watt\*second). Or perhaps
(Kw\*H)
- Power(watts) = Current (Amps) \* Volts
`Electromechanical relay is a switch that's controlled electrically.`
### pros
- Easy to design for
- debugging (listen for satisfying click)
- excelent isolation
- high power control/\$
### cons
- high drive current (mostly)
- noisy (mostly)
- slow
- moving parts (eeew)
[a typical
relay](http://ecommas.tycoelectronics.com/commerce/DocumentDelivery/DDEController?Action=showdoc&DocId=Data+Sheet%7F1308242_T77%7F1104%7Fpdf%7FEnglish%7FENG_DS_1308242_T77_1104.pdf) -
map this mystery relay lab
#### Diode
<figure>
<img src="diodeiv.png" title="Image:diodeiv.png" />
<figcaption>Image:diodeiv.png</figcaption>
</figure>
##### ScaryDataSheetLab
- a favorite led [20](http://www.vishay.com/docs/83012/83012.pdf)
- LED ( Light emitting diode ) are diodes with a clear case.
- electrons only permitted to flow in one direction: cathode to anode
- there are exceptions \[diode breakdown voltage\]
- discontinuous IV curve
- diode logic
- the cathode is marked
- the diode check function of the meter can reveal the correct polarity
of a mystery diode with a suspect cathode mark.
## Light Emitting Diode
- the short lead is the cathode
- LED's need current limiting (see
[BlueSmokeLab](ElectronicsClass#BlueSmokeLab "wikilink"))
##### LEDLab
- solder in 1kOhm resistor for the led , although you may use another if
you can justify the value
- Solder in the LED, with the short lead towards the ground.
## Motor
## Printed Circuits
## Capacitor
`470??f electrolytic cap`
<figure>
<img src="capt.png" title="Image:capt.png" />
<figcaption>Image:capt.png</figcaption>
</figure>
[wikipedia capacitor](http://en.wikipedia.org/wiki/Capacitor)
$\operator {work} (V) =
\frac {1}{2}
2)Cv^2$ Hmm.. no teX support here.
#### Applications
- Filters
- Decoupling - Ripple rejection
- Blocking - DC Bias rejection
- Use in networks - equalization networks
- Storage
- Pump and dump - Photoflash.
- Tank application - DC - DC converters
- Esoteric
- Sensors - Strain gauge
- Microphones - Old school
- nonlinear math - Calculating logs/exponents.
## Transistor
`PN2222 N channel transistor`
`Elliot substitute-taught a class on transistor amplifiers...`
`Notes in PDF are here:`
[`Media:transistorLecture.pdf`](Media:transistorLecture.pdf "wikilink")
### little amplifierlab
- class A amp
- DC blocking caps
- bias resistors
- fixed gain
- inverted waveform
### construction intro
- breadboard intro
- soldering intro
- led circuit
## Digital Logic
- AND C = A & B
- OR C = A \| B
- NOT C = !A
- NOR C = !(A\|B)
- NAND C = !(A&B)
- MUX C = select A(n) based on B(n)
## IC
`LM386 Audio Amplifier `[`21`](http://www.national.com/mpf/LM/LM386.html)
# Links and class notes
- 7-28
- [How bipolar junction transistors actually
work](http://www.allaboutcircuits.com/vol_3/chpt_2/8.html)
[Category:Classes](Category:Classes "wikilink")
+23
View File
@@ -0,0 +1,23 @@
Counter module to be used with the [Spartan 3E Board
tutorial](http://wiki.hacdc.org/index.php/File:ISE_Tutorial_for_S3E.pdf).
module counter(clock, count_out);
input clock;
output [3:0] count_out;
reg [3:0] count_int=0;
reg [26:0] t=0;
always @(posedge clock)
if (t==4)
begin
count_int <= count_int + 1;
t=0;
end
else
t=t+1;
assign count_out=count_int;
endmodule
[Category:FPGAWorkshop](Category:FPGAWorkshop "wikilink")
+251
View File
@@ -0,0 +1,251 @@
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Digital Design and FPPGA Workshop
HacDC
William Gibb (teachmeFPGA@gmail.com)
Week 3 - Introduction to Combinatorial Verilog
Full adder and ALU exercise
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
For our exercises this week, we'll be working with a few different modeling
styles, focused around a 4-bit full adder. We'll be working with a model
where the 1 bit full adder circuit is explicitly defined, and break that down
into half adders, behavioral and structural models.
The full adder circuit can be constructed from 1-bit half adder circuits.
The truth table for the half adder is as follows.
A B | S Cout
=========
0 0 | 0 0
0 1 | 1 0
1 0 | 1 0
1 1 | 0 1
=========
S = A xor B
Cout = A and B
Two of these cells, plus an additional OR gate, can be used to implement a
full adder. The S output of the first half adder cell is connected to the
input of the second cell, as is the Cin. The S output of the second cell is
the sum S. The Cout is computed by ORing the Cout of both cells.
Likewise, the truth table for the Full Adder is as follows, for reference.
Cin A B | S Cout
===============
0 0 0 | 0 0
0 0 1 | 1 0
0 1 0 | 1 0
0 1 1 | 0 1
1 0 0 | 1 0
1 0 1 | 0 1
1 1 0 | 0 1
1 1 1 | 1 1
================
To do
0) Copy the full adder codes below to files in your working directory.
Be sure to copy a makefile to the directory.
0.a) mkdir a new directory for this example. name it something useful, such as "adder_exercise"
0.b) create a new file for each verilog module, in the form modulename.v where module name is the name of the module. We'll need full_adder.v, full_adder_4bit.v, add test_adder.v.
0.c) copy and paste the code for each module into the file. be sure that anything in the file that isn't verilog code is commented out.
0.d) if your in the vm, type copymake.sh into the command line to copy a makefile into your working directory
1) Change the values of the makefile to test the full adder.
1.a) Change the line SRC and TESTBENCH to include only the .v files created earlier. if you need to add a new source to a project, add it to your makefile as well.
2) Verify the full adder works by simulation.
3) Write a description of the half adder, at gate level
4) Write a full adder description, using the half adders you wrote in step
3. Give this full adder module a different module name than the provided
model.
5) Write a 4 bit full adder module using the new 1 bit full adder. Be sure to
give it a module name different than the name of the provided module.
6) Take a break if you feel needed...or keep on coding
7) Write a 4 bit full adder module using the new 1 bit full adder from step 6.
Be sure to give it a module name different than the name of the provided
module.
8) One last adder - Write a 4 bit behavioral adder module. Use 4 bit inputs
and outputs in this module. Again, give it a new name.
9) Add the new models to the makefile.
-half adder
-full adder from half adders
-4 bit full adder from step 5
-full adder from step 6
-4 bit full adder from step 7
-4 bit full adder from step 8
9) Modify the testbench to instantiate the new modules. You'll need to
instantiate the 4 bit full adder from step 5, step 7 and step 8. This is why
they all need to have unique module names. You'll need to add three 4 bit
wires for connecting the sum output of these new adders, as well as
three 1 bit wires for connecting the cout output of these new adders.
10) Simulate and verify all of the models behave the same way.
Once this is done, and you have simulated the adders and shown that they all
behave the same way, you'll have built the following types of modules
- Structural Model (step 5)
- Behavioral & Hierarchical Model (step 7)
- Behavioral Model (step 8)
After that is done, people are encouraged to take the ALU presented in the
slides and are encouraged to expand the functionality of the ALU to 8 total
functions. The functions that should be added to the ALU are as follows:
- r = ~A (R equals the complement of A)
- r = A ^ B (R equals A xor B)
- r = A << B (R equals A left shifted B bits)
After this functionality has been added to the ALU model, the test bench used
for the 4 bit full adder can be modified to simulate the ALU.
Steps to do this
0) Copy the test bench and makefile to your working directory
1) Add/remove wires and regs as needed
2) Replace the DUT with the ALU
3) Expand the inputs in order to test all of the ALU functions.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Full Adder Code
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
module full_adder(a, b, cin, sum, cout);
input a, b, cin;
output sum, cout;
reg sum, cout;
always @(a or b or cin)
begin
sum = a ^ b ^ cin;
cout= (a & b) | (a & cin) | (b & cin);
end
endmodule
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
module full_adder_4bit (a, b, cin, sum, cout);
input[3:0] a, b;
input cin;
output [3:0] sum;
output cout;
wire c1, c2, c3;
// instantiate 1-bit adders
full_adder FA0(a[0],b[0], cin, sum[0], c1);
full_adder FA1(a[1],b[1], c1, sum[1], c2);
full_adder FA2(a[2],b[2], c2, sum[2], c3);
full_adder FA3(a[3],b[3], c3, sum[3], cout);
endmodule
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
module test_adder;
reg[3:0] a, b;
reg cin;
wire [3:0] sum;
wire cout;
full_adder_4bit dut(a, b, cin,
sum, cout);
initial
begin
a = 4'b0000;
b = 4'b0000;
cin= 1'b0;
#50;
a = 4'b0101;
b = 4'b1010;
// sum = 1111, cout= 0
#50;
a = 4'b1111;
b = 4'b0001;
// sum = 0000, cout= 1
#50;a = 4'b0000;
b = 4'b1111;
cin= 1'b1;
// sum = 0000, cout= 1
#50;
a = 4'b0110;
b = 4'b0001;
// sum = 1000, cout= 0
end // initial begin
initial
begin
$dumpfile ("waves.lxt");
$dumpvars(0,test_adder);
end
endmodule// test_adder
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ALU Code
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
module mul16(i0,i1,prod);
input [15:0] i0,i1;
output [31:0] prod;
// this is a magnitude multiplier
// signed arithmetic later
assign prod = i0 * i1;
endmodule
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
module add32(i0,i1,sum);
input [31:0] i0,i1;
output [31:0] sum;
assign sum = i0 + i1;
endmodule
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
module sub32(i0,i1,diff);
input [31:0] i0,i1;
output [31:0] diff;
assign diff = i0 - i1;
endmodule
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
module mux32two(i0,i1,sel,out);
input [31:0] i0,i1;
input sel;
output [31:0] out;
assign out = sel? i1 : i0;
endmodule
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
module mux32three(i0,i1,i2,sel,out);
input [31:0] i0,i1,i2;
input [1:0] sel;
output [31:0] out;
reg[31:0] out;
always @ (i0 or i1 or i2 or sel)
begin
case (sel)
2???b00: out = i0;
2???b01: out = i1;
2???b10: out = i2;
default: out = 32???bx;
endcase
end
endmodule
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
module alu(a, b, f, r);
input [31:0] a, b;
input [2:0] f;
output [31:0] r;
// wire declarations
wire [31:0] addmux_out, submux_out;
wire [31:0] add_out, sub_out, mul_out;
// module declarations
mux32two adder_mux(b, 32'd1, f[0], addmux_out);
mux32two sub_mux(b, 32'd1, f[0], submux_out);
add32 our_adder(a, addmux_out, add_out);
sub32 our_subtracter(a, submux_out, sub_out);
mul16 our_multiplier(a[15:0], b[15:0], mul_out);
mux32three output_mux(add_out, sub_out, mul_out, f[2:1], r);
endmodule
[Category:FPGAWorkshop](Category:FPGAWorkshop "wikilink")
+157
View File
@@ -0,0 +1,157 @@
Homework/Verilog Coding problems
## An Upcounter design
An upcounter can be made with 3 elements - DFFs, XOR and AND gates.
The equations for a simple upcounter are a chain. The Di and Qi notation
refer to the D and Q ports on a DFF.
D0=!Q0 ^ 1
D1=Q1 ^ Q0
D2=Q2 ^ Q1&Q0
D3=Q3 ^ Q2&Q1&Q0
....
Di=Qi ^ Qi-1&Qi-2 .... &Q2&Q1&Q0
Equations 1
A upcounter described as such will continue to count whenever the
flipflops are driven
by the clock.
Say we wanted to turn the counter off and on?
The first bit, Q0, is fed by the equation D0. Its change is dependent on
the second input to the xor gate, which we see is hardwired to a one. If
we xor a zero, there is no change to the least significant digit, and
the counter won't count.
We change the equations to add an enable signal.
D0=!Q0 ^ Enable
D1=Q1 ^ Q0&Enable
D2=Q2 ^ Q1&Q0&Enable
D3=Q3 ^ Q2&Q1&Q0&Enable
....
Di=Qi ^ Qi-1&Qi-2 .... &Q2&Q1&Q0&Enable
Equations 2
Write verilog code to implement a counter like this and use a testbench
to simulate the design. I would do 4 or 8 bits wide.
## Shift Registers
The LFSR is built on the idea of a shift register. This is constructed
by taking the output of a DFF and connecting it directly to the input on
a second DFF. Lets consider the case of a n bit shift register.
module shift(D, Q, Q_regs, clk, rst);
parameter N=4;
parameter TP=1;
input D, clk, rst;
output Q;
output [N-1:0] Q_regs;
reg [N-1:0] Q_regs;
assign Q = Q_regs[n-1];
always@(posedge clk)
if(rst)
Q_regs <= #Tp 'b0;
else
Q_regs <= #Tp {Q_regs[n-2:0],D};
end module
Code 1 // updated from the slides
Data placed on D is shifted into the DFFs modeled by the always@ process
& the reg data type. The data available on the output is the nth data
bit, so over time data would be shifted in and made available. Table 1
below shows the operation of the shift register.
CLK D Q | Q3 Q2 Q1 Q0
^ 0 0 | 0 0 0 0
^ 1 0 | 0 0 0 1
^ 1 0 | 0 0 1 1
^ 0 0 | 0 1 1 0
^ 1 1 | 1 1 0 1
^ 0 1 | 1 0 1 0
^ 0 0 | 0 1 0 0
^ 0 1 | 1 0 0 0
Table 1
I recommend coding up a shift register and simulate it in order to see
the shift register in action.
## Linear Feedback shift register
A LSFR is a shift register, but the data shifted into the register is
actually a linear combination of the data currently in the register.
From Wikipedia
<http://en.wikipedia.org/wiki/Linear_feedback_shift_register>
"The only linear functions of single bits are xor and inverse-xor; thus
it is a shift register whose input bit is driven by the exclusive-or
(xor) of some bits of the overall shift register value.
The initial value of the LFSR is called the seed, and because the
operation of the register is deterministic, the stream of values
produced by the register is completely determined by its current (or
previous) state. Likewise, because the register has a finite number of
possible states, it must eventually enter a repeating cycle. However, an
LFSR with a well-chosen feedback function can produce a sequence of bits
which appears random and which has a very long cycle.
Applications of LFSRs include generating pseudo-random numbers,
pseudo-noise sequences, fast digital counters, and whitening sequences.
Both hardware and software implementations of LFSRs are common."
Fibonacci LSFRs The bits in the LFSR state which influence the input are
called taps. A maximum-length LFSR produces an m-sequence (i.e. it
cycles through all possible 2n ??? 1 states within the shift register
except the state where all bits are zero), unless it contains all zeros,
in which case it will never change. As an alternative to the XOR based
feedback in a standard LFSR, one can also use XNOR. A state with all
ones is illegal when using an XNOR feedback, in the same way as a state
with all zeroes is illegal when using XOR. This state is considered
illegal because the counter would remain "locked-up" in this state.
End Wikipedia
Maximal length LFSRs are built with specially choosen taps, which are
represented by polynomials. The 3 bit LFSR polynomial x^3+x^2+1 could be
represented by the following implementation.
module lfsr_example(D, Q, Q_bus, clk, rst);
parameter N=3;
parameter Tp=1;
input D, clk, rst;
output Q;
output [N-1:0] Q_regs;
reg [N-1:0] Q_regs;
assign Q = Q_regs[0];
always@(posedge clk)
if(rst)
Q_regs <= #Tp N'b1;
else
Q_regs <= #Tp {Q_regs[1],Q_regs[0],Q_regs[1]^Q_regs[2]};
end module
Code 2
Code 2 shows the implementation taking place inside the always@ block.
There are different ways to do this, this is just one example. For
homework/exercise, implement a LFSR with a maximal length polynomial.
Use a 4, 5, 6, 7 or 8 bit polynomial from the Wikipedia LFSR page in
your implementation and build a testbench to simulate it.
Awesomeness points are awarded for a selfchecking testbench which
actually proves that the LFSR is maximal length.
Other LFSR resources <http://homepage.mac.com/afj/lfsr.html>
<http://www.yikes.com/~ptolemy/lfsr_web/index.htm>
[Category:FPGAWorkshop](Category:FPGAWorkshop "wikilink")
+147
View File
@@ -0,0 +1,147 @@
Code from 4 person hacking session on 11/11.
The following code may or may not work properly - It appears to give relatively sane counter output in GTKWAVE.
// FALLING EDGE D FLIP FLIP MODULE:
//==============================================
module d_ff_gates (d, clk, rst, q, q_bar);
input d, clk, rst;
output q, q_bar;
wire n1,n2,n3,q_bar_n;
wire cn,dn,n4,n5,n6;
// First Latch
not (n1,d);
nand (n2,d,clk);
nand (n3,n1,clk);
nand (dn,q_bar_n,n2);
nand (q_bar_n,dn,n3, !rst);
// Second Latch
not (cn,clk);
not (n4,dn);
nand (n5,dn,cn);
nand (n6,n4,cn);
nand (q,q_bar,n5);
nand (q_bar,q,n6, !rst);
endmodule
// FALLING EDGE D FLIP FLIP TESTBENCH:
//==============================================
module d_ff_gates_tb;
reg d, clk;
wire q, q_bar;
d_ff_gates dut(d, clk, q, q_bar);
initial
begin
d=0; #1;
clk=0; #1;
clk=1; #1;
clk=0; #1;
clk=1; #1;
clk=0; #1;
clk=1; #1;
clk=0; #1;
clk=1; #1;
d=1; #1;
clk=0; #1;
clk=1; #1;
clk=0; #1;
clk=1; #1;
clk=0; #1;
clk=1; #1;
clk=0; #1;
clk=1; #1;
end
initial
begin
$dumpfile ("waves.lxt");
$dumpvars (0, d_ff_gates_tb);
end
endmodule
// 4 BIT COUNTER MODULE:
//==============================================
module upcounter (rst, clk, enable, q, qb);
input rst, clk, enable;
output [3:0] q, qb;
wire d0, d1, d2, d3; // input wires
wire a0, a1; // and wires
//q[1] = 1'b0; q[2] = 1'b0; q[3] = 1'b0; // init q
xor (d0, q[0], 1'b1); // d0 = q0 xor 1
d_ff_gates dff0(d0, clk, rst, q[0], qb[0]);
xor (d1, q[1], q[0]); // d1 = q1 xor q0
d_ff_gates dff1(d1, clk, rst, q[1], qb[1]);
and (a0, q[1], q[0]);
xor (d2, q[2], a0); // d2 = q2 xor (q1 && q0)
d_ff_gates dff2(d2, clk, rst, q[2], qb[2]);
and (a1, q[2], q[1]);
xor (d3, q[3], a1); // d3 = q3 xor (q2 && q1 && q0)
d_ff_gates dff3(d3, clk, rst, q[3], qb[3]);
endmodule
// 4 BIT COUNTER TESTBENCH:
//==============================================
module upcounter_tb;
reg rst, clk, enable;
wire [3:0] q, qb;
upcounter dut(rst, clk, enable, q, qb);
initial
begin
rst = 1;
enable = 0;
clk=0; #1;
rst = 0;
clk=1; #1;
clk=0; #1;
clk=1; #1;
clk=0; #1;
clk=1; #1;
clk=0; #1;
clk=1; #1;
clk=0; #1;
clk=1; #1;
clk=0; #1;
clk=1; #1;
clk=0; #1;
clk=1; #1;
clk=0; #1;
clk=1; #1;
end
initial
begin
$dumpfile ("waves.lxt");
$dumpvars (0, upcounter_tb);
end
endmodule
[Category:FPGAWorkshop](Category:FPGAWorkshop "wikilink")
+255
View File
@@ -0,0 +1,255 @@
## Shift Register
//filename sr.v
`include "timescale.v"
module sr(D, Q, Q_regs, clk, rst);
parameter Ndepth=4;
parameter TP=1;
input D, clk, rst;
output Q;
output [Ndepth-1:0] Q_regs;
reg [Ndepth-1:0] Q_regs;
assign Q = Q_regs[Ndepth-1];
/* This is a comment block
Hi Elliot
This works fine! */
always@(posedge clk)
if(rst)
Q_regs <= #TP 0; //This is a comment
else
Q_regs <= #TP {Q_regs[Ndepth-2:0],D};
endmodule
## Shift Register Testbench
//
// filename sr_tb.v
//
// Exercise 6
// FPGA Workshop - HacDC
// Group think
//
`include "timescale.v"
module sr_tb();
// Parameters
parameter CLKPERIOD = 20; // 50Mhz w/ 1ns time increments
parameter FINISHTIME = 1000;
// DUT INPUTS
reg D;
reg clk;
reg rst;
// DUT OUTPUTS
wire Q;
wire [3:0] Q_regs;
// Misc
reg finish;
// Event defitions
event reset;
// DUT Instantiation
// shift(.D(), .Q(), .Q_regs(), .clk(), .rst());
sr DUT(.D(D),
.Q(Q),
.Q_regs(Q_regs),
.clk(clk),
.rst(rst));
// --------
// Stimulus
// --------
// Clk Generation
always
#(CLKPERIOD/2) clk = ~clk;
// Initial Conditions
initial
begin
D = 0;
rst = 0;
clk = 1;
finish = 0;
// Wait to end the simulation
#FINISHTIME
$display("=============================");
$display("I'm done now!");
$display("Finished at time %5d", $time);
$finish;
end
// Inputs
initial
begin
#1 -> reset; //event calls like to occur after some
//period of time
wait(finish);
finish = 0;
repeat (5)
#CLKPERIOD;
D=1;
wait (Q);
#CLKPERIOD
D=1;
#CLKPERIOD
D=0;
#CLKPERIOD
D=1;
#CLKPERIOD
D=0;
repeat (5)
#CLKPERIOD;
$display("================");
$display("End of Stimulus");
$display("Finishing at time %5d", $time);
$finish;
end
// Event defitions
always @(reset)
begin
$display ("Resetting the Registers");
#(CLKPERIOD/2) rst = 1;
#CLKPERIOD rst = 0;
finish = 1;
end
// Monitor
initial
begin
$dumpfile ("waves.lxt");
$dumpvars(0,sr_tb);
end
endmodule
## Linear Feedback Shift Register
module lfsr(Q, Q_regs, clk, rst);
// x^5+x^3+1
parameter N=5;
parameter Tp=1;
input clk, rst;
output Q;
output [N-1:0]
Q_regs; reg [N-1:0] Q_regs;
assign Q = Q_regs[0];
always@(posedge clk)
if(rst)
Q_regs<= #Tp 5'b1;
else
Q_regs<= #Tp {Q_regs[3], Q_regs[2], Q_regs[1], Q_regs[0], Q_regs[4]^Q_regs[2]};
endmodule
## LFSR Testbench
//
// Exercise 6
// FPGA Workshop - HacDC
// Group think
//
`include "timescale.v"
module lfsr_tb();
// Parameters
parameter CLKPERIOD = 20; // 50Mhz w/ 1ns time increments
parameter FINISHTIME = 2*1000;
// DUT INPUTS
reg clk;
reg rst;
// DUT OUTPUTS
wire Q;
wire [4:0] Q_regs;
// Misc
reg finish;
// Event defitions
event reset;
// DUT Instantiation
// lfsr(.Q(), .Q_regs(), .clk(), .rst());
lfsr DUT(.Q(Q),
.Q_regs(Q_regs),
.clk(clk),
.rst(rst));
// --------
// Stimulus
// --------
// Clk Generation
always
#(CLKPERIOD/2) clk = ~clk;
// Initial Conditions
initial
begin
rst = 0;
clk = 1;
finish = 0;
// Wait to end the simulation
#FINISHTIME
$display("=============================");
$display("I'm done now!");
$display("Finished at time %5d", $time);
$finish;
end
// Inputs
initial
begin
#1 -> reset; //event calls like to occur after some
//period of time
wait(finish);
finish = 0;
repeat (62)
#CLKPERIOD;
$display("================");
$display("End of Stimulus");
$display("Finishing at time %5d", $time);
$finish;
end
// Event defitions
always @(reset)
begin
$display ("Resetting the Registers");
#(CLKPERIOD/2) rst = 1;
#CLKPERIOD rst = 0;
finish = 1;
end
// Monitor
initial
begin
$dumpfile ("waves.lxt");
$dumpvars(0,lfsr_tb);
end
endmodule
## Timescale
//
// filename timescale.v
//
`timescale 1ns / 10ps
[Category:FPGAWorkshop](Category:FPGAWorkshop "wikilink")
+144
View File
@@ -0,0 +1,144 @@
## Level-to-pulser
Finite state machine implementation of a device that takes a level
change (low to high) and turns it into a one-period pulse.
module levelToPulse(clk, in, out, reset);
input clk, in, reset;
output reg out;
reg [1:0] state, next;
// States
parameter WAIT_LOW = 0;
parameter WAIT_HIGH = 1;
parameter RISING = 2; // I've just seen a rising edge
parameter PULSE = 3; // I'm in the process of generating a pulse
// Reset or update the state on every clock
always @ (posedge clk or reset)
begin
if (reset)
begin
state <= WAIT_LOW;
next <= WAIT_LOW;
out = 0;
end
else
state <= next;
end
// What to do in each state
always @ (state or in) begin
case (state)
WAIT_LOW:
begin
if (in == 1)
next = RISING;
end
RISING:
begin
out = 1;
next = PULSE;
end
PULSE:
begin
out = 0;
if (in == 0)
next = WAIT_LOW;
else
next = WAIT_HIGH;
end
WAIT_HIGH:
if (in == 0)
next = WAIT_LOW;
endcase // case (state)
end
endmodule
## Level-to-pulser Testbench
module test_stateMachine();
// Parameters
parameter CLKPERIOD = 20; // 50MHz at 1ns
parameter FINISHTIME = 1000; // 1ms
// DUT inputs
reg clk, in, reset;
// DUT outputs
wire out;
// DUT instantiation
//
levelToPulse DUT(clk, in, out, reset);
// Stimulus
// Clock generation
always
#(CLKPERIOD/2) clk = ~clk;
// Initial conditions
initial
begin
in = 0;
clk = 1;
reset = 0;
// When at finishtime -- this shouldn't happen. It's just a safety.
#FINISHTIME $display ("Reached the end of the sidewalk: %5d", $time);
$finish;
end
// Inputs
initial
begin
// Reset and wait
#3 reset = 1;
#3 reset = 0;
repeat(5)
#CLKPERIOD;
// Go level high
in = 1;
repeat(5)
#CLKPERIOD;
// Go low
in = 0;
repeat(4)
#CLKPERIOD;
// Delay a short time so that input is in different phase with the clock
#(CLKPERIOD / 2);
in = 1;
repeat(5)
#CLKPERIOD;
$display("-----------------------");
$display("- Normal End at %5t -", $time);
$display("-----------------------");
$finish;
end
// Monitor
initial
begin
$dumpfile ("test_stateMachine.lxt");
$dumpvars(0, test_stateMachine);
end
endmodule
[Category:FPGAWorkshop](Category:FPGAWorkshop "wikilink")
+110
View File
@@ -0,0 +1,110 @@
- Download the Frequency Counter and Frequency Generator reference
designs from
<http://www.xilinx.com/products/boards/s3estarter/reference_designs.htm>
- Download the Picoblaze processor core from
<http://www.xilinx.com/products/ipcenter/picoblaze-S3-V2-Pro.htm>
- Unzip these projects & picoblaze source to your ~/Projects directory
(or appropriatlely)
- Implementing the projects directly
- Each project comes with a .bit file that you can use to program the
FPGA starter kit with. Use impact to program the chip.
- On Windows, you can run the install batch scripts to run impact
automatically.
- Find a buddy with a board, and each of you program your respective
boards. Grab an SMA cable and use that to check the output of the
generator with the counter.
- Implementing the projects through ISE
- Implementing the frequency counter
- In the frequency counter folder, there is a pdf. It is the readme
for the project. It will be your friend - it details how to
quickly run the project, setup the ISE project, design details for
the hardware and picoblaze software, and some more project ideas.
- In ISE, create a new design called "s3e_ref_freq_count" in your
~/Projects directory.
- Add the existing .vhd and .ucf sources from the frequency counter
reference design folder that you unzipped
- Add the existing .vhd source for kcpsm3.vhd from the picoblaze
VHDL source folder
- A portion of the design uses a undocumented mode of operation for
the S3E DCM. Instructions for enabling this can be found in the
dcm_fixed_osc.vhd file. In my experience, this breaks P&R (-will),
and this should be removed in order to complete the design. The
DCM is simply working in an free-running oscillator mode; this is
merely used to provide a frequency source for testing and its
removal will not adversely affect the design.
- You'll need to modify the **frequency_counter.vhd** file in the
project, to remove the instance of 'dcm_fixed_osc.vhd' from the
design. We won't be doing anything in-depth with VHDL so don't
be intimidated by the different language syntax.
- You'll want to comment out the component dcm_fixed_osc (approx
line 117) . In VHDL, comments are done with double hypens, --.
- Commented out component
<!-- -->
--
-- Fixed frequency oscillator using a DCM
--
--component dcm_fixed_osc
-- port( clk_out : out std_logic;
-- kick_start : in std_logic );
-- end component;
- - The instantiation of the dcm_fixed_osc needs to be commented out
(approximately line 223)
- Commented portion
<!-- -->
-- dcm_fixed_oscillator: dcm_fixed_osc
-- port map ( clk_out => dcm_oscillator,
-- kick_start => source_control(7) );
- - Now we'll need to change the multiplexer. To keep the design nearly
intact, we'll replicate the ring oscillator signal twice (approx
line 245).
- Changed multiplexer
<!-- -->
freq_for_measurement <= sma_clk when (source_control(1 downto 0)="00")
else clk_50mhz when (source_control(1 downto 0)="01")
else ring_oscillator when (source_control(1 downto 0)="10")
else ring_oscillator;
- - Select the top level module, and take it through the implementation
process - synthesis, place and route, generate programming file.
- Use impact to program the .bit file to the FPGA! It should
- - Implementing the frequency generator
- In the frequency generator folder, there is a pdf. It is the
readme for the project. It will be your friend - it details how to
quickly run the project, setup the ISE project, design details for
the hardware and picoblaze software, and some more project ideas.
- In ISE, create a new design called "s3e_ref_freq_ref" in your
~/Projects directory.
- Add the existing .vhd and .ucf sources from the frequency ref
reference design folder that you unzipped
- Add the existing .vhd source for kcpsm3.vhd from the picoblaze
VHDL source folder
- A portion of the design uses a undocumented mode of operation for
the S3E DCM. Instructions for enabling this can be found on page
13 of the Frequency generator documentation. **The design will not
work if the instructions are not followed!**
- Afer this is done, you should be able to implement this design and
program the FPGA with impact.
- Things you can do!
- You can use the .ucf file to move around the pin assignments. For
instance, you can have the frequency counter read the clock input
off of a stake or one of the pmod headers.3
- Easy extension - create a second ring oscillator, called ring_osc2.
You can extend the ring_osc.vhd for this purpose, adding additional
delay stages will decrease the frequency generated. Follow a similar
format, to the rest of the VHDL code, to declare the component,
instantiation, a second ring_oscillator signal, and modify the
multiplexer.
- Once that is done, synthesis, P&R, and program the design. Select
the second ring oscillator and see what its frequency is!
- Look at the PDF's which come with the reference designs for more
ideas!
[Category:FPGAWorkshop](Category:FPGAWorkshop "wikilink")
+85
View File
@@ -0,0 +1,85 @@
Placeholder...
## Verilog Define Statements
Verilog provides a text macro substitution facility. This may be useful
for defining constants, opcodes, or with conditional compilation. To
define a text macro, use the define keyword.
`define myCode 13
When you want to use the macro, simple use the macroname with a accent
key.
a = `myCode;
The following compile directives are available for use
`include Includes another file, avoid using pathnames
`define Define a text macro
`ifdef Starts conditional compilation, dependant on if a macro has been defined
`else Alternate condiational compilation
`endif Ends conditional compilation
`ifndef Starts conditional compilation, like `ifdef
`elseif Alternative conditional compilation
The use of *\`define* doesn't require that the macro be given a value.
This allows for the following code style (exceprt from a defines.v
file).
// Number of bits used for devider register. If used in system with
// low frequency of system clock this can be reduced.
// Use SPI_DIVIDER_LEN for fine tuning theexact number.
//
`define SPI_DIVIDER_LEN_8
//`define SPI_DIVIDER_LEN_16
//`define SPI_DIVIDER_LEN_24
//`define SPI_DIVIDER_LEN_32
`ifdef SPI_DIVIDER_LEN_8
`define SPI_DIVIDER_LEN 5 // Can be set from 1 to 8
`endif
`ifdef SPI_DIVIDER_LEN_16
`define SPI_DIVIDER_LEN 16 // Can be set from 9 to 16
`endif
`ifdef SPI_DIVIDER_LEN_24
`define SPI_DIVIDER_LEN 24 // Can be set from 17 to 24
`endif
`ifdef SPI_DIVIDER_LEN_32
`define SPI_DIVIDER_LEN 32 // Can be set from 25 to 32
`endif
Likewise, conditional compilation of code is possible
module add23(
a,
b,
`ifdef ADD3
c,
`endif
sum);
output [3:0] sum;
input [3:0] a, b;
`ifdef ADD3
input [3:0] c;
`endif
assign sum =
`ifdef ADD3
c+
`endif
a+b;
endmodule
## Verilog Events
Lorem Ipsum
## Verilog Tasks
Lorem Ipsum
[Category:FPGAWorkshop](Category:FPGAWorkshop "wikilink")
+160
View File
@@ -0,0 +1,160 @@
*These notes are intended to highlight bits of information from the
Xilinx KCPSM3 manual distributed with the microprocessor*
**Xilinx Picoblaze**
KCPSM3 - An 8 Bit Microcontroller for Xilinx Spartan 3 & Virtex 2/4
devices
**What is kcpsm3**
Very Simple microcontroller. Can be used for data processing or as a
complex state machine.
**KCPSM** - (**K**)constant **C**oded **P**rogrammable **S**tate
**M**achine
Its very small - 96 Spartan3 slices + 1 block ram
Our boards - 4656 slices -\> that is 2% of the slice resources!
Entirely embedded in the fpga fabric - integrates with all the logic
you've already been writing!
**kcpsm is small**
Konstant explained - notice how the mips = 1/2 clock speed?
CPI of the processor is 2. And fixed at 2. that makes it very easy to
determine the runtime of a program in an embedded system.
**kcpsm3 architecture**
architecture is closed (it is a xilinx macro, not a readily readable
verilog design) but the architecture is not secret though
simple input port/output based IO, up to 256 addressable 8bit
ports/devices 16 general purpose registers 64 byte memory/scratch pad
alu with carry/zero flags single interrupt line/acknowledge program
counter control/instruction decoder program memory
**device features**
program memory - 1 18kb block ram! this stores 1024 18 bit instructions.
16 general purpose registers. No dedicated zero register or accumulator
alu - does add/sub/add&sub with carry alu - load/and/or/xor bitwise
alu - shift/rotates flags and flow control - help determine program flow
with carry/zero flags + conditional jump/call instructions interrupts -
jumps to a single address (initiates CALL 3FF) - an ISR
**using the kcpsm3** used as a verilog module in the design flow. simply
copy the kcpsm3.v file into your project and instantiate it kcpsm3
assembler generates a verilog memory file - use that in your design as
well. connect the two modules together. alternatively - use the
embedded_kcpsm3.v file
**instruction set**
1. program control group
1. unconditional jump
2. conditional jumps (branches!)
3. call/return with stack depth of 31
2. interrupt group
1. enable/disable interrupt
2. return from isr & either enable/disable the interrupt
3. storage group
1. store/fetch data from the scratch pad
4. i/o group
5. arithmetic group
1. add/sub/compare
1. work with 2 operands or 1 operand and a constant
6. logical group
1. load/and/or/xor/test
1. work with 2 operands or 1 operand and a constant
7. shift/rotate group
1. both left/right shifts available
pointers available
**port access**
input and output ports available.
very simple with the two cycle operation
1. 1st cycle - instruction decode
2. 2nd cycle - instruction execute
Read strobe - not needed, port_id used w/ a mux to determine what gets
put on input port. data captured by kcpsm3 on next clock edge.
write strobe - use as a clock enable signal for external circuitry to
capture data from out port.
\<8 output ports, use 1hot addressing
\>8 output ports, use address decoder to enable the correct port
input ports -\> leads itself to a multiplexed architecture
**reset**
synchronous to kcpsm3 clock. blanks the processor and restarts it at
address 0x000.
**picoblaze assembler**
xilinx assembler is a dos program, which accepts .psm (picoblaze
assembler) source files and outputs vhdl/verilog files for your use
multipass, lots of quick information. don't be afraid to dump the file.
possible to run under wine/dosbox, lots of alternatives available.
**program syntax**
1. blank lines are ignored
2. comments begin with ;
3. registers - form sX, where X={0,1,2,..9,A,...,E,F}
4. constants
5. Data value - 00 -\>FF
6. Port value - 00 -\>FF
7. Address - 000 -\>3FF
8. Line labels: Useful for call and jump instructions!
constant -\> define a label used within the program for holding a
constant value. like a C macro
namereg -\> define a label used within the program for identifying a
register. allows for much more readable code.
**Interrupts**
slides are really detailed about this and good - read them
**call/return stack**
31 level call/return stack. program counter preserved upon the calll
instruction or interrupt. registers are not preserved - be careful not
to clobber your registers.
**simulation** picoblaze assembly simulators exist - \> prove your code
by hand (slow) nothing stopping you from simulating the HDL design - but
can be very slow. quicker to fix hardware design -\> then code and
download to picoblaze via jtag and run the software.
**other picoblaze ide/assemblers/simulators/implementations that are not
from xilinx**
1. **pacoblaze** [Pacoblaze](http://www.bleyer.org/pacoblaze/)
opensource, picoblaze compliant verilog implementation. complete
with java assembler.
2. **openPicIDE** [openPicIDE](http://www.openpicide.org/) opensource
picoblaze ide/assembler/simulator. very robust! works on linux, mac,
windows.
3. **mediatronix picoblaze ide**
[mediatronix](http://www.mediatronix.com/tools/index.htm) amazing
windows picoblaze ide
4. **kpicosim** [kpicosim](http://www.xs4all.nl/~marksix/) picoblaze
simulator and assembler. linux
[Category:FPGAWorkshop](Category:FPGAWorkshop "wikilink")
+284
View File
@@ -0,0 +1,284 @@
this is known broke - will
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 11:23:27 01/28/2010
// Design Name:
// Module Name: frequency_counter
// Project Name:
// Target Devices:
// Tool versions:
// Description: Verilog implementatino of the frequency counter reference
// design from Xilinx for Spartan 3E Starter Kit
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module frequency_counter(
output [7:0] led,
input [4:0] sw,
output strataflash_oe,
output strataflash_ce,
output strataflash_we,
inout [7:4] lcd_d,
output lcd_rs,
output lcd_rw,
output lcd_e,
input sma_clk,
input clk_50mhz
);
// signals for counting the test clock
reg [3:0] ab_switch_delay;
reg a_count_ce, b_count_ce;
reg [31:0] a_count, b_count;
reg a_count_rst, b_count_rst;
reg freq_for_measurement;
wire test_clk;
// signals for 1 second interrupt generation and couter switching
reg ab_switch;
reg [99:0] interrupt_delay;
reg [25:0] one_second_count;
reg one_second_pulse;
reg interrupt;
reg [7:0] source_control;
// signals for processor interconnect
reg [7:0] in_port;
wire [7:0] out_port;
wire write_strobe, read_strobe;
wire [7:0] port_id;
wire interrupt_ack;
wire [17:0] instruction;
wire [9:0] address;
// lcd wires
reg [7:0] lcd_reg;
wire lcd_drive;
wire lcd_output_data;
// led reg
reg [7:0] led_reg;
// ring osscillator instantiations
ring_osc logic_oscillator (.reset(source_control[6]),.osc_out(ring_oscillator));
ring_osc2 logic_oscillator2 (.reset(source_control[6]),.osc_out(ring_oscillator2));
// frequency selection mux - purely combinational
always@(sma_clk or clk_50mhz or ring_oscillator or ring_oscillator2)
if(source_control[1:0] == 2'b00)
freq_for_measurement = sma_clk;
else if(source_control[1:0] == 2'b01)
freq_for_measurement = clk_50mhz;
else if(source_control[1:0] == 2'b10)
freq_for_measurement = ring_oscillator2;
else
freq_for_measurement = ring_oscillator;
// global clock buffer the test clock
BUFG buffer_clkin(.O(test_clk), .I(freq_for_measurement));
// counter switch control
always@(posedge test_clk)
begin
ab_switch_delay <= {ab_switch_delay[2:0], ab_switch};
case(ab_switch_delay[3:1])
3'b000: begin
a_count_ce <= 1;
b_count_ce <= 0;
end
3'b111: begin
a_count_ce <= 0;
b_count_ce <= 1;
end
default: begin
a_count_ce <= 1;
b_count_ce <= 0;
end
endcase
end
// test counters
always@(posedge test_clk or posedge a_count_rst)
if(a_count_rst)
a_count <= 'b0;
else if(a_count_ce)
a_count <= a_count+1;
else
a_count <= a_count;
always@(posedge test_clk or posedge b_count_rst)
if(b_count_rst)
b_count <= 'b0;
else if(b_count_ce)
b_count <= b_count+1;
else
b_count <= b_count;
// one second interrupt generation and clock switching
/* always@(posedge clk_50mhz)
begin
// divide by 50,000,000 to generate pulse
if(one_second_count == 26'd49999999)
begin
one_second_count <= 'b0;
one_second_pulse <= 1'b1;
end
else
begin
one_second_count <= one_second_count + 1;
one_second_pulse <= 1'b0;
end
// delay 100 clock cycles before generating interrupt
interrupt_delay <= {interrupt_delay[98:0], one_second_pulse};
// interrupt generation
if (interrupt_ack == 1'b1)
interrupt <= 1'b0;
else if (interrupt_delay[99] == 1'b1)
interrupt <= 1'b1;
else
interrupt <= interrupt;
// counter selection switch toggle's each second
if (one_second_pulse == 1'b1)
ab_switch <= ~ab_switch;
end*/
always@(posedge clk_50mhz)
begin
// divide by 50,000,000 to generate pulse
if(one_second_count == 26'd49999999)
begin
one_second_count <= 'b0;
one_second_pulse <= 1'b1;
end
else
begin
one_second_count <= one_second_count + 1;
one_second_pulse <= 1'b0;
end
end
always@(posedge clk_50mhz)
begin
// delay 100 clock cycles before generating interrupt
interrupt_delay <= {interrupt_delay[98:0], one_second_pulse};
end
always@(posedge clk_50mhz)
begin
// interrupt generation
if (interrupt_ack == 1'b1)
interrupt <= 1'b0;
else if (interrupt_delay[99] == 1'b1)
interrupt <= 1'b1;
else
interrupt <= interrupt;
end
always@(posedge clk_50mhz)
begin
// counter selection switch toggle's each second
if (one_second_pulse == 1'b1)
ab_switch <= ~ab_switch;
else
ab_switch <= ab_switch;
end
// picoblaze instantiation
kcpsm3 processor (.address(address),
.instruction(instruction),
.port_id(port_id),
.write_strobe(write_strobe),
.out_port(out_port),
.read_strobe(read_strobe),
.in_port(in_port),
.interrupt(interrupt),
.interrupt_ack(interrupt_ack),
.reset(reset),
.clk(clk_50mhz));
fc_ctrl program_rom (.address(address),
.instruction(instruction),
.proc_reset(proc_reset),
.clk(clk_50mhz));
// processor input ports
always@ (posedge clk_50mhz)
case(port_id[7:4])
// read A counter
4'b0000: in_port <= a_count[7:0];
4'b0001: in_port <= a_count[15:8];
4'b0010: in_port <= a_count[23:16];
4'b0011: in_port <= a_count[31:24];
// read B counter
4'b0100: in_port <= b_count[7:0];
4'b0101: in_port <= b_count[15:8];
4'b0110: in_port <= b_count[23:16];
4'b0111: in_port <= b_count[31:24];
// read slide switches
4'b1000: in_port <= {3'b000, ab_switch, sw};
// read LC Ddata at address 90 hex
4'b1001: in_port <= {lcd_d, 4'b0000};
// original design used a dont care condition
// I've decided to let it retain its value.
default: in_port <= in_port;
endcase
// output ports
always@ (posedge clk_50mhz)
if(write_strobe)
case(port_id[3:0])
// LED register at address 0x01
4'b0001: led_reg <= out_port;
// Counter reset controls at 0x02
4'b0010: begin
a_count_rst <= out_port[0];
b_count_rst <= out_port[1];
end
// LCD data/controls at 0x04
4'b0100: begin
lcd_reg <= out_port;
end
// Source selection and control at 0x08
4'b1000: source_control <= out_port;
endcase
// LCD controls
assign lcd_rw_control = lcd_reg[1];
assign lcd_drive = lcd_reg[3];
assign lcd_output_data = lcd_reg [7:4];
// LCD Outputs
assign lcd_e = lcd_reg[0];
assign lcd_rw = lcd_rw_control && lcd_drive;
assign lcd_rs = lcd_reg[2];
assign lcd_d = ((lcd_rw_control == 1'b0) && (lcd_drive == 1'b1)) ? lcd_output_data : 4'bZZZZ;
// LED assignment
//assign led = led_reg;
// Debug assignments
assign led[7]=led_reg[7]; //A counter
assign led[6]=led_reg[0]; //B counter
assign led[5]=a_count[10]; // should toggle at 8hz when enabled
assign led[4]=b_count[10]; // should toggle at 8hz when enabled
assign led[3]=one_second_count[24]; // should toggle very fast.
assign led[2]=one_second_pulse; // once per second
assign led[1]=interrupt_ack; //interrupt ack
assign led[0]=interrupt; //interrupt
// strataflash chip enable signals to disable onboard strataflash
assign strataflash_we = 1'b1;
assign strataflash_ce = 1'b1;
assign strataflash_oe = 1'b1;
endmodule
[Category:FPGAWorkshop](Category:FPGAWorkshop "wikilink")
+425
View File
@@ -0,0 +1,425 @@
## PicoBlaze Flow / Tutorial
**THIS SET OF INSTRUCTIONS ASSUMES THE READER IS FAMILIAR WITH THE ISE
SUITE FLOW FOR CREATING, IMPLEMENTING AND PROGRAMING PROJECTS.**
### Overview of Picoblaze / ISE Development flow
The PicoBlaze development flow is different from the FPGA flow we've
seen so far. We have to use a new tool, a PicoBlaze assembler, in
conjunction with the ISE tool set.
<figure>
<img src="Picoblaze_flow.png" title="File:Picoblaze_flow.png" />
<figcaption><a
href="File:Picoblaze_flow.png">File:Picoblaze_flow.png</a></figcaption>
</figure>
I reccomend placing a folder named 'asssembly' or something else
memorable in the root of your desired ISE project. This will keep an
entire project togetheer in a single directory. You'll want to copy the
ROM_form.vhd file from the picoblaze processor distribution to a
convenient place, such as ./assembly directory or your project
directory. We'll need to have a copy of this to use later.
The new tool we'll be working with today is openpicide. It is a project
management IDE, Syntax check, program assembler and device simulator. It
is opensource project, based on the QT framework. We'll be using it to
generate the program ROM as a VHDL block ram file, which will be used
with our design. The structure of our example project will look like the
following:
1. top_level.v
1. embedded_kcpsm3.v
1. kcpsm3.v
2. prog_rom.vhd - This is the file generated by the assembler.
2. project_constraints.ucf
In general, a picoblaze design would look like this
1. top_level.v
1. embedded_kcpsm3.v
1. kcpsm3.v
1. prog_rom.vhd - This is the file generated by the
assembler.
2. periperal1.v
3. periperal2.v
1. sub_module1.v
2. ....
4. other logic as needed
2. project_constraints.ucf
## Example \#1
### Picoblaze simple example / toolchain tutorial
To begin, make sure you've got Xilinx ISE and OpenpicIDE installed. You
can obtain openpicIDE here <http://openpicide.org/> You'll also need to
get the picoblaze download package.
First, we'll create the ISE project. Create a new project called
picoblaze_example1 in your projects directory. Add copies of the
following files from the picoblaze download package.
- embedded_kcpsm3.v
- kcpsm3.v
Then create 2 new source files
- constraints.ucf
- picoblaze_example1.v.
Copy and paste the contents of these files from the wiki \[see below\].
You should note that your missing a file, prog_rom, which is in the
embedded_kcpsm3 module. Do not attempt to implement the design - it will
not work until we generate the program ROM.
When openpicide opens, you'll want to create a project. You should save
the project file in your 'assembly' folder as "picoblaze_example1".
Under the settings for the project, you'll need to do the following:
1. Set the processor to Xilinx picoblaze
2. Under the VHDL tab, set the entity name to "prog_rom"
3. Set the vhdl source file to the ROM_form.vhd file we copied earlier.
4. You can leave the rest of the settings to their default values.
You'll then need to create a new file - use the new file button in the
upper left corner, or go to **File** -\> **New**. Copy and paste the 1st
example source file from the wiki. Using the **Picoblaze Menu** Run a
syntax check on the code to make sure it is correct, and then generate a
VHDL memory file from the code. Save the file as "prog_rom_example1.vhd"
in your assembly section. You can now move back to ISE.
**note: the picoblaze assembly files and the openpicide project file
need to be in the same directory**
Now, add the program file "prog_rom_example1.vhd" to your project, using
"Add Copy of Source". You'll notice that the prog_rom module is no
longer missing. You now need to comment out line 29, defining the
constraint for SW1, from the UCF file. After that is commented out, you
can implement the design. After programming the board, you should now
see the LED's flipping on and off; if so, you have a working Picoblaze
toolchain.
### constraints.ucf
This constraints file can be used with the design examples covered in
this tutorial.
#
# UCF For Picoblaze Examples
#
# Period constraint for 50MHz operation, assume a 50% duty cycle, +/- 10%
#
NET "CLK_50MHZ" PERIOD = 20.0ns HIGH 40%;
#
# soldered 50MHz Clock.
#
NET "CLK_50MHZ" LOC = "C9" | IOSTANDARD = LVTTL;
# Simple LEDs
# Require only 3.5mA.
#
NET "LED<0>" LOC = "F12" | IOSTANDARD = LVTTL | SLEW = SLOW | DRIVE = 4;
NET "LED<1>" LOC = "E12" | IOSTANDARD = LVTTL | SLEW = SLOW | DRIVE = 4;
NET "LED<2>" LOC = "E11" | IOSTANDARD = LVTTL | SLEW = SLOW | DRIVE = 4;
NET "LED<3>" LOC = "F11" | IOSTANDARD = LVTTL | SLEW = SLOW | DRIVE = 4;
NET "led<4>" LOC = "C11" | IOSTANDARD = LVTTL | SLEW = SLOW | DRIVE = 4;
NET "led<5>" LOC = "D11" | IOSTANDARD = LVTTL | SLEW = SLOW | DRIVE = 4;
NET "led<6>" LOC = "E9" | IOSTANDARD = LVTTL | SLEW = SLOW | DRIVE = 4;
NET "led<7>" LOC = "F9" | IOSTANDARD = LVTTL | SLEW = SLOW | DRIVE = 4;
# Simple switches
# Pull UP resistors used to stop floating condition during switching.
# sw0
NET "FPGA_RESET" LOC = "L13" | IOSTANDARD = LVTTL | PULLUP;
# sw1
NET "SW1" LOC = "L14" | IOSTANDARD = LVTTL | PULLUP;
### picoblaze_example1.v
module picoblaze_example1(
input FPGA_RESET,
input CLK_50MHZ,
output [7:0] LED
);
wire clock = CLK_50MHZ;
// reset is active high.
// if no reset signal input
// then tie reset to zero here.
wire reset = FPGA_RESET;
wire [7:0] port_id;
wire write_strobe;
wire read_strobe;
wire [7:0] out_port;
wire [7:0] in_port=0;
wire interrupt=0;
wire interrupt_ack;
embedded_kcpsm3 EMBEDDED(
.port_id(port_id),
.write_strobe(write_strobe),
.read_strobe(read_strobe),
.out_port(out_port),
.in_port(in_port),
.interrupt(interrupt),
.interrupt_ack(interrupt_ack),
.reset(reset),
.clk(clock)
);
// only one bit written to by picoblaze, the LED.
// therefore don't need to decode port_id.
// if write_strobe asserts, grab out_port[0] and
// hold it in userbit.
reg [7:0] userbit = 0;
always @(posedge clock) begin
if(write_strobe) begin
userbit <= out_port;
end
end
assign LED = userbit;
endmodule
### example \#1 source
;
; simple example code, original
;
start: LOAD s9, 0xAA
drive_wave: OUTPUT s9, 0x02 ; write s9 register to userbit
LOAD S2, 0x0F ; S2 initial value
loop2: LOAD S1, 0xFF ; S1 initial value
loop1: LOAD s0, 0xFF ; S0 initial value
loop0: SUB s0, 0x01
JUMP NZ, loop0
SUB s1, 0x01
JUMP NZ, loop1
SUB s2, 0x01
JUMP NZ, loop2
;
XOR s9, 0xFF ;toggle register
JUMP drive_wave
## Example \#2
### Expanding on the example
Create a new picoblaze project, in the assembly directory. Use the
source from example \#2 to create a new program rom file. You can name
this program rom "prog_rom_example2.vhd". Copy this into your ISE
project, and then remove the original prog_rom_example1.vhd from your
project. Rebuild the project and reprogram your board. Your LEDs should
be shifty now, instead of inverting!
### picoblaze_example2.psm source
;
; simple example code, shifting
; wait longer too
;
start: LOAD s9, 0xA5 ; 10100101 ; <---- THIS CHANGED
drive_wave: OUTPUT s9, 0x02 ; write s9 register to userbit
LOAD S2, 0x2F ; S2 initial value <---- THIS CHANGED
loop2: LOAD S1, 0xFF ; S1 initial value
loop1: LOAD s0, 0xFF ; S0 initial value
loop0: SUB s0, 0x01
JUMP NZ, loop0
SUB s1, 0x01
JUMP NZ, loop1
SUB s2, 0x01
JUMP NZ, loop2
;
RL s9 ; shift left register ; <---- THIS CHANGED
JUMP drive_wave
## Example \#3
### Lets add some input
Lets read in a switch now! To do this, you can do one of two things. You
can add a input port, and add the multiplexed input re g manually. I've
already built this example, so you can create a new ISE project. Can
call this project "picoblaze_example3". Follow the instructions from
earlier in the tutorial, but use the following verilog source file.
You'll also need to create a new OpenPicIDE project with the source used
in the following example. Make sure that SW1 is not commented out in
your UCF file.
### picoblaze_example3.v source
module picoblaze_example3(
input FPGA_RESET,
input CLK_50MHZ,
input SW1,
output [7:0] LED
);
wire clock = CLK_50MHZ;
// reset is active high.
// if no reset signal input
// then tie reset to zero here.
wire reset = FPGA_RESET;
wire [7:0] port_id;
wire write_strobe;
wire read_strobe;
wire [7:0] out_port;
reg [7:0] in_port;
wire [7:0] switches;
wire interrupt=0;
wire interrupt_ack;
embedded_kcpsm3 EMBEDDED(
.port_id(port_id),
.write_strobe(write_strobe),
.read_strobe(read_strobe),
.out_port(out_port),
.in_port(in_port),
.interrupt(interrupt),
.interrupt_ack(interrupt_ack),
.reset(reset),
.clk(clock)
);
// only one bit written to by picoblaze, the LED.
// therefore don't need to decode port_id.
// if write_strobe asserts, grab out_port[0] and
// hold it in userbit.
reg [7:0] userbit = 0;
always @(posedge clock)
if(write_strobe)
userbit <= out_port;
// only one bit is read by picoblaze, the SW1.
// therefore don't need to decode port_id.
// if read_strobe asserts, grab swib out_port[0] and
// hold it in userbit.
always @(posedge clock)
if(read_strobe)
in_port <= switches;
else
in_port <= 8'bX;
assign LED = userbit;
assign switches = {7'b0, SW1};
endmodule
### picoblaze_example3.psm
;
; simple example code, shifting and inverting
; wait longer too
;
; read in a switch at each loop, if the switch is 1 then invert
; the register instead of shifting it
;
;
start: LOAD s9, 0xA5 ; 10100101
drive_wave: OUTPUT s9, 0x02 ; write s9 register to userbit
LOAD S2, 0x2F ; S2 initial value
loop2: LOAD S1, 0xFF ; S1 initial value
loop1: LOAD s0, 0xFF ; S0 initial value
loop0: SUB s0, 0x01
JUMP NZ, loop0
SUB s1, 0x01
JUMP NZ, loop1
SUB s2, 0x01
JUMP NZ, loop2
; Read the inport to s8
INPUT s8, 0x01
; test bit 0, if 1, set carry flag
TEST s8, 0x01
; if (s8[0] == 1) invert_wave else shift_wave
JUMP C, invert_wave
; shift the wave and drive it
shift_wave: RL s9 ; shift left register
JUMP drive_wave
; invert the wave and drive it
invert_wave: XOR s9, 0xFF ;toggle register
JUMP drive_wave
However, that code is a bit hard to read!! It can be much easier to read
mnemonics instead of hex value and register id's. After getting the code
above working, go ahead and add the following to the top of your
picoblaze assembly source.
;
; Make it human readable with mnemonics!
;
NAMEREG S0, I_VAR
NAMEREG S1, J_VAR
NAMEREG S2, K_VAR
NAMEREG S9, WAVE_VAR
NAMEREG S8, SCRATCH_VAR
CONSTANT INITIAL_I, 0xFF
CONSTANT INITIAL_J, 0xFF
CONSTANT INITIAL_K, 0x2F
CONSTANT INITIAL_WAVE, 0xA5 ;10100101
CONSTANT BITMASK, 0x01
;
After adding this section to your code, go through and replace the
following items
- Register references, sX, should be replaced with the variable names
- Constants which are named should be replaced.
After replacing the constants, you're code should look like this
start: LOAD WAVE_VAR, INITIAL_WAVE ;
drive_wave: OUTPUT WAVE_VAR, 0x02 ; write s9 register to userbit
LOAD K_VAR, INITIAL_K ; S2 initial value
loop2: LOAD J_VAR, INITIAL_J ; S1 initial value
loop1: LOAD I_VAR, INITIAL_I ; S0 initial value
loop0: SUB I_VAR, 0x01
JUMP NZ, loop0
SUB J_VAR, 0x01
JUMP NZ, loop1
SUB K_VAR, 0x01
JUMP NZ, loop2
; Read the inport to s8
INPUT SCRATCH_VAR , 0x01
; test bit 0, if 1, set carry flag
TEST SCRATCH_VAR , BITMASK
; if (s8[0] == 1) invert_wave else shift_wave\
JUMP C, invert_wave
; shift the wave and drive it
shift_wave: RL WAVE_VAR ; shift left register
JUMP drive_wave
; invert the wave and drive it
invert_wave: XOR WAVE_VAR, 0xFF ;toggle register
JUMP drive_wave
## Run the simulator
Now we have mnemonics entered into our code, we can easily tweak it.
First, we can change the I_Var, J_Var, K_Var, to be smaller values, such
as 0x0F. You can then step through the program, or just run it, in the
OpenPicIDE simulator.
## Acknowledgements / References
This was based on a simple example found here
<http://forums.xilinx.com/xlnx/board/message?board.id=PicoBlaze&thread.id=780>
The Picoblaze download can be found here
<http://www.xilinx.com/products/ipcenter/picoblaze-S3-V2-Pro.htm>
OpenPicIDE is available here <http://openpicide.org>
[Category:FPGAWorkshop](Category:FPGAWorkshop "wikilink")
+4
View File
@@ -0,0 +1,4 @@
My project is a PROM reader/burner for my old Galaga stand-up arcade
game.
[Category:FPGAWorkshop](Category:FPGAWorkshop "wikilink")
+114
View File
@@ -0,0 +1,114 @@
Currently I only have some meta ideas:
I'd like to do something that:
\- can't be done using microcontrollers.
\- that I can complete
------------------------------------------------------------------------
I thought I'd share another meta-idea that might lend itself FPGA
programming. I have to come up with a practical application, to test out
these ideas, but I need help working out an issue, described at the
bottom of this.
This idea follows what I call the "sailing philosophy", that is: meet
requirements using the wind that you get, even if you have to zigzag,
and NOT getting all silly about controlling the wind and rest of the
environment.
This may also be an example of the ["Worse is
better"](http://en.wikipedia.org/wiki/Worse_is_better) philosophy.
## The sloppy redundant full feedback approach to physical computing
-or-
## The Cloud Computing approach to Managing Sensors
Abstract: Physical computing, robotics, and mechatronics suffer from a
mapping problem, a mechanical complexity problem, and a configuration
management problem. These problems can be solved by creating and using
clumps of cheap sensors, attached using modern adhesive materials and
connecting their output wires randomly to the input of the computer
controller. Then, requiring the designer to set a sensor clump for every
movement, the controller can manage it's own configuration
automatically.
Sensor mounting: Wrap-on, spray on, glue on. Must work without perfect
positioning and without careful mounting of screws and mounting plates
-- none of that. It should be like putting on a band aid, a bandanna, or
peeling a Bannana. :^) It should be a blob of clay with wires that you
push into the correct spot for sensing. (Epoxy putty and two part
silicone come to mind.) Or perhaps like a strip of adhesive tape or
Velcro(TM) that you wrap around or along a moving joint.
Sensor clumps: Sensors must be a bunch of more or less redundant wired
outputs that sense different portions of where they are mounted. For
example, an array of light sensors, each positioned and pointed randomly
and distributed. For another example, conductors thinly separated,
changing resistance, distributed around something that moves, or
capacitive around gaps, or hall affect around moving metal. Each sensor
is actually a bundle of cheap sensors, maybe thirty or a hundred tiny
points of electronics that change electrical output in response to a
change in the environment.
Connecting the sensors: Should be a bundle of wires, perhaps a ribbon
cable, that makes it's way to each sensor. The mapping of the wires to
the input on the controller MUST be inconsequential. Figuring out which
wire goes to which sensor is a responsibility of the system, NOT human
that connects them. The wires get bundled together randomly and
connected regardless of what they sense, or even if they are not
connected.
Actuators: Motors, piston cylinders, lights, heaters, anything that
moves, emits radiation, or otherwise changes a physical state MUST have
a sensor clump mounted on or with it. This is practical because sensors
are easy to apply and cheap -- see sensor clumps, and sensor mounts.
Controller initialization: When the controller is powered on it must go
through a series of movements whereby it changes an actuator and records
which sensors are relevant to each movement and what scale . This way it
can set up feedback loops from the control output to the sensor
feedback. This is similar to what I imagine infants do, as they move
randomly and map the sensations produced. It can store this mapping of
actuator to sensor in non-volitale memory for next power up, perhaps use
it as a hint, so that the initialization can be much faster and requires
only a small movement.
Limit sensing 1: Limit sensing must be done carefully since driving a
motor past it's range of motion can damage the structure or the
actuator. One idea perhaps to designated some sensors that report a bad
state and other sensors that can predict the bad state. For example, a
position sensor and a limit switch to indicate a bad state, or a
temperature sensor that can be calibrated to predict an over-heating
sensor. The bad state sensor must be manually calibrated, or positioned
at the limit manually. I don't know how the controller would determine
which is the bad state sensor. Perhaps it could be first initialized
with all bad state sensors in their good state, then record that for the
life of the device.
Limit sensing 2: Another idea for limit sensing is the designer could
associate particular actuators as having limits, so that during
initiation it will search for it's limits by oscillating in small
increments, progressing slowly in one direction, until it senses
feedback with the same frequency as it's oscillation, and then do the
same in the other direction.
The blocking challenge: Another issue with this approach that I have to
solve before I start is that of analog to digital. A wide variety of
analog inputs with unpredictable ranges need to be connected to a large
number of digital inputs. I'm hoping some simple thresholding with
comparators or similar can allow easily connecting to digital inputs. I
guess an analog multiplexer connected to an ADC might do the trick. Then
I just need 8 or 16 bits to connect the signal input to the controller,
and address bits that select a sensor's wire, maybe another few IO pins
to control a gain amplifier for sensors with weak signals.
I had hoped that FPGA's had more analog features at their inputs, but
they seem black and white. This is the part that I haven't yet figured
out. Please help! --[DLotts](User:DLotts "wikilink") 06:39, 28 February
2010 (UTC)
[Category:FPGAWorkshop](Category:FPGAWorkshop "wikilink")
+12
View File
@@ -0,0 +1,12 @@
## Project(s)
Personal page: [User:obscurite](User:obscurite "wikilink")
- Work with Martin on Game of Life simulation models and display (VGA?)
<!-- -->
- Work on bio signals processing (ECG for now) using [DIY
ECG](DIY_ECG "wikilink") circuits
[Category:FPGAWorkshop](Category:FPGAWorkshop "wikilink")
+18
View File
@@ -0,0 +1,18 @@
1\. Port [**AMRAD
Charleston**](http://amrad.org/projects/charleston_sdr/) FPGA loads from
Digilent Nexys2 to the Xilinx Spartan3 dev board
2\. See if
[**nexsys2prog**](http://plausible.org/andy/nexys2prog.tar.gz) can be
adapted to support these boards and allow
[**UrJTAG**](http://packages.debian.org/squeeze/urjtag) to work.
3\. Try to mimic a USRP only using AMRAD Charleston receiver boards. (Or
audio ADC.)
4\. Look into [**VITA Radio Transport (VRT)
protocol**](http://www.digitalif.org/) support
5\. Make use of the Ethernet port, possibly mimic a USRP2.
[Category:FPGAWorkshop](Category:FPGAWorkshop "wikilink")
+41
View File
@@ -0,0 +1,41 @@
Three ideas so far:
Multiple 8-bit game console sound chip emulator. Generate the sounds of
the '80s: C64, NES, Atari, etc. I need to research some of the chips but
it looks like there is plenty of info out there. Manuals/schematics:
- [Mikes Arcade](http://www.mikesarcade.com/arcade/manuals.html)
- [Important Space Invader
information](http://www.brentradio.com/SpaceInvaders.htm)
- [TI 76489 Audio
Chip](http://web.inter.nl.net/users/J.Kortink/home/articles/sn76489/)
- [PicoBlaze D/A converter design
example](http://www.xilinx.com/products/boards/s3estarter/files/s3esk_picoblaze_dac_control.pdf)
- [fpga-synth.net - FPGAs to build/design synthesizers and audio
processing engines](http://www.fpga.synth.net/)
Limited AM radio. Use passive front end Nyquist filter, digital
down-converter and low-pass filter to receive the lower part of the AM
broadcast band. Got the idea from Oct '09 Circuit Cellar article
'Multi-rate Techniques and CIC Filter'. Success would be anything that
worked better than the chunk of geranium and safety pin radio from grade
school.
- [Xilinx LogiCORE CIC (Cascaded Integrator-Comb)
compiler](http://www.xilinx.com/support/documentation/ip_documentation/cic_compiler_ds613.pdf)
Game of life analyzer. Run game of life for many generations while
saving/encoding previous states of the game array to look for repeated
and other patterns. VGA game output would be fun too. Some fun life/CA
links:
<http://web.cecs.pdx.edu/~mperkows/CLASS_573/MARCH_3_06/D_0000_Intro-Cellular-Automata-Artificial-Life.ppt>
<http://web.cecs.pdx.edu/~mperkows/CLASS_573/MARCH_3_06/D_0050.Margolus-Physical-Reversible-Models-of-CAs.ppt>
<http://www.it.lth.se/suleyman/ref_docs/malki_CIMSA%2005.pdf>
1/27/10 - Patched together some Pong code (game not the professor) on
the Spartan 3E dev board to learn VGA interface. Pong code lacks
sounds - might as well give that a try. 8/25/10 - Run ISE simulator
under Win 7 - set webservices to startup automatically
[Category:FPGAWorkshop](Category:FPGAWorkshop "wikilink")
+15
View File
@@ -0,0 +1,15 @@
I've got a couple of ideas so far:
1. WEP or WPA (or other hash/cipher) crack acceleration
- In my dreams, I imagine a crack accelerator embedded in an
autonomous robot that drives itself around cracking networks as it
goes.
2. non-von Neumann computer
- E.g., the Reduceron, which is a machine that does something called
graph reduction, a thing computationally equivalent to a Turing
machine but which is better suited to pure functional languages
like Haskell
- see <http://www.cs.york.ac.uk/fp/reduceron/>
3. SIP \<-\> analog telephone adapter
[Category:FPGAWorkshop](Category:FPGAWorkshop "wikilink")
+23
View File
@@ -0,0 +1,23 @@
**Video scaler with VGA output**
To reduce the high likelihood of this project ending in undebuggable
disaster, I plan to start off with simple goals and add complexity to
the code and input/output circuitry incrementally.
1: (COMPLETED) Generate a simple 640x480 VGA test pattern with all
timing and sync signals controlled by the FPGA.
3: Create a framebuffer in Block RAM or the devboard's SRAM.
4: Use the framebuffer to window low resolution (\<640x480) digital
video input within a 640x480 output frame (no scaling).
5: Attempt to implement scaling algorithms to scale the input resolution
to fill the full frame of the output resolution.
6: Add 24-bit color depth to the output with the addition of a THS8134B
video DAC.
If I can manage to get this far, I will add additional objectives.
[Category:FPGAWorkshop](Category:FPGAWorkshop "wikilink")
+260
View File
@@ -0,0 +1,260 @@
Archive of Materials from the HacDC FPGA Workshop
------------------------------------------------------------------------
### Discussion Materials
<table>
<tbody>
<tr class="odd">
<td><p>Week</p></td>
<td><p>Date</p></td>
<td><p>Topics Covered</p></td>
<td><p>Exercise</p></td>
<td><p>Solutions/Approach</p></td>
</tr>
<tr class="even">
<td><p>1</p></td>
<td><p>October 7th, 2009</p></td>
<td><p><a
href="http://wiki.hacdc.org/index.php/File:Lect1_draft2.pdf">Workshop
Introduction &amp; Introduction to digital systems and
design</a></p></td>
<td><p>Make sure people can run the Virtual Machine or FOSS
tools</p></td>
<td><p>Lorem Ipsum</p></td>
</tr>
<tr class="odd">
<td><p>2</p></td>
<td><p>October 14th, 2009</p></td>
<td><p><a
href="http://wiki.hacdc.org/index.php/File:Lect2_draf3.pdf">Boolean
Logic, combinatorial circuits and timing</a></p></td>
<td><p>Make sure people can run the Virtual Machine or FOSS tools<br />
|<a
href="http://wiki.hacdc.org/index.php/File:Lect2_exercise.pdf">Boolean
&amp; Combinatorial Exercises</a></p></td>
<td><p><a
href="http://wiki.hacdc.org/index.php/File:Lect2_sol.pdf">Exercise
Solutions</a> <a href="Discussion_2_Exercises_Solution_notes"
title="wikilink">Discussion 2 Exercises Solution notes</a></p></td>
</tr>
<tr class="even">
<td><p>3</p></td>
<td><p>October 21st, 2009</p></td>
<td><p><a
href="http://wiki.hacdc.org/index.php/File:Lect3.pdf">Introduction to
Verilog Coding, focusing on combinatorial circuits</a></p></td>
<td><p><a href="FPGAExercise3" title="wikilink">Verilog Coding Modular
Full Adder Design and Simulation and ALU extension project</a></p></td>
<td><p>Solutions</p></td>
</tr>
<tr class="odd">
<td><p>4</p></td>
<td><p>October 28th, 2009</p></td>
<td><p>Make up day</p></td>
<td></td>
<td><p>Solutions</p></td>
</tr>
<tr class="even">
<td><p>4 1/2</p></td>
<td><p>November 4th, 2009</p></td>
<td><p><a
href="http://wiki.hacdc.org/index.php/File:Intro_to_Sequential_Logic.pdf">Introduction
to Sequential Logic and Flip Flops</a></p></td>
<td><p><a
href="http://projects.hacdc.org/tapemachine/SequentialCircuits.mp3">Audio</a></p></td>
<td><p>Placeholder</p></td>
</tr>
<tr class="odd">
<td><p>5</p></td>
<td><p>November 11th, 2009</p></td>
<td><p>No class meeting with Will</p></td>
<td><p><a href="FPGAExercise5" title="wikilink">Different adder
construction, shift register and LFSR construction</a></p></td>
<td><p><a href="FPGAExercise5code" title="wikilink">4 bit counter code
from group hacking session</a></p></td>
</tr>
<tr class="even">
<td><p>6</p></td>
<td><p>November 18th, 2009</p></td>
<td><p><a href="http://wiki.hacdc.org/index.php/File:FPGAWeek6.pdf">DFFs
round 2, Testbenches</a> <a href="FPGAWeek6Followup"
title="wikilink">Notes on the use of Define statements, tasks and
events</a></p></td>
<td><p>Shift Register &amp; LFSR examples from week 5</p></td>
<td><p><a href="FPGAExercise6code" title="wikilink">Shift Register, SR
Testbench, LFSR, LFSR Testbench</a></p></td>
</tr>
<tr class="odd">
<td><p>7</p></td>
<td><p>November 25th, 2009</p></td>
<td><p><a href="Xilinx_ISE_Installation_Instructions"
title="wikilink">Xilinx tool install party</a></p></td>
<td><p><a href="FPGA_Workshop#Xilinx_Links" title="wikilink">Xilinx ISE
In-Depth Tutorial</a></p></td>
<td><p>See Tutorial</p></td>
</tr>
<tr class="even">
<td><p>8</p></td>
<td><p>December 2nd, 2009</p></td>
<td><p><a
href="http://wiki.hacdc.org/index.php/File:Week8_fsm_notes.pdf">Finite
State Machines</a><br />
<a
href="http://wiki.hacdc.org/index.php/File:Week8_clocking_notes.pdf">Clocking
Notes</a></p></td>
<td><p>Vending Machine Simulation from notes</p></td>
<td><p><a href="FPGAExercise8code" title="wikilink">FSM level-to-pulse
converter, testbench</a></p></td>
</tr>
<tr class="odd">
<td><p>9</p></td>
<td><p>December 9th, 2009</p></td>
<td><p>We talked about stuff</p></td>
<td><p><a
href="http://wiki.hacdc.org/index.php?title=FPGA_Workshop#FPGA_Workshop_Projects">People
start posting project ideas</a></p></td>
<td><p><a
href="http://www.google.com/search?q=fpga+project+ideas">Solutions</a></p></td>
</tr>
<tr class="even">
<td><p>10</p></td>
<td><p>December 16th, 2009</p></td>
<td><p><a
href="http://wiki.hacdc.org/index.php/File:Week10_programmable_fabric.pdf">Introduction
to FPGAs - History, Capabilities and Features</a></p></td>
<td><p>Exploring designs and FPGA tools</p></td>
<td><p>Solutions</p></td>
</tr>
<tr class="odd">
<td><p>11</p></td>
<td><p>December 23rd, 2009</p></td>
<td><p><a
href="http://wiki.hacdc.org/index.php/File:ISE_Tutorial_for_S3E.pdf">ISE
Tutorial for Spartan 3E board</a></p></td>
<td><p><a href="FPGAExercise10code" title="wikilink">Counter
Source</a></p></td>
<td><p><a href="http://www.youtube.com/watch?v=_bxUEjCDVZ8">Video of
HacDC FPGA blinkenlites</a></p></td>
</tr>
<tr class="even">
<td><p>12</p></td>
<td><p>December 30th, 2009</p></td>
<td><p>Distribute kits, play with tutorial, work on usb drivers</p></td>
<td></td>
<td></td>
</tr>
<tr class="odd">
<td><p>13</p></td>
<td><p>January 5th, 2010</p></td>
<td><p><a href="FPGAWeek12Exercise" title="wikilink">Implement Frequency
Counter and Frequency Generator reference designs</a></p></td>
<td><p><a
href="http://www.xilinx.com/products/boards/s3estarter/reference_designs.htm">Spartan
3E Reference Designs</a></p></td>
<td></td>
</tr>
<tr class="even">
<td><p>14</p></td>
<td><p>January 26th, 2010</p></td>
<td><p><a href="FPGAWorkshop13notes" title="wikilink">Intro to
PicoBlaze</a></p></td>
<td></td>
<td></td>
</tr>
<tr class="odd">
<td><p>15</p></td>
<td><p>February 2nd, 2010</p></td>
<td><p>Cancelled</p></td>
<td></td>
<td></td>
</tr>
<tr class="even">
<td><p>16</p></td>
<td><p>February 16th, 2010</p></td>
<td><p><a href="FPGAWorkshop16Notes" title="wikilink">Analysis of
Frequency counter PicoBlaze reference design</a></p></td>
<td></td>
<td></td>
</tr>
<tr class="odd">
<td><p>17</p></td>
<td><p>March 2nd, 2010</p></td>
<td><p><a href="FPGAWorkshop17Notes" title="wikilink">Picoblaze Flow /
Hello World</a></p></td>
<td></td>
<td></td>
</tr>
<tr class="even">
<td><p>18</p></td>
<td><p>March 23rd, 2010</p></td>
<td><p>Modify the counter reference design to print data to
UART.</p></td>
<td></td>
<td></td>
</tr>
<tr class="odd">
<td><p>19</p></td>
<td><p>April 6th, 2010</p></td>
<td><p>tbd</p></td>
<td></td>
<td></td>
</tr>
<tr class="even">
<td><p>19</p></td>
<td><p>April 20th, 2010</p></td>
<td><p>tbd</p></td>
<td></td>
<td></td>
</tr>
<tr class="odd">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
### Videos of Discussions
The videos are mpeg4 video with aac audio
{\| border="1" \| Week \| Video Links \| Notes \|- \|1 \| [Part
1](http://wiki.hacdc.org/videos/hacdc-fpga/week01/MOV011.TOD.ff.mp4)
[Part
2](http://wiki.hacdc.org/videos/hacdc-fpga/week01/MOV012.TOD.ff.mp4)
[Part
3](http://wiki.hacdc.org/videos/hacdc-fpga/week01/MOV013.TOD.ff.mp4)
[Part
4](http://wiki.hacdc.org/videos/hacdc-fpga/week01/MOV014.TOD.ff.mp4)
[Part
5](http://wiki.hacdc.org/videos/hacdc-fpga/week01/MOV015.TOD.ff.mp4)
[Part
6](http://wiki.hacdc.org/videos/hacdc-fpga/week01/MOV016.TOD.ff.mp4)
[Part
7](http://wiki.hacdc.org/videos/hacdc-fpga/week01/MOV017.TOD.ff.mp4)
[Part
8](http://wiki.hacdc.org/videos/hacdc-fpga/week01/MOV018.TOD.ff.mp4)
\|not equal length \|- \|2 \| [Part
1](http://wiki.hacdc.org/videos/hacdc-fpga/week02/MOV005.TOD.ff.mp4)
[Part
2](http://wiki.hacdc.org/videos/hacdc-fpga/week02/MOV006.TOD.ff.mp4)
[Part
3](http://wiki.hacdc.org/videos/hacdc-fpga/week02/MOV007.TOD.ff.mp4)
[Part
4](http://wiki.hacdc.org/videos/hacdc-fpga/week02/MOV008.TOD.ff.mp4)
[Part
5](http://wiki.hacdc.org/videos/hacdc-fpga/week02/MOV009.TOD.ff.mp4) \|
Video cuts out at a discussion about Rise and Fall times \|- \|3 \|
[Part 1](http://wiki.hacdc.org/videos/hacdc-fpga/week03/10.avi) [Part
2](http://wiki.hacdc.org/videos/hacdc-fpga/week03/11.avi) [Part
3](http://wiki.hacdc.org/videos/hacdc-fpga/week03/12.avi)
[Part 4](http://wiki.hacdc.org/videos/hacdc-fpga/week03/13.avi) [Part
5](http://wiki.hacdc.org/videos/hacdc-fpga/week03/14.avi) \| \|- \|4 \|
\| \|}
[Category:FPGAWorkshop](Category:FPGAWorkshop "wikilink")
+372
View File
@@ -0,0 +1,372 @@
## Main Topics
1\) Introduction to digital logic & design
2) Verilog HDL modeling & testing
3) FPGA's & using them.
We will be taking an approach of reviewing & learning digital design,
implementing designs and methods of formally simulating and verifying
designs before moving into
[FPGA](http://en.wikipedia.org/wiki/Field-programmable_gate_array)
oriented work. This workshop will be more engineering oriented than
hobbyist/tinkerer oriented.
## Hardware
We'll be covering some FPGA specific topics and projects using real
hardware. The first half of the workshop will cover logic design,
implementation and testing. This will allow people to put off ordering
any hardware until they know that they actually want to pursue FPGA
development, since the dev board I've chosen for this is not cheap but I
feel is robust enough to be a good starting board for this group.
The hardware we'll be using is the Xilinx Spartan 3AN development kit.
This kit is available from a few vendors for 199USD + shipping. This
will be discussed more later on. The kit includes programming cable, and
evaluation copies of some of the Xilinx tools."
## Tools
### Verilog Simulation and Waveform Viewing
Icarus verilog & gtkwave; for doing Verilog compilation, simulation and
waveform viewing. A makefile has been made to simplify the flow for any
exercises and projects we use these tools with. That makefile can be
found [**here**](iverilogmakefile "wikilink"). Instructions for
installing these programs on Mac osX and Ubuntu can be found here:
[**FOSS Verilog tool
installation**](FOSS_Verilog_tool_installation "wikilink")
=== FPGA Toolchain === After we finish up with covering Verilog
modeling, we'll move to the Xilinx ISE Webpack tools and actual work
with FPGAs. This software is available from Xilinx for free, and is
available for Windows and Linux platforms. This will be used for Verilog
compilation, simulation, synthesis of designs, design mapping, place and
routing of designs, bitstream generation and board programming.
Instructions for installing the Xilinx tools on the VM can be found
here:[**Xilinx ISE Installation
Instructions**](Xilinx_ISE_Installation_Instructions "wikilink")
=== Virtual Machine === An OpenSuse Virtual Machine (VMWare based) will
be available for people to use in this course, if they wish. This will
have the icarus verilog tools and GTKwave loaded on it, along with
Firefox, gcc and make. The suseStudio team has encouraged the use of
their VMs in such a manner (teaching workshops). This is being built in
susestudio, and will be available as a live install as well.
When we move over to the Xilinx tools, people will have to download and
install the Xilinx tools by themselves, since that material is
copyrighted. Instructions will be given for doing that.
The VMware VM image is ready (ver 0.5.2) for people to grab if they
wish. [**Get it
here.**](http://susestudio.com/download/d931a0f28972e3505eacf8d0bad28fc0/Digital_Design__FPGA_Workshop_VM_v4.i686-0.5.2.vmx.tar.gz)
The image also works with VirtualBox. Create a new machine, and when it
asks you for a hard drive, select use an existing drive. This takes you
to the hard-drives list dialog box. From there, file..create a new
drive, link it to the .vmdk file, select it, and you're all set. For the
rest, all defaults are ok. (Bother Elliot for hints with VBox.)
There are a few items of note regarding the VM
\* Download is approximately 350MB, the tarball is about 1.5GB in size,
and the virtual disk will expand up to 20gigs dynamically.
- The download link is a virgin, freshly built VM, so you'll be the
first user booting it up since build.
- There are two users, root and workshop. Both have the password 'linux'
- For the user workshop, ~/scripts/ is included in their \$PATH
- Also, user workshop has a few small files in ~/resources/ including a
simple upcounter design example.
- May need to run the network configuration tools to ensure you get
functional networking. I've experienced issues with the VM in suspend
mode, switching networks on the host machine, and completely loosing
network on the VM until rerunning the network config tools. They can
be found poking around in the system settings for yast.
- Currently, the Xilinx Cable Drivers aren't building on the VM (but all
the other Xilinx tools work). If someone is a linux guru and wants to
try to make it work, contact me at <teachmeFPGA@gmail.com>. My next
attempt is to turn the vm into a live-install and try building the
cable drivers on real hardware instead of a VM.
- After loading the Xilinx settings (which will be covered in more
detail when those tools are introduced), the current shell can no
longer run icarus verilog flows. Start a new shell in order to run
icarus verilog.
- Its a fairly minimalist system, with the FOSS tools listed above load,
along with firefox, gcc and nano. Use yast or yast2 in order to
install any additional packages. example yast2 --install *packname*
- If the download link stops working, the build has likely expired on
the SuseStudio server. Please email <teachmeFPGA@gmail.com> if the
download link no longer works.
- Mad props to the susestudio team for making this possible
## Lecture
Lecture/Discussions will mainly be based on content from a pair of
courses in MIT's Opencourseware initiative. This content is licensed on
the Creative Commons Attribution NonCommercial Share-alike 3.0 license;
as a result, the electronic content generated by the workshop will also
need to be made available under the same license. This will allow people
to freely access just the discussion slides without watching through
videos.
A [video](http://www.youtube.com/watch?v=Q06M_j49zRM) archive will be
[link building service](http://www.diamondlinks.net) made available for
those unable to attend. They are available here
[**here**](FPGAWorkshopTopics "wikilink").
### List of Lectures
An archival list of lectures, including presentations and videos, can be
found [**here**](FPGAWorkshopTopics "wikilink")
*This is currently an incomplete list, additional topics will be added
as I solidify them - will*
| | | | | |
|------|---------------------|-----------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
| Week | Date | Topics Covered | Exercise | Solutions/Approach |
| 10 | December 16th, 2009 | [Introduction to FPGAs - History, Capabilities and Features](http://wiki.hacdc.org/index.php/File:Week10_programmable_fabric.pdf) | Exploring designs and FPGA tools | Solutions |
| 11 | December 23rd, 2009 | [ISE Tutorial for Spartan 3E board](http://wiki.hacdc.org/index.php/File:ISE_Tutorial_for_S3E.pdf) | [Counter Source](FPGAExercise10code "wikilink") | [Video of HacDC FPGA blinkenlites](http://www.youtube.com/watch?v=_bxUEjCDVZ8) |
| 12 | December 30th, 2009 | Distribute kits, play with tutorial, work on usb drivers | | |
| 13 | January 5th, 2010 | [Implement Frequency Counter and Frequency Generator reference designs](FPGAWeek12Exercise "wikilink") | [Spartan 3E Reference Designs](http://www.xilinx.com/products/boards/s3estarter/reference_designs.htm) | |
| 14 | January 26th, 2010 | [Intro to PicoBlaze](FPGAWorkshop13notes "wikilink") | | |
| 15 | February 2nd, 2010 | Cancelled | | |
| 16 | February 16th, 2010 | [Analysis of Frequency counter PicoBlaze reference design](FPGAWorkshop16Notes "wikilink") | | |
| 17 | March 6nd, 2010 | [Picoblaze Flow / Hello World](FPGAWorkshop17Notes "wikilink") | | |
| 18 | March 23rd, 2010 | FPGA hackins. | | |
| 19 | April 6th, 2010 | FPGA hackins | | |
| 19 | April 20th, 2010 | FPGA hackins | | |
| | | | | |
## Workshop requirements
This workshop will be free of charge to attend, but there are additional
needs in order to fully benefit from attending the workshop.
- Open mind to learning
- Willingness to read documentation, as the capacity for independent
research is important for doing hardware design.
- Willingness to commit time over this fall
- Either ability to run a VMWare virtual machine, the ability to convert
the VM for virtualBox, or ability to install the icarus
verilog/gtkwave tools on your own. This will likely necessitate a
laptop of some sort.
- Xilinx.com account, for licensing Xilinx tools and IP.
- Hardware will NOT be required at the beginning of the course but will
be needed later on to run exercises and to do any interesting projects
## Workshop Frequently Asked Questions
1. What operating systems will the FPGA toolchain be available on?
1. The Xilinx ISE Webpack is supported on Windows XP Pro, Windows
Vista Business, Redhat Linux and Suse Linux Enterprise. For a
detailed list of official OS support, check out the [Operating
system support page on
Xilinx.com](http://www.xilinx.com/ise/ossupport/index.htm). The
tools will run on openSuse as well. Feel free to try other linux
distros and post your results.
2. What is the cost of the FPGA development board we'll be using?
1. The retail cost of the development board is typically around
199-220 USD, plus shipping, from a few different vendors. Links
for that are
[here](FPGA_Workshop#Spartan_3AN_Starter_Kit "wikilink").
3. Will there be homework?
1. Since this isn't an academic course, there will not be graded
homework in the traditional sense. I'll be choosing a few
additional exercises that people can do outside of the workshop
each week, if they wish, that will further help hone their
skills.
4. Will there be extensive C/C++ coding?
1. C experience is not a prerequisite for this workshop. There will
not be any C/C++ coding involved in the workshop directly. There
is one project that I've got in mind that may be of interest to
people that are proficient in C/C++ and pick up hardware design
rather well.
## Workshop Mailing List
A HacDC Mailman mailling list has been setup for this workshop. That
list is fpga@hacdc.org. You can subscribe to that list by sending an
email to fpga-request@hacdc.org with the subject line "subscribe" or
click the mailto link <fpga-request@hacdc.org?Subject=subscribe> and let
your email application handle it...
## Workshop Instructor
William Gibb, mad scientist. For contacting him regarding the workshop,
please email <teachmeFPGA@gmail.com>.
## References
### Grateful Dead Trees Reference
Fundamentals of Digital Logic with Verilog Design by Brown and
Vranesic
Verilog Quickstart: A Practical Guide to Simulation and Synthesis in
Verilog by Lee
FPGA Prototyping using Verilog Examples by Chu.
These texts will not be required for the course, but are very good
launching points for the topics that we are covering.
### Online References
#### General Resources
[Open Circuit Design](http://www.opencircuitdesign.com/) Open Source
design tools
[Doulos Digital Design Resources](http://www.doulos.com/knowhow/) Good
learning and design references
[**ASIC World**](http://www.asic-world.com/) Good learning references
[Play Hookey Digital Design](http://www.play-hookey.com/digital/) Good
learning references
[*'FPGA4Fun*](http://www.fpga4fun.com/) Lots of available IP
[Companion website for Professor Pong Chu's Verilog
Book](http://academic.csuohio.edu/chu_p/rtl/fpga_vlog.html)
[**OpenCores**](http://www.opencores.org) Very good repository for IP.
Also the home to the OpenRISC System on Chip project
[Bucknell Handbook on Verilog
HDL](http://hdlplanet.tripod.com/verilog/verilog-manual.html#RTFToC0)
(Martin found this) Old but useful?
[KD7IRS's Verilog - OpenHPSDR - Lectures](http://verilog.openhpsdr.org/)
Webcast style class, with lab
[VA Tech Configurable Computing Lab
Wiki](http://pip0.ccm.ece.vt.edu/twiki/bin/view/Main/Spartan3Radio)
Simple Radio Structures on the Spartan3e Starter Kit
[VA Tech Configurable Computing Lab
Wiki](http://pip0.ccm.ece.vt.edu/twiki/bin/view/Main/GNURadio) GNU
Radio - USRP for Spartan 3E
[San Jose State University](http://www.engr.sjsu.edu/crabill/) Digital
design course (EE178) with Spartan 3E Development board and ISE 8.1 -
lecture & lab materials
[George Washington University ECE128
Lab](http://www.seas.gwu.edu/~vlsi/ece128/SPRING/lab.html) Contains good
Verilog coding and testbench resources
[FPGA Arcade](http://www.fpgaarcade.com/) Devoted to gaming on FPGAs,
Space Invaders in VHDL...
[Simplified Floating Point for
DSP](http://instruct1.cit.cornell.edu/courses/ece576/FloatingPoint/index.html)
8-bit exponent and 9-bit mantissa and sign to fit into 18 bit IP
blocks - Thanks Cornell!
#### FPGA Vendors
[Xilinx](http://www.xilinx.com/)
[Altera](http://www.altera.com/)
[Actel](http://www.actel.com/)
[Atmel FPGA](http://www.atmel.com/products/fpga/)
[Silicon Blue](http://www.siliconbluetech.com/)
[Point of Sale System](http://www.merchantos.com)
[Lattice Semiconductor](http://www.latticesemi.com/)
[Achronix](http://www.achronix.com/)
#### Course Resources
[Icaurus Verilog](http://www.icarus.com/eda/verilog/)
[GTKWave](http://gtkwave.sourceforge.net/)
[VMware Player - Free download for Windows and
Linux](http://www.vmware.com/products/player/)
[SUSE Studio](http://www.susestudio.com) SLED/OpenSUSE build service.
Make VMs, live installs, all customized
#### Xilinx Links
[Xilinx Tutorials](http://www.xilinx.com/support/techsup/tutorials/)
[Xilinx ISE 10.1 Tutorial and
files](http://www.xilinx.com/support/techsup/tutorials/tutorials10.htm)
[ISE 10.1 In Depth Tutorial Direct link to
PDF](http://www.xilinx.com/direct/ise10_tutorials/ise10tut.pdf)
[Xilinx
Documentation](http://www.xilinx.com/support/documentation/index.htm)
This includes device data sheets, user guides, IP documentation and
Xilinx software manuals
[Xilinx Design Tools](http://www.xilinx.com/tools/designtools.htm) Xilnx
Software tools can be found here
[Spatan 3E Starter
Kit](http://www.xilinx.com/products/devkits/HW-SPAR3E-SK-US-G.htm) Site
for the Spartan 3E kit
[Spartan 3AN Starter
Kit](http://www.xilinx.com/products/devkits/HW-SPAR3AN-SK-UNI-G.htm)
Site for the Spartan 3AN kit
[Free Video Training
courses](http://www.xilinx.com/support/training/free-courses.htm) Name
says it all
[Yet Another Xilinx ISE 10.1
Tutorial](http://xess.com/appnotes/ise-10.pdf) For Xess Spartan-3
Development Board
#### Spartan 3AN Starter Kit
[Spartan 3AN Starter
Kit](http://www.xilinx.com/products/devkits/HW-SPAR3AN-SK-UNI-G.htm)
[AVNet Spartan 3AN Starter Kit sales
page](http://www.em.avnet.com/evk/home/0,1707,RID%253D0%2526CID%253D45129%2526CCD%253DUSA%2526SID%253D32214%2526DID%253DDF2%2526LID%253D32232%2526PRT%253D0%2526PVW%253D%2526BID%253DDF2%2526CTP%253DEVK,00.html)
[NuHorizons - Xilinx Vendor](http://www.nuhorizons.com/) Do a search for
HW-SPAR3AN-SK-UNI-G
[Digi-key Spartan 3AN Starter Kit Sales
page](http://search.digikey.com/scripts/DkSearch/dksus.dll?Cat=2621773&k=spartan%203an)
Probably also at other [suppliers](suppliers "wikilink").
#### Spartan 3E Starter Kit
[Digilent](http://www.digilentinc.com/)
##### Group Order Participants
NOTE: Xilinx has donated 15 spartan3 boards, which should arrive before
12/7
- Daniel (obscurite on \#hacdc on freenode)
- Alden
- Dan Barlow
- Navid
- Matt Liggett
- Maitland Bottoms
- Ben Peizik (benparse@yahoo.com)
- Martin
- Rob Seastrom (rs@seastrom.com)
- Phillip Stewart
- Tim F (smilemoose@gmail.com)
- Nick
- Brian
<!-- -->
- Elliot
- Justin
#### MIT OpenCourseWare links
[MIT OCW Terms of
Use](http://ocw.mit.edu/OcwWeb/web/terms/terms/index.htm)
[OCW site for 6.004 - Computation
Structures](http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-004Computation-StructuresFall2002/CourseHome/index.htm)
[OCW site for 6.111 Introductory Digital Systems,
2006](http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-111Spring-2006/CourseHome/index.htm)
## FPGA Workshop Projects
List of FPGA projects people are working on at HacDC
| | |
|-------------------------------------------|-----------------------------------------------------------------------------------------------------------------|
| Person | Project |
| William Gibb | [AD/DA controller for Spartan 3E/3A/3AN Development Kits](http://opencores.org/project,spi_core_dsp_s3ean_kits) |
| Daniel (obscurite on \#hacdc on freenode) | [Daniel's Project (Game of Life w/ Martin & Breakout VGA/LED?)](FPGAWorkshopDaniel "wikilink") |
| Alden | [Alden's Project](FPGAWorkshopAlden "wikilink") |
| Dan Barlow | [Barlows's Project](FPGAWorkshopBarlow "wikilink") |
| Navid | [Navid's Project](FPGAWorkshopNavid "wikilink") |
| Matt Liggett | [Matt's Project](FPGAWorkshopMatt "wikilink") |
| Maitland Bottoms | [Maitland's Project](FPGAWorkshopMaitland "wikilink") |
| Ben Peizik (benparse@yahoo.com) | [Ben's Project](FPGAWorkshopBen "wikilink") |
| Martin | [Martin's Project](FPGAWorkshopMartin "wikilink") |
| Rob Seastrom (rs@seastrom.com) | [Justin's Project](FPGAWorkshopJustin "wikilink") |
| Phillip Stewart | [Phillip's Project](FPGAWorkshopPhillip "wikilink") |
| Tim F (smilemoose@gmail.com) | [Tims Project](FPGAWorkshopJustin "wikilink") |
| Nick | [Nick's Project](FPGAWorkshopNick "wikilink") |
| Brian | [PROM Burner/Reader](FPGAWorkshopBrian "wikilink") |
| Elliot | [Elliots's Project](FPGAWorkshopElliot "wikilink") |
| Justin | [Justin's Project](FPGAWorkshopJustin "wikilink") |
| Arc | [Arcs SMT oven](FPGAWorkshopArc "wikilink") |
| Davel (DLotts) | [Davel's Project](FPGAWorkshopDLotts "wikilink") |
[Category:Classes](Category:Classes "wikilink")
[Category:FPGAWorkshop](Category:FPGAWorkshop "wikilink")
+122
View File
@@ -0,0 +1,122 @@
This is the source code for the float switch 3d printed parts for the
water level detector for the [Cheap Chinese
Laser](Cheap_Chinese_Laser "wikilink"). It is made in two parts: the
head and the base. You also need 4 pieces of 1/4-20 all thread to
connect the two of them and 8 nuts. The base is internally threaded. The
head needs nuts top and bottom. Washers would be good too.
![<File:Float-switch-head.stl>](Float-switch-head.stl "File:Float-switch-head.stl")
rendered on 5/1/2017
![<File:Float-switch-base.stl>](Float-switch-base.stl "File:Float-switch-base.stl")
rendered on 5/7/2017
/*
low water level detector
safety interlock for cheap Chinese laser at Hac DC
This water level detector is a two piece assembly connected by threaded rod. This model uses 1/4-20 rod. The lower foot has a 40mm home in the bottom to insert a pingpong ball as the float.
James Sullivan
5-8-17
Mk 5 - removed tolerance variable and adjusted threads, ppbd, and head threaded rod holes diameters
OpenSCAD version 2015.03-1
*/
ppbd=41; //ping pong ball diameter, includes 1mm tolerance
ppbw=2.7; //ping pong ball weight in grams
shd=2; //switch hole diameter
shp=10; //switch hole pitch, i.e. center to center spacing of mounting holes on microswitch
wlh=200; //water level height
sbw=6; //switch body width
nfw=4; //nut face width, switch mounting nuts
nt=1; //nut thickness, switch mounting nuts
thick=5; //thickness
eps=0.1; //epsilon
br=50; //base radius
rod=25.4/4; //rod outer diameter
tpi=20; //threads per inch
td=13.74/tpi; //thread depth
fph=25.4*5/tpi;//foot pillar height
bfw=ppbd+2*thick; //base flange width
$fn=48;
function mod(num,den) = num - floor(num/den)*den;
//dimensions taken from Front Door Switch Holder
wr=4; //wrench size for nuts width across flats
nh=1; //nut height, depth of nut sockets
//head
module head() {
color("cyan") difference(){
union(){
for(angle=[45:90:315]){
rotate([0,0,angle]) translate([ppbd/2+rod/2+td,0,0]) cylinder(d=rod+thick*2,h=thick); //leg cylinders
}
cylinder(h=thick,r=ppbd/2+rod/2+td-thick/2);
}
translate([0,0,-thick/2]) cylinder(h=thick*2,r=ppbd/2+rod/2-3*thick/2); //center bore to reduce material amount and print time
for(angle=[45:90:315]){
rotate([0,0,angle]) translate([ppbd/2+rod/2+td,0,-thick/2]) cylinder(d=rod*1.1,h=thick*2); //leg holes for threaded rods
}
}
translate([sbw/2,(ppbd+rod-2*thick)/(-2),0]) cube([thick,ppbd+rod-2*thick,thick]); //support for switch mounting block
translate([sbw/2,shp/2,thick]) difference(){ //switch mounting block, aligned with z-plane and x-plane, centered on y-plane
translate([0,-shp/2-nfw,0]) color("green") cube([thick,shp+2*nfw,2*nfw]);
for (y=[-shp/2,shp/2]) {
translate([thick/2,y,nfw]) rotate([0,90,0]) cylinder(d=shd,h=thick*2,center=true); //screw holes
translate([sbw-nh,y,nfw]) union(){ //nut sockets
for (ang=[0,120,240]) rotate([ang,0,0]) cube([nh*2,wr,wr/sqrt(3)],center=true);
}
}
translate([sbw/2+thick,bfw/2-nfw-shp,nfw]) union(){ //center nut socket
cube([nh*2,wr,wr/sqrt(3)],center=true);
rotate([120,0,0]) cube([nh*2,wr,wr/sqrt(3)],center=true);
rotate([240,0,0]) cube([nh*2,wr,wr/sqrt(3)],center=true);
}
}
}
module socket(nd,tpi,tl,thick) {
//nd = nominal diameter
//tpi = threads per inch
//tl = thread length
ror=nd/2; //rod outer radius
pitch=25.4/tpi; //thread pitch in mm
td=13.74/tpi; //thread depth in mm
rir=ror-td; //rod inner radius
sor=ror+thick; //socket outer radius
vert= [for (ang=[0:360/$fn:720]) ang<=90 ? [cos(ang),sin(ang)]*rir :
ang<202.5 ? [cos(ang),sin(ang)]*(rir+td*(ang-90)/112.5) :
ang<=247.5 ? [cos(ang),sin(ang)]*ror :
ang<360 ?[cos(ang),sin(ang)]*(rir+td*(360-ang)/112.5) :
[cos(ang),sin(ang)]*sor];
path1=[for(p=[0:$fn]) p<$fn ? p : 0 ];
path2=[for(p=[$fn:2*$fn]) p<2*$fn ? p : $fn ];
color("green") difference(){
linear_extrude(height=tl,center=false,convexivity=20,twist=tl/25.4*tpi*360){
polygon(points=vert,paths=[path1,path2]);
}
translate([0,0,tl-ror*tan(30)]) cylinder(r2=ror,r1=0,h=ror*tan(30)); //inlet chamfer
}
}
//foot
module foot(){
difference(){
union(){
translate([0,0,thick/2]) cube([ppbd+2*thick,ppbd+2*thick,thick],center=true);
for (angle=[45:90:315]){
rotate([0,0,angle]){
translate([ppbd/2+rod/2+13.74/tpi,0,thick]) socket(rod*1.1,tpi,fph,thick); //pillar
translate([0,-thick,0]) cube([br-thick,thick*2,thick]); //leg
translate([br-thick,0,0]) cylinder(r=thick,h=thick); //foot
} //end rotate
} //end for
} //end union
translate([0,0,-eps/2]) cylinder(d=ppbd,h=fph+eps+thick); //ping pong ball entry
} //end difference
} //end foot module
//head();
foot();
[Category: CheapChineseLaser](Category:_CheapChineseLaser "wikilink")
+176
View File
@@ -0,0 +1,176 @@
# Introduction
There are a few pieces of software you'll definitely want for AVR
programming:
- A compiler and/or assembler
([avr-gcc](http://www.nongnu.org/avr-libc/)) to convert human-readable
code to binary
- Manipulation of binaries
([binutils-avr](http://www.nongnu.org/avr-libc/)). You'll need to
convert from the ELF file to something your chip will like.
- Something to talk to your AVR programmer
([AVRDUDE](http://www.bsdhome.com/avrdude/)), that is the piece of
hardware you plug into both your computer and the chip you want to
program.
- Not required, but something to make your life easier: ([GNU
make](http://www.gnu.org/software/make/))
Note that both avr-gcc and binutils-avr come from the
[avr-libc](http://www.nongnu.org/avr-libc/) project. avr-libc itself
isn't software per-se; it's a library that implements standard C
functions for AVRs.
# Installation
## Linux
### Ubuntu
Install the following packages:
- avrdude
- avrdude-doc
- binutils-avr
- avr-libc
- gcc-avr
You can get them in one shot using:
`sudo aptitude install avrdude avrdude-doc binutils-avr avr-libc gcc-avr`
### Gentoo
Install the following packages:
- dev-embedded/avrdude
- sys-devel/crossdev
Run (as root):
`crossdev -t avr`
This will install cross-avr/gcc, cross-avr/binutils, and
cross-avr/avr-libc (pulled from an avr portage overlay).
Finally, the following command is necessary to make the linker happy
(again, as root):
`ln -s /usr/lib/binutils/avr/2.21/ldscripts /usr/x86_64-pc-linux-gnu/avr/binutils-bin/2.21/ldscripts`
You'll want to adjust the path above to match your architecture and
binutils version.
## OS X
> NOTE: In trying to program the AVR without using CrossPack (below), we
> were unable to get OS X to recognize the FTDI device until we
> installed FTDI USB Serial drivers. The easiest way to do this is to
> download the [latest Arduino installer
> archive](http://arduino.cc/en/Main/Software) and installing the
> FTDIUSBSerialDriver_10_4_10_5_10_6.mpkg (its name as of 3/27/11) from
> it.
[CrossPack](http://www.obdev.at/products/crosspack/index.html) Will take
care of you. It doesn't require you to have Xcode installed, but if you
do, you can do your development in Xcode and run your makefile from that
IDE. If you have an open terminal.app session open when you install it,
you'll need to reload your .profile to use crosspack.
**You don't have to use the crosspack tools to manage a build projects,
you can use elliots makefile as well. You'll need to modify it
appropriately**
When you install crosspack, you'll be presented with documentation in
your web browser. These docs are also located at
/Applications/Crosspack-AVR-Manual.html. This is important, as the
Crosspack docs are not on the www.obdev.at site :\\
### Making Crosspack projects work with Elliot's boards
Follow the crosspack 'getting started' section to create your first
hello world project.
First, make a demo project.
bash$ cd ~/Documents
bash$ mkdir AVR
bash$ cd AVR
bash$ avr-project Demo
bash$ open Demo
bash$ cd Demo
bash$ ls -l
drwxr-xr-x 5 cs cs 170 Nov 19 13:58 Demo.xcodeproj
drwxr-xr-x 4 cs cs 136 Nov 19 13:58 firmware
bash$ cd firmware
bash$ ls -l
-rw-r--r-- 1 cs cs 4139 Nov 19 13:58 Makefile
-rw-r--r-- 1 cs cs 348 Nov 19 13:58 main.c
You can see, your code lives in the projects' firmware folder. You can
replace the code (\*.c) as you please with whatever blinkenlights
project you see fit. You'll want to open up the Makefile and edit two
lines - the DEVICE and PROGARMMER line. The device we are using is the
"atmega88". The programmer needs to be set to avr109, the baud rate to
9600, and the port to whatever your /tty.usbserial device (read: FTDI
cable) is called. Mine shows up as /dev/tty.usbserial-FTEA4CYY, yours
may very well show up with a different name.
DEVICE = atmega88
CLOCK = 8000000
PROGRAMMER = -c avr109 -P /dev/tty.usbserial-FTEA4CYY -b 9600
OBJECTS = main.o
FUSES = -U hfuse:w:0xd9:m -U lfuse:w:0x24:m\
One you've edited your make file, you can run the following commands
make
make flash
Make will compile the c code into object code and then to the correct
HEX code for the device. Make flash will try to program the code. Make
sure you've held down reset and button A in order to let the device
reset into programming mode! Grab Elliots blinking led code and try it
out!
-Will
## Windows
[WinAVR](http://winavr.sourceforge.net/) has everything you need.
For the programmer type, select AVR109 or Butterfly. For the serial
port, select the USB device.
# Special-Needs Hardware
#### Atmel Dragon Hardware Programmer with avrdude on Ubuntu
Apparently there are two bugs that get in the way when trying to use
avrdude with the dragon.
- avrdude 5.8 (via apt-get) segfaults after writing 1 byte:
<http://savannah.nongnu.org/bugs/?27507> - there is a patch for 5.8
posted there
- avrdude 5.9 (via the official site) source apparently has some other
bug that prevents the build from completing
First, get the dependencies for building the code.
`sudo apt-get build-dep avrdude`
The solution (aside from applying patches to the above versions) is to
use the patched 5.10 SVN code. The instructions are from this link:
<http://www.avrfreaks.net/index.php?name=PNphpBB2&file=printview&t=87972&start=20>
- svn co <svn://svn.savannah.nongnu.org/avrdude/trunk> .
- cd avrdude
- ./bootstrap
- ./configure
- ./make
- sudo ./make install
That seems to have worked for me! I'm on 9.04 32bit and I also installed
bison/flex/autoconf --obscurite
[Category:Microcontrollers](Category:Microcontrollers "wikilink")
+323
View File
@@ -0,0 +1,323 @@
## Integrated Circuits
Paul Charles Leddy donated these June 29,2010
10x ADC0817CCN
8-Bit Microprocessor Compatible A/D Converter With 16-Channel
Multiplexer, equivalent to MM74C948-1 100 ??s
12x ADC0833BCN
8-Bit Serial I/O A/D Converter with 4-Channel Multiplexer
27x ADC0848CCN
8-bit 40uS Parallel IO Analog to Digital Converter with 8 input
Multiplexer
16x AF100-1CN
Universal Active Filter - Highpass, Lowpass, Bandpass
6x IDM2909ANC
Nonvolatile, dual, linear-taper, digital potentiometers perform the
function of a mechanical potentiometer, but replace the mechanics with a
simple 2-wire digital interface. Each device performs the same function
as a discrete potentiometer or variable resistor and has 256 tap points.
25x MM74C00J
Quad 2-input NAND
17x MM74C02N
Quad 2-Input NOR Gate
13x MM74C14N
Hex Schmitt Trigger
18x DM74H74N
Dual Positive-Edge-Triggered D-Type Flip-Flops with Preset, Clear
65x DM7483J
4-Bit Parallel Full Adder
50x DM7490AN
counter binary/decade
15x MM74C93J
4-Bit Decade, Binary Counter
14x DM74148N
Priority Encoders
30x DM74154N 9311 -831
Decodes 4 binary-coded inputs into one of 16 mutually exclusive outputs
Performs the demultiplexing function by distributing data from one input
line to any one of 16 outputs
20x MM74C175N
Quad D-type Flip Flop
14x MM74C193N
Synchronous 4-Bit Up/Down Decade Counter
4x MM74C244N
Inverting Octal buffer and line driver
5x MM74C373N
Three-state Octal D-type latch
22x MM74C915N
7 segment to bcd decoder
9x DS1488N
Quad Line Driver for RS-232
5x MM14543BCN
BCD TO 7 SEGMENT DECODER DRIVER
15x DP8340N
IBM 3270 Protocol Transmitter / Encoder
15x DP8341N
IBM 3270 Protocol Receiver / Decoder
5x DP8342N S=B8624
Parallel to multibyte serial high speed transmitter, up to 3.5 MBit/Sec
5x DP8390N
10 mBit Ethernet MAC
5x DP8391N
10 mBit Ethernet Serial Network Interface (use with 8390)
5x DP8392AN
Coaxial Transceiver Interface 10Base2
20x DM8602N
Dual Retriggerable / Resettable One Shots
49x DM9093N
DTL dual JK flip-flops
76x DM946N
Quad 2-input DTL gate (Diode-Transistor Logic)
50x DM949N
DTL part
50x DM961N
DTL dual 4-input AND gate with expanders
20x CD4029BMJ 12x CD4029BJC
Presettable Binary/Decade Up/Down Counter
20x CD4051BCJ
Single 8-Channel Analog Multiplexer/Demultiplexer
22x MM5307AA/N
??? 1 GENERATOR, BAUD RATE
7x MM5303N
UNIVERSAL ASYNCHRONOUS RECEIVER/TRANSMITTER DC:94 NATIONAL 40 PIN DIP
25x MM54C04J
Hex Inverter
25x DM5486N
2-Input Exclusive-OR
22x MM54C221J
Dual Monostable Multivibrator
16x DM54S287J
60 ns, (256 x 4) 1024-bit TTL PROM
20x MM54C906J
Hex Open Drain N-Channel Buffers
15x DM9300N
4-Bit Parallel-Access Shift Register
5x DAC1265LCJ
+/-18 V, hi-speed(200ns/5MHz) 12-bit D/A converter with reference in
24-pin DIP package. Operational temperature range from 0??C to 70??C.
3x DAC1266LCJ
0 V to -18 V, hi-speed 12-bit D/A converter
10x LF347N
Quad JFET Input Op-Amp
44x LF13300D (gold ceramic case)
INTEGRATING A/D ANALOG BUILDING BLOCK
20x LM318D
Fast general purpose op-amps Small-Signal Bandwidth . . . 15 MHz Typ
Slew Rate . . . 50 V/??s Min Bias Current . . . 250 nA Max (LM118,
LM218) Supply Voltage Range . . . ?? 5 V to ?? 20 V Internal Frequency
Compensation Input and Output Overload Protection Same Pin Assignments
as General-Purpose Operational Amplifiers
25x LM339N
Single Supply Quad Comparators
17x LM1800AN
Phase-Locked Loop FM Stereo Demodulator
18x MK4564N-20
64K by 1 bit 200nS DRAM
5x LMC669CD
Auto-Zero for Input Offset Voltage of any Op-Amp
[Category:Materiel](Category:Materiel "wikilink")
+567
View File
@@ -0,0 +1,567 @@
## Concept
The idea behind this course structure is for six sessions held a week
apart. In order to provide a tangible end for students to feel like
they???re working toward, each week will have a project; students will
be walked through building that project and completing it by the end of
the session.
In that sense, each week stands alone — a project started in one week
does not need a future week in order to be complete. That said, later
projects will depend on the knowledge gained in previous projects, and
some of them will even be based on previous projects. (For example,
[Week 5???s
project](Intro_to_Electronics#Week_5:_Digital_logic "wikilink") is a
Larson scanner, and it uses [Week 4???s
project](Intro_to_Electronics#Week_4:_Oscillators_.E2.80.94_and_the_venerable_555 "wikilink")
— a typical 555-based astable multivibrator circuit — to provide its
clock signal.)
The course starts with a few basic circuit components (a voltage source,
a resistor and an LED) and an explanation of typical prototyping
equipment (breadboard and multimeter) and builds up to include regulated
power supplies, basic optoelectronics and eventually digital logic.
It does not (at least in this draft) include much in the way of detailed
exploration of analog electronics; it???s intended more as an
introduction to the field of hobbyist electronics as a whole and to an
assortment of the basic components one might find in a variety of
projects.
Suggestions are, of course, welcome, as are other potential projects to
use in place of some of the ones listed here. (In particular, a good
introductory op-amp project might be handy to have.) I???ve listed
[component prices](Intro_to_Electronics#Components "wikilink") for 25
students; my goal would be to keep the cost per student at \$25 or less
— preferably more in the \$20 range.
## Syllabus
### Week 1: Getting familiar with components
**Goal:** Light an LED with AA batteries and an on-off switch
**Slides:**
[Media:Intro_to_Electronics-Week1-Slides.pdf](Media:Intro_to_Electronics-Week1-Slides.pdf "wikilink")
Explanations:
- Breadboard
- What is it?
- How is it organized?
- Why is it useful?
- **Hands-on:** Here's a breadboard
- LED
- What is it?
- How does it work?
- Not at the P/N junction level
- Current goes in, light comes out
- Current only flows in one direction (diode!)
- Too much current = bad
- **Hands-on:** Plug one into the breadboard
- Battery
- What is it?
- How does it work?
- Roughly constant voltage source for a while
- Discharges over time — voltage decreases
- Definition of "dead"
- Maybe some chemistry? Doubtful, though
- **Hands-on:** Batteries (three or four AAs) in a holder
- Plug them into the breadboard
- Switch
- What is it?
- How does it work?
- Define poles and throws
- **Hands-on:** Plug one (SPST) into the breadboard
- Resistor
- What is it?
- How does it work?
- Ohm's Law
- Units of measurement
- Ohm
- Ampere
- Volt
- Non-polarized
- Describe color codes
- Give resources — memorizing is a bit daunting right now, I
imagine
- Tolerances — nothing's perfect
- What does a ±5% tolerance mean?
- **Hands-on:** Pick a resistor and plug it in to the breadboard
- Select using Ohm's Law
- Schematic
- What is it?
- Symbols
- LED
- Battery (DC source)
- Switch
- Resistor
- Ground!
- Define ground
- Draw one
- **Hands-on:** Connect components to match [this schematic (tested
April 2,
2012)](Media:Intro_to_Electronics-Week1-0-LED.svg "wikilink")
- Moment of truth: Turn it on!
### Week 2: Test equipment
**Goal:** Build a power supply
**Slides:**
[Media:Intro_to_Electronics-Week2-Slides.pdf](Media:Intro_to_Electronics-Week2-Slides.pdf "wikilink")
Explanations:
- Multimeter
- What is it?
- Review units of measurement
- Ohm
- Ampere
- Volt
- **Hands-on:** Measure [last week's LED
circuit](Intro_to_Electronics#Week_1:_Getting_familiar_with_components "wikilink")
- Voltages at different nodes
- Current through LED branch?
- Resistance of current-limiting resistor
- Voltage divider
- What is it?
- How does it work?
- Ohm's Law!
- Walk through the analysis
- **Hands-on:** Build one ([Schematic here (tested April 2,
2012)](Media:Intro_to_Electronics-Week2-0-divider.svg "wikilink"))
- Measure no-load output voltage
- Regulated versus unregulated power supply
- What's the difference?
- **Hands-on:** Add a load to the voltage divider ([Schematic here
(tested April 2,
2012)](Media:Intro_to_Electronics-Week2-1-divider-loaded.svg "wikilink"))
- Measure difference in output voltage
- Why does this happen?
- Equivalent resistances in series and in parallel
- Datasheet
- What are they?
- How can you find them?
- **Hands-on:** Here's an LM317 ([Schematic here (tested April 2,
2012)](Media:Intro_to_Electronics-Week2-2-LM317.svg "wikilink"))
- Look up example circuits in [the
datasheet](http://www.ti.com/lit/ds/symlink/lm117.pdf)
- Capacitor
- What is it?
- How does it work?
- Polarized (electrolytic) versus non-polarized (ceramic)
- Filter capacitors
- Show them on the datasheet's example circuit
- **Hands-on:** Build the example circuit ([Schematic here (tested
April 2,
2012)](Media:Intro_to_Electronics-Week2-3-LM317-filtered.svg "wikilink"))
- Measure input voltage over time with and without filter
capacitors
- Not sure if we'll be able to notice on the multimeter
- Oscilloscope (if there's time)
- What is it?
- How does it work?
- Time axis
- Voltage axis
- **Hands-on:** Look at regulator's output waveform
- Vary load and see what happens!
### Week 3: Optoelectronics
**Goal:** Build a night light (Many thanks to
[EMSL](http://www.evilmadscientist.com/article.php/nightlight))
**Slides:**
[Media:Intro_to_Electronics-Week3-Slides.pdf](Media:Intro_to_Electronics-Week3-Slides.pdf "wikilink")
Explanations:
- LED (review)
- What does it take to light one?
- Remember to limit current
- **Hands-on:** Light one
- Probably just rebuild [Week 1's
circuit](Intro_to_Electronics#Week_1:_Getting_familiar_with_components "wikilink")
([schematic here (tested April 2,
2012](Media:Intro_to_Electronics-Week3-0-LED.svg "wikilink")),
though you really don't even need the switch for this
- Transistor (BJT)
- What is it?
- How does it work?
- Amplifier
- Switch — what we'll focus on for now
- What are the different terminals?
- Base
- Collector
- Emitter
- NPN versus PNP
- **Hands-on:** Use one to control the LED ([Schematic here (tested
April 2,
2012](Media:Intro_to_Electronics-Week3-1-BJT.svg "wikilink"))
- Phototransistor
- What is it?
- How does it work?
- Apply light instead of base current
- **Hands-on:** Add one to our circuit to switch the other transistor
([Schematic here (tested April 2,
2012](Media:Intro_to_Electronics-Week3-2-phototransistor.svg "wikilink"))
- Should look essentially identical to [the EMSL
circuit](http://www.evilmadscientist.com/article.php/nightlight),
except that we'll keep a current-limiting resistor in series with
the LED
- Note: This phototransistor (like many others) is mainly sensitive
to infrared and will consider a room lit only by fluorescent bulbs
to be "dark". Bring around a different lamp to test the projects.
- Bonus: Start talking about digital logic
- What is it?
- Logic gates
- High-level explanation
- Names: AND, OR, NOT (maybe XOR)
- Show examples of 7400-series ICs
- Show a schematic of a NOT gate (for example: [this
one](http://www.kpsec.freeuk.com/trancirc.htm#inverter),
[presentation schematic
here](Media:Intro_to_Electronics-Week3-3-NOT.svg "wikilink"))
- **Hands-on (ish):** Compare the NOT gate schematic to our night
light
- We've made one with a phototransistor!
- Could have been done with a normal transistor, too
- Way less useful that way
### Week 4: Oscillators ??? and the venerable 555
**Goal:** Build a 555 circuit to blink an LED
**Slides:**
[Media:Intro_to_Electronics-Week4-Slides.pdf](Media:Intro_to_Electronics-Week4-Slides.pdf "wikilink")
Explanations:
- 555 timer
- What is it?
- How does it work?
- High-level explanation, though more detail can come afterward for
anyone who wants to know
- Modes of operation
- Look at [the
datasheet](http://www.ti.com/lit/ds/symlink/ne555.pdf)
- We're interested in the astable multivibrator
- What does that mean?
- What crazy things do people do with it? ([All kinds of
things.](http://www.555contest.com/))
- **Hands-on:** Wire one up ([Schematic here (tested April 4,
2012)](Media:Intro_to_Electronics-Week4-0-555.svg "wikilink"))
- Show output on an oscilloscope
- LED (review)
- Look up forward voltages
- Use a different LED this time (maybe blue!)
- **Hands-on:** Figure out an appropriate current-limiting resistor
- Hook it up to the output of the 555 ([Schematic here (tested April
4,
2012)](Media:Intro_to_Electronics-Week4-1-555-LED.svg "wikilink"))
- Potentiometer
- What is it?
- How do I use one?
- **Hands-on:** Measure resistances between different terminals
- Could have used it in [Week
2](Intro_to_Electronics#Week_2:_Test_equipment "wikilink") to vary
regulator output voltage
- **Another hands-on:** Replace one of the 555 frequency-setting
resistors ([Schematic here (tested April 4,
2012)](Media:Intro_to_Electronics-Week4-2-555-potentiometer.svg "wikilink"))
- Change its resistance and watch what happens!
### Week 5: Digital logic
**Goal:** Build a Larson scanner (Schematic (more or less) from
[EMSL](http://www.evilmadscientist.com/article.php/CylonOLantern))
**Slides:**
[Media:Intro_to_Electronics-Week5-Slides.pdf](Media:Intro_to_Electronics-Week5-Slides.pdf "wikilink")
(with notes here:
[Media:Intro_to_Electronics-Week5-Slides_and_Notes.pdf](Media:Intro_to_Electronics-Week5-Slides_and_Notes.pdf "wikilink")
- Use [Week 4's 555
project](Intro_to_Electronics#Week_4:_Oscillators_.E2.80.94_and_the_venerable_555 "wikilink")
for the clock signal
- Can change resistor values to EMSL-recommended values to change
speed
- Leave out the low-pass filter because of time and cost
Explanations:
- Digital logic (in general)
- What is it?
- Compare to analog electronics — also has cool applications
- What can I do with it?
- State machines
- Multiplexers
- Counters
- **Hands-on:** Manual logic switch ([Schematic here (tested April 4,
2012)](Media:Intro_to_Electronics-Week5-0-switch.svg "wikilink"))
- SPST on a line with a pull-up (or pull-down) resistor
- How does such a resistor work? What does it do?
- Watch it on a multimeter
- How does it differ from the SPST without the resistor?
- Decimal counter
- What is it?
- How does it work?
- **Hands-on:** Hook one up to power and the 555 circuit from [Week
4](Intro_to_Electronics#Week_4:_Oscillators_.E2.80.94_and_the_venerable_555 "wikilink")
- Watch what happens — connect each output pin to an LED to make it
more obvious ([schematic here (tested April 4, 2012) with
different (i.e., faster) resistor values as suggested by
EMSL](Media:Intro_to_Electronics-Week5-1-counter.svg "wikilink"))
- OR gate
- Review logic gates (if we got to them at the end of [Week
3](Intro_to_Electronics#Week_3:_Optoelectronics "wikilink"))
- Why are we interested in these?
- Plot out Larson scanner details/excitation table
- We need four of them
- **Hands-on:** Add them to the circuit ([Schematic here (tested April
4, 2012)](Media:Intro_to_Electronics-Week5-2-Larson.svg "wikilink"))
- Watch the lights scan back and forth
### Week 6: Soldering
**Goal:** Solder [Week 5's
project](Intro_to_Electronics#Week_5:_Digital_logic "wikilink") on a
printed circuit board
Explanations:
- Solder
- What is it?
- How do I use it?
- Leaded versus lead-free
- **Hands-on (ish):** Here's some solder
- Soldering iron
- What is it?
- How do I clean and tin the tip?
- **Demo:** How do I form a good solder joint?
- Heat both terminals
- Apply solder
- Examples of solder joints
- Ideal
- Cold
- Bridged
- **Hands-on:** Solder two wires together
- Printed circuit board
- What is it?
- Fiberglass
- Copper traces/pads
- Drilled holes/plated vias
- Silkscreened markings
- **Hands-on:** Solder a component
- Assembly
- **Hands-on:** Finish the board! ([PCB design (EAGLE) here, still
untested](Media:Intro_to_Electronics-Week6-EAGLE.zip "wikilink"))
- Bonus: Do I need one of these? (Other ways to mount circuits)
- Prototyping board, layout tools, etching (chemical and mechanical)
## Bill of materials
Pricing assumes 25 kits with no special discounts (e.g., [Adafruit
hackerspace
discount](http://www.adafruit.com/blog/2010/06/01/big-news-all-hacker-spaces-in-the-world-get-adafruit-reseller-pricing-starting-today/)).
Total cost — not including breadboard jumpers, multimeter, PCB and
shipping for all of these things — comes out to \$368.20 (or \$14.73 per
person).
### Equipment
- Multimeter
- Relatively inexpensive (but maybe more than we want students to
spend)
- Voltage, current, resistance, continuity
- Diode test would be nice to have
- Do we want people to get their own, or do we want to use the
space's?
- MAS830 (\$337.50 for 25:
[Adafruit](http://www.adafruit.com/products/71))
- Does the space have enough working meters? (If not, can we
convince some place to donate some more?)
- Breadboard
- Full size x1 (\$180 for 25:
[Adafruit](https://www.adafruit.com/products/239))
- Battery holder
- 4xAA x1 (\$21.18 for 25:
[Digi-Key](http://search.digikey.com/us/en/products/BH14AAW/BH14AAW-ND/66735))
- Batteries
- Alkaline AA x4 (\$33.48 for 100-pack:
[Amazon](http://www.amazon.com/Duracell-Coppertop-MN1500-Batteries-Count/dp/B006W9QIM2/))
### Things we could make ourselves
- Assorted breadboard jumpers
- We could cut these ourselves to reduce cost, assuming we have enough
small solid-core wire
- Apparently Digi-Key also sells these in [packs of 150 or
200](http://search.digikey.com/us/en/cat/prototyping-products/jumper-wire/2359516?stock=1&pbfree=1&rohs=1)
for various lengths for \$16.48
- Beginners might be more comfortable with longer pieces of wire
(e.g., [these packs of 75](http://www.adafruit.com/products/153)
for \$6.00 each), though — thoughts?
- Printed circuit board for [Week
6](Intro_to_Electronics#Week_6:_Soldering "wikilink")
- Do we etch or mill these ourselves? Do we have some batch PCB
service (e.g., Seeed, Sparkfun) get them done?
- First design (EAGLE files [here](https://gist.github.com/2067344))
is 1.70 x 3.00 inches
- BatchPCB price at that size for 25: \$328.75 (\$13.15 each)
- Fusion PCB price at that size for 30: \$84.70 (\$2.83 each)
- Fusion PCB price at that size for 50: \$84.90 (\$1.70 each)
- Both Fusion PCB prices are with the extra fee for testing all of
them (instead of half) since it'd be nice not to have to
troubleshoot the boards themselves in addition to the students'
work
- Still have some room in the corner if we're interested in doing
anything else with it
### Components
- LEDs
- 5mm red x10 (\$19.38 for 250:
[Digi-Key](http://search.digikey.com/us/en/products/WP7113SRC%2FDU/754-1274-ND/1747673))
- [Week
1](Intro_to_Electronics#Week_1:_Getting_familiar_with_components "wikilink"):
x1 (light)
- [Week 3](Intro_to_Electronics#Week_3:_Optoelectronics "wikilink"):
x1 (light)
- [Week
4](Intro_to_Electronics#Week_4:_Oscillators_.E2.80.94_and_the_venerable_555 "wikilink"):
x1 (555 output)
- [Week 5](Intro_to_Electronics#Week_5:_Digital_logic "wikilink"):
x10 (4017 output, later x6 for Larson scanner)
- [Week 6](Intro_to_Electronics#Week_6:_Soldering "wikilink"): x6
(Larson scanner)
- 5mm blue x1 (\$4.75 for 25:
[Digi-Key](http://search.digikey.com/us/en/products/C503B-BCS-CV0Z0461/C503B-BCS-CV0Z0461-ND/1922944))
- [Week
4](Intro_to_Electronics#Week_4:_Oscillators_.E2.80.94_and_the_venerable_555 "wikilink"):
x1 (555 output)
- Switches
- SPDT slider x1 (\$14.72 for 25:
[Digi-Key](http://search.digikey.com/us/en/products/EG1218/EG1903-ND/101726))
(Note: We only need SPST, but for some reason those are several
times more expensive. Not sure why that is. SPDT will take a tad
more explanation, but it shouldn't be that big of a deal.)
- [Week
1](Intro_to_Electronics#Week_1:_Getting_familiar_with_components "wikilink"):
x1 (power)
- [Week 5](Intro_to_Electronics#Week_5:_Digital_logic "wikilink"):
x1 (logic)
- Voltage regulator
- LM317 x1 (\$9.80 for 25:
[Digi-Key](http://search.digikey.com/us/en/products/LM317KCS/296-13869-5-ND/521368))
- [Week 2](Intro_to_Electronics#Week_2:_Test_equipment "wikilink"):
x1 (regulator)
- Resistors
- 220 Ω x1 (\$4.23 for 250:
[Digi-Key](http://search.digikey.com/us/en/products/CFM14JT220R/S220QCT-ND/2617711))
- [Week
1](Intro_to_Electronics#Week_1:_Getting_familiar_with_components "wikilink"):
x1 (current limiting)
- [Week 2](Intro_to_Electronics#Week_2:_Test_equipment "wikilink"):
x1 (voltage divider load), x1 (LM317 R1)
- [Week 3](Intro_to_Electronics#Week_3:_Optoelectronics "wikilink"):
x1 (current limiting)
- [Week 5](Intro_to_Electronics#Week_5:_Digital_logic "wikilink"):
x10 (current limiting)
- [Week 6](Intro_to_Electronics#Week_6:_Soldering "wikilink"): x6
(current limiting)
- 360 Ω x1 (\$1.38 for 25:
[Digi-Key](http://search.digikey.com/us/en/products/CFM14JT360R/S360QCT-ND/2617740))
- [Week 2](Intro_to_Electronics#Week_2:_Test_equipment "wikilink"):
x1 (voltage divider top half), x1 (LM317 R2)
- 1 kΩ x1 (\$1.38 for 25:
[Digi-Key](http://search.digikey.com/us/en/products/CFM14JT1K00/S1KQCT-ND/2617685))
- [Week 2](Intro_to_Electronics#Week_2:_Test_equipment "wikilink"):
x1 (voltage divider bottom half)
- [Week 3](Intro_to_Electronics#Week_3:_Optoelectronics "wikilink"):
x1 (BJT base current)
- [Week 5](Intro_to_Electronics#Week_5:_Digital_logic "wikilink"):
x1 (pull-up or pull-down resistor)
- 180 kΩ x2 (\$1.50 for 50:
[Digi-Key](http://search.digikey.com/us/en/products/CFM14JT180K/S180KQCT-ND/2617681))
- [Week 5](Intro_to_Electronics#Week_5:_Digital_logic "wikilink"):
x2 (555 R1, 555 R2)
- [Week 6](Intro_to_Electronics#Week_6:_Soldering "wikilink"): x2
(555 R1, 555 R2)
- 1 MΩ x1 (\$1.38 for 25:
[Digi-Key](http://search.digikey.com/us/en/products/CFM14JT1M00/S1MQCT-ND/2617692))
- [Week
4](Intro_to_Electronics#Week_4:_Oscillators_.E2.80.94_and_the_venerable_555 "wikilink"):
x1 (555 R1)
- 2 MΩ x1 (\$1.38 for 25:
[Digi-Key](http://search.digikey.com/us/en/products/CFM14JT2M00/S2MQCT-ND/2617726))
- [Week
4](Intro_to_Electronics#Week_4:_Oscillators_.E2.80.94_and_the_venerable_555 "wikilink"):
x1 (555 R2)
- 150 Ω x1 (\$1.38 for 25:
[Digi-Key](http://search.digikey.com/us/en/products/CFM14JT150R/S150QCT-ND/2617674))
- [Week
4](Intro_to_Electronics#Week_4:_Oscillators_.E2.80.94_and_the_venerable_555 "wikilink"):
x1 (current limiting)
- Capacitors
- 0.1 µF ceramic x1 (\$2.91 for 25:
[Digi-Key](http://search.digikey.com/scripts/DkSearch/dksus.dll?x=20&y=11&lang=en&site=us&KeyWords=490-3859-ND))
- [Week 2](Intro_to_Electronics#Week_2:_Test_equipment "wikilink"):
x1 (LM317 input filter)
- 0.22 µF ceramic x1 (\$5.00 for 25:
[Digi-Key](http://search.digikey.com/us/en/products/FK18Y5V1H224Z/445-4806-ND/2050155))
- [Week
4](Intro_to_Electronics#Week_4:_Oscillators_.E2.80.94_and_the_venerable_555 "wikilink"):
x1 (555 C)
- [Week 5](Intro_to_Electronics#Week_5:_Digital_logic "wikilink"):
x1 (555 C)
- [Week 6](Intro_to_Electronics#Week_6:_Soldering "wikilink"): x1
(555 C)
- 0.01 µF ceramic x1 (\$4.70 for 25:
[Digi-Key](http://search.digikey.com/scripts/DkSearch/dksus.dll?x=7&y=18&lang=en&site=us&KeyWords=490-3813-ND))
- [Week
4](Intro_to_Electronics#Week_4:_Oscillators_.E2.80.94_and_the_venerable_555 "wikilink"):
x1 (555 filter)
- [Week 5](Intro_to_Electronics#Week_5:_Digital_logic "wikilink"):
x1 (555 filter)
- [Week 6](Intro_to_Electronics#Week_6:_Soldering "wikilink"): x1
(555 filter)
- Potentiometer
- 2 MΩ x1 (\$15.08 for 25:
[Digi-Key](http://search.digikey.com/us/en/products/CT6EP205/CT6EP205-ND/738311))
- [Week
4](Intro_to_Electronics#Week_4:_Oscillators_.E2.80.94_and_the_venerable_555 "wikilink"):
x1 (555 R1)
- Transistors
- 2N3904 x1 (\$6.90 for 25:
[Digi-Key](http://search.digikey.com/us/en/products/2N3904-AP/2N3904-APCT-ND/950591))
- [Week 3](Intro_to_Electronics#Week_3:_Optoelectronics "wikilink"):
x1 (switch for output LED)
- Phototransistor
- x1 (\$6.75 for 25:
[Digi-Key](http://search.digikey.com/us/en/products/PT334-6C/1080-1159-ND/2675650))
- [Week 3](Intro_to_Electronics#Week_3:_Optoelectronics "wikilink"):
x1 (light sensor)
- 555 timer
- NE555N x1 (\$6.99 for 25:
[Digi-Key](http://search.digikey.com/us/en/products/NE555N/497-1963-5-ND/599557))
- [Week
4](Intro_to_Electronics#Week_4:_Oscillators_.E2.80.94_and_the_venerable_555 "wikilink"):
x1 (oscillator)
- Decimal counter
- 74HC4017 x1 (\$17.05 for 25:
[Digi-Key](http://search.digikey.com/us/en/products/M74HC4017B1R/497-1835-5-ND/591928))
- [Week 5](Intro_to_Electronics#Week_5:_Digital_logic "wikilink"):
x1 (counter)
- [Week 6](Intro_to_Electronics#Week_6:_Soldering "wikilink"): x1
(counter)
- OR gates
- 74HC32 x1 (\$6.88 for 25:
[Digi-Key](http://search.digikey.com/us/en/products/SN74HC32N/296-1589-5-ND/277235))
- [Week 5](Intro_to_Electronics#Week_5:_Digital_logic "wikilink"):
x1 (count reverser)
- [Week 6](Intro_to_Electronics#Week_6:_Soldering "wikilink"): x1
(count reverser)
[Category:Intro_to_Electronics](Category:Intro_to_Electronics "wikilink")
+96
View File
@@ -0,0 +1,96 @@
This page is a resource for keysigning parties @ HacDC.
## Upcoming Parties
Friday, November 13th @ 7:30PM
## Past Parties
September 10th, 2009
- We had about 20 folks and about 10 of whom were productively
keysigning.
## Intro to KeySigning
- You have a private key and a public key, which you generate (your
keypair).
- gpg --gen-key
<!-- -->
- People use your public key to send you encrypted messages that only
you can open via the magic of crypto!
- gpg --output doc.gpg --encrypt --recipient obscurite@hacdc.org doc
<!-- -->
- You decrypt these messages with your private key, which only you have
access to.
- gpg --output doc --decrypt doc.gpg
<!-- -->
- But first, you must share your public key, either directly or by
uploading it to a keyserver.
- gpg --keyserver pgp.mit.edu --send-keys D34DB33F
<!-- -->
- If it's on a keyserver, they must download it from the keyserver.
- gpg --keyserver pgp.mit.edu --recv-key D34DB33F
<!-- -->
- If it was a file (called obscurite.gpg for example), they can import
it manually.
- gpg --import obscurite.gpg
<!-- -->
- Now they can sign the key and send the key back to the keyserver.
- gpg --sign-key D34DB33F
<!-- -->
- But before anyone signs anyone elses key they have to make sure that
person actually owns that key (checking physical ID).
- Minimum recommendation is state photo ID + secondary photo ID
(school, employer)
<!-- -->
- You can see who has signed someone's public key. If their key has been
signed by someone in your web of trust, then that person is in your
web of trust as well.
- gpg --list-sigs D34DB33f
<!-- -->
- Don't forget to generate a revokation certificate for your public key
in case you lose your passphrase or your key is compromised!
- gpg --gen-revoke
## DETAILS
- Obscurite generally uses the pgp.mit.edu keyserver, but
keyserver.ubuntu.com is well liked and they do sync regularly, so it
doesn't especially matter which one you use, except that pgp.mit.edu
has a nice web search interface.
- I will pass around copies of signatures so you can check people off as
you confirm their identity
- I recommend using a valid state photo ID as a minimum validation. It
is up to your personal "keysigning policy."
## Links
- [Keysigning
commands](http://commandline.org.uk/command-line/ten-steps-for-attending-a-keysigning-party/)
- [Keysigning
HOWTO](http://www.cryptnet.net/fdp/crypto/keysigning_party/en/keysigning_party.html#overview)
- [Perl script to generate keyring
list](http://cryptnet.net/fdp/crypto/keysigning_party/en/extra/party-table.pl)
- [Checking the integrity of the installer, even without GPG already
installed](http://www.gnupg.org/download/integrity_check.en.html)
[Category:Previous_Projects](Category:Previous_Projects "wikilink")
+46
View File
@@ -0,0 +1,46 @@
At the moment this is Katie's page for planning an LED Embroidery
workshop. It may later become a resource page for workshop participants.
[LED Calculator](http://led.linear1.org/1led.wiz)
[one way to do
it](http://makeprojects.com/Project/Electronic-Embroidery/44/1)
Resources already on hand:
- coin cell batteries (3V)
- ~~resistors~~ [not
needed](http://www.evilmadscientist.com/article.php/throw/print) in
this case
- Limor says lithium coin batteries are internally current-limited
- conductive thread (~25Ohms/foot)
- white 3mm LEDs (3.5V, 20mA)
What each participant should get:
1. embroidery needle
2. regular embroidery thread
3. conductive thread
4. LEDs
5. embroidery hoop
6. dark fabric
7. fabric pencil?
8. coin cell battery
9. tape to secure battery?
10. needle threader
Resource I should provide:
1. books with constellation drawings
2. photo and sample of finished piece
Instructions:
1. Choose a design.
2. Layout the design with fabric pencil.
3. Prep LEDs (punch through fabric and twist leads).
4. Sew circuit with conductive thread.
5. Test with battery.
6. Sew decorative part with regular thread.
[Category:Proposed_Projects](Category:Proposed_Projects "wikilink")
+70
View File
@@ -0,0 +1,70 @@
# Efficiency
Interesting factoids about [replacing sodium vapor lamps with
LEDs](http://dansdata.blogsome.com/2008/12/27/led-street-lighting-not-as-good-as-you-think/)
for city-wide lighting.
- The theoretical lumen/Watt figures for LEDs are worse than
low-pressure sodium vapor lamps (100 lm/W versus 200 lm/W)
- White LEDs are actually blue LEDs with a consumable phosphor layer
that turns opaque after a few years of operation.
- Combined RGB LEDs will have better efficiency than a "white" LED.
Other real-world tests have concluded that LED street lights have about
the same lumen/Watt in practice as the sodium vapor lamps ([64 lm/W
LEDs](http://www.olino.org/us/articles/2008/11/02/streetlamp-lioris-aduro-52)
versus [67 lm/W Sodium
vapor](http://www.olino.org/us/articles/2008/12/29/indal-industria-aurora-streetlamp)).
Neon and florescent efficiency [depends on the color and
shape](http://www.signindustry.com/neon/articles/2003-07-11-RC-NeonandFlour.php3):
> \[...\] the fluorescent tube produces between 50 and 100 lumens of
> light per watt depending upon design. Compare this with the typical
> incandescent light bulb that produces between 10 and 20 lumens per
> watt. Neon light efficiency is based upon much fancier pants, the
> color of its output, which ranges from 10 lumens per watt for red to
> 60 lumens per watt for green or blue. One reason that green and blue
> tubes are more efficient is that phosphor coatings used to produce
> such colors better ballyhoo the high-energy ultraviolet light from the
> argon/mercury mix into visible colors. One reason that the fluorescent
> tube is more efficient than a neon tube is that a large straight tube
> offers less resistance to electrical current flow than a skinny bent
> one.
# Obstacles
Little Rock, AK wanted to replace their inefficient shielded lights with
more efficient fixtures, but their contract with Entergy is not a simple
\$/kW formula: [the energy company sets the price based on the type of
fixture](http://www.arktimes.com/Articles/ArticleViewer.aspx?ArticleID=fce07cab-0dea-4fc5-b57e-f1145715f01e).
> \[...\] According to Henry, the city tested out more efficient
> 100???watt HPS bulbs in one Little Rock neighborhood about five years
> ago. When the city asked Entergy to set a rate for those fixtures, it
> was almost double the rate for the 150-watt HPS type.
>
> When asked if Entergy was keeping Little Rock from being more energy
> efficient, Henry said simply, "Yes."
>
> "But how do you fight Entergy?" Henry asked. "I mean, we've had people
> come in and show us new, more efficient lights and we've said, well,
> the problem is, it's not going to save us anything. It will be a whole
> lot less wattage and it will put light out on the street but we can't
> get any benefit out of it because of the tariffs."
# Commercial LED lamps
[SparkFun](http://sparkfun.com) sells LED lamps that are screw
compatible with US light sockets:
- [75
W](http://www.sparkfun.com/commerce/product_info.php?products_id=8716)
- [12
W](http://www.sparkfun.com/commerce/product_info.php?products_id=8714)
- [3
W](http://www.sparkfun.com/commerce/product_info.php?products_id=8717)
- [1
W](http://www.sparkfun.com/commerce/product_info.php?products_id=8715)
[Category:Useful_Info](Category:Useful_Info "wikilink")