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.

[SOLVED] PIC 16f877a pwm varying by using PC serial communication data

Status
Not open for further replies.

ragav4456

Full Member level 4
Joined
Aug 1, 2012
Messages
228
Helped
19
Reputation
38
Reaction score
17
Trophy points
1,308
Activity points
2,568
How to calculate CCPR1L in varying data?

and also,
CCPR1L contains the upper 8 bits of the 10 bit Duty Cycle value CCP1CON<5:4> contain the lower 2 bits
How to divide the 8 bits and 2 bits in calculation?

- - - Updated - - -

I have formula and i got a pwm in standard data but i am confused,about automatic calculation in program?

I am using Hi-tech c compiler.
 

CCP1CON<5:4> are the LSBs. You may think of them as "decimal places". Unless that much accuracy is required, you may avoid the use of CCP1CON<5:4> and only work with the 8-bits of CCPR1L.

What is the varying data that you receive? A better description of the data would help.

You have to remember that the duty cycle is a percentage of the Period Register (PR2) and the calculation must take this into account.

Hope this helps.
Tahmid.
 

ok.

Varying data is 0 to FF; How can change data to PR2 value (0 to 24)?

- - - Updated - - -

I need sample code for the calculation?
Check the following calculation is correct or not?

Example:
duty_cycle=data; //receiving data;
PWM_frequency=0.000005;
Tosc=0.00000005;
duty_cycle2=duty_cycle/PWM_frequency;
value=(duty_cycle2*Tosc)/tmr2_prescaler;
CCPR1L=value>>2;

Its correct or not?
 

i need to vary pwm 0 to 255 by using com port. PR2=0x3F: // 8bit resolution

//CCPxCON calculation
Value=ucdata;
Value=Value<<4;
CCP8CON= 0b00001100 | Value;

//CCPRxL calculation
data=ucdata/4; // changing 128 bit resolution
CCPR8L=data;

this calculation is changing PWM only vary 0 to 128 only.

how to vary the pwm (0 to 255) by using this calculation?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top