I have a 10 bit ADC value and I am trying to multiply/divide it and then display the resulting float. The float displays 0.00 and doesn't change, this has something to do with the calculations. perhaps it is because I am trying to multiply/divide a 10 bit binary number and I need to break it down into a decimal?...But I have declared it as an integer so I would have thought the calculations would be fine and the result would be e.g 7.65 and then that is broken into a char ready to be displayed.
Here is the relevant code;
Here is the relevant code;
C:
unsigned int ADC_result;
float ADC_result_new;
float Power_result_new;
float Power_result;
unsigned char temp[6];
unsigned char temp_p[6];
void main (void)
{
while(1)
{
ADCON0bits.GO=1; //Sets Go_Done bit
while(ADCON0bits.GO==1); //Waits for conversion to finish
__delay_us(10);
ADC_result=ADRESL+(ADRESH*256); //gets 10 bit result
//ADC_result=0xAF; //Test purposes COMMENT OUT BEFORE BUILD.
Power_result=(ADC_result*(23/1023)); //*(5/1023))/5)*current)*230)/1000); changes ADC value to power in Watt
lcd_cmd(0x80); //Start of Line 1
lcd_WriteStr("Input V = ");
ADC_result_new =((ADC_result/1023)*5); //changes digital to analog
//At this point both ADC/Power are ready to be displayed, both floats.
sprintf(temp, "%4.2f", ADC_result_new);
lcd_WriteStr(temp); //writes the value (0-5.0V)
lcd_cmd(0xC0); //Starts Line 2
lcd_WriteStr("Power W = ");
sprintf(temp_p, "%4.2f", Power_result); //Turns float into a ASCII char that can be displayed
lcd_WriteStr(temp_p); //write it
}//while
} //main
Cheers
JSwale