Elektronik-Labor Projekte AVR Tiny85
'Sound1Im ersten Versuch wurden jeweils 400 Bytes gespeichert und wieder abgespielt. Die Abtastrate musste so tief wie möglich gebracht werden, damit die Speicherzeit so lang wie möglich wurde. Könnte man wenigstens einen Klang erkennen, der in einer Endlosschleife abgespielt wird? Das soll hier mit einem zweiten Basom-Programm getestet werden.
$regfile = "attiny85.dat"
$crystal = 8000000
$hwstack = 8
$swstack = 4
$framesize = 4
Config Adc = Single , Prescaler = 4
Start Adc
Config Timer0 = Pwm , Prescale = 1 , Compare A Pwm = Clear Up
Dim D(400) As Byte
Dim U As Word
Dim N As Word
Dim I As Byte
Do
'Aufnahme
For N = 1 To 400
U = Getadc(2)
Shift U , Right , 2
D(n) = U
Waitus 400
Next N
'Abspielen
For N = 1 To 400
Pwm0a = D(n)
Waitus 420
Next N
Loop
End
'Sound2
$regfile = "attiny85.dat"
$crystal = 8000000
$hwstack = 8
$swstack = 4
$framesize = 4
Config Adc = Single , Prescaler = 4
Start Adc
Config Timer0 = Pwm , Prescale = 1 , Compare A Pwm = Clear Up
Dim D(400) As Byte
Dim U As Word
Dim N As Word
Dim I As Byte
Do
'Aufnahme
For N = 1 To 400
U = Getadc(2)
Shift U , Right , 2
D(n) = U
Waitus 400
Next N
'10-mal abspielen
For I = 1 To 10
For N = 1 To 400
Pwm0a = D(n)
Waitus 420
Next N
Next I
Loop
End
'Sound3
$regfile = "attiny85.dat"
$crystal = 8000000
$hwstack = 8
$swstack = 4
$framesize = 4
Config Adc = Single , Prescaler = 4
Start Adc
Config Timer0 = Pwm , Prescale = 1 , Compare A Pwm = Clear Up
Dim D(400) As Byte
Dim U As Word
Dim N As Word
Dim I As Byte
Do
U = Getadc(2)
Shift U , Right , 2
Pwm0a = U
Waitus 400
Loop
End
'Sound4, PCM
$regfile = "attiny85.dat"
$crystal = 8000000
$hwstack = 8
$swstack = 4
$framesize = 4
Config Adc = Single , Prescaler = 4
Start Adc
'Config Timer0 = Pwm , Prescale = 1 , Compare A Pwm = Clear Up
Ddrb.0 = 1
Dim D(400) As Byte
Dim U As Word
Dim P As Byte
P = 128
Do
U = Getadc(2)
Shift U , Right , 2
If U > P Then
If P < 245 Then P = P + 4
Portb.0 = 1
Else
If P > 10 Then P = P - 4
Portb.0 = 0
End If
Waitus 100
Loop
End
'Sound5, PCM
$regfile = "attiny85.dat"
$crystal = 8000000
$hwstack = 8
$swstack = 4
$framesize = 4
Config Adc = Single , Prescaler = 4
Start Adc
Ddrb.0 = 1
Dim D(400) As Byte
Dim U As Word
Dim P As Byte
Dim N As Word
Dim I As Byte
Dim B As Byte
P = 128
Do
'Aufnahme
For N = 1 To 400
For I = 1 To 8
Shift B , Right
U = Getadc(2)
Shift U , Right , 2
If U > P Then
If P < 245 Then P = P + 2
B.7 = 1
Else
If P > 10 Then P = P - 2
B.7 = 0
End If
Waitus 100
Next I
D(n) = B
Next N
'Abspielen
For N = 1 To 400
B = D(n)
For I = 1 To 8
Portb.0 = B.0
Shift B , Right
Waitus 120
Next I
Next N
Loop
End