Credits Terms of
A Project Report On
JCOLLEGE OF TECHNOLOGY
G.B.PANT UNIVERSITY OF AGRICULTURE AND TECHNOLOGY
PANTNAGAR
Page 1 of 47
CERTIFICATE
This is to certify that the project entitled TIMING SIGNAL GENERATION OF CONTROL
CARD submitted by SHUBHAM PANDEY (43187) , COLLEGE OF TECHNOLOGY,
G.B.PANT UNIVERSITY OF AGRICULTURE AND TECHNOLOGY, PANTNAGAR in
partial fulfillment of the requirement of the Degree of Bachelor Of Technology embodies the
work done by him under my guidance , for the purpose of summer industrial training.
Name:
15/07/2015
ACKNOWLEDGEMENT
Page 3 of 47
INDEX
List of Tables
List of Figures
Content
Page no.
8-16
17-30
b)
c)
d)
e)
f)
PIC16
PIC17
PIC18
PIC24 & dsPIC
PIC32MX
31-34
35-44
4.1
4.2
4.3
4.4
4.5
Introduction
Analog Circuits
Digital Control
CCP Modules
CCP1 Modules
a) CCP1 in PWM Mode
b) PWM Period
c) PWM Resolution
4.6 Code for Generating the Timing Signals
CONCLUSION
45
REFERENCES
46
Page 5 of 47
LIST OF TABLES
TABLE 1
LIST OF FIGURES
Figure No.
Caption
1.1
1.2
1.3
MANORA PEAK
1.4
130 cm Telescope
1.5
104 cm Telescope
1.6
1.7
1.8
2.1
2.2
2.3
4.1
4.2
CCP1 Module
4.3
4.4
4.5
PWM Mode
4.6
PWM Module
4.7
4.8
Page 7 of 47
Chapter 1
ABOUT ARIES
The Institute hosts five telescopes of different apertures ranging from 15cm to 104cm.
There are two 15-cm telescopes dedicated for solar observations. The 104-cm optical telescope is
being used as a main observing facility by the ARIES scientists since 1972. It is equipped with 2k
x 2k, and 1k x 1k liquid N cooled CCD cameras, fast photometer, spectrophotometer, and
standard astronomical 2 filters. The telescope uses a SBIG ST-4 camera for auto-guiding through
an auxiliary 20-cm telescope.
In order to carry out observations in the frontier areas of astronomy, the Institute has
telescopes at a site called 'Devasthal' at a distance of ~ 60-Km from ARIES, which has the
advantages of having dark skies and excellent observing conditions.
The Scientists from the Solar group of ARIES are also participating in the national
projects like space coronagraph and National Large Solar Telescope (NLST). There are different
Page 8 of 47
instruments for observation of physical and optical properties of aerosols and trace gas. An 84cm micro-pulse LIDAR system for high altitude studies of aerosols and a ST Radar (Stratosphere
Troposphere Radar) to measure winds speed up to an altitude of around 20 km is also being
setup.
For different research activities in the field of atmospheric sciences, different instrument
have been at ARIES, which provide many interesting data. In order to fulfill the objective of
ARIES, it has also started initiative to set up a modern technique in the field of atmospheric
sciences.
Aryabhatta Research Institute of observational sciencES (ARIES) was the new name
when SO came under the Department of Science & Technology (DST), Govt. of India as an
autonomous body. The ARIES came into existence on 22nd March 2004, following the decision
of the cabinet of Ministers of the Govt. of India on 07th January, 2004.
The telescope has been fabricated by DFM Engineering Inc. USA. The telescope uses a
modified Ritchey-Chretien Cassegrain design and the focal length to diameter ratio (focal-ratio)
of the overall optics was kept at 4 making it a very fast system providing 40 arcsec view of the
sky in 1 mm scale at the focal plane. A single element corrector provides a nearly flat field view
of the sky up to 66 arcmin in diameter.
The tube of the 130-cm telescope is of open truss allowing the telescope to cool faster in
the ambient. The telescope mount is of fork-equatorial type. The telescope can be pointed to a
celestial object with an accuracy of 10 arcsec rms. The mechanical system provides a tracking
accuracy at nearly 0.5 arcsec rms over 10- min without any external guider. The images obtained
with the telescope show best FWHM at nearly 1 arcsec. The atmospheric extinction at Devasthal
is measured as 0.24 mag in B (Blue), 0.14 mag in V (Visual), and 0.08 mag in R (Red) band on
the first week of December, 2010. The sky brightness is measured as 21.2 mag/arcsec2 in the V
band in moonless night.
Page 11 of 47
A field of around 45 arcmin with corrector is available at the cassegrain end of the
telescope. The tracking accuracy is around 7 arcsec/hr (0.1 arcsec/min) without guider and is
around 0.7 arcsec/hr with guider. The off-axis guiding of the telescope is done through 8- inch
finder telescope using ST4.Fundamental Parameters for the 104-cm Sampurnanand Telescope
Parameter Value Unit Primary Diameter 104 cm Primary focal length 416 (f/4) cm Effective
focal length 1330 (f/13) cm Separation 292 cm .
1.2.3 LIDAR:
LIDAR, stands for Light Detection And Ranging. The LIDAR has designed and
developed at National Atmospheric Research laboratory (NARL), Gadanki, Tirupati. Since,
Manora Peak is located geographically in free tropospheric zone, the site is conducive for
evaluating the aerosol loading effects on the atmosphere due to the aerosol transportation from
nearby polluted valley regions and also the long range aerosol transportation from far off regions
to this height, apparently discernible during the major dust storms. In this perspective the LIDAR
observations of tropospheric aerosols are being carried out for the first time, in the central
Himalayan region at an altitude of ~2.0 km above mean sea level with a range resolution of 0.03
Page 12 of 47
km. During the observations the LIDAR system collects the backscattered laser returns from the
atmospheric aerosol and high altitude clouds.
Page 13 of 47
1.2.4 Aethalometer:
An Aethalometer is an instrument for measuring the concentration of optically absorbing
(black) suspended particulates in a gas colloid stream; commonly visualized as smoke or haze,
often seen in ambient air under polluted conditions. The word aethalometer is derived from the
Classical Greek verb aethaloun, meaning to blacken with soot.
The main uses of aethalometers relate to air quality measurements, with the data being
used for studies of the impact of air pollution on health; climate; and visibility. Other uses
include measurements of the emission of black carbon from combustion sources such as vehicles;
industrial processes; and biomass burning, both in wild fires and in domestic and industrial
settings. The Aethalometer currently in use at ARIES is spectrum AE4 series of Aethalometer,
which performs simultaneous measurements of BC at 7 Wavelengths from 370nm (UV) to
950nm (Near IR).
Page 14 of 47
Data collections are being carried out on regular basis by using both manual and
automatic weather stations. Automatic weather station (Campbell scientific, USA) installed at
ARIES is used for standard meteorological measurements like wind speed, wind directions, solar
radiation, soil/air temperature, relative humidity, barometric pressure and precipitation at ground
level. The system is fully programmed for hourly and daily measurements of above parameters.
Active Phased Array, Circular Aperture, Triangular grid of 588 individual 3-elements Yagi's
Provides both DBS & SAD mode of operation
Page 15 of 47
MODE
Height Coverage
Resolution
DBS-1/SAD mode
0.5-5 km
75m to 150m
DBS-2 mode
5km - 20km
300m
Coherent 588 solid state T/R modules with peak power of - 400 Watt
Direct RF signal Digitization with baseband sampling
Advanced 4-channel digital Rx - having 16 bit ADC and Vertex-5 FPGA
Control Area Network(CAN) based beam steering and control
NAS Box storage in NetCDF format.
Page 16 of 47
Chapter 2
PIC MICROCONTROLLER
2.1 Introduction:
PIC is a family of modified Harvard architecture microcontrollers made by Microchip
Technology, derived from the PIC1650 originally developed by General Instrument's
Microelectronics Division. The name PIC initially referred to Peripheral Interface
Controller. The first parts of the family were available in 1976; by 2013 the company
had shipped more than twelve billion individual parts, used in a wide variety
of embedded systems.
Early models of PIC had read-only memory (ROM) or field-programmable EPROM
for program storage, some with provision for erasing memory. All current models
use Flash memory for program storage, and newer models allow the PIC to reprogram
itself. Program memory and data memory are separated. Data memory is 8-bit, 16-bit
and in latest models, 32-bit wide. Program instructions vary in bit-count by family of
PIC, and may be 12, 14, 16, or 24 bits long. The instruction set also varies by model,
with more powerful chips adding instructions for digital signal processing functions.
The hardware capabilities of PIC devices range from 8-pin DIP chips up to 100pin SMD chips, with discrete I/O pins, ADC and DAC modules, and communications
ports such as UART, I2C, CAN, and even USB. Low-power and high-speed variations
exist for many types.
Page 19 of 47
b) Code space
The code space is generally implemented as ROM, EPROM or flash ROM. In general,
external code memory is not directly addressable due to the lack of an external memory
interface. The exceptions are PIC17 and select high pin count PIC18 devices.
c) Word size
All PICs handle (and address) data in 8-bit chunks. However, the unit of addressability of the
code space is not generally the same as the data space. For example, PICs in the baseline
(PIC12) and mid-range (PIC16) families have program memory addressable in the same
wordsize as the instruction width, i.e. 12 or 14 bits respectively. In contrast, in the PIC18
Page 20 of 47
series, the program memory is addressed in 8-bit increments (bytes), which differs from the
instruction width of 16 bits.
In order to be clear, the program memory capacity is usually stated in number of (singleword) instructions, rather than in bytes.
d) Stacks
PICs have a hardware call stack, which is used to save return addresses. The hardware stack
is not software-accessible on earlier devices, but this changed with the 18 series devices.
Hardware support for a general-purpose parameter stack was lacking in early series, but this
greatly improved in the 18 series, making the 18 series architecture more friendly to highlevel language compilers.
e) Instruction set
PIC's instructions vary from about 35 instructions for the low-end PICs to over 80
instructions for the high-end PICs. The instruction set includes instructions to perform a
variety of operations on registers directly, the accumulator and a literal constant or the
accumulator and a register, as well as for conditional execution, and program branching.
Some operations, such as bit setting and testing, can be performed on any numbered register,
but bi-operand arithmetic operations always involve W (the accumulator), writing the result
back to either W or the other operand register. To load a constant, it is necessary to load it
into W before it can be moved into another register. On the older cores, all register moves
needed to pass through W, but this changed on the "high-end" cores.
PIC cores have skip instructions, which are used for conditional execution and branching.
The skip instructions are "skip if bit set" and "skip if bit not set". Because cores before PIC18
had only unconditional branch instructions, conditional jumps are implemented by a
conditional skip (with the opposite condition) followed by an unconditional branch. Skips are
also of utility for conditional execution of any immediate single following instruction. It is
Page 21 of 47
possible to skip skip instructions. For example, the instruction sequence "skip if A; skip if B;
C" will execute C if A is true or if B is false.
The 18 series implemented shadow, registers which save several important registers during
an interrupt, providing hardware support for automatically saving processor state when
servicing interrupts.
In general, PIC instructions fall into 5 classes:
Operation on working register (WREG) with 8-bit immediate ("literal") operand.
E.g. movlw (move literal to WREG), andlw (AND literal with WREG). One instruction
peculiar to the PIC is retlw, load immediate into WREG and return, which is used with
computed branches to produce lookup tables.
Operation with WREG and indexed register. The result can be written to either the Working
register (e.g. addwf reg,w). or the selected register (e.g. addwf reg,f ).
Bit operations. These take a register number and a bit number, and perform one of 4 actions:
set or clear a bit, and test and skip on set/clear. The latter are used to perform conditional
branches. The usual ALU status flags are available in a numbered register so operations such
as "branch on carry clear" are possible.
Control transfers. Other than the skip instructions previously mentioned, there are only
two: goto and call .
A few miscellaneous zero-operand instructions, such as return from subroutine, and sleep to
enter low-power mode.
2.4) Performance
The architectural decisions are directed at the maximization of speed-to-cost ratio. The PIC
architecture was among the first scalar CPU designs and is still among the simplest and
cheapest. The Harvard architecture, in which instructions and data come from separate
sources, simplifies timing and microcircuit design greatly, and this benefits clock speed,
price, and power consumption.
Page 22 of 47
The PIC instruction set is suited to implementation of fast lookup tables in the program space.
Such lookups take one instruction and two instruction cycles. Many functions can be modeled
in this way. Optimization is facilitated by the relatively large program space of the PIC (e.g.
4096 14-bit words on the 16F690) and by the design of the instruction set, which allows
embedded constants. For example, a branch instruction's target may be indexed by W, and
execute a "RETLW", which does as it is named return with literal in W.
Interrupt latency is constant at three instruction cycles. External interrupts have to be
synchronized with the four-clock instruction cycle, otherwise there can be a one instruction
cycle jitter. Internal interrupts are already synchronized. The constant interrupt latency allows
PICs to achieve interrupt-driven low-jitter timing sequences. An example of this is a video
sync pulse generator. This is no longer true in the newest PIC models, because they have a
synchronous interrupt latency of three or four cycles.
2.5) Advantages
RISC architecture
Easy entry level, in-circuit programming plus in-circuit debugging PICkit units available
for less than $50
Inexpensive microcontrollers
Wide range of interfaces including IC, SPI, USB, USART, A/D, programmable
comparators, PWM, LIN, CAN, PSP, and Ethernet .
Availability of processors in DIL package make them easy to handle for hobby use.
2.6) Limitations
One accumulator
Operations and registers are not orthogonal; some instructions can address RAM
and/or immediate constants, while others can use the accumulator only.
Page 23 of 47
The following stack limitations have been addressed in the PIC18 series, but still apply to
earlier cores:
The hardware call stack is not addressable, so preemptive task switching cannot be
implemented
With paged program memory, there are two page sizes to worry about: one for CALL and
GOTO and another for computed GOTO (typically used for table lookups). For example, on
PIC16, CALL and GOTO have 11 bits of addressing, so the page size is 2048 instruction
words. For computed GOTOs, where you add to PCL, the page size is 256 instruction words.
In both cases, the upper address bits are provided by the PCLATH register. This register must
be changed every time control transfers between pages. PCLATH must also be preserved by
any interrupt handler.
Watchdog timer
2.8) Variants
Within a series, there are still many device variants depending on what hardware resources
the chip features:
is selected by the high 3 bits of the FSR. This affects register numbers 1631; registers 015
are global and not affected by the bank select bits.
Because of the very limited register space (5 bits), 4 rarely read registers were not assigned
addresses, but written by special instructions ( OPTION and TRIS).
The ROM address space is 512 words (12 bits each), which may be extended to 2048 words
by banking. CALL and GOTO instructions specify the low 9 bits of the new code location;
additional high-order bits are taken from the status register. Note that a CALL instruction
only includes 8 bits of address, and may only specify addresses in the first half of each 512word page.
Lookup tables are implemented using a computed GOTO (assignment to PCL register) into a
table of RETLW instructions. Baseline core devices (12 bit).
b) PIC16:
These devices feature a 14-bit wide code memory, and an improved 8 level deep call stack.
The instruction set differs very little from the baseline devices, but the 2 additional opcode
bits allow 128 registers and 2048 words of code to be directly addressed. There are a few
additional miscellaneous instructions, and two additional 8-bit literal instructions, add and
subtract. The mid-range core is available in the majority of devices labeled PIC12 and PIC16.
The first 32 bytes of the register space are allocated to special-purpose registers; the
remaining 96 bytes are used for general-purpose RAM. If banked RAM is used, the high 16
registers (0x700x7F) are global, as are a few of the most important special-purpose
registers, including the STATUS register which holds the RAM bank select bits. (The other
global registers are FSR and INDF, the low 8 bits of the program counter PCL, the PC high
preload register PCLATH, and the master interrupt control register INTCON.)
The PCLATH register supplies high-order instruction address bits when the 8 bits supplied
by a write to the PCL register, or the 11 bits supplied by a GOTO or CALL instruction, is
not sufficient to address the available ROM space.
Page 26 of 47
c) PIC17
The 17 series never became popular and has been superseded by the PIC18 architecture. It is
not recommended for new designs, and availability may be limited.
Improvements over earlier cores are 16-bit wide opcodes (allowing many new instructions),
and a 16 level deep call stack. PIC17 devices were produced in packages from 40 to 68 pins.
The 17 series introduced a number of important new features:
Page 27 of 47
direct register to register moves (prior cores needed to move registers through the
accumulator)
d) PIC18
In 2000, Microchip introduced the PIC18 architecture. Unlike the 17 series, it has proven to
be very popular, with a large number of device variants presently in manufacture. In contrast
to earlier devices, which were more often than not programmed in assembly, C has become
the predominant development language.
The 18 series inherits most of the features and instructions of the 17 series, while adding a
number of important new features:
call stack is 21 bits wide and much deeper (31 levels deep)
extending the FSR registers to 12 bits, allowing them to linearly address the entire data
address space
The RAM space is 12 bits, addressed using a 4-bit bank select register and an 8-bit offset in
each instruction. An additional "access" bit in each instruction selects between bank 0 (a=0)
and the bank selected by the BSR (a=1).
A 1-level stack is also available for the STATUS, WREG and BSR registers. They are saved
on every interrupt, and may be restored on return. If interrupts are disabled, they may also be
used on subroutine call/return by setting the s bit (appending ", FAST" to the instruction).
Page 28 of 47
The auto increment/decrement feature was improved by removing the control bits and adding
four new indirect registers per FSR. Depending on which indirect file register is being
accessed it is possible to postdecrement, postincrement, or preincrement FSR; or form the
effective address by adding W to FSR.
In more advanced PIC18 devices, an "extended mode" is available which makes the
addressing even more favorable to compiled code:
a new offset addressing mode; some addresses which were relative to the access bank are
now interpreted relative to the FSR2 register
the addition of several new instructions, notable for manipulating the FSR registers.
These changes were primarily aimed at improving the efficiency of a data stack
implementation. If FSR2 is used either as the stack pointer or frame pointer, stack items may
be easily indexedallowing more efficient re-entrant code. Microchip's MPLAB C18 C
compiler chooses to use FSR2 as a frame pointer.
barrel shifting
bit reversal
dsPICs can be programmed in C using Microchip's XC16 compiler (formerly called C30)
which is a variant of GCC.
Instruction ROM is 24 bits wide. Software can access ROM in 16-bit words, where even
words hold the least significant 16 bits of each instruction, and odd words hold the most
significant 8 bits. The high half of odd words reads as zero. The program counter is 23 bits
wide, but the least significant bit is always 0, so there are 22 modifiable bits.
Instructions come in 2 main varieties. One is like the classic PIC instructions, with an
operation between W0 and a value in a specified f register (i.e. the first 8K of RAM), and a
destination select bit selecting which is updated with the result. The W registers are memorymapped. so the f operand may be any W register,
Page 30 of 47
f) PIC32MX
In November 2007, Microchip introduced the new PIC32MX family of 32-bit
microcontrollers. The initial device line-up is based on the industry standard MIPS32 M4K
Core. The device can be programmed using the Microchip MPLAB C Compiler for PIC32
MCUs, a variant of the GCC compiler. The first 18 models currently in production
(PIC32MX3xx and PIC32MX4xx) are pin to pin compatible and share the same peripherals
set with the PIC24FxxGA0xx family of (16-bit) devices allowing the use of common
libraries, software and hardware tools. Today starting at 28 pin in small QFN packages up to
high performance devices with Ethernet, CAN and USB OTG, full family range of mid-range
32-bit microcontrollers are available.
The PIC32 architecture brings a number of new features to Microchip portfolio, including:
Real-time trace
Page 31 of 47
Chapter 3
Development Software
a) Boot loading:
Many of the higher end flash based PICs can also self-program (write to their own
program memory), a process known as bootloading. Demo boards are available
with a small bootloader factory programmed that can be used to load user programs
over an interface such as RS-232 or USB, thus obviating the need for a programmer
device.
Alternatively there is bootloader firmware available that the user can load onto the
PIC using ICSP. After programming the bootloader onto the PIC, the user can then
reprogram the device using RS232 or USB, in conjunction with specialized
computer software.
The advantages of a bootloader over ICSP is faster programming speeds,
immediate program execution following programming, and the ability to both
debug and program using the same cable.
Page 32 of 47
b) Third party:
There are many programmers for PIC microcontrollers, ranging from the extremely
simple designs which rely on ICSP to allow direct download of code from a host
computer, to intelligent programmers that can verify the device at several supply
voltages. Many of these complex programmers use a pre-programmed PIC
themselves to send the programming commands to the PIC that is to be
programmed. The intelligent type of programmer is needed to program earlier PIC
models (mostly EPROM type) which do not support in-circuit programming.
Third party programmers range from plans to build your own, to self-assembly kits
and fully tested ready-to-go units. Some are simple designs which require a PC to
do the low-level programming signalling (these typically connect to
the serial or parallel port and consist of a few simple components), while others
have the programming logic built into them (these typically use a serial or USB
connection, are usually faster, and are often built using PICs themselves for
control).
3.2) Debugging:
a) In-circuit debugging:
All newer PIC devices feature an ICD (in-circuit debugging) interface, built into
the CPU core, that allows for interactive debugging of the program in conjunction
with MPLAB IDE.MPLAB ICD and MPLAB REAL ICE debuggers can
communicate with this interface using the ICSP interface.
This debugging system comes at a price however, namely limited breakpoint count
(1 on older devices, 3 on newer devices), loss of some I/O (with the exception of
some surface mount 44-pin PICs which have dedicated lines for debugging) and
loss of some on-chip features.
b) In-circuit emulators:
Microchip offers three full in-circuit emulators: the MPLAB ICE2000 (parallel
interface, a USB converter is available); the newer MPLAB ICE4000 (USB 2.0
connection); and most recently, the REAL ICE (USB 2.0 connection). All such
Page 33 of 47
tools are typically used in conjunction with MPLAB IDE for source-level
interactive debugging of code running on the target.
Page 34 of 47
a) Features:
mikroC PRO for PIC allows you to quickly develop and deploy complex
applications:
Write your C source code using the built-in Code Editor (Code and
Parameter Assistants, Code Folding, Syntax Highlighting, Auto Correct,
Code Templates, and more.)
Use included mikroC PRO for PIC libraries to dramatically speed up the
development: data acquisition, memory, displays, conversions,
communication etc.
Monitor your program structure, variables, and functions in the Code
Explorer.
Generate commented, human-readable assembly, and standard HEX
compatible with all programmers.
Use the integrated mikroICD (In-Circuit Debugger) Real-Time debugging
tool to monitor program execution on the hardware level.
Inspect
program flow and debug executable logic with the
integrated Software Simulator.
Generate COFF (Common Object File Format) file for software and
hardware debugging under Microchip's MPLAB software.
Active Comments enable you to make your comments alive and interactive.
Get detailed reports and graphs: RAM and ROM map, code statistics,
assembly listing, calling tree, and more.
mikroC PRO for PIC provides plenty of examples to expand, develop, and
use as building bricks in your projects. Copy them entirely if you deem fit
thats why we included them with the compiler.
Page 35 of 47
Chapter 4
Pulse Width Modulation (PWM)
4.1 Introduction:
Pulse-width modulation (PWM), or pulse-duration modulation (PDM), is a
technique used to encode a message into a pulsing signal. It is a type of modulation.
Although this modulation technique can be used to encode information for
transmission, its main use is to allow the control of the power supplied to electrical
devices, especially to inertial loads such as motors. In addition, PWM is one of the
two principal algorithms used in photovoltaic solar battery chargers, the other
being MPPT.
The average value of voltage (and current) fed to the load is controlled by turning
the switch between supply and load on and off at a fast rate. The longer the switch
is on compared to the off periods, the higher the total power supplied to the load.
The PWM switching frequency has to be much higher than what would affect the
load (the device that uses the power), which is to say that the resultant waveform
perceived by the load must be as smooth as possible. Typically switching has to be
done several times a minute in an electric stove, 120 Hz in a lamp dimmer, from
few kilohertz (kHz) to tens of kHz for a motor drive and well into the tens or
hundreds of kHz in audio amplifiers and computer power supplies.
The term duty cycle describes the proportion of 'on' time to the regular interval or
'period' of time; a low duty cycle corresponds to low power, because the power is
off for most of the time. Duty cycle is expressed in percent, 100% being fully on.
The main advantage of PWM is that power loss in the switching devices is very
low. When a switch is off there is practically no current, and when it is on and
power is being transferred to the load, there is almost no voltage drop across the
switch. Power loss, being the product of voltage and current, is thus in both cases
close to zero. PWM also works well with digital controls, which, because of their
on/off nature, can easily set the needed duty cycle.
Page 36 of 47
applied to the load, and the off-time is the period during which that supply is
switched off. Given a sufficient bandwidth, any analog value can be encoded with
PWM.
Figure 4.1 shows three different PWM signals. Figure 4a shows a PWM output at a
10% duty cycle. That is, the signal is on for 10% of the period and off the other
90%. Figures 4b and 4c show PWM outputs at 50% and 90% duty cycles,
respectively. These three PWM outputs encode three different analog signal values,
at 10%, 50%, and 90% of the full strength. If, for example, the supply is 9V and the
duty cycle is 10%, a 0.9V analog signal results.
Page 38 of 47
Page 39 of 47
In Compare mode, if enabled by software, the timer TMR1 reset may occur on
match. Besides, the CCP1 module can generate PWM signals of varying frequency
and duty cycle.
Bits of the CCP1CON register controls the CCP1 module.
Another example, common in practice, is the usage of PWM signals in the circuit
for generating signals of arbitrary waveforms, for example, sinusoidal waveform.
Page 40 of 47
Page 41 of 47
The figure below shows the block diagram of the CCP1 module setup in PWM
mode. In order to generate a pulse of arbitrary form on its output pin, it is necessary
to determine only two values- pulse frequency and duration.
b) PWM Period:
The output pulse period (T) is specified by the PR2 register of the timer TMR2.
The PWM period can be calculated using the following equation:
PWM Period(T) = (PR2 +1) * 4Tosc * TMR2 Prescale Value
Page 42 of 47
If the PWM Period (T) is known then, it is easy to determine the signal frequency F
because these two values are related by equation F=1/T.
d) PWM Resolution
PWM signal is nothing more than the pulse sequence with varying duty cycle. For
one specified frequency (number of pulses per second), there is a limited number of
duty cycle combinations. This number is called resolution measured by bits. For
example, a 10-bit resolution will result in 1024 discrete duty cycles, whereas an 8bit resolution will result in 256 discrete duty cycles etc. In relation to this
microcontroller, the resolution is specified by the PR2 register. The maximal value
is obtained by writing number FFh.
Page 44 of 47
Fig 4.7: Two PWM waves having PWM period as 1S and 16S respectively.
Page 45 of 47
Conclusion
This project is compiled under the guidance of Mr. Samaresh Bhattacharjee, Engineer
D ARIES. While compiling I learned about TIMING SIGNAL GENERATION OF
CONTROL CARD.
While compiling I learned about "PIC Microcontroller and its programming
using mikroC Pro for PIC. I also learned about various PWM techniques and its use in producing
signals having different pulse width.
I also learned how to stimulate different circuits by using PROTEUS and also to
debug the code into a microcontroller using MPLAB ICD.
Page 46 of 47
References
1. http://www.mikroe.com/download/eng/documents/compilers/mikroc/pro/pic/help/introdu
ction_to_mikroc_pro_for_pic.htm
2. http://www.embedded.com/electronics-blogs/beginner-s-corner/4023833/Introduction-toPulse-Width-Modulation
3. http://www.mikroe.com/chapters/view/6/chapter-5-ccp-modules/
4. https://www.google.com
5. https:// www.wikipedia.com
6. https://electrosome.com/category/tutorials/pic- microcontroller/
Page 47 of 47