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.

PIC12F683 UART_Soft problems

Status
Not open for further replies.
T2CON = 0x04; // prescaler + turn on TMR2;
PR2 = 0x31; // freq 0x31 for 40kHz
CCPR1L = 0x17; // set low time 0x17 for 40kHz
CCP1CON = 0x30; // duty lowest bits + PWM mode (PWM off)

If i want to set frequency 56kHz so what will be change in above values and where i find CCPR1L register in
datasheet?
 

You haven't stated the oscillator frequency (Fosc) of the PIC12F683, however from the values you have supplied above the Fosc appears to be 8MHz.

Reference: PIC12F683 Datasheet, Section: 11.3.1 PWM PERIOD, Page: 79

PWM Period = [(PR2) + 1] • 4 • TOSC • (TMR2 Prescale Value)

Note: TOSC = 1/FOSC

Rearrange:

PR2 = Fosc/(Fpwm * 4 *(TMR2 Prescale Value) ) - 1

Pulse Width Modulation (PWM) Calculations for PIC Micros


Not all PWM frequencies (Fpwm) are viable for a given device oscillator frequency (Fosc).

The closest obtainable PWM frequency to the desired 56kHz for the given 8MHz maybe 55.5556kHz.

Which requires a PR2 = 35/0x23 for TMR2 prescaler of 1 and 50% duty cycle CCPR1L = 17/0x11, CCP1CON = 60/0x3C

Or requires a PR2 = 8/0x08 for TMR2 prescaler of 4 and 50% duty cycle CCPR1L = 4, CCP1CON = 28/0x1C

Code:
/*
 * PWM registers configuration
 * Fosc = 8000000 Hz
 * Fpwm = 55555.56 Hz (Requested : 56000 Hz)
 * Duty Cycle = 50 %
 * Resolution is 7 bits
 * Prescaler is 4
 * 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 = 0b00001000 ;
T2CON = 0b00000101 ;
CCPR1L = 0b00000100 ;
CCP1CON = 0b00011100 ;


You can also use the following calculator for PWM module values:

PIC PWM Calculator & Code Generator



The CCPR1L register is discussed throughout Section 11.0 CAPTURE/COMPARE/PWM(CCP) MODULE, beginning on Page 75.

Is there something in particular you wish to know concerning the CCPR1L Register?



BigDog
 
Please let me know what is problem in my attached ADC_PWM code it is not working properly.
 

Attachments

  • PWM.gif
    PWM.gif
    63.9 KB · Views: 91
  • PWM_Code.txt
    231 bytes · Views: 77

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top