May 28, 2013 #1 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 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
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
May 28, 2013 #2 FvM Super Moderator Staff member Joined Jan 22, 2008 Messages 52,485 Helped 14,756 Reputation 29,794 Reaction score 14,121 Trophy points 1,393 Location Bochum, Germany Activity points 298,363 You'll preferably want to reduce the problem to a multiply with an integer factor and a right shift. E.g x*164 >> 8
You'll preferably want to reduce the problem to a multiply with an integer factor and a right shift. E.g x*164 >> 8
May 29, 2013 #3 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 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?
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?
May 29, 2013 #4 FvM Super Moderator Staff member Joined Jan 22, 2008 Messages 52,485 Helped 14,756 Reputation 29,794 Reaction score 14,121 Trophy points 1,393 Location Bochum, Germany Activity points 298,363 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? Click to expand... 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.
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? Click to expand... 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.