ADC介紹
ADC (Analog to Digital Converter), 它可以將類比的電壓訊號轉成數位訊號,Ameba的ADC是12-bit的精準度, 可測量的電壓範圍是0V ~ 3.3V, 所以可測量到的最小電壓差距為 3.3V / (2^12-1) = 8mV。
材料準備
Ameba x 1
10KΩ電位器(可變電阻器),如果沒有電位器也沒關係, 可以使用Ameba版子上的3V3 & 5V
範例說明
ADC可用於類比訊號,像是處理電壓、聲音、光亮、溫度等等,實際應用的情況裡可用來測量電池的電壓,或是讀取音量旋鈕的大小等等。
這個範例裡我們使用ADC讀取電壓值。
這個範例在 “File” -> “Example” -> “01.Basics” -> “ReadAnalogVoltage”
Ameba共有3根ADC,分別是A0~A2, 這個範例裡我們使用A0,所以將電位器的輸出接到A0, 並將電位器的VDD與GND如下圖連接:
接著我們要從Serial Monitor視窗來看Ameba印出讀到的數據 首先我們要找到Ameba的Serial Port, 點Windows的[開始] 按鈕 、[控制台]、[系統及安全性],然後在 [系統] 下方按一下 [裝置管理員],開啟 [裝置管理員]。 會看到Ports那邊有個mbed Serial Port(COM15), 這邊COM15就是就是Ameba的Port Number
接著我們將Arduino的Port選到COM15, 它在 “Tools” -> “Port” -> COM15 (Ameba目前的Mbed Serial Port)。
每當我們要從Arduino IDE看Ameba印出的訊息, 都要設定成正確的port:
接著我們打開Serial Monitor, 在 “Tools” -> “Serial Monitor”:
此時會在Serial Monitor上面看到Ameba一直印出從A0讀到的電壓值, 我們可以調整電位器來改變Ameba讀到的數值。
或者你手上沒有電位器的話,也可以將接一條線將3V3與A0接在一起,會看到值大約在3.3左右,代表電壓是3.3V,這樣就代表讀到的值是正確的。
這個範例裡我們使用ADC讀取電壓值。
這個範例在 “File” -> “Example” -> “01.Basics” -> “ReadAnalogVoltage”
Ameba共有3根ADC,分別是A0~A2, 這個範例裡我們使用A0,所以將電位器的輸出接到A0, 並將電位器的VDD與GND如下圖連接:
接著我們要從Serial Monitor視窗來看Ameba印出讀到的數據 首先我們要找到Ameba的Serial Port, 點Windows的[開始] 按鈕 、[控制台]、[系統及安全性],然後在 [系統] 下方按一下 [裝置管理員],開啟 [裝置管理員]。 會看到Ports那邊有個mbed Serial Port(COM15), 這邊COM15就是就是Ameba的Port Number
接著我們將Arduino的Port選到COM15, 它在 “Tools” -> “Port” -> COM15 (Ameba目前的Mbed Serial Port)。
每當我們要從Arduino IDE看Ameba印出的訊息, 都要設定成正確的port:
接著我們打開Serial Monitor, 在 “Tools” -> “Serial Monitor”:
此時會在Serial Monitor上面看到Ameba一直印出從A0讀到的電壓值, 我們可以調整電位器來改變Ameba讀到的數值。
或者你手上沒有電位器的話,也可以將接一條線將3V3與A0接在一起,會看到值大約在3.3左右,代表電壓是3.3V,這樣就代表讀到的值是正確的。
程式碼說明
我們使用跟Arduino同樣的程式碼, 所以可以在Arduino的官方網站上找到說明:
https://www.arduino.cc/en/Tutorial/ReadAnalogVoltage
使用analogRead()就可以直接讀到ADC的數據0~3.3:
https://www.arduino.cc/en/Reference/AnalogRead
https://www.arduino.cc/en/Tutorial/ReadAnalogVoltage
使用analogRead()就可以直接讀到ADC的數據0~3.3:
https://www.arduino.cc/en/Reference/AnalogRead
Introduction of ADC
ADC (Analog to Digital Converter) component is capable of coverting analog signal to digital signal. The ADC component of Ameba is of 12-bit precision, and its effective range of measurement is 0V ~ 3.3V, so the minimum measurable difference i voltage is 3.3V / (2^12-1) = 8mV.
Materials
Ameba x 1
10KΩ Potentiometer (Variable Resistor) x 1, if you don't have potentiometer in hand, the 3V3 & 5V on Ameba can be used instead.
Procedure
ADC is widely used in processing analog signal, such as voltage, audio signal, light, temperature, ...etc. In real-life use case, ADC can be used to measure the voltage of a battery, or read the value of a volume knob.
In this example, we use ADC to get the voltage value.
Open the sample code in "File" -> "Example" -> "01.Basics" -> "ReadAnalogVoltage"
There are 3 ADC pins on Ameba (A0~A2), we will use A0 in this example. First, connect the output of the potentiometer to A0, then connect VDD of the potentiometer to GND as the figure:
To read data from Ameba, we have to find out the serial port connected to Ameba.
Open "Device Manager" in Windows, find "mbed Serial Port". For example in the figure, we can find "mbed Serial Port(COM15)", then "COM15" is the port number connected to Ameba.
Next, we connect Ameba to the correct port in Arduino IDE. Go to "Tools" -> "Port", and select the port number (here we select port COM15).
When we want to read the message output from Ameba, it is necessary that the port is set to the correct port connecting to Ameba:
Then we open the "Serial Monitor" in "Tools" -> "Serial Monitor":
In the Serial Monitor, Ameba prints the voltage value output from A0 continuously. We can adjust the potentiometer to change the output.
If you don't have potentiometer in hand, you can connect 3V3 and A0, and the output value would be 3.3V approximately.
In this example, we use ADC to get the voltage value.
Open the sample code in "File" -> "Example" -> "01.Basics" -> "ReadAnalogVoltage"
There are 3 ADC pins on Ameba (A0~A2), we will use A0 in this example. First, connect the output of the potentiometer to A0, then connect VDD of the potentiometer to GND as the figure:
To read data from Ameba, we have to find out the serial port connected to Ameba.
Open "Device Manager" in Windows, find "mbed Serial Port". For example in the figure, we can find "mbed Serial Port(COM15)", then "COM15" is the port number connected to Ameba.
Next, we connect Ameba to the correct port in Arduino IDE. Go to "Tools" -> "Port", and select the port number (here we select port COM15).
When we want to read the message output from Ameba, it is necessary that the port is set to the correct port connecting to Ameba:
Then we open the "Serial Monitor" in "Tools" -> "Serial Monitor":
In the Serial Monitor, Ameba prints the voltage value output from A0 continuously. We can adjust the potentiometer to change the output.
If you don't have potentiometer in hand, you can connect 3V3 and A0, and the output value would be 3.3V approximately.
Code Reference
You can find detailed information of this example in the documentation of Arduino:
https://www.arduino.cc/en/Tutorial/ReadAnalogVoltage
We use analogRead(pin) to read the value from the specified analog pin directly:
https://www.arduino.cc/en/Reference/AnalogRead
https://www.arduino.cc/en/Tutorial/ReadAnalogVoltage
We use analogRead(pin) to read the value from the specified analog pin directly:
https://www.arduino.cc/en/Reference/AnalogRead
0 comments:
Post a Comment