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.

PIC16f877 PWM doubt in resolution

Status
Not open for further replies.

ragav4456

Full Member level 4
Full Member level 4
Joined
Aug 1, 2012
Messages
228
Helped
19
Reputation
38
Reaction score
17
Trophy points
1,308
Visit site
Activity points
2,568
Hi friends

I need to vary pwm duty cycle in 0 to 255(50khz). but 50khz resolution is 8.64 bits(0 to 398).

i need scale the value 0 to 398 into 0 to 255? How to scale the values?

input data 255=398/1.56 ;

correct or not? how to use float value?
____________________
Hitech C compiler
 

You'll preferably want to reduce the problem to a multiply with an integer factor and a right shift. E.g x*164 >> 8
 

    V

    Points: 2
    Helpful Answer Positive Rating
could you please check the format

CCPR1L= (x*164)>>8
Value=x%4;
Value=Value<<4;
CCP1CON= 0b00001100 | Value;

164 means?
x=input data(0 to 255)? correct or not?
 

x must have an unsigned int16 type, otherwise you'll get an overflow in the multiplication.

164 means?
x=input data(0 to 255)? correct or not?
The input value x is assumed with a range of 0 to 398, as asked in your post. I suggest to check the method yourself by putting in different values.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top