Académique Documents
Professionnel Documents
Culture Documents
PR2
The PR2 register affects the PWM frequency/period.
The value to use for the PR2 register is calculated
using Equation A-6.
CCPR1L:CCP1CON<5:4>
The PWM duty cycle has a full resolution of ten bits.
Since all registers on PIC16F684 are 8 bits wide, the
ten bits are spread over two registers. CCPR1L
contains the upper eight bits and CCP1CON<5:4>
contains the lower two bits. The 10-bit value for
CCPR1L:CCP1CON<5:4> is calculated using
Equation A-7.
CCP1CON
In addition to storing the lower two bits of the 10-bit
PWM duty cycle, CCP1CON is used to set up the
ECCP in PWM mode using bits CCP1CON<3:0>. It can
also change the motor direction using bits
CCP1CON<7:6>. When setting up the ECCP in PWM
mode, there are four possible configurations. These
configurations accommodate H-bridges with
MOSFETS that are active-high, active-low or a
combination of both active-high and active-low. Motor
direction can be changed in hardware by configuring
bits CCP1CON<7:6> to be ‘01’ for forward or ‘11’ for
reverse. The PIC16F684 ECCP hardware switches
channels for activating and modulating the appropriate
MOSFET drivers in the H-bridge.
T2CON
The T2CON register is used for setting up the Timer2
prescaler and turning on Timer2. The Timer2 prescaler
is contained in bits T2CON<1:0> and is used in
determining the PWM frequency, duty cycle and
resolution. Timer2 must be turned on by setting bit
T2CON<2> before the PWM signal starts. An algorithm
that calculates the Timer2 prescaler and PR2 values for
PWM frequencies is shown in Figure B-1.
FET QA QC FET
PIC16F684 Driver Driver
Logic ‘1’
P1A
Logic ‘0’
P1C QD
QB
P1D
CCP1CON<3:0> = 1100
CCP1CON<7:6> = 01
FET QA QC FET
PIC16F684
Driver Driver
Logic ‘0’
P1A
BDC
P1B
FET I FET
Driver Driver
Logic ‘1’
P1C QD
QB
Logic ‘0’
P1D
CCP1CON<3:0> = 1100
CCP1CON<7:6> = 11
FET QA QC FET
PIC16F684
Driver Driver
Logic ‘1’
P1A
Logic ‘0’
P1C QD
QB
Logic ‘0’
P1D
CCP1CON<3:0> = 1100
CCP1CON<7:6> = 01
FET QA QC FET
PIC16F684
Driver Driver
Logic ‘1’
P1A
I
Logic ‘0’ BDC
P1B
FET FET
Driver Driver
Logic ‘0’
P1C QD
QB
VACTUAL
0.1 Current Sensing
Resistor
P1D
CCP1CON<3:0> = 1100
CCP1CON<7:6> = 01
Windows® GUI
PIC16F684
Sensorless
BDC RPM and
Motor Current
Measurements
Physical Process
REFERENCES
1. PIC16F684 14-Pin, Flash-Based 8-Bit CMOS
Microcontrollers with nanoWatt Technology
Data Sheet (DS41202):
www.microchip.com/PIC16F684
2. MCP6S21/2/6/8 Single-Ended, Rail-to-Rail I/O,
Low Gain PGA Data Sheet (DS21117):
www.microchip.com/MCP6S26
3. MPLAB® IDE: www.microchip.com/archives
1
Frequency = ------------------
Period
DC
V BDC = V DD ------------------
Period
Period
PR2 = ----------------------------------------------------------------------- – 1
4 T OSC TMR2Prescaler
DC
CCPR1L:CCP1CON<5:4> = --------------------------------------------------------------
T OSC TMR2Prescaler
ADRESH:ADRESL
RPM = 1 – ------------------------------------------------ RPM MAX
1024
2 2
P = I MAX R = 3 0.1 = 0.9W
X V GAINMAX
2 = --------------------------- 1024 , where X is bits of resolution
V DD
V --------------------------- 1024
GAINMAX 4.8
log ------- 1024
V DD 5.0
X = log --------------------------------------------------- = --------------------------------------- = 9.94 bits
log 2 log 2
ADRESH:ADRESL
V GAIN = ------------------------------------------------ V GAINMAX
X
2
V GAIN
V ACTUAL = ----------------
Gain
V ACTUAL
I = -----------------------
R
FIGURE B-1: CALCULATING TIMER2 PRESCALER AND PR2 ALGORITHM GIVEN A PWM
FREQUENCY
Start
i=0
PR2 = 1000
Prescaler = 1
No
Is PR2 > 255? Done
Yes
No
Is Prescaler > 16? Prescaler = 2i
Yes
No
i=i+2
Start
Start
Initialize
PIC16F684
Measure PWM
Period
Is command No
received?
All samples Yes Average
taken? Samples
Yes
No
Is command No
Done
Synchronize on valid?
PWM High-Edge
Yes
Process
Delay Command
Is A/D
conversion No
complete?
Yes
Log Sample
Increment Delay
Note 1: The <command> is lower case. FW Command: Requests the PIC16F684 firmware
2: The <response> is the upper case of version.
the <command>. PC Command: (f)
3: If there is no <data> to be sent, the PIC16F684 Response: [F1.0]
<command end> can be the next
character sent. Motor Control Command: Loads data into
CCP1CON<7:6>.
4: All <data> is sent in Hex format.
PC Command: (g3)
5: All <data> is sent Most Significant Byte
first. PIC16F684 Response: [G]
6: Invalid commands are ignored and RPM Measurement Command: Requests a RPM
responded with a [?]. measurement.
7: Invalid <command start> is ignored PC Command: (h)
and not responded to. PIC16F684 Response: [H3FF]
8: Commands and responses are currently
set to ten characters each, this can be Current Measurement Command: Requests a
adjusted in the source code on both the Current measurement.
Windows software and PIC16F684 PC Command: (i)
firmware.
PIC16F684 Response: [I2BC]
PIC16F684
• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
• Microchip is willing to work with the customer who is concerned about the integrity of their code.
• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.