You are on page 1of 7

MICRO CONTROLLER PROJECTS

1.Driving Stepper

M1 is a stepper taken from an old disk drive. There are five pins, i.e., common, coil 1, 2, 3 and 4.
Resistance measured between common pin and each coil is about 75 Ohms. Driving current for each
coil is then needed about 60mA at +5V supply. A darlington transistor array, ULN2003 is used to
increase driving capacity of the 2051 chip. Each output provides 500mA max at 50V. P1.4 to P1.7,
four output pins are connected to the input of the ULN2003 as shown in the circuit. Four 4.7k
resistors help the 2051 to provide more sourcing current from the +5V supply. The serial port is
optional for your exercises. Many have provided useful technical, and application of using stepper,
see the links below.

stepper.c

stepper.c
stepper.hex

I have changed a 10ms time base with a simple TF0 polling instead of using interrupt.
The program is just to send the stepper's energizing pattern to the P1 every 10ms. Flag1 is
used for intertask communication.

/*
* STEPPER.C
* sweeping stepper's rotor cw and cww 400 steps
* Copyright (c) 1999 by W.Sirichote
*/

visit website for more information


MICRO CONTROLLER PROJECTS

#include c:\mc51\8051io.h /* include i/o header file */


#include c:\mc51\8051reg.h

register unsigned char j,flag1,temp;


register unsigned int cw_n,ccw_n;

unsigned char step[8]={0x80,0xc0,0x40,0x60,0x20,0x30,0x10,0x90}


#define n 400

/* flag1 mask byte


0x01 run cw()
0x02 run ccw()
*/

main()

{
flag1=0;
serinit(9600);
disable(); /* no need timer interrupt */
cw_n = n; /* initial step number for cw */
flag1 |=0x01; /* initial enable cw() */

while(1){
{
tick_wait(); /* wait for 10ms elapsed */

energize(); /* round-robin execution the following tasks every 10ms */


cw();
ccw();
}
}

cw(){
if((flag1&0x01)!=0)
{
cw_n--; /* decrement cw step number */
if (cw_n !=0)
j++; /* if not zero increment index j */
else
{flag1&=~0x01; /* disable cw() execution */
ccw_n = n; /* reload step number to ccw counter */
flag1 |=0x02; /* enable cww() execution */

visit website for more information


MICRO CONTROLLER PROJECTS

}
}

ccw(){
if((flag1&0x02)!=0)
{
ccw_n--; /* decremnent ccw step number */
if (ccw_n !=0)
j--; /* if not zero decrement index j */
else
{flag1&=~0x02; /* disable ccw() execution */
cw_n = n; /* reload step number to cw counter */
flag1 |=0x01; /* enable cw() execution */
}
}

tick_wait(){ /* cputick was replaced by simpler ASM code 10ms wait */

asm" JNB TCON.5,*"; /* wait for TF0 set */


asm" CLR TCON.5"; /* clear TF0 for further set */
asm" ORL TH0,#$DC"; /* reload TH0 with $DC, TL0 = 0 */
}

energize(){

P1 = step[(j&0x07)]; /* only step 0-7 needed */


}

Exercises

• change the speed showing the rotation becomes faster or slower than 10ms time
delay.
• with an additional serial port, write an initializing function that receives ascii
command from terminal to set the number of step for cw and ccw, say.
• while energizing the stepper coils, write a function that read ascii character from
terminal on the fly to decrease or increase rotating speed, say.

Stepper Links

visit website for more information


MICRO CONTROLLER PROJECTS

• Jones on Stepping Motors Jones provides a tutorial covering the basic of stepping
motors and control systems, including physics of the motor, circuits and software
for motor control.
• Basic Stepper Motor Concepts Understanding electromagnetic principle
underlying the stepper.
• Motorize Your Telescope Mel Bartels describes how to motorize telescope, many
links for amateur astronomy.

Night Light Saver V5.0


Build a device that turn on and off a night light automatically. Save Energy, No
EMI, No Battery, Built-in Lamp Fixture, and Peak Shaving.

Introduction

The Saver V5.0 runs simple clock emulation program, turns a night light on and off with
preset time, say 19:00 to 22:00 everyday. The design features low cost, easy installation,
no battery backup and no EMI. The AT89C2051 uses external oscillator generated by
schmitt trigger gate CD4093, ~680kHz. Reference frequency was derived from 50Hz
main line. Time setting only allows at 18:00 by pressing time set button once. If main line
has failed, functioning LED will blink at high rate . Since there is no battery backup, thus
repressing the button is then needed. The output is capable of driving say, a 25W
incandescent lamp.

Circuit Description

The schematic of the SAVER V5.0 is depicted in Figure 1.


Caution!! High Voltage!! Do not touch any conductive parts of the circuit

visit website for more information


MICRO CONTROLLER PROJECTS

Figure 1: Schematic of the Saver V5.0


Explanation of the circuit operation for each parts is as follows;

1)Transformerless direct supply: R1 and C1 forms a simple current limitting AC source.


D1 and D2 converts AC to DC with C2 performing a reservoir. D3 limits voltage across
the circuit to ~5V.

2)External oscillator: A reliable schmitt gate oscillator with R8 and C5 produces clock
approx. 680kHZ. One machine cycle is ~18us.

3)89C2051 circuits: C4, 33uF and R4, 10k forms a reset circuit that need time for riasing
logic at least two machines cycle. S1 is a momentary button for setting time to 18:00 by
pulling P3.0 to logic low. The functioning LED is connected to P3.7. Q2 is a small triac
MAC97A6, and is drived by Q1, PNP transistor sinking through P1.7.

4)Reference frequency: R3 and C3 integrates a 50Hz main frequency and unwanted


transients producing triangle-like waveform which is fed to U2 schmitt gate. The output
pin4 is clean 50Hz square wave tied to int0.

Software

visit website for more information


MICRO CONTROLLER PROJECTS

Saver5.hex is HEX file suitable for Easy-Downloader V1.1 for writing the code to the
chip. This file sets time to 18:00 when press S1 once. Time on and off is set to 19:00 to
22:00 everyday. And finally the reference main frequency is 50Hz!!

The original source program SAVER5.C was written in 'C' language. User may change
set time when press S1 and change time on/off. It is a good idea to include peak shaving
period, say 20:00 to 20:30 depending on living area. By placing timeOn3 and timeOff3 in
the function comparetime(), see the source program. To recompile the source file you
need a Micro-C Compiler from Dunfield Development System with tiny memory model
and need some modification of the runtime file by putting external interrupt service
routine that increments cputick variable.

Installation

The Saver may be built-in any kind of lamp fixtures. Figure 2 shows the author's concept
for building-in a 25W lamp fixture.
under preparation
Figure 2: The author's concept lamp fixture with built-in Saver circuit
Although the Saver can operate even wrong connection of L and N to the circuit. The
author suggests to correct AC line connection to L and N of the circuit. After finished
installtion, turn the main switch on, functioning LED will blink at high rate. Let try press
S1 once, the lamp will turn on 1 minute then off. The Saver assumes the current time is
18:00. Then wait for the clock at your home reachs 18:00, press S1 again.

Note that everytime you press S1, the lamp will turn on 1 minute only once. The day after
the lamp will then turn on and off at preset time. Functioning LED will blink at low rate
indicating normal operation.

If high blink rate is noticed when return home, power failed should happen, no problem
just wait again 18:00 then press S1. If the LED is not blinked, someone may turn main
switch off, turn it back on again and wait for 18:00.

Energy Saving Lamp

The Saver was not designed for turning such energy saving lamps on and off. They
mostly use internal high frequency inverter. I have been tested with one from National, it
works!! But I am not guarantee for your energy saving lamp. I would be grateful if you
could test and let me know the result.

Components Listing

1. C1 0.44 uF 250Vac AC capacitor


2. C2 330 uF 25V electrolytic capacitor
3. C3 1uF 16V nonpolar polyester capacitor
4. C4 33uF 16V electrolytic capacitor
5. C5 50pF disceramic capacitor

visit website for more information


MICRO CONTROLLER PROJECTS

6. R1 50Ohm 1/4W resistor


7. R2 1M 1/4W
8. R3,R4,R8 10k 1/4W
9. R5 220Ohm 1/4W
10. R6,R7 1k 1/4W
11. D1,D2 1N4007 rectifying diode
12. D3 zener diode 5.1V 1/2W
13. D4 small LED
14. Q1 2N2907 PNP transistor
15. Q2 MAC97A6 triac
16. U1 AT89C2051 Flash Microcontroller
17. U2 CD4093 schmitt nand gate

visit website for more information

You might also like