Author Topic: Arduino uno Bit overflow... need help solving this  (Read 2726 times)

0 Members and 1 Guest are viewing this topic.

MikeJuszkie

  • Guest
Arduino uno Bit overflow... need help solving this
« on: July 31, 2012, 11:33:14 pm »
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.

Quote
        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.




 

MikeJuszkie

  • Guest
Re: Arduino uno Bit overflow... need help solving this
« Reply #1 on: July 31, 2012, 11:53:03 pm »
I actually just fixed the issue. I just needed to add a  .00 to the end of the numbers I was using.
 

MikeJuszkie

  • Guest
Re: Arduino uno Bit overflow... need help solving this
« Reply #2 on: July 31, 2012, 11:53:40 pm »
Quote
 
        int Vout = analogRead(pinVread);
        int Cout = analogRead(pinCread);
       
        float Vset = (voltage / 25.5);
        float Cset = current * (1000.00 / 255.00);
       
        float vout = (Vout / 102.3);
        float cout = Cout * (1000.00/ 1023.00);
       
 

Offline Chet T16

  • Frequent Contributor
  • **
  • Posts: 537
  • Country: ie
    • Retro-Renault
Re: Arduino uno Bit overflow... need help solving this
« Reply #3 on: July 31, 2012, 11:55:02 pm »
Is it not because you're using integer division? Changing it to 1000.0 will force it to using floating point?

Or am I not reading the question right?
Chet
Paid Electron Wrestler
 

Offline Chet T16

  • Frequent Contributor
  • **
  • Posts: 537
  • Country: ie
    • Retro-Renault
Re: Arduino uno Bit overflow... need help solving this
« Reply #4 on: July 31, 2012, 11:56:10 pm »
Damn you tapatalk and your non notification of replies :p
Chet
Paid Electron Wrestler
 

Offline darrylp

  • Regular Contributor
  • *
  • Posts: 127
  • Country: gb
Re: Arduino uno Bit overflow... need help solving this
« Reply #5 on: August 01, 2012, 12:20:52 am »
the MAP function will scale values from one range to another.

its documented on the arduino.cc web page.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf