Forum: Compiler & IDEs Funktioniert sowas mit dem CubeMX oder GCC?


von Max M. (Gast)


Lesenswert?

adc_value is real/float


This doesn't work
1
  adc_value :=(ADC1_Get_Sample(1) / 4096)*3.3;

OR this
1
Floattostr(((ADC1_Get_Sample(1) / 4096)*3.3),adc_value_str);

This works
1
 adc_value := ADC1_Get_Sample(1);
2
  adc_value :=(adc_value / 4096)*3.3;

Why, dos the first one always show 0?

von Gustl B. (gustl_b)


Lesenswert?

Schreib mal 4096.0 damit das eine float Division wird.

von Tilo (Gast)


Lesenswert?

Is ADC1_Get_Sample(1) an inteher and smaller than 4096?
When yes the devision is done as integer.
What types are you using?

von Max M. (Gast)


Lesenswert?

Ahhhhh, das wars:-)
Danke

Gustl B. schrieb:
> Schreib mal 4096.0 damit das eine float Division wird.

von J. S. (jojos)


Lesenswert?

Das ist aber ein double, 4096.0f ist float.

von Max M. (Gast)


Lesenswert?

In Pascal ist es Float oder Real :-) In C double

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.