So confused - floating point math not working

This forum handles questions and discussions concerning Microchip’s 8-bit compilers, assemblers, linkers and related tools.

So confused - floating point math not working

Postby ATX_PICuser » Mon Nov 10, 2014 8:19 pm

I am seriously confused. I am working on a project that requires the use of a linearization equation and I can't get the equation to work properly because any number less than 1 is converted to a zero even when using data type of float.

In a nutshell this is what I have:

float corrected_pwm;
unsigned int a = 35;
unsigned int b = 50

corrected_pwm = 6 * (a/b);

The variable "corrected_pwm" always comes back as zero because the division step (a/b) is being rounded to zero.

Can someone explain to me how I should be doing this?
ATX_PICuser
 
Posts: 1
Joined: Mon Nov 10, 2014 8:04 pm
PIC experience: Professional 1+ years with MCHP products

Re: So confused - floating point math not working

Postby ric » Tue Nov 11, 2014 2:37 am

Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products


Return to MPLAB XC8

Who is online

Users browsing this forum: No registered users and 4 guests

cron