PDF -ELECTRICAL ENGINEERING LABORATORY LAB MANUAL - LAB 4 DC motor speed control using pulse width modulation (PWM)
Wait Loading...

PDF :1 PDF :2 PDF :3 PDF :4 PDF :5 PDF :6 PDF :7 PDF :8 PDF :9 PDF :10

Like and share and download

LAB 4 DC motor speed control using pulse width modulation (PWM)


LAB 4 DC motor speed control using pulse width modulation (PWM) web mit edu 2 75 resources random Lab 4 pdf Lab 4 Motor Control Assigned 10 5 09 1 Overview So far we have learnt how to use the Arduino to acquire various types of signals from sensors such as the GPS receivers, temperature sensors, potentiometers, photo

Related PDF

Lab 4: Motor Control - Massachusetts Institute of Technology

web mit edu 2 75 resources random Lab 4 pdf Lab 4 Motor Control Assigned 10 5 09 1 Overview So far we have learnt how to use the Arduino to acquire various types of signals from sensors such as the GPS receivers, temperature sensors, potentiometers, photo resistors, push buttons, Reed switches, etc We will now turn our attention to actuator control,

Experiment 5 DC Motor Speed Control - Walter Scott, Jr

engr colostate edu ECE462 labs ECE461 motor lab Experiment – 5 DC Motor Speed Control 5 1 Introduction In experiment 3 and 4, the speed of the DC motor was controlled by using an open loop voltage control The purpose of this experiment is to design and implement a close loop speed control of a DC motor drive We shall use the same DC motor for which the parameters were calculated in the


me sc edu courses emch367 Download Labs Lab 4 pdf The experimental setup for this experiment consists of a DC electric motor, a speed control potentiometer and its electronics, an emitter detector sensor, a disk with an aperture (hole) attached to the DC motor shaft, and a pair of 7 LED displays connected through appropriate electronics to a 8 pin


eng auburn edu ~nelson courses elec3040 3050 4 Measurement of the motor characteristics 5 A control program to control the speed of the motor 6 Demonstration and presentation of results (final week of lab) This week, students design and test the amplifier that drives the dc motor Such an amplifier is commonly called a motor drive Signal Microcontroller Figure 1 Dc motor control

Lab 8 Speed Control of a Dc motor - Auburn University

eng auburn edu ~nelson courses elec3040 3050 Motor Speed Control Project 1 Generate PWM waveform 2 Amplify the waveform to drive the motor 3 Measure tachometer signal (motor speed) 4 Find parameters of a motor model 5 Control motor speed with a computer algorithm microcontroller 12 Vdc Motor ac Tachometer Amplifier 9 Vdc Power Supply Signal Conditioning (Frequency

USER MANUAL University of Minnesota - Electrical and Computer

people ece umn edu groups power labs ed ed manual pdf The system for the speed control of a DC motor is shown in Fig 1 3 Note that the currA1 (i e phase current of DC motor) and encoder signal (speed of DC motor) is fed back to the DS1104 board via CP 1104 The requirement of feeding back phase current and speed of the motor will be studied in Experiment 4 For now, assume that these two

ENGS 26 CONTROL THEORY Lab 2: Motor Speed Control Laboratory

dartmouth edu ~lray lrr Lab2 pdf for post lab analysis, so that you can complete the experimental portion during the lab period 1 Objective The objective of this lab is to identify the transfer function of a DC motor and to design and implement proportional and proportional integral controllers to control motor speed 2 System modeling The DC motor is driven by a voltage

EE 448 Lab Experiment No 4 - Iowa State University

home eng iastate edu ~rkumar EE442 448 LABS 448lab4 pdf EE 448 Laboratory Experiment 4 Introduction to DC Motors 3 accidentally, there is a comp lete loss of the stator field DC motors have been known to fly apart under these over speed conditions


ocw mit edu labs MIT2 017JF09 slides4 pdf Servomotor Control • Can be positioned from 0 to 180 degrees • An internal DC motor connected to a potentiometer • High torque gearing • Internal feedback circuitry to control motor position • Three wire connector Ground, +5 V, and PWM (typically at 50 Hz) Modify the code to use a potentiometer (or a photo resistor) to control the




  1. reflexão sobre educação e trabalho

Microsoft Windows 8.1 komplett

WorldShip 2019 - upscom

windows and office information online Windows 8 1 PRO 1 Probieren Sie die ONLINE Aktivierung 2 3 Mal (bei Erfolgignorieren Sie die weitere Nummerierung) 2 Installieren Sie Ihr Gerät komplett neu mit der OEM Software (wählen Sie bitte den korrekten Link entsprechend Ihres Gerätes!) WINDOWS 8 1 PRO


Informe Final Evaluación de Actividades y Resultados Proyecto

ramajudicial pr odin formularios en linea OAT 1796 pdf En caso de presentación tardía del informe estadístico anual de actividad notarial, el Director o la Directora de la Oficina de Inspección de Notarías requerirá del notario o de la notaria una carta en la cual explique el motivo de

  1. informe anual de actividades 2018
  2. informe anual de actividades 2018 cndh
  3. informe anual de actividades semarnat
  4. informe anual de actividades unicef
  5. informe anual de actividades cndh
  6. informe anual de actividades unam
  7. informe anual de actividades 2017 cndh
  8. informe anual de actividades del comite de seguridad y salud laboral
  9. informe anual de actividades de fiscalización ambiental
  10. informe anual de actividades ejemplo
  11. informe anual de actividades 2018 ipn
  12. informe anual de actividades fes iztacala 2018
  13. informe anual de actividades del departamento de consejeria estudiantil
  14. informe anual de actividades infonavit 2018
  15. informe anual de actividades docentes secundaria
  16. informe anual de actividades fes iztacala
  17. informe anual de actividades comite de etica
  18. informe anual de actividades 2016 cndh
  19. informe anual de actividades docentes
  20. informe anual de actividades escolares secundaria

Working with Educational Games

Gender Equity Activities - Education & Early Development

his diva portal smash get diva2 744438 FULLTEXT02 pdf in using educational games Page 13 The Developer Perspective Creating games for educational use, and sustaining a business doing so, is very different from working with entertainment games This section describes the differences between the

fibertown uploads 2017 11 buyers guide1 pdf Colocation Buyers Guide Learn the benefits of colocation and decide if a third party data center makes sense for your business quotecolo 2013 06 Colocation Buyers Guide pdf COLOCATION BUYER’S GUIDE Considerations

Jacob Funds IRA Application For Traditional, ROTH, SEP, and SIMPLE IRAs

4rd Quarterly Newsletter: June—August 2017 4-H GROWS HERE

arkansashighways fiscal services division using post tax dollars or funds transferred by a direct rollover from a 401k, traditional IRA, or a 457 deferred compensation plan “Actuarial Equivalent” means the amount the member will pay is the same as the actuarial cost of the benefit The calculator

kefdergi pdf 24 4 2016 Eylul 2016 Eylul Eylül Zenginleştirilmiş 5E Modelinin Öğrenci Kavramsal Değişimi Üzerine Etkisi Astronomi Örneği Tülay ŞENEL ÇORUHLU, Salih ÇEPNİ 1785 Bilgisayar Destekli Öğretimin (BDÖ) Altı Yaş Çocuklarına Zaman ve Mekân Kavramlarını Kazandırmaya Etkisi Nadir Çeliköz, Suat KOL 1803 acarindex

kolegia sgh waw pl pl KES czasopisma kwartalnik archiwum Integracja rynków finansowych w Unii Europejskiej 187 W teorii ekonomii pojawiło się dotąd wiele opinii na temat międzynarodowej integracji gospodarczej i jej oddziaływania na wzrost gospodarczy krajów core ac uk download pdf 143490850 pdf mira Bukowskiego

  1. integracja rynków finansowych w unii europejskiej
  2. proces integracji rynku finansowego w ramach we i ue

bvespirita Um Defunto Que Se Recorda de Tudo professores Enrique Morselli e Francisco Porro, da Universidade de Gênova No decurso de cinco anos consecutivos, graças ao intenso trabalho desenvolvido, esse pequeno grupo propiciou vasto material ? imprensa italiana e, ultrapassando as fronteiras da península, chegou a vários países,

Home back 153515361537153815391540 Next

speed control using pulse width modulation (PWM) Submitted by Vishal Bharam and Bicky Shakya ENGR 323 P...


LAB 4 DC motor speed control using pulse width modulation (PWM) Submitted by Vishal Bharam and Bicky Shakya ENGR 323 Prof.

Taikang Ning

Introduction As we saw in the previous projects,

such as in the field of automobiles,

In this laboratory,

we use the 8051 microcontroller to design an embedded system that would run according to allowable target speed desired by the user.

Problem Statement: This design laboratory is to help us learn and become familiar with designing and implementing a DC motor speed control embedded system,

which involves Pulse-Width Modulation (PWM) and the proportional,

integral and derivative (PID) controller design.

Specific Design Goal: The design goal of this lab is to use the SilliconLab-C8051F120 kit to implement a PID controller that allows the user to enter the desired target speed.

With feedback,

the PID controller can make timely adjustment to the PWM to accommodate the changing shaft-load to maintain the desired rotating speed.

The system block diagram for the system is given in fig.1.

Fig 1: System configuration of DC motor speed control Following constrains are to be taken into the consideration while designing the lab: 

Allow users to easily adjust the desired motor rpm speed

Use the PWM signal to control the DC motor speed

Use the pushbutton to control the rotating direction

Implement a properly working adjustable feedback controller

Display the system information (desired speed and actual speed of the DC motor ) using a 16x2 LCD

Hardware: Silicon Laboratories C8051F500DK: For this lab,

we used the SiliconLabs C8051F500DK evaluation board.

The board consists of the 8051 microcontroller but with a lot of added features.

Some of the features include a 12 bit analog-to-digital converter,

All in all,

the C8051F500 is designed to be a stand-alone ‘system on a chip’ solution,

as claimed by the manufacturer.

The C8051F500 board was connected to the PC using the USB Debug Adapter to DEBUG_A on the target board with the 10-pin ribbon cable as shown in the figure 2.

Fig.2: Hardware Setup of C8051F500 using a USB DEBUG Adapter The C8051F500 also has two 12-bit Analog to Digital Converters (ADC).

We connected one of the ADC’s to the 1k potentiometer via P1.2 pin (A-22 on C8051F500 Female Socket).

This allowed us to easily adjust the desired speed.


the PWM generated from the C8051F500 was sent through P0.2 (A-12,

CEX0) to the EN1,2 (Enable pin) on the H-Bridge.

The pulses generated by the motor amplified from the op-amp were to be counted using the counter 0.


counter 0 which was counting the pulses was connected to the pin P0.3 (C-11).

DC Motor: For this lab,

we used a 9V DC motor (model # ESCAP 28 D2R 11) with a built in optical encoder,

consisting of a slotted disk and a phototransistor-LED pair.

The phototransistor outputs a pulse whenever the slot in the disk passes by the phototransistor-LED pair.

The phototransistor/LED sensor pair is powered by 5 volts and generates a sinusoidal signal with 80 counts per turn and 0.2 – 2V peak-to-peak.

The DC motor itself,

is rated at 9V and has a maximum continuous torque of 3.32 oz-in and maximum continuous current of 1.5A at 1.5 oz-in load.

Under normal operating conditions,

the motor drains about 650 mA of current at 3000 rotations per minute (RPM).

The motor came with the following six wires whose specifications are mentioned below:

Motor +,

Motor – These two pins connect to the outputs (1Y and 2Y) of the H-bridge chip and supply the motor with current from the H-bridge chip.

Collector This pin connects to a voltage source of 5V through a 1kΩ resistor to generate a current (max of 5 mA) for the phototransistor in the encoder,

Anode This pin connects to a voltage source of 5V through a 220kΩ resistor,

so that about 27 mA of current (max recommended is 30 mA) is allowed to flow through the photodiode in the encoder.


Cathode Both of these pins were connected to ground.

Fig.3: DC Motor with Encoder

H-Bridge: In order to allow control of the motor through PWM,

we need a motor controller chip.

For this lab,

we employed the SN754410 IC chip.

This chip,

inputs PWM and direction and outputs high voltage power supply to the motors.

Fig.4: Pin Configuration for the SN754410 The chip consists of two separate H-Bridge circuits and can be used to drive up to 2 DC motors.

For directional control,

a signal from +5V was connected to pin 2 (1A) and the same +5V signal was put through an inverter (74LS04) and the output of the inverter was connected to pin 7 (2A).

This +5V comes from a logic switch on the CADET board and flipping the switch will cause the motor to change its direction of rotation.

Pin 1 (1,2 EN) was connected to the PWM output from the C8051F500 board so that the duty cycle of the motor could be changed.

Pins 3 and 6 (1Y and 2Y) were connected to the two terminals of the DC motor and were the actual pins that powered up the DC motor.

Pins 4,5,12 and 13 were all connected to ground.


to power the motors) and 16 (VCC1,

logic supply voltage) were both connected to +5V.


when an enable input was high,

the associated drivers were enabled and their outputs became active and in phase with their inputs.

When the enable input was low,

the drivers were disabled and their outputs were off and in a high-impedance state.

As for the technical specifications,

the chip can provide directional current to motors at up to 1A and from 4.5V to 36V.

It also has an operating temperature of

Signal Conditioning Circuit: To interface the encoder from the motor with the C8051F500 board,

we would need a signal conditioning circuit that can be used to detect and remove the non-zero DC offset voltage of the signal.

Analog comparators compare two analog voltage values where one input is typically a reference voltage and the other the unknown value.

When the unknown voltage exceeds the reference,

the output of the comparator switches from one binary state to another.

A DC-Level detection comparator circuit was built using the LM741 op amp.

The oscilloscope was used to measure the sine waves from the DC motor and an appropriate reference voltage was determined for detection.

Parts Needed for Conditioning Circuit: LM741 (Op Amp),

Fig.5: Signal Conditioning Circuit Used

LCD Display:

Fig.6: Regular 16x2 LCD Display We made use of the LCD display in this lab to display actual and target RPM of the motor.

The LCD that we used was 16x2,

meaning it could display an array of characters that was 16 columns by 2 rows (total 32 characters) as shown in fig 6.

The LCD display (CFAH1602A-YYH-JPE) had the following pins:

Vss : Ground

Vdd: Supply Voltage (5V)

VO: Operating voltage for LCD (for adjusting contrast of display through 10K potentiometer)

RS: Flag,

High for Data,

Low for Instruction Code,

Connected to P3.0

R/W: High for Read,

Low for Write,

Connected to P3.1

E: Chip Enable,

Connected to P3.2

DB0 => DB7: Data Bit 0 to Data Bit 7,

where DB7 is also the busy flag,

Connected to P2.0 – P2.7,

Where busy flag is P2.7

The operating voltage (VO) for the LCD contrast was connected to a potentiometer circuit to easily adjust the contrast (brightness of the pixels of the LCD).

It was to be noted that if Vo was set too high,

there would be a chance of burning out the LCD display.


the grounds of the LCD and the supply line (the CADET board) were shorted.

The LCD interacting circuit that was built on the small CADET board is given in figure 7.

Fig.7: Wiring Diagram for the 16x2 LCD Display

Software: For this lab,

there were many components that were to be used for the software configuration.


we had to make sure that the LCD display was working properly.

After confirming with working LCD display,

PCA initialization to implement PWM generation,

implementation of analog to digital conversion and pulse-counting using a timer as a counter was configured.


to maintain the same motor speed when load varies,

a stable PID feedback control system was designed and employed to provide acceptable speed control.

While configuring the software,

the programs for each part were written in small step and next part was approached only after making sure that previous part was working perfectly.

The whole software configuration for the system was programmed using C8051F500 board,

The details of each part in given below: LCD Operation The LCD consists of two registers – the Instruction Register (IR),

to which commands are sent to control the LCD actions and Data Register (DR),

where the display data is sent.

The IR can store instructional codes such as display clear and cursor shift,

and address information for display data RAM (DDRAM) and character generator RAM (CGRAM).


the IR can be programmed from the 8051.

Table 1: Register Selection RS



IR- write as internal operation (Display clear,

Read Busy Flag (DB7) and Address Counter (DB0-DB6)

DR => write as internal operation DR to DDRAM or CG RAM

DR-read as internal operation (DDRAM or CGRAM to DR)

The IR is chosen by setting the Register Select (RS) to ‘0’ and DR with ‘1’.

The LCD is also equipped with a busy flag (DB7).

When it is ‘1’,

the LCD is in internal operation mode and the next instruction will not be accepted.

As per the Register selection table,

the busy flag is output to DB7 when RS = 0 and R/W = 1.

The next instruction cannot be written unless the busy flag is set to ‘0’.

In our program,

LCD_Init() was created.

In this function,

the busy flag was constantly checked to ensure that the commands are being accepted by the LCD.

For the checking part,

LCD_busy_flag() was created,

which selected the IR and set the R/W and LCD Enable to high to read the busy flag from the IR.

The busy flag at line DB7 was read from P2.7 and returned as an integer (configured as input).

a sequence of six steps were performed one after the other.

In each step,

the enable was set to high and then to low because the internal operations work only when the enable is high and there is a high to low transition.

The six steps of initialization and the pattern of data bus lines and select bits are shown below in the table.

Table 2: Instructions and Their Corresponding Codes DB7

Function 0 Set

Display Off

Entry Mode

Display On

Return Home

Clear Display

It is to be noted that before the instructions are executed,

the status of the busy flag should be checked so that it is clear.

Given below is the initialization code: /*

LCD_Init_ISR setup Timer_0 overflow interrupt service routine to perform LCD initialization Function

EA = 0

TH0 = RTH0

TL0 = RTL0

EA = 1

if(LCD_init_flag == 0) { msec_count++


case 16: //send entry mode set LCD_en = 1

RS = 0

RW = 0

P2 = 0x06

switch(msec_count) { case 5:case 10:case 11:case 12: //function set four times LCD_en = 1

RS = 0

RW = 0

P2 = 0x3F

case 18: //send display ON LCD_en = 1

RS = 0

RW = 0

P2 = 0x0F

case 13: //send display off LCD_en = 1

RS = 0

RW = 0

P2 = 0x08

LCD_init_flag = 1

} //end of switch-case } //end of if

case 14: //send display clear LCD_en = 1

RS = 0

RW = 0

P2 = 0x01

if(LCD_init_flag == 1){ SFRPAGE = ACTIVE_PAGE

TR0 = 0

//disable Timer_0 overflow interrupt,

LCD is initailized ET0 = 0

} //end of if SFRPAGE = SFRPAGE_SAVE

After the initialization was complete,

the LCD needed to be setup for writing.

For our application purposes,

we were only writing to the data lines.

For displaying,

the LCD needs to be refreshed constantly to update the display.

The refreshing was achieved by using Timer 1 Overflow Interrupt and the advised refresh rate was 50Hz.

We also needed to specify the cursor to move to the next line when the 16th character was reached in a row.

When the 32nd character was displayed,

the LCD was instructed to return to the home position.

The position of this cursor was monitored using a LCD_pointer variable.

Fig.10: The LCD Display Refresh Function For the actual display of the text,

we implemented the following numeric to character data type function:

the TARGET RPM and ACTUAL in RPM were assigned as four bit signed decimal numbers.

In the part of the program with those numbers,

we can see the conversion of numeric data type to character data type.

PWM Generation using Programmable Counter Array (PCA) PWN is used to control the duty cycle of a square wave,

and provides the necessary flexibility for many application.

In this lab,

the SiliconLab-C8051F500 is being employed to generate the appropriate PWM signal to control motor rotation speed.

The PWM output is connected directly to an intelligent PWM control H-Bridge chip that will translate the duty cycle information to drive the DC motor accordingly.

In order to this,

C8051F500 provides a Programmable Counter Array (PCA0) consisting of a dedicated 16-bit counter/timer and six 16-bit capture/compare modules.

Each capture/compare module has its own associated I/O line (CEXn),

which is routed through the crossbar to port I/O when enabled.

For this lab,

we were using capture/compare module 0,

where CEX0 was used to generate PWM pulses,

while PCA0 timer was driven by the system clock divided by 12.

The mode of the PWM was set to 8-bit pulses.


when the value in the low byte of the PCA counter/timer (PCA0L) was equal to the value in PCA0CPL0,

the PWM signal switches to high and the output on the CEX0 pin will be set.

When the count value in PCA0L overflows,

the CEX0 output will be reset.

This process will repeat to generate PWM signal with intended duty cycle.

The duty cycle of PWM signal was modulated by changing the value stored in

PCA0CPL0 register as shown: Setting ECOM0 and PWM0 bits in the PCA0CPM0 register,

and setting CLSEL bits in register PCA0PWM to 00b,

the internal oscillator frequency was set at 750000 and we were still able to generate the PWM pulses.

After measuring the frequency of the PWM signal in oscilloscope,


Ning’s instructions,

the H-bridge works best at PWM signal frequency of 1 KHz.


internal oscillator frequency was set to 3 MHz using configuration wizard.

Fig.13: Oscillator Initialization with SYSCLK of 3MHz As soon as clock was changed from the 0.75MHz to 3 MHz,

the LCD display started acting weird as expected as it was not getting enough time to settle down.


we increased the setting time for the LCD display refreshing from 25 TIMER-1 overflow interrupts to 100 TIMER-1 overflow interrupts,

as the clock was also changed by a factor of 4.


in the LCD display refresh function,

it was still unable to get to the best condition.


we decided to create same delay in the LCD Busy_flag function,

Analog-Digital Conversion: As specified in the design contains,

the most important design goal of this lab was to Allow the users to easily adjust the desired motor rpm speed.

In order to do so,

A/D converter (ADC0 for 12-bit A/D) on the Silicon-Lab C8051F500 microcontroller was used.

The ADC0 on the C8051F50x/F51x consists of an analog multiplexer (AMUX0) with 35/28 total input selections and a 200 kilo-samples-per-second (ksps),

programmable attenuation (1:2),

In order to initiate the conversion,

we chose TIMER 2 overflow interrupt as repeated A/D conversions can be achieved in fixed intervals.

Fig 12: Timer 2 overflow interrupt used to initiate A/D conversion The conversion mode is determined by the programmed states of the ADC0 bits (AD0CM1,

AD0CM0) in bit-adorable SFR ADC0CN.

ADC0CN was set to 11,

representing the conversion initialization to TIMER 2 overflow interrupt.

AD0BUSY bit in the ADC0CN SFR was set to 1 during conversion and cleared when conversion complete.

The falling edge of the AD0BUSY bit triggers an interrupt and sets the ADOINT interrupt flag.

The converted data then become available in the ADC0H and ADC0L.

Output in our case is right-justified in our case,

so the most significant 8 bits of the converted data would reside in ADC0L and ADC0H would carry the least significant 4 bits.

While configuring ADC0,

the example program from the Silicon-Lab library proved to be very helpful.

ADC0 on the C8051F500 implements a selectable gain adjustment option because input sources have small part-to-part variations that must be accounted for to achieve accurate results and the programmable gain value could be used as a calibration value to eliminate these part-to-part variations.


gain was initialized to account for a 5V input and Vref was set to ground.

The gain value was calculated using the following formula,

which is represented as a 12-bit frame ranging from 0x000 to 0Xfff.

The gain enable bit [ADC0CF.0] was set and ADC0H were loaded with ADC0GNH,


As mentioned earlier,

ADC0L was then loaded with the upper bytes GAIN value,


an ADC conversion should not be performed while the GAINEN bit is set .

Thus the gain bit is set to 0 after proper configuration.

ADC0 is then disabled and normal tracking conversion is triggered on TIMER 2 overflow interrupt by setting ADC0CN to 0x03.

P1.2 is used as the analog input pin and ADC0 conversion complete interrupt was enabled by setting EIE1 to 0x04 and AD0EN to 1.

The detailed code is given in fig.

In order to find the actual RPM of running DC motor,

the pulse counts per second is required to be measured.

In order to measure the pulses,

we needed to use a timer that can be used as a counter.


all four timers were already being used.

Then we realized that we are not using TIMER 0 after the LCD display is initialized once.


we decided use TIMER 0 after the LCD display initialization was completed to count the pulses generated.

In order to measure the current RPM of the motor,

we configured Timer 0 as an 8 bit auto-reload counter.

In the configuration wizard,

we set T0 to P0.3 in order to record the number of pulses.

The pulses,

could not be directly used by the C8051F120,

therefore we had to send the signal through the comparator circuit.

The output of the comparator circuit was then sent to the C8051F120 in order to count the pulses.

While loading the TIMER 2 overflow values,

we had to take care of internal oscillator frequency.

As mentioned earlier,

the internal oscillator clock used in this system was 3MHz.


when we were loading the values for the auto-reload mode,

we had to make sure that they were properly calculated.

The TIMER-2 was configured as SYSCLK/12,

so I took 4 μs (1/(3000000/12)) for one machine cycle.


when we trying to measure pulse-counts per 100 ms,

actual delay was supposed to be (100 ms/4) = 25 ms.


else if(LCD_init_flag == 1) { EA = 0

TMR3CN = 0x04

TMOD = 0x15

TH0 = 0x00

//Start running Timer 3 //Timer_0 set as event counter and Timer_1 still in 16-bit mode //Timer 0 high and low bytes set

TL0 = 0x00

ET0 = 0

Timer 0 will now be used to count pulses

EIE1 |= 0x40

//Timer 3 interrupt enabled and used to record pulses counted by Timer0

TMR3L= 0x57

//Timer 3 high and low bytes set to record pulse every 100 msec

TMR3H = 0x9E

TMR3RLL = 0x57

//Timer 3 auto reload values set

TMR3RLH = 0x9E

EA = 1

After configuring TIMER 0 as a counter to count pulses and TIMER 3 overflow interrupt to record the counted pulses,

which is equal to (total_pulse_count = TH0*256 + TL0).

The total_pulse_count is then used to measure the actual speed of the running DC motor in rpm using the following formula.

where total_pulse_count is in x-msec.

As suggested by prof.


mechanical devices like DC motor is not fast enough to adjust the speed in very small time frame like 100 msec.


we decided to record the pulses after 500 ms or ½ second.

A small counter was used to count the 100 ms delay set by TIMER 3 overflow interrupt and after such 5 interrupt,

total_pulses_counts were recorded using the above equation.


after trying multiple combinations of TIMER-3 overflow delay,

we were not getting the result expected.

Then we decided to measure the frequency of the pulses recorded and we noticed the counter in the TIMER-3 overflow interrupt subroutine was not going through.

After going through the manual,

we got to know that in TMR3CN (Timer 3 control) register,

bit TF3H and bit TF3L are not automatically cleared by the hardware (fig.


when first TIMER-3 overflow happened,

the timer was not going back to reset and was not running again.

In order to do so,

we had to clear TF3H and TF3L to start the timer again.


the TIMER-3 was enabled after each overflow interrupt.

After enabling TIMER-3 again in TIMER-3 overflow interrupt subroutine,

we were getting the results expected.


though we were getting better result,

the values were still fluctuating so much.


we decided to record the pulses after 1000ms or 1 second.


after 10 TIMER-2 overflow interrupts (each with 100ms),

total_pulses_counts were recorded and used to find current speed of motor in rpm as shown in following equation.

The number

of pulses comes from TL0 and TH0 because Timer 0 was set to record pulses

//Interrupts every 100msec (auto reload)


//refreshes actual_rpm every 100*10 = 1000 msec

TH0 = 0x00

//Timer 0 high and low bytes reset

TL0 = 0x00

//Routine convert pulses into RPM here //rpm = pulse_count(1/1000msec)(1000msec/1sec)(60sec/1min)(1turn/80counts) actual_rpm = pulse_count * 0.75

ISRT3_count = 0


16: Timer

After configuring the LCD display,

PWM generation using Programmable Counter Array (PCA),

desired speed target using A/D converter and calculating the actual rpm,

everything was placed together to check the whole embedded system.

We were able to change the desired target speed and thus,

the actual speed of the motor.

The change in the target speed and actual speed was successfully displaced on the LCD display.


there was no proper correlation between the desired target speed and actual speed.

In order to adjust the PWM signal to achieve a desired target speed a feedback controller was necessary.


feedback control was designed using the difference between the desired target speed and the actual speed of the motor.


when the desired target speed was different than the actual speed,

duty cycle of the PWM signal was adjusted accordingly by the controller to maintain the desired speed.

When target speed was higher than actual speed of the motor,

duty cycle of PWM signal was increased accordingly by decreasing the value of PCA0CPH0 in programmable counter array (PCA) and vice versa.

- 0x01

} else if(rpm_change < 0 && PCA0CPH00) && (PCA0CPH0> 0x00)) { if((rpm_change>=1200)) { PCA0CPH0 = PCA0CPH0

- 0x05

} else if((rpm_change>=1000) && (rpm_change=800) && (rpm_change=500) && (rpm_change=300) && (rpm_change=100) && (rpm_change=50) && (rpm_change10) && (rpm_change0) && (rpm_change