Instrumentation Control Engg Section Electrical Engineering Department Ahmedabad
Instrumentation & Control Engg. Section Electrical Engineering Department Ahmedabad - 382481, Gujarat
§ Arithmetic Operations § Logic Operations § Conditions § Loops § Both Assembly language and C language
Input Devices § Switch § Push-button, POT § Sensors (temperature, strain gauge, level) (m. V) § Touchscreen § Keypad matrix § Infrared (PIR motion sensor) § Camera § PING Sensor § RPM Measurement IR sensor § LM 35 § Etc….
Output Devices § LED § Seven Segment § LED Matrix § LCD § Motor (DC, AC, Servo, Stepper) § Relay § Solenoid Valve § Etc…
§ RFID Tag and Reader § GSM Module § GPS module § Motor Driver
§ READSW: NXT: MOV P 0, #83 H // Initializing push button switches and initializing LED in OFF state. MOV A, P 0 // Moving the port value to Accumulator. RRC A // Checking the vale of Port 0 to know if switch 1 is ON or not JC NXT // If switch 1 is OFF then jump to NXT to check if switch 2 is ON CLR P 0. 7 // Turn ON LED because Switch 1 is ON SJMP READSW // Read switch status again. RRC A // Checking the value of Port 0 to know if switch 2 is ON or not JC READSW // Jumping to READSW to check status of switch 1 again (provided switch 2 is OFF) SETB P 0. 7 // Turning OFF LED because Switch 2 is ON SJMP READSW // Jumping to READSW to read status of switch 1 again. END
§ #include<reg 52. h> //including sfr registers for ports of the controller § #include<lcd. h> //Can be download from bottom of this article § //LCD Module Connections § sbit RS = P 0^0; § sbit EN = P 0^1; § sbit D 4 = P 2^4; § sbit D 5 = P 2^5; § sbit D 6 = P 2^6; § sbit D 7 = P 2^7; § //End LCD Module Connections § void Delay(int a) § { § int j; § int i; § § for(i=0; i<a; i++) { § § for(j=0; j<100; j++) § { § } } § § } § void main() § { § int i; § Lcd 4_Init(); § while(1) § { § § Lcd 4_Set_Cursor(1, 1); Lcd 4_Write_String("electro. Some LCD Hello World");
§ for(i=0; i<15; i++) { § § Delay(1000); § Lcd 4_Shift_Left(); § } § for(i=0; i<15; i++) § { § Delay(1000); § Lcd 4_Shift_Right(); § } § Lcd 4_Clear(); § Lcd 4_Set_Cursor(2, 1); § Lcd 4_Write_Char('e'); § Lcd 4_Write_Char('S'); § Delay(2000); § § } }
§ #include<reg 52. h> //including sfr registers for ports of the controller § #include<lcd. h> § //Keypad Connections § sbit R 1 = P 1^0; § sbit R 2 = P 1^1; § //LCD Module Connections § sbit R 3 = P 1^2; § sbit RS = P 0^0; § sbit R 4 = P 1^3; § sbit EN = P 0^1; § sbit C 1 = P 1^4; § sbit D 0 = P 2^0; § sbit C 2 = P 1^5; § sbit D 1 = P 2^1; § sbit C 3 = P 1^6; § sbit D 2 = P 2^2; § sbit C 4 = P 1^7; § sbit D 3 = P 2^3; § //End Keypad Connections § sbit D 4 = P 2^4; § sbit D 5 = P 2^5; § void Delay(int a) § sbit D 6 = P 2^6; § { § sbit D 7 = P 2^7; § int j; § //End LCD Module Connections § int i; §
§ for(i=0; i<a; i++) § § if(C 1==0){Delay(100); while(C 1==0); return { '7'; } § for(j=0; j<100; j++) § { § } § } § if(C 2==0){Delay(100); while(C 2==0); retur n '8'; } § if(C 3==0){Delay(100); while(C 3==0); retur n '9'; } § if(C 4==0){Delay(100); while(C 4==0); retur n '/'; } § R 1=1; § char Read_Keypad() § R 2=0; § { § R 3=1; R 4=1; § C 1=1; § § C 2=1; § § C 3=1; if(C 1==0){Delay(100); while(C 1==0); retur n '4'; } § C 4=1; § if(C 2==0){Delay(100); while(C 2==0); retur n '5'; } § R 1=0; § R 2=1; § R 3=1; §
§ if(C 3==0){Delay(100); while(C 3==0); return § '6'; } § R 1=1; if(C 4==0){Delay(100); while(C 4==0); return 'X'; } § R 2=1; § R 3=1; § R 4=0; § R 1=1; § R 2=1; § R 3=0; § R 4=1; § § § if(C 1==0){Delay(100); while(C 1==0); retur n 'C'; } § if(C 1==0){Delay(100); while(C 1==0); return '1'; } if(C 2==0){Delay(100); while(C 2==0); retur n '0'; } § if(C 2==0){Delay(100); while(C 2==0); return '2'; } if(C 3==0){Delay(100); while(C 3==0); retur n '='; } § if(C 3==0){Delay(100); while(C 3==0); return '3'; } if(C 4==0){Delay(100); while(C 4==0); retur n '+'; } § if(C 4==0){Delay(100); while(C 4==0); return ' -'; } § } return 0;
§ void main() § Lcd 8_Write_Char(c); § { § int i=0; § Lcd 8_Set_Cursor(2, 7); § char c, p; § Lcd 8_Write_Char(i+48); § Lcd 8_Init(); § Delay(100); § while(1) § while(!(c = Read_Keypad())); § { § } § Lcd 8_Set_Cursor(1, 1); § i=0; § Lcd 8_Write_String("Keys Pressed: "); § Lcd 8_Clear(); § Lcd 8_Set_Cursor(2, 1); § § Lcd 8_Write_String("Times: "); § while(!(c = Read_Keypad())); § p=c; § while(p==c) § { § i++; § Lcd 8_Set_Cursor(1, 14); § } }
§ #include<stdio. h> § void Delay_ms(int k) §{ § sbit relay_pin = P 2^0; § void Delay_ms(int); § int j; § int i; § for(i=0; i<k; i++) § void main() § { §{ § for(j=0; j<100; j++) § do § { § } § { § § §} relay_pin = 1; //Relay ON Delay_ms(1000); relay_pin = 0; //Relay OFF Delay_ms(1000); }while(1); § } §}
§ #include<stdio. h> § Delay_ms(1000); § }while(1); § #define relayport P 2 §} § void Delay_ms(int); § void Delay_ms(int k) §{ § void main() § int j; §{ § int i; § do § for(i=0; i<k; i++) § { § relayport = 0 x. FF; //All relays On § for(j=0; j<100; j++) § Delay_ms(1000); § { § relayport = 0 x 00; //All relays Off § } §}
§ A Stepper Motor is a brushless, synchronous DC Motor. It has many applications in the field of robotics and mechatronics. The total rotation of the motor is divided into steps. The angle of a single step is known as the stepper angle of the motor. There are two types of stepper motors Unipolar and Bipolar. Due to the ease of operation unipolar stepper motor is commonly used by electronics hobbyists. Stepper Motors can be easily interfaced with a microcontroller using driver ICs such as L 293 D or ULN 2003. § Unipolar stepper motors can be used in three modes namely the Wave Drive, Full Drive and Half Drive mode. Each drive have its own advantages and disadvantages, thus we should choose the required drive according to the application and power consumption.
§ In this mode only one electromagnet is energized at a time. Generated torque will be less when compared to full drive in which two electromagnets are energized at a time but power consumption is reduced. It has same number of steps as in the full drive. This drive is preferred when power consumption is more important than torque. It is rarely used. Wave Drive Stepping Sequence Step A B C D 1 1 0 0 0 2 0 1 0 0 3 0 0 1 0 4 0 0 0 1
§ In this mode two electromagnets are energized at a time, so the torque generated will be larger when compared to Wave Drive. This drive is commonly used than others. Power consumption will be higher than other modes. Full Drive Stepping Sequence Step A B C D 1 1 1 0 0 2 0 1 1 0 3 0 0 1 1 4 1 0 0 1
§ Half Drive § In this mode alternatively one and two electromagnets are energized, so it is a combination of Wave and Full drives. This mode is commonly used to increase the angular resolution of the motor but the torque will be less, about 70% at its half step position. We can see that the angular resolution doubles when using Half Drive Stepping Sequence Step A B C D 1 1 0 0 0 2 1 1 0 0 3 0 1 0 0 4 0 1 1 0 5 0 0 1 0 6 0 0 1 1 7 0 0 0 1 8 1 0 0 1
§ #include<reg 52. h> § P 2=0 x 08; //1000 § #include<stdio. h> § § § void delay(int); delay(1000); } § while(1); § } § void main() §{ § do § { § void delay(int k) § { § int i, j; § for(i=0; i<k; i++) { § P 2=0 x 01; //0001 § § delay(1000); § for(j=0; j<100; j++) § P 2=0 x 02; //0010 § {} § delay(1000); § § P 2=0 x 04; //0100 § } § delay(1000); § }
§ #include<reg 52. h> § P 2 = 0 x 09; //1001 § #include<stdio. h> § delay(1000); § } § void delay(int); § while(1); §} § void main() § void delay(int k) §{ § do § { §{ § int i, j; § for(i=0; i<k; i++) § P 2 = 0 x 03; //0011 § delay(1000); § P 2 = 0 x 06; //0110 § delay(1000); § } § P 2 = 0 x 0 C; //1100 §} § delay(1000); § § { § for(j=0; j<100; j++) § {}
§ #include<reg 52. h> § delay(1000); § #include<stdio. h> § P 2=0 x 08; //1000 § void delay(int); § delay(1000); § void main() § P 2=0 x 09; //1001 § { § delay(1000); § do § { § } while(1); § } § P 2=0 x 01; //0001 § delay(1000); § P 2=0 x 03; //0011 § delay(1000); § int i, j; § P 2=0 x 02; //0010 § for(i=0; i<k; i++) § delay(1000); § { § P 2=0 x 06; //0110 § for(j=0; j<100; j++) § delay(1000); § {} § P 2=0 x 04; //0100 § § delay(1000); § void delay(int k) § { § } }
§ #include<reg 52. h> § P 2=0 x 08; //1000 § #include<stdio. h> § delay(1000); § }while(1); § void delay(int); §} § void main() § void delay(int k) §{ §{ § do § int i, j; § { § for(i=0; i<k; i++) § P 2=0 x 01; //0001 § { § delay(1000); § for(j=0; j<100; j++) § P 2=0 x 04; //0100 § {} § delay(1000); § } § P 2=0 x 02; //0010 §} § delay(1000); §
§ Control Signals and Motor Status P 2. 0/IN 1 P 2. 1/IN 2 Motor Status LOW Stops LOW HIGH Clockwise HIGH LOW Anti-Clockwise HIGH Stops
§ #include<reg 52. h> § #include<stdio. h> § motor_pin_2 = 1; //Rotates Motor Clockwise § delay(); § void delay(void); § motor_pin_1 = 0; § sbit motor_pin_1 = P 2^0; § motor_pin_2 = 0; //Stops Motor § sbit motor_pin_2 = P 2^1; § delay(); § }while(1); § void main() § } § { § do § void delay() § { § § motor_pin_1 = 1; motor_pin_2 = 0; //Rotates Motor Anit Clockwise § int i, j; § for(i=0; i<1000; i++) § { § for(j=0; j<1000; j++) § { } § delay(); § motor_pin_1 = 1; § § motor_pin_2 = 1; //Stops Motor § § delay(); § motor_pin_1 = 0; § § } }
§ A servo motor uses servo mechanism, which is a closed loop mechanism that uses position feedback to control the precise angular position of the shaft. Stepper Motors, which is an open loop system can also be used for precise angular control. But Servo Motors are preferred in angular motion applications such as robotic arm. Moreover controlling of servo motors are very simple, easy and needs no extra hardware like stepper motor. § It uses Pulse Width Modulated (PWM) waves as control signals. The angle of rotation is determined by the width of the pulse at the control pin. The servo motor used here is having angle of rotation from 0 to 180 degrees. We can control the exact angular position by varying the pulse between 1 ms to 2 ms
§ #include<reg 52. h> § Delay_servo(82); § #include<stdio. h> § motor_pin=0; § #include <intrins. h> § while(us--) § { _nop_(); § § sbit motor_pin = P 2^0; § Delay(1000); § void Delay(unsigned int); § § //Turn to 180 degree § void Delay_servo(unsigned int); § } § motor_pin=1; § void main() § Delay_servo(110); § { § void Delay_servo(unsigned int us) § motor_pin=0; § { § motor_pin = 0; § do § § { § Delay(1000); }while(1); § //Turn to 0 degree § motor_pin = 1; § Delay_servo(50); § void Delay(unsigned int ms) § motor_pin = 0; § { § Delay(1000); § § //Turn to 90 degree § } § while(us--) § { § } § _nop_(); § § unsigned long int us = ms*1000; } }
THANK YOU
- Slides: 49