Skip to content

Commit d291251

Browse files
committed
First Version of L14
1 parent 87fcba3 commit d291251

22 files changed

Lines changed: 590 additions & 0 deletions

14_ADC.md

Lines changed: 498 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
from scipy.optimize import curve_fit
4+
5+
# Generierung der "Realen Messungen"
6+
f = 40 # Hz
7+
tmin = -0.3
8+
tmax = 0.3
9+
t = np.linspace(tmin, tmax, 400)
10+
s = np.cos(2*np.pi*f*t)
11+
12+
# Abtastung mit einer Frequenz kleiner der Grenzfrequenz
13+
T = 1/35.0
14+
nmin = np.ceil((tmin) / T)
15+
nmax = np.floor(tmax / T)
16+
n = np.arange(nmin, nmax) * T
17+
y = np.cos(2*np.pi*f*n)
18+
19+
# Fitting eines Cosinussignals anhand der Messungen
20+
21+
22+
def test(x, a):
23+
return np.cos(a * x)
24+
25+
26+
# Berechnung des Signalverlaufes mit der geschätzten Periodendauer
27+
param, param_cov = curve_fit(test, n, y)
28+
ans = np.cos(param[0]*t)
29+
30+
# Ausgabe
31+
fig, ax = plt.subplots()
32+
ax.plot(t, s)
33+
ax.plot(n, y, '.', markersize=8)
34+
ax.plot(t, ans, '--', color='red', label=f"Estimated Signal")
35+
ax.grid(True, linestyle='-.')
36+
ax.tick_params(labelcolor='r', labelsize='medium', width=3)
37+
38+
plt.show()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#define F_CPU 16000000UL
2+
#include <avr/io.h>
3+
4+
int main()
5+
{
6+
ADCSRB = (1<<ACME);
7+
DDRB = (1<<PB5);
8+
9+
while(1)
10+
{
11+
if (ACSR & (1<<ACO))/* Check ACO bit of ACSR register */
12+
PORTB = (1<<PB5); /* Turn ON PB5 pin */
13+
else /* If ACO bit is zero */
14+
PORTB &= ~(1 << PB5); /* Then turn OFF PB5 pin */
15+
}
16+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef F_CPU
2+
#define F_CPU 16000000UL // 16 MHz clock speed
3+
#endif
4+
5+
#include <avr/io.h>
6+
#include <util/delay.h>
7+
8+
int readADC(int channel) {
9+
int i; int result = 0;
10+
// Den ADC aktivieren und Teilungsfaktor auf 64 stellen
11+
ADCSRA = (1<<ADEN) | (1<<ADPS2) | (1<<ADPS1);
12+
// Kanal des Multiplexers & Interne Referenzspannung (2,56 V)
13+
ADMUX = channel | (1<<REFS1) | (1<<REFS0);
14+
// Den ADC initialisieren und einen sog. Dummyreadout machen
15+
ADCSRA |= (1<<ADSC);
16+
while(ADCSRA & (1<<ADSC));
17+
//4 Leseoperationen
18+
for(i=0; i<4; i++) {
19+
ADCSRA |= (1<<ADSC);
20+
while(ADCSRA & (1<<ADSC)); // Auf Ergebnis warten...
21+
result += ADCW; }
22+
// ADC wieder deaktivieren
23+
ADCSRA &= ~(1<<ADEN);
24+
return result>>2;
25+
}
26+
27+
int main(void)
28+
{
29+
Serial.begin(9600);
30+
while (1) //infinite loop
31+
{
32+
int result = readADC(0);
33+
Serial.println(result);
34+
Serial.flush();
35+
_delay_ms(10); //1 second delay
36+
}
37+
return 0; // wird nie erreicht
38+
}

images/14_ADC/ADCTrigger.png

31.1 KB
Loading

images/14_ADC/ADC_prinzip.png

95 KB
Loading

images/14_ADC/AVR_ADC.png

73.7 KB
Loading

images/14_ADC/AnalogCompAVR.png

51.7 KB
Loading

images/14_ADC/Comperator.png

63.4 KB
Loading
154 KB
Loading

0 commit comments

Comments
 (0)