最近剛入手了Arduino Due,原因是因為是用Cortex-M3的MCU,想試一下這片板子的功能,
首先,來測是Due提供的DAC功能,分別有DAC0, DAC1兩個接腳可以使用,
經過一些搜尋,主要有幾點要注意:
1. You must use Arduino IDE 1.5 or later to program the Due-->要使用Arduino IDE 1.5以上的版本。
2. The microcontroller mounted on the Arduino Due runs at 3.3V, this means that you can power your sensors and drive your actuartors only with 3.3V. Connecting higher voltages, like the 5V commonly used with the other Arduino boards will damage the Due.-->使用3.3V,5V的電壓會傷害Due。
3.https://www.arduino.cc/en/Guide/ArduinoDue -->安裝與升級Due Driver
於是我下載了Arduino IDE 1.6.5,升級了 Due德driver,
程式碼:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
analogWriteResolution(12); // set the analog output resolution to 12 bit (4096 levels)
}
void loop() {
// put your main code here, to run repeatedly:
analogWrite(DAC1,0);
delay(1000);
analogWrite(DAC1,1024);
delay(1000);
analogWrite(DAC1,2048);
delay(1000);
analogWrite(DAC1,4095);
delay(1000);
}
結果從三用電表量到的是:
analogWrite(DAC1,0); -->0.549V
analogWrite(DAC1,1024); -->1.102V
analogWrite(DAC1,2048);-->1.655V
analogWrite(DAC1,4095);-->2.761V
其值並非從0~3.3V,
從其他爬文也有得知類似狀況,
如有更新的結果,會再進行資料更新。