A sine wave (yellow) processed through an FFT
function (purple). Each vertical division
corresponds to 500 Hz and the screen spans
from 0 Hz to 5 kHz. A very distinct peak
appears at the fourth division with no
significant peaks anywhere else — meaning the
input was a pure 2 kHz signal.
Development
Environment
Source code was developed in C using the
freely available Code Warrior for 56800/E
Digital Signal Controllers Special Edition
( www.freescale.com/webapp/sps/site/
prod_summary.jsp?code=CW-56800E-DSC).
Fast Fourier Transform
(FFT)
A fast Fourier transform is a mathematical function
used to split sounds into their discrete frequency elements
and is the core element of the DEFCON 17 badge. The FFT
is a complex and processor-intensive function suited for a
DSP or DSC, fitting in perfectly with our microcontroller
selection. Detailed information on FFTs can be found at
http://en.wikipedia.org/wiki/Fast_Fourier_transform and
www.edn.com/article/CA6643362.html.
On the badge, the FFT function takes in the audio
signal from the microphone via a 12-bit analog-to-digital
conversion at an 8 kHz sample rate and separates it into
four discrete bins. Each bin corresponds to a particular
frequency range. The power of three of the four bins are
calculated and those values are used to directly set the
color and brightness of the red, green, and blue elements
of the LED:
PWMRed_SetRatio16(~(unsigned int)FFTVal[0]);
// Bin 1
PWMGreen_SetRatio16(~(unsigned int)FFTVal[1]);
// Bin 2
PWMBlue_SetRatio16(~(unsigned int)FFTVal[2]);
// Bin 3
There are two other modes triggered when the audio input
meets certain specifications for a given amount of time:
1) When the badge detects a specific frequency of 2
kHz being played for a few seconds, it uses the RGB
LED to blink a secret URL in Morse code.
2) When the audio level received by the microphone
remains above the pre-defined threshold of Party
mode for 15 minutes, the RGB LED will blink an
“SOS” mayday call three times in Morse code. If this
mode gets triggered, the attendee is having too
much fun and needs to take a break!
only two pins (SCL, Serial Clock and SDA, Serial Data) and
ground, the Human badge serves as the master and
communicates with all the other badge types which are
slaves on the bus. This feature was designed purely with
social interaction and badge hacking in mind. The
expectation was that conference attendees with different
badge types would join forces and connect them together
to see what would happen. Only one team actually did
that. When badges are connected together, the default
functionality is for the master badge to control the RGB
LED state of all the slave badges and cycle through a
variety of different colors. Having run into problems with
communication reliability in attempting to do a “hot plug”
detection of badges connecting to the bus, my final
implementation had only the master checking for slave
badges on power-up. This meant that all slave badges had
to be turned on first before applying power to the master.
Each badge on the bus is individually addressable and its
address (A2-A0) is set by the presence or absence of three
zero ohm resistors (R1-R3) on the circuit board according
to the schematic and Table 1.
Notice in the graphic (on the following page) an
oscilloscope capture of badge-to-badge data being
transmitted over the I2C bus. The packet length is seven
bytes. The first byte is the destination address (0x00 is the
broadcast address that is accepted by any badges on the
bus). The remaining six bytes form three 16-bit words, each
corresponding to the PWM duty cycle of the red, green,
and blue diodes in the RGB LED. When the slave badge
receives the packet, it will parse the data, set the PWM
registers accordingly, and then wait for another packet to
be received.
Badge-to-Badge Communication
Not only do the badges connect together mechanically
as a puzzle, but up to seven of them can be connected
electrically and communicate with each other via I2C. Using
Bootloader
In order to provide a mechanism for attendees to easily
load new firmware into U1’s Flash memory to aid in badge
hacking and customization, I implemented a static
bootloader based heavily on Freescale’s AN3814
July 2010 47