AddThis

Bookmark and Share

Thursday, 29 July 2010

DC Motor Speed Control using PWM

This project gives a speed control of DC motor through PWM method. The Dc motor is derived by the L298 driver IC.

You can also control the direction of the motor.

There are three buttons to control the motor. Also a bar graph Led display indicate the speed of the motor.

An proteus simulation file is also available at the download so that you can check the code on your PC.

Project from this Link

Circuit Diagram

DC-moto-speed-control

Bascom Code

$regfile = "m16def.dat"
$crystal = 1000000
'============================================================================
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Prescale = 1024
Config Portb = Input
Config Portc = Output
Config Porta = Output
'============================================================================
Dim A As Word , B As Bit
'============================================================================
Declare Sub Progress(num As Word)
'============================================================================
A
= 100
Pwm1a = A

Portc.0 = 1
Portc.1 = 0
B
= 0
'============================================================================
Do
'////////////////////////////////////////////////////////////////////////////
If Pinb.0 = 1 Then
A
= A + 10
If A >= 250 Then A = 250
Pwm1a = A
Waitms 250
End If
'////////////////////////////////////////////////////////////////////////////
If Pinb.1 = 1 Then
A
= A - 10
If A <= 10 Then A = 10
Pwm1a = A
Waitms 250
End If
'////////////////////////////////////////////////////////////////////////////
If Pinb.2 = 1 Then

If B = 0 Then
B
= 1
Portc.0 = 0
Portc.1 = 1
Elseif B = 1 Then
B
= 0
Portc.0 = 1
Portc.1 = 0
End If
Waitms 250

End If
'////////////////////////////////////////////////////////////////////////////
Call Progress(a)
'////////////////////////////////////////////////////////////////////////////
Loop
'============================================================================
End
'/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

Sub Progress(num As Word)

If Num < 25 Then
Portc.7 = 1
Portc.6 = 0
Porta = 0
End If
If Num < 50 And Num >= 25 Then
Portc.6 = 1
Portc.7 = 1
Porta = 0
End If
If Num < 75 And Num >= 50 Then
Portc.6 = 1
Portc.7 = 1
Porta = &B00000001
End If
If Num < 100 And Num >= 75 Then
Portc.6 = 1
Portc.7 = 1
Porta = &B00000011
End If
If Num < 125 And Num >= 100 Then
Portc.6 = 1
Portc.7 = 1
Porta = &B00000111
End If
If Num < 150 And Num >= 125 Then
Portc.6 = 1
Portc.7 = 1
Porta = &B00001111
End If
If Num < 175 And Num >= 150 Then
Portc.6 = 1
Portc.7 = 1
Porta = &B00011111
End If
If Num < 200 And Num >= 175 Then
Portc.6 = 1
Portc.7 = 1
Porta = &B00111111
End If
If Num < 225 And Num >= 200 Then
Portc.6 = 1
Portc.7 = 1
Porta = &B01111111
End If
If Num < 255 And Num >= 225 Then
Portc.6 = 1
Portc.7 = 1
Porta = &B11111111
End If

End Sub

Temperature Indicator project

his project indicates the temperature from a 1 wire temperature sensor DS1820 and display it over an LCD display. The circuit uses Atmega8515 and 16x2 LCD display.

Atmega8515 is selected because it is pin compatible with 8051 Microcontroller. ATmega uses the inbuilt RC oscillator for this project, so select the fuse bits for internal oscillator of 8mhz.

About DS1820

The DS1820 Digital Thermometer provides 9–bit centigrade temperature measurements and has an alarm function with nonvolatile user-programmable upper and lower trigger points. The DS1820 communicates over a 1-wire bus that by definition requires only one data line (and ground) for communication with a central microprocessor. It has an operating temperature range of –55°C to +125°C and is accurate to ±0.5°C over the range of –10°C to +85°C. In addition, the DS1820 can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply.

Circuit Diagram

Program

'-----------------------------------------------------------------------------------------
'copyright : (c) 2008-2009, AVRprojects.info
'purpose : DS1820 / DS18S20 Temperature Indicator
'-----------------------------------------------------------------------------------------

$regfile = "m8515.dat" ' specify the used micro
$crystal = 8000000 ' used crystal frequency

Declare Sub Read1820

Config 1wire = Portd.7
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Porta.2 , Db5 = Porta.3 , Db6 = Porta.4 , Db7 = Porta.5 , E = Porta.1 , Rs = Porta.0


'Temp variables
Dim Bd1 As Byte
Dim Bd2 As Byte
Dim Bd7 As Byte
Dim Bd8 As Byte

Dim I As Byte , Tmp As Byte
Dim T As Integer , T1 As Integer
Dim Bd(9) As Byte 'Scratchpad 0-8 72 bits incl CRC, explanations for DS1820
'Sc(1) 'Temperature LSB
'Sc(2) 'Temperature MSB
'Sc(3) 'TH/user byte 1 also SRAM
'Sc(4) 'TL/user byte 2 also SRAM
'Sc(5) 'config also SRAM x R1 R0 1 1 1 1 1 - the r1 r0 are config for resolution - write FF to byte for 12 bit - others dont care
'Sc(6) 'res
'Sc(7) 'res
'Sc(8) 'res
'Sc(9) '8 CRC

'DALLAS DS1820 ROM and scratchpad commands''''''''''''''''''''''''''1wwrite....
'&H 33 read rom - single sensor
'&H CC skip rom
'&H BE read scratchpad
'&H 44 convert T

' Main loop
Cls
Cursor Off
Do
1wwrite &HCC : 1wwrite &H44 ' start measure
Waitms 400 ' wait for end of conversion
Read1820
Wait 1
Loop
End 'end program

'Read the DS1820 by skipping the ROM checking, since we are using only 1 sensor

Sub Read1820 ' reads sensor ans calculate ' T for 0.1 C
1wreset ' reset the bus
1wwrite &HCC ' read internal RAM
1wwrite &HBE ' read 9 data bytest
Bd
(1) = 1wread(9)
Bd1
= Bd(1)
Bd2
= Bd(2)
Bd7
= Bd(7)
Bd8
= Bd(8)
' read bytes in array
1wreset ' reset the bus
Tmp
= Bd1 And 1
If Tmp = 1 Then Decr Bd1 ' 0.1C precision
T
= Bd1
T
= T * 50
T
= T - 25
T1
= Bd8 - Bd7
T1
= T1 * 100
T1
= T1 / Bd8
T
= T + T1
T1
= T / 100 'store tens
T
= T Mod 100 'store decimal number
Cls
Locate 1 , 3
Lcd "Temperature"
Locate 2 , 7
Lcd T1 ; "." ; T
End Sub

End

Traffic light controller

Here's a traffic light controller using avr microcontroller. It can be adopted for a four way road.

The code is written in Codevision C. You can download the C code and the proteus file from the download.

Circuit Diagram

Bluetooth Based Smart Home

This project is used to automate the home appliances through Bluetooth enabled PC. You can use the USB Bluetooth at the PC side and an Serail Bluetooth converter is used at the microcontroller side. The sparkfun bluetooth module is used here, but you can use any serial luetooth module which supports SPP profile. Atmega8 microcontroller is used in this project

The PC application software was written using visual basic and the microcontroller coding was done through Bascom Basic. The project had the following features

  • 2 Temperature sensor (1 Indoor & 1 Outdoor)
  • High resolution temperature sensors are used (0.06deg)
  • 1 Light sensor with help of LDR
  • 1 PIR motion sensor
  • 5 Devices can be controlled
  • LCD & LED interface to display the status

Post your doubts on the Forum

Circuit Diagram

PC Screenshot

Digital Voltmeter project

This project gives you a digital voltmeter which can measure voltage from 0v to 25V DC. The values are displayed over the 7segment display. Atmega8 is used and the internal ADC is used to measure the DC voltage. The resistor network is used to reduce the input voltage to the 0-5v.

Circuit Diagram

Photo

LCD Interface tut

Interface LCD with AVR MIcrocontroller

Frequently, an AVR program must interact with the outside world using input and output devices that communicate directly with a human being. One of the most common devices attached to an AVR is an LCD display. Some of the most common LCDs connected to the AVR are 16x2 and 20x2 displays. This means 16 characters per line by 2 lines and 20 characters per line by 2 lines, respectively.

Fortunately, a very popular standard exists which allows us to communicate with the vast majority of LCDs regardless of their manufacturer. The standard is referred to as HD44780U, which refers to the controller chip which receives data from an external source (in this case, the AVR) and communicates directly with the LCD.

LCD Pin descriptions

The LCD discussed in this section has 16 pins. The function of each pin is given in Table.

Pin Symbol I/O Description
1 Vss - Ground
2 Vcc - +5V Power supply
3 VEE - Power supply to control Contrast
4 RS I RS = 0 to select command register RS = 1 to select data register
5 R/W I R/W = 0 for write, R/W = 1 for read
6 E I/O Enable
7 DB0 I/O The 8-bit data bus
8 DB1 I/O The 8-bit data bus
9 DB2 I/O The 8-bit data bus
10 DB3 I/O The 8-bit data bus
11 DB4 I/O The 8-bit data bus
12 DB5 I/O The 8-bit data bus
13 DB6 I/O The 8-bit data bus
14 DB7 I/O The 8-bit data bus
15 LED- I +5v for LED backlight
16 LED+ I Ground for LED backlight

44780 BACKGROUND

The 44780 standard requires 3 control lines as well as either 4 or 8 I/O lines for the data bus. The user may select whether the LCD is to operate with a 4-bit data bus or an 8-bit data bus. If a 4-bit data bus is used, the LCD will require a total of 7 data lines (3 control lines plus the 4 lines for the data bus). If an 8-bit data bus is used, the LCD will require a total of 11 data lines (3 control lines plus the 8 lines for the data bus).

The three control lines are referred to as EN, RS, and RW.

The EN line is called "Enable." This control line is used to tell the LCD that you are sending it data. To send data to the LCD, your program should first set this line high (1) and then set the other two control lines and/or put data on the data bus. When the other lines are completely ready, bring EN low (0) again. The 1-0 transition tells the 44780 to take the data currently found on the other control lines and on the data bus and to treat it as a command.

The RS line is the "Register Select" line. When RS is low (0), the data is to be treated as a command or special instruction (such as clear screen, position cursor, etc.). When RS is high (1), the data being sent is text data which sould be displayed on the screen. For example, to display the letter "T" on the screen you would set RS high.

The RW line is the "Read/Write" control line. When RW is low (0), the information on the data bus is being written to the LCD. When RW is high (1), the program is effectively querying (or reading) the LCD. Only one instruction ("Get LCD status") is a read command. All others are write commands--so RW will almost always be low.

Finally, the data bus consists of 4 or 8 lines (depending on the mode of operation selected by the user). In the case of an 8-bit data bus, the lines are referred to as DB0, DB1, DB2, DB3, DB4, DB5, DB6, and DB7.
BASCOM supports 4bit interface, so that we need just 6 lines for an LCD interface. They are 4 data lines, 1 EN(Enable) line and RS (Register Select) line.

Circuit Diagram

Program for LCD interface with AVR Microcontroller.

'-----------------------------------------------------------------------------------------
'copyright : (c) 2008-2009, AVRprojects.info
'purpose : LCD Interface
'-----------------------------------------------------------------------------------------

$regfile = "m8515.dat" ' specify the used micro
$crystal = 8000000 ' used crystal frequency

Config Lcdpin = Pin , Db4 = Porta.2 , Db5 = Porta.3 , Db6 = Porta.4 , Db7 = Porta.5 , E = Porta.1 , Rs = Porta.0
Cls 'Clear display
Cursor Off
Locate 1 , 3 'set cursor position
Lcd "Welcome to"
Lowerline 'second line
Lcd "avrprojects.info"

End

Capacitance and Inductance meter using Atmega8

This project can measure capacitance and inductance using the Atmega8 microcontroller and the code is written in Bascom AVR.

The limitations of this project is

Inductance Range: 0.1?H to 2H
Capacitance Range: 1pF to 2.5?F
Electrolytic Capacitor Measurement Range: 0.1?F to 30000?F

Circuit Diagram:

lc-meter

Hardware Pictures:

lc-meter3

lc-meter1

lc-meter2

Downloads:

IDE for Microcontrollers

IDE

It can be expanded as Integrated Development Environment or Integrated Design Environment. As discussed before, it is a software package used to write programs for Micro-controller IC’s. Other than normal software’s, this integrated package has some more features. Let us discuss one by one.

1. This Software Consists of:

  • Assembler/ Compiler
  • Simulator
  • Debugger
  • Programmer (optional)
  • Emulator (optional)

Assembler:

The program is usually written in user’s language (BASIC, Assembly, C or C++).
If the program is in BASIC, then the BASIC compiler will convert the BASIC codes to HEX codes. The Assembler automatically converts the assembly language to machine language (HEX codes).If the program is written in C or C++, then the C compiler does this work.

Simulator:

The written program should be run to check out. Simulator does this job correctly and we can check the outputs easily. The simulation can be done for each and every line. We can stop the program execution at whatever line we desire. The simulator also shows the mode of running of program by a pointer. The pointer runs between the program and shows the exact line of execution at time.

Debugger:

The errors are pointed out in the Error column present at the bottom of the programming column. The errors are displayed with line number, so that it is easy to debug the error.

Programmer:

After debugging, the converted codes should be loaded to the chip. Before loading the program it should be compiled, simulated and debugged. Then the program is loaded into the chip by the programmer. This option is not available with all IDE’s. But most of the popular IDE’s have this option.

Emulator:

With this option you can communicate via the RS-232 interface to the computer. This enables the serial port. This option is not available with all IDE’s. But most of the popular IDE’s have this option.

2. It also contains the details of List of IC’s along with it. The IC’s will be clearly given with the pin details and the port details. Different colours will be enabled when a particular pin is chosen. Along with it, the description of the selected pin will be displayed with it.

3. The written program can be converted in HTML format, Graphics format or PDF format by using the built-in tools easily. The program edition is very easy as in the format of WINWORD.

4. There is a built-in LCD designer, which is use to design any mode of design in the LCD panel.

5. It can be connected to the hardware by connecting through the serial port, or USB or Parallel port of PC. It depends on the hardware. The advanced way of connecting is, through Ethernet. Through this Ethernet connection, the software can be updated into the hardware from any place in the world – perhaps, if the hardware is connected to the network.

6. There are direct commands to control your Keyboard or mouse.

7. There is a library manager, which is used to drive the flashcard connected via the Ports A, B and C.

The famous IDE’s are CODEVISION AVR, SDCC compiler (free compiler), BASCOM etc.

Hope all this may help you to develop your knowledge about programming. Wish you all the best.

There was an error in this gadget