SlideShare a Scribd company logo
Control system
project
Dc motor speed
control.
Bilal Mustafa Bsee01113037
Khawaja Mohtisham Bsee01113181
Farrukh asgher Bsee01093129
Dc motor speed control.
This project describes the control for dc motor control. In this project the speed is measured by
optocoupler encoder and is sent to the controller and a reference speed is set by the user with
the push buttons and the controller tries to achieve that speed (set by the user) and the output is
displayed on LCD. The controller used in this project is stm32.
Sensor
Controller=Stm32
Plant=Dc Motor
Sensor=opto coupler encoder
PlantInput
by user
Controller Output
(speed)
Display
LCD 16x2.
LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of applications.
A 16x2 LCD display is very basic module and is very commonly used in various devices and circuits. These
modules are preferred over seven segments and other multi segment LEDs. The reasons being: LCDs are
economical; easily programmable; have no limitation of displaying special & even custom characters
A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each
character is displayed in 5x7 pixel matrix. This LCD has two registers, namely, Command and Data.
The command register stores the command instructions given to the LCD. A command is an instruction
given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position,
controlling display etc. The data register stores the data to be displayed on the LCD. The data is the ASCII
value of the character to be displayed on the LCD. Click to learn more about internal structure of a LCD.
Pin Diagram:
Pin Description
Pin No Function Name
1 Ground (0V) Ground
2 Supply voltage; 5V (4.7V – 5.3V) Vcc
3 Contrast adjustment; through a variable resistor VEE
4 Selects command register when low; and data register when high Register Select
5 Low to write to the register; High to read from the register Read/write
6 Sends data to data pins when a high to low pulse is given Enable
7
8-bit data pins
DB0
8 DB1
9 DB2
10 DB3
11 DB4
12 DB5
13 DB6
14 DB7
15 Backlight VCC (5V) Led+
16 Backlight Ground (0V) Led-
Link stm with LCD
Stm pins Lcd pins
Pc10 4
Pc11 5
Pc12 6
Pc0 11
Pc1 12
Pc2 13
Pc3 14
5v 2
Gnd 1
Uln2003
The ULN2001A, ULN2002A, ULN2003 and ULN2004A are high voltage, high current Darlington arrays
each containing seven open collector Darlington pairs with common emitters. Each channel rated at
500mA and can withstand peak currents of 600mA. Suppression diodes are included for inductive load
driving and the inputs are pinned opposite the outputs to simplify board layout.
The STM32F100RB
 24 MHz Cortex-M3 core
 8kByte SRAM, 128kByte flash
 51 high speed I/O Pins
 7 x 16-bit timers
 2 x Watchdog timers
 1 x RTC
 16 channel 12 bit ADC
 2 channel 12 bit DAC
 2 x SPI
 2 x I2C
 3 x USART
 1 x CEC (Consumer Electronics Control)
 PLL
 DMA
Code
#include "main.h"
#include "PWM.h"
#include "LCD.h"
uint32_t volatile rpm=0;
uint16_t volatile speed=0,set_speed=0,moter=0;
void Cyclic_Start(const uint16_t PERIOD)
{
RCC_APB1ENR |= 0x00000001;
TIM2_CR1 = 0;
TIM2_CNT = 0;
TIM2_PSC = 8-1; //1us
if(PERIOD > 1)
{
TIM2_ARR = (PERIOD-1);
}
else
{
TIM2_ARR = 1;
}
TIM2_CR1 = 0x0001;
}
void Cyclic_Wait(void)
{
while((TIM2_SR & 0x00000001)==0)
{
}
TIM2_SR = 0; //
}
void EXTI0_IRQHandler(void)
{
rpm=rpm+1;
EXTI_PR |= 0x00000001;
}
void display_lcd(void)
{
uint16_t num=0,num1=0,num2=0,num3=0;
int16_t static volatile count = 0;
if(++count>=320)
{
count=0;
LCD_Write_Str_To_Buff("SPEED=",6,0);
num=speed;
num1=num/100;
num=num%100;
num2=num/10;
num=num%10;
num3=num;
LCD_Write_Char_To_Buff('0'+num1,6);
LCD_Write_Char_To_Buff('0'+num2,7);
LCD_Write_Char_To_Buff('0'+num3,8);
// LCD_Write_Str_To_Buff("RPM",3,9);
LCD_Write_Str_To_Buff("SET-SPEED=",10,16);
num=set_speed;
num1=num/100;
num=num%100;
num2=num/10;
num=num%10;
num3=num;
LCD_Write_Char_To_Buff('0'+num1,26);
LCD_Write_Char_To_Buff('0'+num2,27);
LCD_Write_Char_To_Buff('0'+num3,28);
// LCD_Write_Str_To_Buff("RPM",3,29);
}
}
void moter_rpm_control(void)
{
if(speed>set_speed)
{
if(moter>0)
Set_PWM1(50*(--moter));
}
if(speed<set_speed)
{
if(moter<800)
Set_PWM1(50*(++moter));
}
}
void press_down(void)
{
int16_t static volatile state=0,count=0;
switch(state)
{
case 0:
if((GPIOC_IDR&0x00000080)!=0)
state=1;
break;
case 1:
if(++count>10)
{
count=0;
if((GPIOC_IDR&0x00000080)!=0)
{
set_speed=set_speed-1;
state=3;
}
else
state=0;
}
break;
case 3:
if((GPIOC_IDR&0x00000080)==0)
state=0;
break;
}
}
void press_up(void)
{
int16_t static volatile state=0,count=0;
switch(state)
{
case 0:
if((GPIOC_IDR&0x00000040)!=0)
state=1;
break;
case 1:
if(++count>10)
{
count=0;
if((GPIOC_IDR&0x00000040)!=0)
{
set_speed=set_speed+1;
state=3;
}
else
state=0;
}
break;
case 3:
if((GPIOC_IDR&0x00000040)==0)
state=0;
break;
}
}
int main(void)
{
RCC_APB2ENR |= 0x00000005; //enable clock to GPIOA and AFIO
GPIOA_CRL &=0xFFFFFFF0;
GPIOA_CRL |=0x00000008;
GPIOA_ODR &=0xFFFFFFFE;
AFIO_EXTICR1 &=0xFFFFFFF0;
AFIO_EXTICR1 |=0x00000000;
EXTI_RTSR &= 0xFFFFFFFE;
EXTI_RTSR |= 0x00000001;
EXTI_IMR = 0x00000001;
NVIC_ISER0 |= 1<<6;
RCC_APB2ENR |= 0x00000014; //GPIOC clock on
GPIOC_CRL &= 0x0000FFFF;
GPIOC_CRL |= 0x88110000;
GPIOC_ODR &= 0xFFFFFF3F;
GPIOA_CRH &= 0xFFFFFFF0; //clear previous config for port C pin 8
GPIOA_CRH |= 0x00000009;//config port A pin 8 as alternate functin output push-pull.
uint16_t volatile count=0,count1=0;
Cyclic_Start(1000); //1ms
LCD_Init();
PWM_INIT();
while(1) //every 1ms
{
if(++count1>50)
{
speed=(rpm/2);
rpm=0;
moter_rpm_control();
count1=0;
}
press_up();
press_down();
display_lcd();
if(++count>=10) // every 10ms
{
count = 0;
LCD_Update();
}
Cyclic_Wait();
}
return(1);
}
void SystemInit(void)
{
}

More Related Content

What's hot

89 c2051
89 c205189 c2051
89 c2051
Nitin Joshi
 
131080111003 mci
131080111003 mci131080111003 mci
131080111003 mci
jokersclown57
 
m.tech esd lab manual for record
m.tech esd lab manual for recordm.tech esd lab manual for record
m.tech esd lab manual for record
G Lemuel George
 
Intel Quark HSUART
Intel Quark HSUARTIntel Quark HSUART
Intel Quark HSUART
Shubham Kumar
 
8-Bit CMOS Microcontrollers with nanoWatt Technology
8-Bit CMOS Microcontrollers with nanoWatt Technology8-Bit CMOS Microcontrollers with nanoWatt Technology
8-Bit CMOS Microcontrollers with nanoWatt Technology
Premier Farnell
 
Meta88full
Meta88fullMeta88full
Meta88full
Tony Tagle
 
Introduction to PIC18FX6J Series MCUs
Introduction to PIC18FX6J Series MCUsIntroduction to PIC18FX6J Series MCUs
Introduction to PIC18FX6J Series MCUs
Premier Farnell
 
pandu-vivek (1)
pandu-vivek (1)pandu-vivek (1)
pandu-vivek (1)
Vivek Shukla
 
PSC9131UG_C4_FD
PSC9131UG_C4_FDPSC9131UG_C4_FD
PSC9131UG_C4_FD
Haim Amir
 
Laptop syllabus 1 month
Laptop syllabus 1 monthLaptop syllabus 1 month
Laptop syllabus 1 month
chiptroniks
 
chip level repairing
chip level repairingchip level repairing
chip level repairing
Swastik Pandey
 
DEF CON 23 - Rodringo Almeida - embedded system design from electronics
DEF CON 23 - Rodringo Almeida - embedded system design from electronics DEF CON 23 - Rodringo Almeida - embedded system design from electronics
DEF CON 23 - Rodringo Almeida - embedded system design from electronics
Felipe Prado
 
MODULO TS-12864A-2
MODULO TS-12864A-2MODULO TS-12864A-2
MODULO TS-12864A-2
ESPOL
 
Atmel 2486-8-bit-avr-microcontroller-atmega8 l-datasheet
Atmel 2486-8-bit-avr-microcontroller-atmega8 l-datasheetAtmel 2486-8-bit-avr-microcontroller-atmega8 l-datasheet
Atmel 2486-8-bit-avr-microcontroller-atmega8 l-datasheet
sang2792
 
FPGA IMPLIMENTATION OF UART CONTTROLLER
FPGA IMPLIMENTATION OF UART CONTTROLLERFPGA IMPLIMENTATION OF UART CONTTROLLER
FPGA IMPLIMENTATION OF UART CONTTROLLER
Varun Kambrath
 
project report
project reportproject report
project report
Nashath Hussain
 
Uart
UartUart
Lecture 10 _serial_communication
Lecture 10 _serial_communicationLecture 10 _serial_communication
Lecture 10 _serial_communication
Md Rakibul islam chowdhury
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming II
Omar Sanchez
 

What's hot (19)

89 c2051
89 c205189 c2051
89 c2051
 
131080111003 mci
131080111003 mci131080111003 mci
131080111003 mci
 
m.tech esd lab manual for record
m.tech esd lab manual for recordm.tech esd lab manual for record
m.tech esd lab manual for record
 
Intel Quark HSUART
Intel Quark HSUARTIntel Quark HSUART
Intel Quark HSUART
 
8-Bit CMOS Microcontrollers with nanoWatt Technology
8-Bit CMOS Microcontrollers with nanoWatt Technology8-Bit CMOS Microcontrollers with nanoWatt Technology
8-Bit CMOS Microcontrollers with nanoWatt Technology
 
Meta88full
Meta88fullMeta88full
Meta88full
 
Introduction to PIC18FX6J Series MCUs
Introduction to PIC18FX6J Series MCUsIntroduction to PIC18FX6J Series MCUs
Introduction to PIC18FX6J Series MCUs
 
pandu-vivek (1)
pandu-vivek (1)pandu-vivek (1)
pandu-vivek (1)
 
PSC9131UG_C4_FD
PSC9131UG_C4_FDPSC9131UG_C4_FD
PSC9131UG_C4_FD
 
Laptop syllabus 1 month
Laptop syllabus 1 monthLaptop syllabus 1 month
Laptop syllabus 1 month
 
chip level repairing
chip level repairingchip level repairing
chip level repairing
 
DEF CON 23 - Rodringo Almeida - embedded system design from electronics
DEF CON 23 - Rodringo Almeida - embedded system design from electronics DEF CON 23 - Rodringo Almeida - embedded system design from electronics
DEF CON 23 - Rodringo Almeida - embedded system design from electronics
 
MODULO TS-12864A-2
MODULO TS-12864A-2MODULO TS-12864A-2
MODULO TS-12864A-2
 
Atmel 2486-8-bit-avr-microcontroller-atmega8 l-datasheet
Atmel 2486-8-bit-avr-microcontroller-atmega8 l-datasheetAtmel 2486-8-bit-avr-microcontroller-atmega8 l-datasheet
Atmel 2486-8-bit-avr-microcontroller-atmega8 l-datasheet
 
FPGA IMPLIMENTATION OF UART CONTTROLLER
FPGA IMPLIMENTATION OF UART CONTTROLLERFPGA IMPLIMENTATION OF UART CONTTROLLER
FPGA IMPLIMENTATION OF UART CONTTROLLER
 
project report
project reportproject report
project report
 
Uart
UartUart
Uart
 
Lecture 10 _serial_communication
Lecture 10 _serial_communicationLecture 10 _serial_communication
Lecture 10 _serial_communication
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming II
 

Similar to report cs

LCD WITH 8051.docx
LCD WITH 8051.docxLCD WITH 8051.docx
LCD WITH 8051.docx
bhattparthiv23
 
Lcd interfacing
Lcd interfacingLcd interfacing
Lcd interfacing
AshuKaranam
 
Final Presentation
Final PresentationFinal Presentation
Final Presentation
Susmit Sircar
 
Automatic room light controller with visible counter
Automatic room light controller with visible counterAutomatic room light controller with visible counter
Automatic room light controller with visible counter
Mafaz Ahmed
 
1 PageAlarm Clock Design Using PIC18F45E.docx
1  PageAlarm Clock Design Using PIC18F45E.docx1  PageAlarm Clock Design Using PIC18F45E.docx
1 PageAlarm Clock Design Using PIC18F45E.docx
mercysuttle
 
Calculator design with lcd using fpga
Calculator design with lcd using fpgaCalculator design with lcd using fpga
Calculator design with lcd using fpga
Hossam Hassan
 
Lcd
LcdLcd
summer training report (2)
summer training report (2)summer training report (2)
summer training report (2)
Kavya Gupta
 
Moving message display
Moving message displayMoving message display
Moving message display
viraj1989
 
SIMPLE Frequency METER using AT89c51
SIMPLE Frequency METER using AT89c51 SIMPLE Frequency METER using AT89c51
SIMPLE Frequency METER using AT89c51
aroosa khan
 
Keypad interfacing 8051 -NANOCDAC
Keypad interfacing 8051 -NANOCDACKeypad interfacing 8051 -NANOCDAC
Keypad interfacing 8051 -NANOCDAC
nanocdac
 
Microcontroller part 4
Microcontroller part 4Microcontroller part 4
Microcontroller part 4
Keroles karam khalil
 
microcontroller board ppt
microcontroller board pptmicrocontroller board ppt
microcontroller board ppt
shashank tiwari
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming II
Omar Sanchez
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming II
Omar Sanchez
 
ESD -DAY 24.pptx
ESD -DAY 24.pptxESD -DAY 24.pptx
ESD -DAY 24.pptx
BhagvatShukla
 
Lcd & keypad
Lcd & keypadLcd & keypad
Lcd & keypad
Izwanizam Yahaya
 
Embedded Systems using Microwave oven
Embedded Systems using  Microwave ovenEmbedded Systems using  Microwave oven
Embedded Systems using Microwave oven
BOOMIKAD
 
AUTOMATIC WIRELESS POWER GRID CONTROL
AUTOMATIC WIRELESS POWER GRID CONTROLAUTOMATIC WIRELESS POWER GRID CONTROL
AUTOMATIC WIRELESS POWER GRID CONTROL
shiv kapil
 
Analog to Digital Converter
Analog to Digital ConverterAnalog to Digital Converter
Analog to Digital Converter
Ariel Tonatiuh Espindola
 

Similar to report cs (20)

LCD WITH 8051.docx
LCD WITH 8051.docxLCD WITH 8051.docx
LCD WITH 8051.docx
 
Lcd interfacing
Lcd interfacingLcd interfacing
Lcd interfacing
 
Final Presentation
Final PresentationFinal Presentation
Final Presentation
 
Automatic room light controller with visible counter
Automatic room light controller with visible counterAutomatic room light controller with visible counter
Automatic room light controller with visible counter
 
1 PageAlarm Clock Design Using PIC18F45E.docx
1  PageAlarm Clock Design Using PIC18F45E.docx1  PageAlarm Clock Design Using PIC18F45E.docx
1 PageAlarm Clock Design Using PIC18F45E.docx
 
Calculator design with lcd using fpga
Calculator design with lcd using fpgaCalculator design with lcd using fpga
Calculator design with lcd using fpga
 
Lcd
LcdLcd
Lcd
 
summer training report (2)
summer training report (2)summer training report (2)
summer training report (2)
 
Moving message display
Moving message displayMoving message display
Moving message display
 
SIMPLE Frequency METER using AT89c51
SIMPLE Frequency METER using AT89c51 SIMPLE Frequency METER using AT89c51
SIMPLE Frequency METER using AT89c51
 
Keypad interfacing 8051 -NANOCDAC
Keypad interfacing 8051 -NANOCDACKeypad interfacing 8051 -NANOCDAC
Keypad interfacing 8051 -NANOCDAC
 
Microcontroller part 4
Microcontroller part 4Microcontroller part 4
Microcontroller part 4
 
microcontroller board ppt
microcontroller board pptmicrocontroller board ppt
microcontroller board ppt
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming II
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming II
 
ESD -DAY 24.pptx
ESD -DAY 24.pptxESD -DAY 24.pptx
ESD -DAY 24.pptx
 
Lcd & keypad
Lcd & keypadLcd & keypad
Lcd & keypad
 
Embedded Systems using Microwave oven
Embedded Systems using  Microwave ovenEmbedded Systems using  Microwave oven
Embedded Systems using Microwave oven
 
AUTOMATIC WIRELESS POWER GRID CONTROL
AUTOMATIC WIRELESS POWER GRID CONTROLAUTOMATIC WIRELESS POWER GRID CONTROL
AUTOMATIC WIRELESS POWER GRID CONTROL
 
Analog to Digital Converter
Analog to Digital ConverterAnalog to Digital Converter
Analog to Digital Converter
 

report cs

  • 1. Control system project Dc motor speed control. Bilal Mustafa Bsee01113037 Khawaja Mohtisham Bsee01113181 Farrukh asgher Bsee01093129
  • 2. Dc motor speed control. This project describes the control for dc motor control. In this project the speed is measured by optocoupler encoder and is sent to the controller and a reference speed is set by the user with the push buttons and the controller tries to achieve that speed (set by the user) and the output is displayed on LCD. The controller used in this project is stm32. Sensor Controller=Stm32 Plant=Dc Motor Sensor=opto coupler encoder PlantInput by user Controller Output (speed) Display
  • 3. LCD 16x2. LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of applications. A 16x2 LCD display is very basic module and is very commonly used in various devices and circuits. These modules are preferred over seven segments and other multi segment LEDs. The reasons being: LCDs are economical; easily programmable; have no limitation of displaying special & even custom characters A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers, namely, Command and Data. The command register stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position, controlling display etc. The data register stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD. Click to learn more about internal structure of a LCD. Pin Diagram:
  • 4. Pin Description Pin No Function Name 1 Ground (0V) Ground 2 Supply voltage; 5V (4.7V – 5.3V) Vcc 3 Contrast adjustment; through a variable resistor VEE 4 Selects command register when low; and data register when high Register Select 5 Low to write to the register; High to read from the register Read/write 6 Sends data to data pins when a high to low pulse is given Enable 7 8-bit data pins DB0 8 DB1 9 DB2 10 DB3 11 DB4 12 DB5 13 DB6 14 DB7 15 Backlight VCC (5V) Led+ 16 Backlight Ground (0V) Led- Link stm with LCD Stm pins Lcd pins Pc10 4 Pc11 5 Pc12 6 Pc0 11 Pc1 12 Pc2 13 Pc3 14 5v 2 Gnd 1 Uln2003 The ULN2001A, ULN2002A, ULN2003 and ULN2004A are high voltage, high current Darlington arrays each containing seven open collector Darlington pairs with common emitters. Each channel rated at 500mA and can withstand peak currents of 600mA. Suppression diodes are included for inductive load driving and the inputs are pinned opposite the outputs to simplify board layout.
  • 5. The STM32F100RB  24 MHz Cortex-M3 core  8kByte SRAM, 128kByte flash  51 high speed I/O Pins  7 x 16-bit timers  2 x Watchdog timers  1 x RTC  16 channel 12 bit ADC  2 channel 12 bit DAC  2 x SPI  2 x I2C  3 x USART  1 x CEC (Consumer Electronics Control)  PLL  DMA
  • 6.
  • 7. Code #include "main.h" #include "PWM.h" #include "LCD.h" uint32_t volatile rpm=0; uint16_t volatile speed=0,set_speed=0,moter=0; void Cyclic_Start(const uint16_t PERIOD) { RCC_APB1ENR |= 0x00000001; TIM2_CR1 = 0; TIM2_CNT = 0; TIM2_PSC = 8-1; //1us if(PERIOD > 1) { TIM2_ARR = (PERIOD-1); } else { TIM2_ARR = 1; } TIM2_CR1 = 0x0001; } void Cyclic_Wait(void) { while((TIM2_SR & 0x00000001)==0)
  • 8. { } TIM2_SR = 0; // } void EXTI0_IRQHandler(void) { rpm=rpm+1; EXTI_PR |= 0x00000001; } void display_lcd(void) { uint16_t num=0,num1=0,num2=0,num3=0; int16_t static volatile count = 0; if(++count>=320) { count=0; LCD_Write_Str_To_Buff("SPEED=",6,0); num=speed; num1=num/100; num=num%100; num2=num/10; num=num%10; num3=num; LCD_Write_Char_To_Buff('0'+num1,6); LCD_Write_Char_To_Buff('0'+num2,7); LCD_Write_Char_To_Buff('0'+num3,8); // LCD_Write_Str_To_Buff("RPM",3,9); LCD_Write_Str_To_Buff("SET-SPEED=",10,16); num=set_speed;
  • 11. switch(state) { case 0: if((GPIOC_IDR&0x00000040)!=0) state=1; break; case 1: if(++count>10) { count=0; if((GPIOC_IDR&0x00000040)!=0) { set_speed=set_speed+1; state=3; } else state=0; } break; case 3: if((GPIOC_IDR&0x00000040)==0) state=0; break; } } int main(void) { RCC_APB2ENR |= 0x00000005; //enable clock to GPIOA and AFIO GPIOA_CRL &=0xFFFFFFF0; GPIOA_CRL |=0x00000008;
  • 12. GPIOA_ODR &=0xFFFFFFFE; AFIO_EXTICR1 &=0xFFFFFFF0; AFIO_EXTICR1 |=0x00000000; EXTI_RTSR &= 0xFFFFFFFE; EXTI_RTSR |= 0x00000001; EXTI_IMR = 0x00000001; NVIC_ISER0 |= 1<<6; RCC_APB2ENR |= 0x00000014; //GPIOC clock on GPIOC_CRL &= 0x0000FFFF; GPIOC_CRL |= 0x88110000; GPIOC_ODR &= 0xFFFFFF3F; GPIOA_CRH &= 0xFFFFFFF0; //clear previous config for port C pin 8 GPIOA_CRH |= 0x00000009;//config port A pin 8 as alternate functin output push-pull. uint16_t volatile count=0,count1=0; Cyclic_Start(1000); //1ms LCD_Init(); PWM_INIT(); while(1) //every 1ms { if(++count1>50) { speed=(rpm/2); rpm=0; moter_rpm_control(); count1=0; } press_up(); press_down(); display_lcd();
  • 13. if(++count>=10) // every 10ms { count = 0; LCD_Update(); } Cyclic_Wait(); } return(1); } void SystemInit(void) { }