DIFFERENT BITS
see the following behavior from
your circuit:
1) The LEDS perform their startup blink
and the “hi!” message prints out the
serial port.
2) Initial weight values print out the
serial port, I/O lights blink and the top
LED on the error meter lights up.
3) Every 50 iterations, a count and
error measurement print out the
serial port.
FIGURE 7. Input/
output display.
FIGURE 6. Error level meter.
4) The error level starts to fall lower;
the level meter changes accordingly.
• feedforward receives the current
input values and calculates each
neuron’s current activation.
• train receives the current input values
and the desired output value. It calls
feedforward to activate the network
and get the output_activation. It then
measures the actual output against the
desired output and backpropagates
the error, adjusting each weight value
accordingly.
tests to ensure that the serial port
and LEDs are working. It initializes
random hidden and output weights
and iterates through a training loop
8,000 times or until the root mean
square error is less than 0.35 (it
usually takes about 400 iterations).
Every 50 iterations, it prints the count
and current error value. When the
loop completes, it prints how many
iterations it took, the final error value,
and loops once through an LED
display sequence demonstrating what
it has learned.
5) After 400-8,000 iterations, the
network has learned the XOR
function (have patience!). The last
LED in the error level meter lights
up and the program performs its
ending dance.
Final Thoughts
• main initializes the microcontroller
settings and performs a couple quick
After programming, you should
This is a simple circuit to display
neural network principles, but the
same ideas and basic code apply to
more complex problem sets.
Experiment with the code and circuit
and try to create your own input/
output mappings. Think about what
you would like to teach a robot to
learn, and how you could modify this
code so that your circuit could learn
from experience and feedback from its
environment. Have fun! SV
• Breadboard
• PIC16F877A microcontroller and
programmer
• 20 MHz ceramic resonator with
built-in capacitors (or equivalent)
• Eight 220 ohm resistors (or similar)
• One 10K resistor
• Eight light emitting diodes (LEDs)
• One pushbutton (for reset)
• RS-232 level shifter (MAX233 or
similar)
• 1 µF capacitor (if using MAX233)
• Serial cable with receive pin
available for breadboard use
18 SERVO 09.2007