I am currently working on my own power supply that is controlled by an arduino. I am having issues with bit overflow, for current 5 volts is going to represent 1 Amp. The 5 volts in pwm is represented with a value of 255 but I would like to convert this value to 1000 mA. Everything I have tried has failed and I know the issue is that there is a loss of data when doing the math due to bit overflow. Can somebody please help.
here is the section of code that I am dealing with that I am having the problems with.
int Vout = analogRead(pinVread);
int Cout = analogRead(pinCread);
float Vset = (voltage / 25.5);
float Cset = current * (1000 / 255);
float vout = (Vout / 102.3);
float cout = Cout * (1000/ 1023);
The variables (voltage) and (current) are used much earlier in the program as the PWM outputs.
whenever it goes to display the value, instead of displaying a max of 1000 mA it shows a max of 765. and if you do the math, you will see that am losing everything after the decimal place for the "(1000/255)"
In the case of the second half those values are read from the analog inputs which are 10 bit not 8 bit. That one will not even show that value at all.