Tuesday, 12 August 2014

Random number generator using 8051
A  random number generator using 8051 that  displays a random number between 0 & 99 is shown in this article. The circuit it self is very simple and may not find any applications in serious embedded projects and this article is just an illustration. The circuit is based on AT89S51 microcontroller, two seven segment LED displays, two transistors and few passive components.

Circuit diagram.



Random number generator using 8051
The two seven segment LED displays are multiplexed together and their data lines are connected to Port0  of the microcontroller. Transistors Q1 and Q2 drives the corresponding displays D1 and D2. The driving signals for there transistors are obtained from P1.1 and P1.2. Push button switch S1,capacitor C1 and resistor R10 forms a debouncing reset circuit. Resistor R9, capacitor C2 and pushbutton switch S2 will provide an active low harware  interrupt signal at INTO (pin12) when ever S2 is pressed. Here also R9 and C2 are meant for debouncing. After power ON the display will show blank and when push button S2 is pressed the display will show a random number between 0 and 99. For another try you have to press the reset switch and then switch S2. If you need a single digit setup only, the remove display D2 and its associated components. Everything else is same.

Program

ORG 000H
SJMP MAIN
ORG 003H // sets the starting address for the ISR
ACALL ISR // calls the ISR subroutine when S2 is pressed
RETI // return from interrrupt
 
MAIN:SETB IP.0 // this part sets the initial conditions
     SETB TCON.0
     SETB IE.0
     SETB IE.7
     MOV P0,#00000000B
     MOV P1,#00000000B
     MOV DPTR,#LUT // moves the starting address of LUT to DPTR
 
LABEL:MOV R6,#99D // this part generates the random number
      LOOP:MOV A,R6
      DJNZ R6,LOOP
      SJMP LABEL
 
ISR: MOV A,R6 // Subroutine ISR displays the current random number
     MOV B,#10D
     DIV AB
     SETB P1.2
     ACALL DISPLAY
     MOV P0,A
     ACALL DELAY
     MOV A,B
     CLR P1.2
     SETB P1.1
     ACALL DISPLAY
     MOV P0,A
     ACALL DELAY
     CLR P1.1
     SJMP ISR
     RET
 
DELAY: MOV R3,#02H // this subroutine creates 1mS delay for switching the displays
DEL1: MOV R2,#0FAH
DEL2: DJNZ R2,DEL2
      DJNZ R3,DEL1
      RET
 
DISPLAY: MOVC A,@A+DPTR // produces the digit drive pattern for the current digit in A
         RET
 
LUT: DB 3FH // Look up table
     DB 06H
     DB 5BH
     DB 4FH
     DB 66H
     DB 6DH
     DB 7DH
     DB 07H
     DB 7FH
     DB 6FH
     END

About the program.

The first part of the program is the portion labelled MAIN which sets the initial conditions and the interrupt parameters. The next part is the loop named LABEL which loads 99D to register R6  then decrements it by 1 until 0 and then repeats the cycle again. This is the part which generates the random number. Every time R6 is decremented the resultant value is moved to accumulator A. Next part is the interrupt service routine which is written as a subroutine named ISR. When ever there is an interrupt at INT0 (push button S2 is pressed), the ISR is called. The ISR perfoms necessary mathematical manipulations on the content of A in order to split out the two digits and then proceeds to show it on the display. Subroutine DELAY produces roughly 1ms delay for switching the displays. Subroutine DISPLAY adds the current value in A with the address stored in DPTR (starting address of LUT) and moves the target content to A. The result will be the digit drive pattern for the current digit in A.



http://www.hubcity.net
Police siren using NE555
Description
A lot of electronic circuits using NE555 timer IC are already published here and this is just another one.Here is the circuit diagram of a police siren based on NE55 timer IC. The circuit uses two NE555 timers ICs and each of them are wired as astable multivibrators.The circuit can be powered from anything between 6 to 15V DC and is fairly loud.By connecting an additional power amplifier at the output you can further increase the loudness.
IC1 is wired as a slow astable multivibrator operating at around 20Hz @ 50% duty cycle and IC2 is wired as fast astable multivibrator operating at around 600Hz.The output of first astable mutivibrator is connected to the control voltage input (pin5) of IC2. This makes the output of IC2 modulated by the output frequency of IC1, giving a siren effect. In simple words, the output frequency of IC2 is controlled by the output of IC1.
For all of you who do not have a clear understanding of the working and basics of the NE555IC, we have provided an online book store  for you. Here 3 books are reviewed in detail with links to buy the books online itself. Get your copy now by clicking here:- 3 Great Books to Learn 555 Timer Circuits and Projects
Circuit diagram.

  • The circuit can be assembled on a Perf board.
  • I used 12V DC for powering the circuit.
  • Instead of using two NE55 timer ICs, you can also use a single NE556 timer.
  • NE556 is nothing but two NE555 ICs in one package.
  • Refer the datasheets of NE555 and NE556 to have a clear idea.
  • Speaker can be a 64ohm, 500mW one.



http://www.hubcity.net




Touch controlled musical bell.
This circuit produces a musical tone whenever someone touches the touch point designated as TP in the circuit. The circuit works from two AA cells and produces enough sound.
The circuit uses IC UM 3481 commonly used in musical circuits. The IC contains a ROM with 512 musical notes, tone generator, rhythm generator, modulator, run off control, oscillators, frequency divider and preamplifiers,.  So a very few number of components is  required for this circuit.C1 and R1 act as  the timing components for  the built in oscillator. The transistor Q1 is used for driving the loud speaker. The base of the transistor Q2 is used as the touch point to trigger the musical bell.
Circuit diagram with Parts list.
  • The circuit can be assembled on a general purpose PCB.
  • Use two AA cells in series for powering the circuit.
  • The speaker can be 2 W, 8 Ohm.
Phone Busy Indicator
Have you ever been using the modem or fax and someone else picks up the phone, breaking the connection? Well, this simple circuit should put an end to that. It signals that the phone is in use by lighting a red LED. When the phone is not in use, a green LED is lit. It needs no external power and can be connected anywhere on the phone line, even mounted inside the phone. Note: This circuit may cause problems for some when used. You may want to build a different circuit.
Schematic




Parts:

Part
Total Qty.
Description
Substitutions
R1
1
3.3K 1/4 W Resistor
R2
1
33K 1/4 W Resistor
R3
1
56K 1/4 W Resistor
R4
1
22K 1/4 W Resistor
R5
1
4.7K 1/4 W Resistor
Q1, Q2
2
2N3392 NPN Transistor
BR1
1
1.5 Amp 250 PIV Bridge Rectifier
LED1
1
Red LED
LED2
1
Green LED
1. This is a very simple circuit and is easily made on a perf board and mounted inside the phone.
2. LED1 and LED2 flash on and off while the phone is ringing.
3. Do not worry about mixing up the Tip and Ring connections.
4. The ring voltage on a phone line is anywhere from 90 to 130 volts. Make sure no one calls while you are making the line connections or you'll know it. :-)
5. In some countries or states you will have to ask the phone company before you connect this to the line. It might even require an inspection.
6. If the circuit causes distortion on the phone line, connect a 680 ohm resistor in between one of the incoming line wires and the bridge rectifier.


http://www.hubcity.net





Nite Rider Lights




As a keen cyclist I am always looking for ways to be seen at night. I wanted something that was a novelty and would catch the motorists eye. So looking around at my fellow cyclists rear lights, I came up with the idea of 'NITE-RIDER'. NINE extra bright LED's running from left to right and right to left continuously. It could be constructed with red LEDs for use on the rear of the bike or white LED's for an extra eye catcher on the front of the bike.

All IC's are CMOS devices so that a 9V PP3 battery can be used, and the current drawn is very low so that it will last as long as possible.


The circuit comprises of ...

1 555 timer IC4.
1 4027 flip flop IC1.
2 4017 Decade Counter IC2 and IC3.
3 4071 OR gate IC5, IC6 and IC7.
1 470 Ohm resistor 1/4 watt R3.
2 10K resistors 1/4 watt R1 and R2.
1 6.8UF Capasitor 16V C1.
9 Super brght LED's 1 to 9.
1 9V PP3 Battery.
1 single pole switch SW1.
1 Box.

How The Circuit Works.

IC4, C1, R1 and R2 are used for the clock pulse which is fed to both the counters IC2 and IC3 Pin 14.

IC1 is a Flip Flop and is used as a switch to enable ether IC2 or IC3 at pin 13.

IC7a detects when ether IC2 or IC3 has reached Q9 of the counter pin 11.

IC5, IC6 and IC7a protects the outputs of the counters IC2 and IC3 using OR gates which is then fed to the Anodes of the
LED's 1 to 9.















http://www.hubcity.net

Motorola Hi-Fi power amplifier
This is a very simple, low cost, Hi-Fi quality power amplifier. You can build it 5 ways, like its shown in the table (from 20 W to 80 W RMS).
Some comments:
- The first thing that you must do, is to measure the end transistors (T3 and T4) amplifying coefficient, the hfe or β. If their disagreement is bigger than 30 %, the amplifier would not give a clear sound. I used MJ3001 and MJ2501 transistors, and this disagreement was around 5%.
- Before the first “turning on” you must short circuit the inputs of the amp, and put a mA-meter on the output, than turn the amplifier on, and tune the R13 pot, to decrease the DC current on the output, to some uA-s, or in a lucky situation to zero. I was able to decrease it to 10 uA.



 
This amplifier can be used as a stereo or mono power amplifier. Used as a stereo amplifier this will deliver a solid 60 Watts per channel or in mono mode will deliver 110 Watts (8 ohms). With PSX-R up...
Our monobloc power amp provides the ultimate system performance. Cyrus designed Zero-feedback technology and bespoke power supply componentry provides a massive 150watt burst power for truly enthralli...
<sub3< sub="">
</sub3<>
-
It gives a very good sound quality.


http://www.hubcity.net




Motorcycle Universal Gear Indicator
This is a new design for a universal gear indicator that can be fitted to any motorcycle as an aftermarket accessory. Its main advantage is that its operation depends entirely on the gear shift lever movement, instead of connecting to speedometer and tachometer sensors (found in expensive commercial devices), which are rarely available in older motorcycles. It consists of a main circuit including a 7‑segment LED indicator, two Hall sensors that are attached to the motorcycle frame, and a small magnet placed on the gear shift lever.
The main circuit is based on an AVR ATTINY25/45/85 microcontroller, which reads the signals of the two Hall sensors and the neutral switch and outputs the current gear number to a 7‑segment LED indicator, through a 4026 counter/decoder.
At maximum output power there is significant heat produced by IC1 and for that reason we mounted it directly on the ground plane to achieve maximum heat radiation.


Source Code
The source code is written in AVR-GCC (WinAVR) and can be programmed with the default fuses using an AVR programmer (default : ATTINY25 microcontroller and USBTiny programmer). Moreover, the constant TOP_GEAR 5 should be changed to 6 for six-gear motorbikes.
PCB Design
The suggested implementation for the main circuit is a small size, double-sided PCB, with SMD packages for the microcontroller and the decoder ICs. The 7-segment LED is placed in a secondary PCB, connected vertically to the main one in a modular fashion (see pictures). Two PCBs for different Kingbright LED footprints (red and blue) are also provided.
Parts List
Part
Value
Comments (for suggested PCB)
R1
10 to 220 Ω ½W
Depending on preferred LED brightness
R2, R3
10 ΚΩ ¼W

C1
220 μF / 35V
Electrolytic capacitor
C2
100 nF
MKT/polyester capacitor
MCU
ATTINY25/45/85
Mouser Part 556-ATTINY25-20SU
COUNTER
4026
Mouser Part 595-CD4026BPWE4
IC1, IC2
Hall sensor
Melexis US5881LUA (available from adafruit)
IC3
7805
5V Regulator TO-220
BLUE
Kingbright 0.3"
Mouser part 604-SC03-11PBWA/A
RED
Kingbright 0.3"
Mouser part 604-SC03-12EWA
JPx
Pin connectors
As shown in silkscreen and pictures

Possible improvement
In the current design, when the neutral switch is open (there is a gear on), there appears to be a very small current (< 0.5 mA) sinking through R3, due to the voltage difference between the neutral switch connection (TO_POWER-4) and the microcontroller. If the neutral indicator is of LED type (not a resistor bulb), there is a possibility that it stays dimmed, instead of being completely off. In that case, a small switching diode (1N4148) can nicely replace R3 (on the same PCB) in order to block this small incoming current when the neutral switch is open, as shown in the figure below :
http://www.electronics-lab.com/projects/automotive/006/Image_15.png
$ 1 5.0E-6 10.20027730826997 62 5.0 50
R 192 96 192 48 0 0 40.0 5.0 0.0 0.0 0.5
R 512 96 512 48 0 0 40.0 12.0 0.0 0.0 0.5
r 192 96 192 176 0 10000.0
x 231 142 309 145 0 12 internal pullup
x 125 25 277 31 0 24 Gear Indicator
x 456 26 571 32 0 24 Motorcycle
M 192 176 96 176 0 2.0
x 65 157 118 160 0 12 AVR Input
w 192 176 192 256 0
162 512 96 512 160 1 2.1024259 1.0 0.0 0.0
r 512 160 512 256 0 470.0
d 512 320 512 400 1 0.805904783
x 413 388 499 391 0 12 protective diode
s 512 400 640 400 0 1 false
g 640 400 640 448 0
x 539 422 615 425 0 12 neutral switch
x 309 240 391 246 0 24 1N4148
x 132 377 269 380 0 12 in place of R3, and watch
d 304 256 400 256 1 0.805904783
r 304 336 400 336 0 10000.0
x 337 371 367 377 0 24 R3
S 192 320 272 320 0 1 false 0
w 192 256 192 320 0
w 304 256 272 256 0
w 272 256 272 304 0
w 304 336 272 336 0
w 400 256 400 304 0
w 400 304 448 304 0
w 400 336 400 304 0
w 448 304 512 304 0
w 512 304 512 320 0
w 512 304 512 256 0
x 131 359 276 362 0 12 flip switch to insert a diode
x 134 394 272 397 0 12 current drop to zero when
x 134 412 254 415 0 12 neutral switch is open
Connections
A successful circuit build will do a self-test when connected solely to 12V power (pins TO_POWER_1 and TO_POWER_2), by cycling through all digits on the 7-segment display (see video below). After the self-test, the current gear will be shown and can be changed by the shift lever movement. Note that a gear is changed when the magnet's south pole is drawn away from the sensor (north pole will not work). Moreover, if a neutral gear is detected (from the neutral switch connected to TO_POWER_4), the display resets to zero (also acting as a self-calibrating feature if anything goes wrong). Finally, when the power is turned off, the last shown gear is stored in the MCU's flash EEPROM and restored when the device is turned on again.