Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Noob question with PWM

Status
Not open for further replies.

kasamiko

Full Member level 3
Full Member level 3
Joined
May 23, 2004
Messages
154
Helped
16
Reputation
32
Reaction score
18
Trophy points
1,298
Location
Philippines
Activity points
1,121
hi,

can somebody tells me how this guy got the value of

CCPR1L = 25 and
CCP1CON = 12

here's part of the code:

@ DEVICE HS_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF
DEFINE OSC 20 ' We're using a 20MHz crystal
CCPR1L = 25 ' 25=20% PWM Duty-Cycle
PR2 = 124 ' Set PWM for ~40KHz
T2CON = 4 ' Timer2 ON + 1:1 prescale
TRISB=%00000100 ' Set PortB TRIS register
PORTB=%00000011 ' LEDs off, pulsout pins set for logic 1 pulses

....

Begin: ' Eats up 1 line, but we need it
CCP1CON = 12 ' Turn hardware PWM On
LOW PortB.0 ' Turn on left IR LED
PAUSE 10 ' Wait 10mS to allow IR detector output to change
Hits[0]=IR_Output ' Read detector output into Bit0
Portb=%00000001 ' Turn off left IR LED, turn on right IR LED
PAUSE 10 ' Wait 10mS to allow IR detector output to change
Hits[1]=IR_Output ' Read detector output into Bit1
HIGH PortB.1 ' Turn off right IR LED
CCP1CON = 0 ' Turn hardware PWM Off


I tried using the online PWM calculator which can be found here:

PIC PWM Calculator & Code Generator

but got CCPR1L and CCP1CON values as follows:

CCPR1L = 0b00011000 or 24 decimal
CCP1CON = 0b00111100 or 60 decimal

which of them are correct?

TIA



`

---------- Post added at 11:02 ---------- Previous post was at 10:19 ----------

bit 7-6 Unimplemented: Read as '0'
bit 5-4 CCP1X:CCP1Y: PWM Least Significant bits
Capture Mode: Unused
Compare Mode: Unused
PWM Mode: These bits are the two LSbs of the PWM duty cycle. The eight MSbs are found in
CCPRxL.
bit 3-0 CCP1M3:CCP1M0: CCPx Mode Select bits
0000 = Capture/Compare/PWM off (resets CCP1 module)
0100 = Capture mode, every falling edge
0101 = Capture mode, every rising edge
0110 = Capture mode, every 4th rising edge
0111 = Capture mode, every 16th rising edge
1000 = Compare mode, set output on match (CCP1IF bit is set)
1001 = Compare mode, clear output on match (CCP1IF bit is set)
1010 = Compare mode, generate software interrupt on match (CCP1IF bit is set, CCP1 pin is
unaffected)
1011 = Compare mode, trigger special event (CCP1IF bit is set; CCP1 resets TMR1
11xx = PWM mode


11xx = PWM mode

Well I think this is constant for CCP1CON to be 12 for PWM mode?
 

first check datasheet for formula

given things are:
Fosc=20MHz F=40KHz, DC=20% TMR2 prescaler =1

PR2=[RWM period/4*Tosc]-1 =[25us/.02us]-1=124

NOW

CCPR1L:CCP1CON <4:5>= PWM DC /Tosc * TMR2 prescaler =.2*25us/.05us =100d =1100100

so CCP1CON<4:5>=0 and CCPR1L=11001 =25d

so it gives CCP1CON=0x0C

hope it will help u
 
Last edited:
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top