Вы находитесь на странице: 1из 24

PIC Circuits Gallery

LED flasher

I made LED flash circuit which is often used as the PIC software making practice.
This circuit controls the blink of eight LEDs with the software of PIC.
The blinking pattern can be changed with five switches.

Pattern 1

Pattern 2

Pattern 3

Pattern 4

Pattern 5

Specification

PIC PIC16F84A

Processor Frequency 10MHz

LED High brightness LED x 8

Blink pattern Five kinds

PIC Project collection by Hassan Alameer 1


Circuit drawing of LED flasher

Pattern drawing of LED flasher


(Wiring side)

PIC Project collection by Hassan Alameer 2


Circuit explanation of LED flasher

Key-in circuit

Five pins from RA0 to RA4 are used as the input pin.
These pins are pull-uped with 10K ohm resisters. So,
when a switch isn't pushed, the input becomes H level
( +5V ). and when a switch is pushed, it will become
L level ( 0V ). When the switch closes, the chattering
occurs. The chattering is the phenomenon which
occurs with the bound of the point of contact. The opening and shutting of a point of contact
is repeated in short time..
I don't put the prevention circuit of the chattering at the circuit this time. When the software
detects that the switch is closed once, the blink processing of LEDs are executed in the time
which is longer than the chattering.

LED control circuit

Eight pins from RB0 to RB7 are used for the output pin.
The anode side of the LED is connected with +5 V and the cathode side is
controlled by PIC via the resistor. So, when the output of PIC is H level (+5V),
the LED goes out and when the output of PIC is L level (0V), the LED lights
up. I am using high brightness type LED to make an current flow little.

……..

Clock generator circuit

This is the circuit which used 10-MHz resonator.


It is very simple.

Power supply circuit

3 terminal regulator is used to get +5V output from +12V power in.
Because it is suppressing the current of the LED, a 100 mA-type regulator is
enough.

PIC Project collection by Hassan Alameer 3


Parts explanation of LED flasher

PIC

This is PIC16F84A. In case of


PIC16F84A, it is possible to use
clock frequency upto 20 MHz. The
circuit this time, I am using 10-MHz
resonator.

78L05

This regulator is used to make the stable power of +5 V.


The maximum output current is 100 mA.

Data sheet for 78L05

Resonator

I used 10-MHz resonator. A ceramic vibrator and capacitors for the oscillation are combined inside.

PIC Project collection by Hassan Alameer 4


PIC Circuits Gallery
LED flasher 2

This flasher moves, while lighting of LED drags on.


The brightness of LED is four kinds, bright, less bright, almost dim and dim. These lighting states are moved
with time.
Control of brightness is performed in lighting time of LED like PWM(Pulse Width Modulation).
There is no PWM function in PIC16F84A. Therefore, I divided lighting of LED into four cycles, and
controlled them. It is "Bright" when all periodic lightings are carried out. 2 cycle lighting state is "Less bright".
1 cycle lighting state is "almost dim". It is "Dim" in OFF a total cycle.
At first, I was going to prepare much more cycles. However, because PIC16F84A carried only 1K-word
program memory, I made into four cycles.

Patern 1 Patern 0 Patern 2


(Left) (Center) (Right)

Circuit drawing of LED flasher 2

PIC Project collection by Hassan Alameer 5


Pattern drawing of LED flasher 2
(Wiring side)

PIC Project collection by Hassan Alameer 6


Voltage regulator (7805)

This device is used in order to get the voltage of stable +5V.


1A type is used.
When there is little LED made to turn on simultaneously, 100mA type 78L05 can be used.

Data sheet for 7805

PIC Project collection by Hassan Alameer 7


Software flow chart of LED flasher
2 (1/2)

PIC Project collection by Hassan Alameer 8


Project 3
PIC Circuits Gallery
Count-down timer

On this page, I will introduce the Count-down timer with PIC16F84A.


I am putting a count-down timer by the hardware on Electronic Circuits Application Garage.
The function of the timer is the same as it approximately. (The stop switch is added)
Because this unit was made compactly, the wiring of the back becomes quite complicated.

I tyied to use following technique for the software of this equipment.

Mode changing method of I/O port


7 segment LED (Output), BCD switch (Input) and Start switch (Input) are connected
with PORTB in parallel. Each device is switched using the decoder. The mode of the
input/output of PORTB is changed according to it.

Control method of the 7 segment LED


The control code of 7 segments LED is controlled by the binary-coded decimal
code(BCD).

Display control mothod in case of borrow


The next of 00 seconds, it is displayed with 59 seconds. When each digit becomes 0,
the time out processing is done.

Precision of the hardware timer


The timer is count-downed every second by hardware timer.
I examined this accuracy.

Specification

PIC PIC16F84A

Processor Frequency 10MHz

Time range 1 minute - 99 minutes

Timer setting method BCD switches

Minute : 00 - 99
Display
Second : 00 - 59

PIC Project collection by Hassan Alameer 9


During count-down, it controls a voltageless contact.
Output
It lights up an LED as the display during control.

Circuit drawing
of Count-down timer

PIC Project collection by Hassan Alameer 10


Circuit explanation
of Count-down timer

Device selection
by 3-8 decoder

At this circuit, the


selection of seven devices
are done using the
decoder(74HC138).

Device number Device

0 BCD-SW for 10th of the minute

1 BCD-SW for 1st of the minute

2 Start switch

3 Unused

4 7 segment LED for 10th of minute

5 7 segment LED for 1st of minute

6 7 segment LED for 10th of second

7 7 segment LED for 1st of second

A device number is specified by RA0,1,2 of PIC.

PIC Project collection by Hassan Alameer 11


The selection of the device is done by setting the output of the decoder into the PNP-type
transistor(2SA1015).
The flow of the current through the transistor at the selected device is possible. The
transistor of the device which isn't selected is detached from the circuit because it is in the
OFF condition.
BCD switch (Input), Start switch (Input) and LED (Output) are controlled only by port B.
According to the selected device, a mode of port B is changed.

Short circuit prevention circuit of BCD-SW

As for the terminal of the BCD switch, the terminals become a short circuit condition each other with
the specified figure. The illegal current flow through the BCD switch. The diodes are used to prevent
from this.
The 7 segment LEDs are connected with port B,too, but the illegal current dosen't flow because LED
itself is a diode.

When only one BCD-SW is connected with port B, this circuit is unnecessary. However, when more
than one BCD-SW and 7 segment LED are connected, it is indispensable.

PIC Project collection by Hassan Alameer 12


Pull up circuit
As for the BCD switch, the terminal except the grounded terminal is in the open
condition(It is connected with nowhere). The pull-up function of PIC is used to
make an open terminal H level surely. The pull-up circuit works when making the
RPBI bit of OPTION_REG '0'.
The pull-up function works only when the port is an input mode. In the output
mode, this circuit doesn't influence.
A start switch is made H level by the pull-up function in the off condition of the switch in the same
way the BCD switch.

The port A which connects a stop switch doesn't have a pull-up function. Therefore, it is pull-uped by
the resistor outside.

Output relay circuit

RA3 port is used for the relay control to make do a relay in the continuous control action.
The 25-mA can be applied to the port of PIC16F84A.
In case of the relay which was used this time, when adding +5 V to the drive coil, the flowing current is
about 23-mA. This is near the upper limit. So, I decided to drive a relay using the transistor for the
safety. The maximum of 150-mA current can be passed to the collector of the used transistor.

Parts explanation
of Count-down timer

PIC

This is PIC16F84A. In case of


PIC16F84A, it is possible to use a clock
frequency upto 20 MHz. The circuit this
time, I am using 10-MHz resonator.

PIC Project collection by Hassan Alameer 13


3-to-8 line Decoder ( 74HC138 )
This is the IC which decodes the binary code of 3 bits.
8 conditions can be expressed by 3 bits. 74HC138 outputs only one an L
level out of 8 by the 3-bit input condition.

Data sheet for 74HC138

The following table shows correspondence of the input and the output of 74HC138.
Input Output
C B A 00 01 02 03 04 05 06 07
L L L L H H H H H H H
L L H H L H H H H H H
L H L H H L H H H H H
L H H H H H L H H H H
H L L H H H H L H H H
H L H H H H H H L H H
H H L H H H H H H L H
H H H H H H H H H H L

Transistor for the device selection ( 2SA1015 )


These transistors are used to select the device which PIC controls. This is PNP type.
The NPN type can be used, too. In the case, output level becomes opposite. When using PNP
type, the transistor becomes ON in L level (0). In case of the NPN type, the transistor becomes
ON in H level (1).

Data sheet for 2SA1015

PIC Project collection by Hassan Alameer 14


Software flow chart of Count-down timer
This is the flow chart which showed the outline of the software processing.

PIC Project collection by Hassan Alameer 15


PIC Project collection by Hassan Alameer 16
!‫ﺧﻄﺄ‬

PIC Project collection by Hassan Alameer 17


Project 4
PIC Circuits Gallery
Stepper Motor controller

On these pages, I will introduce a control circuit for stepper motor.


The software of this project is adapted to Embedded Systems(Lab13) for 2002 of Cleveland State
University.

Circuit drawing of Stepper Motor controller


!‫ﺧﻄﺄ‬

PIC Project collection by Hassan Alameer 18


Circuit explanation of Stepper
Motor controller

Motor driving circuit


This is the circuit which drives the coil of
stepper motor. There are circuits which drive
coil, coil, coil and coil respectively.
Darlington connection-type transistor is used for
the drive of the coil. As for the Darlington
connection, 2 stages of transistors are connected
inside in series. The "hfe" of this transistor is the
multiplication of the "hfe" of each transistor
inside. In case of 2SD1209K which was used
this time, the hfe is over 4000. Because the ratio of the input electric current and the output
current is big, the rising edge and the falling edge of the control signal can be made sharp.
The diode to be putting between the collector and the power is for the protection of the
transistor. When the transistor becomes OFF from ON, the coil of the motor tries to continue
to pass an electric current and generates high voltage. An electric current by this voltage is
applied to the diode and the high voltage which applies over the transistor is prevented.

Speed control circuit


This is the circuit which controls the rotational speed of the motor.
TR1 becomes ON condition when RB7 becomes H level. In this condition,
the electric charge of capacitor C1 flows through the transistor and the voltage
of the both edges of the capacitor becomes 0 V almost.
When RB7 becomes an L level, the transistor becomes OFF condition. In this
condition, the electric current flows through VR1 and R4 into capacitor C1
and the charging to the capacitor begins. The voltage of the both edges of the
capacitor becomes high gradually as charging is done. As for the change of
".Integration circuitthis voltage, refer to "
The voltage of the capacitor is detected by RB5. The software of PIC
interrupts the control of the motor until it checks RB5 after making RB7 an L
level and RB5 becomes H level. When making the value of VR1 small, the
charging time of the capacitor is short and the control of the motor becomes
quick. The control of the motor becomes slow when making VR1 big. The speed control range can be
changed by changing the value of the capacitor.

Start/stop circuit
This is the circuit for the clockwise rotating, the counterclockwise rotating or stopping a
motor. The baton switch of the non lock is used. Pull-up resistor is used for the port to
become H level when the switch is OFF. The RB port of PIC16F84A has an internal pull
up feature. However, because RB5 is used for the voltage detection of the capacitor at the
circuit this time, an internal pull up feature isn't used. If using RA port for the voltage
detection of the capacitor, the RB internal pull up feature can be used. The circuit this
time put an external pull-up resistor in the relation of the pattern

PIC Project collection by Hassan Alameer 19


Parts explanation of Stepper Motor controller

Stepper motor ( 42SPM-24DCZA )

This is a 2-phase unipolar PM type stepper motor with 48-poles.


Step angle : 7.5 degrees ( 360 degrees/48 )
Drive voltage : 5 to 6V
Coil current : 250mA(5V)/2 coils

PIC16F84A

The control of the stepper motor is done by this PIC. To have


explained in the operation principle, coil, coil, coil and
coil are controlled by the software.

Data sheet for PIC16F84A

3 terminal regulator ( 78L05 )

This is used to make the stable voltage of +5V.


A 100-mA type is used.

Data sheet for 78L05

Motor drive transistor ( 2SD1209K )


This is a Darlington connection-type transistor.

At first, I used 2SD1590 ( 8A type ) as the transistor for the drive. However, in case of
the motor which was used this time, the coil current was about 250 mA. So, I changed into the small
type transistor. The maximum collector current of 2SD1209K is 1A and
"hfe" is more than 4000.

Data sheet for 2SD1209K

PIC Project collection by Hassan Alameer 20


Project 5
PIC Circuits Gallery
DC motor speed controller
I will introduce the constant speed controller for DC motor.
It detects and controls the rotational speed of the motor. When lower than the specification
speed, it increases a control electric current. When higher than the specification speed, it
reduces a control electric current. It is possible to use when wanting to keep constant speed
even if the load to the motor changes.
With the circuit this time, I used a motor for the speed detection apart from the main unit
motor. The speed can be detected in the other way, too. LEDs are lit up to confirm the
control situation of the motor.
A circuit like "Light controller" is used for the control unit of this circuit

Circuit drawing
for DC motor speed controller

PIC Project collection by Hassan Alameer 21


Pattern drawing
for DC motor speed controller
!‫ﺧﻄﺄ‬

Circuit explanation
Control voltage input circuit
This is the circuit which inputs the control voltage
which was created by the turning of the motor in
PIC. The input voltage to PIC is converted by A/D
converter. Changed voltage is used for the PWM
function of the CCP to control the motor drive. At
the circuit this time, a small motor is used as the
generator to detect the number of rotations of the
motor. The input voltage (the control voltage) to PIC
is changed by the fluctuation of the number of
rotations of the motor. The other way can be used to
detect the number of rotations of the motor. It is need to change control voltage to proportional to the
number of rotations of the motor. PIC controls the drive electric current of the motor for the control
voltage to become a regulation value. When the revolution of the motor slows down, i.e. control
voltage goes down, the drive electric current of the motor is increased and number of rotations is
raised. When the control voltage reaches a regulation value, an drive electric current at the point is
held. Oppositely, when the number of rotations of the motor is high, i.e. the control voltage is high, the
drive electric current of the motor is reduced and number of rotations is lowered. When the control
voltage reaches a regulation value, an drive electric current at the point is held.
DB1 is used to make not conscious of the polarity of the motor. When never making a mistake in the
connection, to use isn't necessary. When the voltage of the motor for the speed detection is small, it is
better not to put.
D1 is used to protect PIC when the voltage of the detection motor is high. C1 is to make bypass the

PIC Project collection by Hassan Alameer 22


noise of the detection motor. VR1 is the variable resistor to set the number of rotations of the main
motor. The input voltage of PIC becomes low when bringing VR1 close to the side 1 and PIC increases
the drive electric current of the motor. That is, the revolution of the motor rises. The input voltage of
PIC becomes high when bringing VR1 close to the side 3 and PIC reduces the drive electric current of
the motor. That is, the revolution of the motor slows down.

For the details of the CCP, refer to "CCP feature of PIC16F873".

Motor drive circuit


The PWM(Pulse Width Modulation) function of PIC is used for
the electric current control to drive a motor.PWM can change
the duty of the pulse to output into CCP1 by the data. When the
time which is made the H level of the pulse of CCP1 is short,
the time of ON (the L level) becomes long in TR2. That is, the
drive electric current of the motor increases. Oppositely, when
the H level time of the pulse of CCP1 is long, the ON time of
TR2 becomes short and the drive electric current of the motor
decreases.
The duty of the pulse of CCP1 is controlled in the voltage (the
control voltage) which was taken in with the control voltage
input circuit. When the control voltage is higher than the
regulation value, the H level time of the CCP1 pulse is made
long and the number of rotations of the motor is lowered. When the control voltage is lower than the
regulation value, the H level time of the CCP1 pulse is made short and the number of rotations of the
motor is raised.
I used N-channel MOS FET for the drive of the motor. The P-channel MOS FET can be used, too. In
the case, the duty control of the CCP1 pulse becomes opposite. It becomes low-speed when the H level
of the pulse is short and when long, it becomes high-speed. The way of connecting between the motor
and the FET becomes opposite. In this case, the power of the transistor for the FET drive should be
connected with the source terminal of P-FET.

Because the output of the motor which was used this time is big, there is a gravity that the motor for the
speed detection breaks. Therefore, an electric current is suppressed by the resistor to have put in series.

".MOS FETFor the details of MOS FET, refer to "


".CCP feature of PIC16F873For the details of the CCP, refer to "

PIC Project collection by Hassan Alameer 23


Parts explanation
for DC motor speed controller

PIC16F873
In the circuit this time, PIC16F873 is used.
At the circuit this time, the control of the drive electric
current of the motor is done using the PWM function of
the CCP. The voltage according to the number of
rotations of the motor is taken in to the analog-to-digital
converter and has the control of the drive electric current.
This time, it is using a motor for the speed detection.
Also, LEDs for the monitor are lit up to know the
situation of the motor drive.

Data sheet for PIC16F873

Transistor for MOS FET drive ( 2SC1815 )

This transistor is used to drive MOS FET by the output of PIC. It is


converting the output of PIC (0V to 5V) into the voltage to control an FET
(0V to 12V).

Data sheet for 2SC1815

Zener diode ( RD5A )

The voltage which is applied to the terminal of PIC is a maximum of +5V. This
diode prevents the destruction of PIC when the speed detection voltage of the motor
exceeds 5V. When more than +5V voltage be applied never from outside, it is
unnecessary.

PIC Project collection by Hassan Alameer 24

Вам также может понравиться