This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Error in calculations

Hi guys

I'm having trouble to get this code works. I want to multiply and divide and I use the following code:

valor1=ADC0;
valor1=valor1*2;
valor1=valor1*12;
valor1=valor1/5;
valor1=valor1/4095;

with valor1 as float but the variable valor1 never is the right number. what is wrong?? can be another way to do this multiplication:

valor1*2*2.42/4095

Thanks

Parents
  • "When I read the adc I read 925 and 924 values but when I don't put brakpoints the calculation is bad."

    Erik's point is: how do you know that it's the calculation that's bad?
    How do you know that you're not just reading a bad value from the ADC?

    As Erik said, noise could cause this.
    You could also have a timing problem, such that your ADC reading only works when you delay the code with a breakpoint!

    You might also have a faulty interrupt that is corrupting stuff...

    You need to save the actual value read from the ADC, and include that in your diagnostic printout.

Reply
  • "When I read the adc I read 925 and 924 values but when I don't put brakpoints the calculation is bad."

    Erik's point is: how do you know that it's the calculation that's bad?
    How do you know that you're not just reading a bad value from the ADC?

    As Erik said, noise could cause this.
    You could also have a timing problem, such that your ADC reading only works when you delay the code with a breakpoint!

    You might also have a faulty interrupt that is corrupting stuff...

    You need to save the actual value read from the ADC, and include that in your diagnostic printout.

Children