2013-10-18 07:49 PM
2013-10-18 08:17 PM
%f not %d
Should have 3 decimal places, so %5.3f ?float yourVoltage = (float)ADCResult * voltsPerBit;2013-10-18 08:26 PM
Thanks for the reply.
Variables window shows: ADCResult 4026 maxAdcBits 4095.0 maxVolts 3.0 voltsPerBit 7.3260075E-4 Made the changes but the semi-hosting still shows output as: PC1 Value is: 4027 PC1 Volts is: : 40272013-10-18 08:30 PM
Most likely a half-assed printf() implementation on the CooCox side, try converting to millivolts, as an integer
printf(''PC1 MilliVolts is: %d \n\n'', (int)(yourVoltage * 1000.0f) );
2013-10-18 08:37 PM
Thank-you, that works:
C1 Value is: 3413 PC1 Volts is: : 3413 PC1 MilliVolts is: 2500 3413/4095 * 3 = 2.5003663 Is there anyway to take that milli value and turn it to decimal?2013-10-18 08:47 PM
For positive values
int mv = (int)(yourVoltage * 1000.0f);int x = mv / 1000;int y = mv % 1000;printf(''%d.%03d V\n'',x,y); // assuming printf() implementation supports leading zero properly2013-10-18 08:50 PM
Works:
PC1 Value is: 3414 PC1 MilliVolts is: 2501 PC1 Voltage is: 2.501 V thanks a bunch.2013-10-18 09:06 PM
Assuming that the printf() library is a light-weight integer only version, you might want to see if there is some option to include one that supports floats. Mind you it might have a significantly larger memory footprint, and have more features that you actually want, need, or might use.