Книга: Advanced PIC Microcontroller Projects in C

PROJECT 6.1 — Chasing LEDs 

Project Description

In this project eight LEDs are connected to PORTC of a PIC18F452-type microcontroller, and the microcontroller is operated from a 4MHz resonator. When power is applied to the microcontroller (or when the microcontroller is reset), the LEDs turn ON alternately in an anticlockwise manner where only one LED is ON at any time. There is a one-second delay between outputs so the LEDs can be seen turning ON and OFF.

An LED can be connected to a microcontroller output port in two different modes: current sinking and current sourcing.

Current Sinking Mode

As shown in Figure 6.1, in current sinking mode the anode leg of the LED is connected to the +5V supply, and the cathode leg is connected to the microcontroller output port through a current limiting resistor.


Figure 6.1: LED connected in current sinking mode

The voltage drop across an LED varies between 1.4V and 2.5V, with a typical value of 2V. The brightness of the LED depends on the current through the LED, and this current can vary between 8 and 16mA, with a typical value of 10mA.

The LED is turned ON when the output of the microcontroller is at logic 0 so the current flows through the LED. Assuming the microcontroller output voltage is about 0.4V when the output is low, we can calculate the value of the required resistor as follows:

 

    (6.1)

where

 VS is the supply voltage (5V)

 VLED is the voltage drop across the LED (2V)

 VL is the maximum output voltage when the output port is low (0.4V)

 ILED is the current through the LED (10mA)

Substituting the values into Equation (6.1) we get,

 

The nearest physical resistor is 270 ohms.

Current Sourcing Mode

As shown in Figure 6.2, in current sourcing mode the anode leg of the LED is connected to the microcontroller output port and the cathode leg is connected to the ground through a current limiting resistor.


Figure 6.2: LED connected in current sourcing mode

In this mode the LED is turned ON when the microcontroller output port is at logic 1 (i.e., +5V). In practice, the output voltage is about 4.85V and the value of the resistor can be determined as: 

 

    (6.2)

where

 VO is the output voltage of the microcontroller port when at logic 1 (+4.85V).

Thus, the value of the required resistor is:

 

The nearest physical resistor is 290 ohm.

Оглавление книги


Генерация: 4.558. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз