8 years, 1 month ago.

AD変換について

AD変換が開始されるタイミングがわかりません。 read()でAD変換が開始されて、アナログ値を読み取ってAD変換が完了すると理解していたのですが、違うのでしょうか。

下記のプログラムでは、temperature.read()でアナログ値を読み取る前に、temperatureをif文の条件式にしています。 これでは、temperatureにはまだAD変換した値が入っていないと思うのですが。どのタイミングでAD変換は開始されるのでしょうか。

/media/uploads/y_3781/analoginc.jpg

1 Answer

8 years, 1 month ago.

Expressions temperature and temperature.read() are in this program synonymous and operate identical.

Using both versions of the name, resulting conversion of ADC and returning its result.
This happens because, in the AnalogIn class definition (and many other classes in mbed library) is provided operator shorthand.

For example in AnalogIn class:

    operator float() {
        return read();
    }

Consequently, in this program are two ADC conversions (for each loop transition). One is in the if statement and the other in the printf statement