PIC PWM Calculator
PIC PWM Calculator
P16 FAMILY :
PIC16F627 PIC16F627A PIC16F628 PIC16F628A PIC16F648A PIC16F684 PIC16F690 PIC16F716 PIC16F72 PIC16F73 PIC16F737 PIC16F74 PIC16F747 PIC16F76 PIC16F767 PIC16F77 PIC16F777 PIC16F785 PIC16F818 PIC16F819 PIC16F87 PIC16F870 PIC16F871 PIC16F872 PIC16F873 PIC16F873A PIC16F874 PIC16F874A PIC16F876 PIC16F876A PIC16F877 PIC16F877A PIC16F88 PIC16F913 PIC16F914 PIC16F916 PIC16F917 PIC16F946
P18 FAMILY :
This should work with all P18 family devices
My PIC is clocked at :
Herz My PWM frequency must be : Leave blank to see all solutions (it may take a few seconds, no code will be generated) My PWM duty cycle must be : % From 0 to 100 %
PWM
(Bits) 6 6 6 6 1 0b00011001 0b00000100 0b00001100 0b00111100 1 0b00011000 0b00000100 0b00001100 0b00011100 4 0b00000101 0b00000101 0b00000010 0b00111100 1 0b00010111 0b00000100 0b00001011 0b00111100
C Source code example for highlighted frequency : /* * PWM registers configuration * Fosc = 4000000 Hz * Fpwm = 40000.00 Hz (Requested : 40000 Hz) * Duty Cycle = 50 % * Resolution is 6 bits * Prescaler is 1 * Ensure that your PWM pin is configured as digital output * see more details on http://www.micro-examples.com/ * this source code is provided 'as is', * use it at your own risks */ PR2 = 0b00011000 ; T2CON = 0b00000100 ; CCPR1L = 0b00001100 ; CCP1CON = 0b00011100 ;
/* * * * * * * * * * * * * * * *
this example smoothly blinks LEDs on RC1 and RC2 alternatvely using PIC CCP module configured as PWM output source code example for mikroC feel free to use this code at your own risks target : PIC16F877A, 8 Mhz crystal HS clock, no watchdog. easyPIC4 settings : LEDs on PORTC enabled Author : Bruno Gavand, September 2007 see more details on http://www.micro-examples.com/
*************************************************************************** ****
/* * configure CCP module as 4000 Hz PWM output */ PR2 = 0b01111100 ; T2CON = 0b00000101 ; CCP1CON = 0b00001100 ; CCP2CON = 0b00111100 ; for(;;) // forever { /* * PWM resolution is 10 bits * don't use last 2 less significant bits CCPxCON, * so only CCPRxL have to be touched to change duty cycle */ for(dc = 0 ; dc < 128 ; dc++) { CCPR1L = dc ; CCPR2L = 128 - dc ; Delay_ms(10) ; } for(dc = 127 ; dc > 0 ; dc--) { CCPR1L = dc ; CCPR2L = 128 - dc ; Delay_ms(10) ; } }