I’m a CSI & WIN student at Fleming College and this is a blog.

Test: Pulse-Width Modulation with PIC18F458 microcontroller

Configuration bits for CCP1CON and T2CON registers

0
0
0
0
1 (This bit is set to 1 for PWM MODE)
1
0
0

0000 1100 = h0C

^CCP1CON = 0C

0
1 (1:16 post-scale)
1
1
1
0
0
0

0111 1000 = h78

^T2CON = 78

Calculating the PWM Period

Known values: 30kHz Fpwm 20 MHz Fosc

PWM Period = [(PR2)+1] 4 Tosc* (TMR2 prescale)

PWM Period = [(PR2)+1] 4 20MHZ* ( 1 )

PR2 = (PWM Period / (4* 20MHz * 1)) -1

PR2 = (XTAL_FREQ_/ (PWM_freq4TMR2 pre))

PR2 = (20MHz / (30kHz * 4 * 1))

PR2 = 20,000,000 / 120,000

PR2 = 166.66666

PR2 = A7

CCPR1L:CCP1CON < 5:4 > = PR2+1(167) x duty cycle/100

Duty cycle twenty-five percent is 41 (0x2)

Duty cycle for fifty percent is 84 (0x54)

Duty cycle for seventy-five percent is 123 (0x7B)

Duty cycle for one hundred percent is 166 (0xA7)

Leave a Reply

Your email address will not be published. Required fields are marked *

css.php