Danke für die Antworten. Es geht um eine Semesterarbeit. Ich soll einen Arduino Giga-R1 in ein Oszilloskop umwandeln.
Als Erstes müssen zwei Signale abgetastet werden, und die Abtastwerte sollen danach ausgewertet werden. Diese Abtastwerte soll ich anhand einer einzigen Abtastung bekommen. Wenn ich ein 1 kHz Signal mit einer Abtastrate von 10 KHz nur einmal abtaste, dann soll ich theoretisch 10.000 Werte erhalten und diese anschließend auswerten.
Inzwischen habe ich ein Beispiel mit STMSpeeduino gefunden und entsprechend geändert:
#include "STMSpeeduino.h"
const long ValuesToStore = 100000; //How many values to store, max 30000, the more the higher accuracy
int16_t CurrentValue = 0; //tracks current stored value
uint16_t ADC1Values[ValuesToStore] = {};
uint16_t ADC2Values[ValuesToStore] = {};
// ADC-Konfiguration
const int ADC1Channel = A0; //ADC 1 channel
const int ADC2Channel = A1; //ADC 2 channel
const int Resolution = 16; //8, 10, 12, 14, 16
double ClockSpeed = 10; //Clock speed in mhz, stable up to 40mhz, may decrease range further
int SampleTime = 0; //0 to 7
int Samplenum = 0; //Number of samples, is 1 more, 0 to 1023
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("Start des Programms");
ADCSimultaneous(ADC1Channel, ADC2Channel, Resolution, ClockSpeed, SampleTime, Samplenum);
Serial.println("Beginne mit der Datenerfassung...");
// Werte sammeln
for (int i = 0; i < ValuesToStore; i++) {
ADC1Values[i] = CatchADCValue(ADC1);
ADC2Values[i] = CatchADCValue(ADC2);
}
Serial.println("Datenerfassung abgeschlossen. Ausgabe der Werte:");
// Werte ausgeben
for (int i = 0; i < ValuesToStore; i++) {
Serial.print(i);
Serial.print(" ");
float voltage1 = ADC1Values[i] * 3.3f / pow(2, Resolution);
float voltage2 = ADC2Values[i] * 3.3f / pow(2, Resolution);
Serial.print(voltage1, 4);
Serial.print(",");
Serial.println(voltage2, 4);
}
Serial.println("Ausgabe abgeschlossen.");
while (1); // Endlosschleife, um das Programm zu stoppen
}
void loop() {
//
}
Die Ausgaben sehen gut aus, ob mit 1 oder 10 MHz.
Ist meine Denk- und Arbeitsweise hier richtig?
Mit Arduino_AdvancedAnalog muss ich weiter testen:
#include <Arduino_AdvancedAnalog.h>
const float MAX_VOLTAGE = 3.3;
const int Resolution = 16; //8, 10, 12, 14, 16
const int buffSize = 10000; // Number of samples to capture
bool dataCaptured = false;
AdvancedADC adc1(A0); // ADC channel A0
AdvancedADC adc2(A1); // ADC channel A1
AdvancedADCDual adc_dual(adc1, adc2); // Dual ADC object
void setup() {
Serial.begin(9600);
while (!Serial) {
}
// Initialize the dual ADC with resolution, sample rate, buffer size, and queue depth
if (!adc_dual.begin(AN_RESOLUTION_10, 10000, buffSize, 4)) {
Serial.println("Error: ADC_Dual initialization failed!");
while (1);
}
Serial.println("Waiting for data capture...");
// Wait until both ADCs have data available
while (!adc1.available() || !adc2.available()) {
// Optionally, add a small delay to avoid busy-waiting
delay(10);
}
// Capture the buffers
SampleBuffer buf1 = adc1.read();
SampleBuffer buf2 = adc2.read();
Serial.println("Captured data from A0 and A1:");
// Process and output the data
for (int i = 0; i < buffSize; i++) {
float voltage1 = buf1[i] * 3.3f / pow(2, Resolution);
float voltage2 = buf2[i] * 3.3f / pow(2, Resolution);
// Print the data
Serial.print(i);
Serial.print(" A0: ");
Serial.print(voltage1, 4);
Serial.print(" V, A1: ");
Serial.print(voltage2, 4);
Serial.println(" V");
}
buf1.release();
buf2.release();
Serial.println("Data capture and output complete.");
while (1);
}
void loop() {
// Empty loop
}