0% found this document useful (0 votes)
69 views27 pages

Application of 8051 Microcontroller

Done

Uploaded by

Somenath Dutta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
69 views27 pages

Application of 8051 Microcontroller

Done

Uploaded by

Somenath Dutta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 27
yeu f E ohfequency Measuremen’ ing 80! » Frequency Measurement Using 8051 { [ Frequency Measurement Using 8051 ss °e ° eoooo°o ° Frequency of the given pulse train is equal to the number of pulses per second. Frequency= Number of pulses/Time To find the frequency using the microcontroller, both the Timers TO and T1 of 8051 are used. Normally if T0 is used as a counter, the T1 is used as a Timer. The procedure is, the external pulse train is applied at the PinP3.3 or P3.4. The Timer1 is configured to lapse for a known time say, 1000 micro seconds. During this time the Timer0 is used as a counter and it counts the total number of pulses appeared at the PinP3.3 or P3.4. From this the number of pulses per second is calculated, which is nothing but the frequency of the pulse. ‘To measure the frequency, it is recommended to use a square wave pulses. If exact square wave is not available from a function generator, a Schmitt trigger circuit can be used, which converts a sine wave into a square wave. © The circuit diagram is shown below. Vee xTAL1— xTaL2 <——— eh 8051 Ko) | 2x16 LCD or “ P3.3 ae ials Schmitt Trigger Gnd Fig 1: Schmitt trigger with 8051 © In the procedure the Timer( is configured as a counter and the Timert is configured as a 16 bit timer: In the procedure the Timer() is configured as a counter and the Timert is configured as a 16 bit timer. Timer 1 is pre-loaded with a suitable value so that it will run for time which generates a time lapse of 100 microseconds. During this time the Timer() which is configured as a counter will count the number of pulses. The count value is divided by the time. This give the frequency of the pulse train applied externally at the PinP3.3. The maximum frequency measured by the microcontroller depends on the clock frequency. Normally the 8051 microcontroller can measure accurately those frequencies which do not exceed f/24, where fis clock frequency of the controller. The assembly language program for the measurement of frequency is given below. Assembly Language program START | MOVTCON, #00 | Initialize TCON register vovrcon.eso | sartinerandoumer SETB PSW, 3 Initialize Banks 1 eee Movie 88 | Enable global and. TL MOV RO, #00 Initialize RO Register ve low interrupt MOY R1, #00 Initialize R1 Register JBCOF LOOPL CLR PSW.3 Return Bank 1 Loop2: | sIMPLOOP2 MOV TMOD, #25 | Timer 0 asa counter LOOPI: | MOVR6, TLD Load the count values into : R6&RT registers ‘Timer 1 asa counter MOVR7, THO MOVTLI,#9C | Start TL1 at 9CH UCALL Display | Display subroutine to MOV THO, #00 ‘THA Overflowing 100 docks display the data CLR FLAG SMP START Ready for the next MOVTCON, #50 | Starttimerand counter 4 Neer Measurement Of Current Using 8051 <4 © Small currents can be measured using the microcontroller, for this a resistor of small value between 0.1 to 1 ohm is connected to the load and Vcc in series as shown in the diagram. © The voltage source must be always a regulated power supply. ° The voltage across the resistor is connected to the inverting terminal for signal conditioning This will make the voltage suitable to apply to one of the inputs of the ADCO809. This ADC will converts this analog voltage into equivalent digital value. This digital value is applied to the port 1 of the microcontroller. The data is processed and displayed on the LCD module. The calculate the current Ohms law, V=IR is used. eooooo°d In the above circuit the sense resistor’s value is 1 ohm and when 1 ampere of current is flowing in the resistor, then 1 Volt will be developed across the sense resistor. So, I= V/R. © By Measuring the voltage using the microcontroller, the Current in the resistor can be found. © Note: © This method is useful to measure small currents only, because with large currents the small resistor will dissipate large heat. So, to measure large currents high wattage wire wound resistors or Toroid must be used. RPS@ Vec 5v Load By 2X16 LCD apc 0809 Resistor P20) lohm po 8051 P27 EA. Gnd Fig 1: Circuit for current measurement using 8051 “a Assembly Language program 9000 | START | SETB P34 Send ALE & SOC high NoP No Operation NoP No Operation CLR P34 ALE & SOC low Loop1 | JNB P3.5, LOOP1 |Is conversion over? Mov APL Read digital data(Voltage) CALL CONV Convert the hex value into Decimal value Mov B,#Resistor|Load the resistor Value value into B resistor DIV AB Divide voltage by resistance CALL DISPLAY [Display subroutine to display current on LCD symp [START Measure the current continuously 4 Measurement Of Voltage Using 8051 = ° ° eooo°o Small DC Voltages can be measured using the microcontroller, for this a resistor of small value around 1 ohm is connected to the load and Vcc in series as shown in the diagram. The voltage source must be always a regulated power supply. The voltage across the resistor is connected to the inverting terminal for signal conditioning. This will make the voltage suitable to apply to one of the inputs of the ADC0809. This ADC will convert this analog voltage into equivalent digital value. This digital value is applied to the port 1 of the microcontroller. ‘The data is processed and displayed on the LCD module. RPS@ Vee Load Resistor 1ohm Fig 1: Circuit for Voltage measurement using 8051 OQ Note: © This method is useful to measure small currents only. Because with large currents the small resistor will dissipate large heat. So, to measure large voltages high wattage wire wound resistor or Toroid must be used. Assembly Language program 9000 | START | SETB P34 Send ALE & SOC high Nop No Operation Nop No Operation CLR P34 ALE & SOC low Loop1 | JNB P3.5, LOOP! |Is conversion over? Mov APL Read digital data(Voltage) CALL CONV Convert the hex value into Decimal value CALL DISPLAY Display subroutine to display Voltage on LCD sJMP START Measure the voltage continuously “A 4 » Generation of triangular waveform » Generation of staircase waveform Generation of square waveform © To generate square wave first we have to output FF and then 00 on Port 1 of 8051. © The Port 1 is connected as an input to the DAC 0808. @ According to frequency requirement delay is provided between the two outputs. Lable Mnemonics Comments MOV SP, #08H Initialize the stack pointer. REPEAT | MOV PI, #0FFH Load all 1's in Port 1 LCALL DELAY Call delay routine Mov P, #00H Load all 0's in Port 1 LCALL DELAY Call delay routine LIMP REPEAT Repeat DELAY MOV RO, #0FFH Load delay count BACK DJNZ RO, BACK Decrement and check whether delay count is zero if not repeat the operation Generation of triangular waveform Sx ° Qo The method is to increment the data outputted to the DAC, from 0 to FFH. On conversion to analog form, it will give a gradually increasing output from 0 to the maximum output voltage. Then, decrement the number from FFH to 0. This will give the high to low triangular transition. As the clock frequency of the 8051 is reasonably high, the time for incrementing the number 0 to FFH and decrementing from FFH to 0 will be quite small. Thus, the wave- form generated will have a very short duration. To obtain a slower increase and decrease in analog voltage, a good idea will be to have a small delay after each increment or decrement of the digital number. The delay must be small, such that steps are not see n in the increasing or decreasing port ions of the analog voltage. The amount of this small delay can also be used to control the periods of the generated waveforms. Assembly Language program DAC EQU P2 name port 2 as DAC orGo Mov a, #0 start with A= 0 REP. MOV DAC, A move the content of A to the DAC ACALL DELAY call a very small delay INCA increment A CINE A, HOFFH, REP | ifthe value in Al = FFH, repeat cn: | Mov paca if A= FPH, start the downward swing ACALL DELAY call a very small delay DECA decrement A CINE A, #0, AGN, if Al = 0, repeat the cycle SJMP REP if A = 0, start the upward swing petay: | MovR3, #10 sur: | DINZR3, SELF RET END Generation of staircase waveform <4 © To generate a staircase waveform using the DAC chip is given in the figure and the hardware is assumed to be the same. vi ve v5] Fig 3: Staircase wave form © Three levels V 1, V2, and Vs are assumed in the output voltage waveform. © The hexadecimal output to be given to the portis calculated using the formula. © Equivalent value for voltage output Vi= [(2"- 1)/ Maximum output voltage] x Vi © where nis the number of binary bits in the input to the DAC. @ The following program assumes these three values as DATA1, DATA2, and DATA3. © The fixed time delay is used in all the three levels. 4 pao} 22 Ing Tou pay}___._ 57 2 +12V 10 = ¢ 8051PPI Ae 1a pales i — # al 3 |®5 pacosoo soit PA4); ————_—= 84 ce 16 1} pas}___7_»Jp3 oy : 3 mq ir, Es 0-12V (sb) PA7y} 5 = 51 at vic|+ WWW Ve => ees) Ve Fig 4: Interfacing DAC 0800 with 8051 2H I-to-V converter network eer ear LM741 Analog cw output 2] 75 tp voltage Assembly Language program START: | MOV P1, #DATAL load the hexadecimal equivalent of Vi in port 1. CALL DELAY call the subroutine DELAY. MOV P1, DATA2 load the hexadecimal equivalent of Vp in port 2. CALL DELAY call the subroutine DELAY. MOV P1, DATA3 load the hexadecimal equivalent of V3 in port 3. CALL DELAY call the subroutine DELAY. SJMP START loop again to get a continuous waveform. DELAY: | MOVRO,#COUNT | load a register with a count value. RPT: DJNZ RO, RPT Decrement it and loop. RET if the value of count become zero. return from subroutine. Bese: PWM control of DC motor Q ° The speed of the DC motor depends on the applied voltage. The DC motor's speed is varied by varying the DC voltage (or current) supplied to it Instead of using a DAC to provide a variable DC voltage, the pulse width modulation (PWM) method can be used to provide variable power/voltage. By changing (modulating) the width of a pulse the average (DC) voltage can be varied. i ae 25% DC Power ‘il a = 50% DC Power 75% DC 3 Power 100% DC full Power Fig 1: Power variation using PWM © When the pulse width is zero, the DC voltage is zero and when the pulse width is 100%, the DC voltage is maximum. © When the pulse width is 50%, the DC voltage is Vinx /2- Q Byvarying the pulse width the DC voltage can be varied. PWM out from MCUL GND Fig 2: PWM output interface circuit - © Thus the speed of the DC motor can be controlled by PWM method. © PWM circuitry is embedded in the microcontroller, only the duty cycle has to be programmed. © Duty cycle, D Ton + Tore Duty cycle | Power o/p | Pulse 0% 0 25% 1/4 Pane 50% HP ee ee (ee (| Ton/Tose 75% 3/4 seta ee (ne 2 100% Pas = ae Table 1: Duty cycle Program @ Interface a DC motor to an 8051 microcontroller using optoisolator write a ‘C’ program to move the DC motor with 25% duty cycle pulse. © The DC motor interfaced with optocoupler is shown in the below figure 10. +12V9 = 0.1086 | +5V i 1L074 OPTO isolator Al ANN —f 8 8 0 WA d 7 D=Diode P1.0 o M = Motor 5 Di 1 Fig 3: Interfacing of DC motor to an 8051 microcontroller using optocoupler Q Given data Duty cycle = 25%, Ton = 25ms and Torr = 75ms. © Algorithm ® Step 1: Make P1.0 low to ON the motor. © Step 2: Call delay for 25ms (Ton). © Step 3: Make P1.0 high to OFF the motor. © Step 4: Call delay for 25ms (Torr). © Step 5: Repeat from step1. Assembly Language program ORG 00H ‘AGAIN. [CLRPLO Motor ON ACALL DON | Toy Call DON subroutine to ON the motor SETB PLO Motor OFF ACALLDOFF | Torr, Call DON subroutine to ON the motor SIMP AGAIN | Control transfers to AGAIN DON [Mov Ro, #25 | 5% TON Loop2 [MOVRI, #FFH | Load PRH into RE Loop! [DINZ R1,LOOPI] Decrement the contents of RI, ifnon-zero jump to Lori DJNZRO, LOOP2 | Decrement the contents of RO, I non-zero jump to Loor2 DJNZRO, LOOP2 | DJNZ RO, LOOP2 RET Return DOFF | MOVRO, #75 | 75% Torr Loops [MOVRi,#FFH | Load FFH into RI Loops | DjNZ Ri, LooP3| Decrement the contents of 1, ifnon-zero jump to Loops DINZ RO, LOOP4 | Decrement the contents of RO, ifnon-zero jump to oor RET Return END

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy