|
OK, your circuit is powered up but is your microcontroller
running? We can set a LED blinking to indicate this.
The setup is similar; the only difference is that instead
of connecting the resistor to the power rail, we connect
it to the microcontroller’s I/O pin.

After setting the I/O pin to be an output
we can set it to logic 1. The voltage at the port pin
will be equal to Vcc (say 5V) and our circuit may be
considered to behave exactly as the previous one, the
LED will be on. When the port pin is at logic 0, it
is basically grounded, no current flows and the LED
is off. By alternating 1s and 0s in regular time intervals
we can sense the LED blinking. Let’s see another
configuration.

Here, to have current flowing through the
LED, the port pin must be grounded. When it is at logic
1 there is no voltage difference across the resistor
and the LED, no current flows and the LED is off. Remember
inverse logic for this one, 1 for off, 0 for on.
Which one should we choose? Observe the two configurations,
in the first case the current flowing is provided by
the microcontroller. In other terms the microcontroller
is “sourcing” the circuit. In the second
case the microcontroller is “sinking” the
flowing current. Which one is easier do you think? The
second and this is why it is preferred. If you look
at the ATmega8 datasheet you will find that it can source
or sink the same amount of current 20mA at Vcc = 5V,
10mA at Vcc = 3V, still most people like the second
option. There are microcontrollers out there with better
sinking than sourcing capabilities. Bear in mind that
this is another limiting factor when you setup your
LED’s operating conditions.
Have fun!
|