Micro Unit 4 Question Answers - Watermark
Micro Unit 4 Question Answers - Watermark
• The timers are used to measure the time or generate the accurate time delay.
• The timer takes the internal clock as a reference clock, while the counter counts external
clocks or pulses applied through port pins.
• PIC18F Family has 2 to 5 has independent timers which can be used as timer, Counters
or for PWM generation.
• Below table provides the details of the twoTimers
Prescalar Concept
It can be used to divide the clock frequency input to the timer module.
For example, if the instruction clock is 5MHz and we use a prescaler of 2 to divide it which
effectively makes the clock 2.5MHz.
1 = Enable timer 0
0 = Disable timer 0
1 = Enable timer 1
0 = Disable/STOP timer 1
1 = External Clock
0 = Internal Clock
The PIC18F devices have multiple interrupt sources and an interrupt priority feature that allows
each interrupt source to be assigned a high priority level or a low-priority level
• Four pins of PORTB can cause an interrupt when any changes detected on them, They
are referred as PORTB change interrupt
• The interrupt can be enabled/disabled by setting/clearing enable bit, RBIE and it has flag
RBIF Located in INTCON
INTCON Register
Q. 6 Elaborate Timer Interrupts and Steps for Programming PIC18F4550 Timer using
Interrupt.
Timer Interrupt Flag Bits and Associated Registers are given below
6. When TMR1IF = 1, code will jump to ISR to execute it, and after execution control
returns to the main program.
• PIC 18 has 0 and 5 CCP modules inside it as CCP1, CCP2 and CCP so on.
• PWM feature of the CCP has been enhanced for better DC motor control. It is called
enhanced CCP [ECCP].
• Each Capture/Compare/PWM module is associated with a control register (generically,
CCPxCON) and a data register (CCPRx).
• The data register, in turn, is comprised of two 8-bit registers: CCPRxL (low byte) and
CCPRxH (high byte).
• Capture Mode provides access to the current state of a register which constantly changes
its value. In this case, it is the timer TMR1 register. The Capture Mode is used to time a
particular event
• Compare Mode constantly compares values of two registers. One of them is the timer
TMR1 register. This circuit also allows the user to trigger an external event when a
predetermined amount of time has expired.
• PWM (Pulse Width Modulation) This mode allow us to generate pulses with variable
width through Program. PWM is widely used in DC Motor control
•
•
Mrs. Trupti Thite, TE ENTC Microcontroller Page 9
10. Explain Generation of PWM using CCP Module
PIC 18 CCP Module has PWM feature, which allows programmer to create pulses of variable
widths.
Pulse Width Modulation (PWM) is a technique by which the width of a pulse is varied while
keeping the frequency of the wave constant.
In creating pulses with variable widths for PWM two factors are important
1. Setting Period of Pulse
2. Setting Duty Cycle of Pulse
11. Explain Interfacing of PIC 18 F with DC Motor for speed control using CCP Module
Or
Write code of DC Motor Control Using PWM Module
Or
Write a program for 2.5KHz and 75% duty cycle PWM generation with N=4. Assume
Fosc = 10MHz
Answer:
Program:
#include<PIC18F4550.h>
Analog to digital converters are mostly used for data acquisition to convert analog sensor output
into Digital.
PIC 18 F has inbuilt on chip ADC with 10 bit resolution and having 16 Channels
Following table gives details about registers required for ADC programming
Program is as below,
• LM35 is a temperature sensor that can measure temperature in the range of -55°C to 150°C.
• It is a 3-terminal device that provides an analog voltage proportional to the temperature.
• The higher the temperature, the higher is the output voltage.
• The output analog voltage can be converted to digital form using ADC so that a
microcontroller can process it.
• Let’s interface the LM35 temperature sensor with PIC18FXX and display the surrounding
temperature on the LCD16x2 display.
• LM35 gives output in the analog form so connect out pin of a sensor to one of the ADC
channels of PIC18FXX.