kramann.info
© Guido Kramann

Login: Passwort:










Robuste Systemintegration
1 Grundlagen
..1.1 Newton
....1.1.1 LinearSchwinger
....1.1.2 Daempfung
....1.1.4 ODE
....1.1.5 Saaluebung
..1.2 NewtonEuler
....1.2.1 Traegheitsmomente
....1.2.2 Modellgleichungen
....1.2.3 Einfachpendel
..1.3 Scilab
....1.3.1 Erste_Schritte
....1.3.2 Skripte
....1.3.3 Funktionen
..1.4 Laplace
....1.4.1 Eigenwerte
....1.4.2 PT1
..1.5 Regleroptimierung
....1.5.1 Guetefunktion
....1.5.2 Heuristiken
....1.5.3 Scilab
..1.6 Einstellregeln
....1.6.1 Totzeit
....1.6.2 Methode1
....1.6.3 Methode2
....1.6.4 Scilab
..1.7 Zustandsregler
..1.8 Polvorgabe
..1.8 Polvorgabe_alt
..1.9 Beobachter
....1.9.1 Haengependel
..1.10 Daempfungsgrad
..1.11 Processing
....1.11.1 Installation
....1.11.2 Erste_Schritte
....1.11.3 Mechatronik
....1.11.4 Bibliotheken
....1.11.5 Uebung
....1.11.6 Snippets
......1.11.6.1 Dateioperationen
......1.11.6.2 Bilder
......1.11.6.3 GUI
......1.11.6.4 Text
......1.11.6.5 PDF
......1.11.6.8 Maus
......1.11.6.10 Zeit
......1.11.6.13 Animation
......1.11.6.15 Simulation
....1.11.7 Referenzen
..1.12 Breakout
2 Beispiel
3 Beispielloesung
4 Praxis
5 javasci
6 Fehlertoleranz1
7 Reglerentwurf
..7.1 Sprungantwort
..7.2 Messdaten
..7.3 Systemidentifikation
..7.4 Polvorgabe
..7.5 Beobachter
..7.6 Robuster_Entwurf
..7.7 SIL
8 Systementwicklung
9 Arduino
..9.1 Lauflicht
..9.2 Taster
..9.3 Sensor
..9.12 Motor_PWM1
..9.13 Motor_PWM2_seriell
..9.14 Motor_PWM3_analogWrite
..9.15 Scheduler
..9.20 AV
..9.21 Mikrofon
..9.22 Universal
....9.22.1 Laborplatine
....9.22.2 LED_Leiste
....9.22.3 Motortreiber
....9.22.4 Sensoreingaenge
....9.22.5 Taster
....9.22.6 Tests
....9.22.7 Mikrofon
....9.22.8 Lautsprecher
....9.22.9 Fahrgestell
..9.23 Zauberkiste
..9.24 OOP
....9.24.1 Uebungen
..9.25 AVneu
....9.25.1 Tests
..9.26 DA_Wandler
..9.27 CompBoard
....9.27.1 Tastenmatrix
....9.27.2 ASCIIDisplay
..9.28 CTC
..9.29 Tonerzeugung
10 EvoFuzzy
..10.1 Fuzzy
....10.1.1 Fuzzylogik
....10.1.2 FuzzyRegler
....10.1.3 Uebung9
....10.1.5 Softwareentwicklung
......10.1.5.1 AgileSoftwareentwicklung
......10.1.5.2 FuzzyRegler
......10.1.5.3 Uebung
....10.1.6 Umsetzung
......10.1.6.1 FuzzyRegler
......10.1.6.2 Simulation
......10.1.6.3 Optimierung
......10.1.6.4 Uebung
....10.1.7 Haengependel
......10.1.7.1 Haengependel
......10.1.7.2 Simulation
......10.1.7.3 FuzzyRegler
......10.1.7.4 Optimierer
......10.1.7.5 Genetisch
....10.1.8 Information
....10.1.9 Energie
..10.2 Optimierung
....10.2.1 Gradientenverfahren
....10.2.2 Heuristiken
....10.2.3 ModifizierteG
....10.2.4 optim
..10.3 Genalgorithmus
..10.4 NeuronaleNetze
....10.4.1 Neuron
....10.4.2 Backpropagation
....10.4.3 Umsetzung
....10.4.4 Winkelerkennung
..10.5 RiccatiRegler
11 Agentensysteme
12 Simulation
20 Massnahmen
21 Kalmanfilter
..21.1 Vorarbeit
..21.2 Minimalversion
..21.3 Beispiel
30 Dreirad
31 Gleiter
..31.1 Fehlertoleranz

9.29 Tabellen zur genauen Erzeugung von Tonhöhen mit den Timern 0, 1 oder 3 des Arduino Micro

Tonhöhen mit Timer 1 und 3

midi N OCR f soll [Hz] f ist [Hz] Fehler [cent]
0 8 61155 8.175798915643707 8.175812675779973 -0.0029137209248050995
1 8 57723 8.661957218027254 8.66190839165685 0.009758777497125948
2 8 54483 9.177023997418987 9.177006093532047 0.0033775490754521797
3 8 51425 9.722718241315029 9.722708357640105 0.001759895003431211
4 8 48539 10.300861153527185 10.300782859497321 0.01315868677772869
5 8 45814 10.913382232281373 10.913456291607552 -0.011748291168373726
6 8 43243 11.562325709738577 11.562297659790953 0.004199940783905731
7 8 40816 12.249857374429666 12.249797878335007 0.00840841748981802
8 8 38525 12.978271799373287 12.978248455588433 0.0031139424526145376
9 8 36363 13.75 13.749862501374986 0.01731225392950364
10 8 34322 14.56761754744031 14.567491186667832 0.015016938757980824
11 8 32395 15.433853164253879 15.434004198049141 -0.016941561304520292
12 8 30577 16.351597831287414 16.351625351559946 -0.002913720924880181
13 8 28861 17.32391443605451 17.3238167833137 0.009758777496926996
14 8 27241 18.354047994837973 18.354012187064093 0.003377549075821662
15 8 25712 19.445436482630058 19.44541671528021 0.0017598950037154282
16 8 24269 20.60172230705437 20.601565718994642 0.013158686777615003
17 8 22907 21.826764464562746 21.82643617950061 0.02603879069533832
18 8 21621 23.124651419477154 23.124595319581907 0.004199940784019418
19 8 20407 24.499714748859333 24.500196001568014 -0.034006636450385486
20 8 19262 25.956543598746574 25.956496911176867 0.0031139424527282245
21 8 18181 27.5 27.499725002749972 0.01731225392950364
22 8 17160 29.13523509488062 29.13583124526543 -0.03542326953720476
23 8 16197 30.867706328507758 30.868008396098283 -0.016941561304065544
24 8 15288 32.70319566257483 32.70325070311989 -0.002913720924880181
25 8 14430 34.64782887210902 34.6476335666274 0.009758777497609117
26 8 13620 36.70809598967594 36.708024374128186 0.0033775490755942883
27 8 12855 38.890872965260115 38.89234598630989 -0.06557054930453887
28 8 12134 41.20344461410874 41.203131437989285 0.013158686777842377
29 8 11453 43.65352892912548 43.65287235900122 0.0260387906946562
30 8 10810 46.24930283895431 46.249190639163814 0.004199940784019418
31 8 10203 48.99942949771867 49.00039200313603 -0.03400663645061286
32 8 9630 51.91308719749315 51.915688921191986 -0.0867619329246736
33 8 9090 55.0 54.999450005499945 0.01731225392950364
34 8 8580 58.27047018976125 58.26826710173639 0.06545567750072223
35 1 64792 61.735412657015516 61.73506397296004 0.009778106081284932
36 1 61155 65.40639132514966 65.40650140623978 -0.002913720924880181
37 1 57723 69.29565774421803 69.2952671332548 0.009758777496699622
38 1 54483 73.41619197935188 73.41604874825637 0.0033775490755942883
39 1 51425 77.78174593052023 77.78166686112084 0.0017598950039428018
40 1 48539 82.40688922821748 82.40626287597857 0.013158686778751871
41 1 45814 87.30705785825096 87.30765033286042 -0.011748291168260039
42 1 43243 92.49860567790861 92.49838127832763 0.004199940783109923
43 1 40816 97.99885899543735 97.99838302668006 0.008408417489590647
44 1 38525 103.8261743949863 103.82598764470747 0.0031139424527282245
45 1 36363 110.0 109.99890001099989 0.017312253929048893
46 1 34322 116.5409403795225 116.53992949334265 0.01501693875707133
47 1 32395 123.47082531403103 123.47203358439313 -0.016941561304520292
48 1 30577 130.8127826502993 130.81300281247957 -0.002913720924880181
49 1 28861 138.59131548843604 138.5905342665096 0.009758777496244875
50 1 27241 146.83238395870382 146.83209749651274 0.0033775490755942883
51 1 25712 155.56349186104046 155.56333372224168 0.0017598950034880545
52 1 24269 164.81377845643496 164.81252575195714 0.01315868677738763
53 1 22907 174.614115716502 174.6114894360049 0.026038790695565694
54 1 21621 184.99721135581723 184.99676255665526 0.004199940783109923
55 1 20407 195.9977179908746 196.0015680125441 -0.03400663645061286
56 1 19262 207.65234878997262 207.65197528941493 0.003113942453637719
57 1 18181 220.0 219.99780002199978 0.017312253929958388
58 1 17160 233.0818807590449 233.08664996212343 -0.035423269538114255
59 1 16197 246.9416506280621 246.94406716878626 -0.016941561304520292
60 1 15288 261.6255653005986 261.62600562495913 -0.0029137209239706863
61 1 14430 277.1826309768721 277.1810685330192 0.009758777496244875
62 1 13620 293.66476791740763 293.6641949930255 0.003377549076503783
63 1 12855 311.1269837220809 311.13876789047913 -0.06557054930453887
64 1 12134 329.6275569128699 329.6250515039143 0.013158686778297124
65 1 11453 349.228231433004 349.2229788720098 0.026038790695565694
66 1 10810 369.99442271163446 369.9935251133105 0.004199940783109923
67 1 10203 391.9954359817492 392.0031360250882 -0.03400663645061286
68 1 9630 415.30469757994524 415.3255113695359 -0.08676193292285461
69 1 9090 440.0 439.99560004399956 0.017312253929048893
70 1 8580 466.1637615180898 466.14613681389113 0.06545567749890324
71 1 8098 493.8833012561242 493.8881343375725 -0.016941561303610797
72 1 7644 523.2511306011972 523.2177894048398 0.11031653838290367
73 1 7214 554.3652619537442 554.4005544005544 -0.11021170514504774
74 1 6809 587.3295358348153 587.3715124816447 -0.12372748009784118
75 1 6427 622.2539674441618 622.2775357809583 -0.06557054930453887
76 1 6066 659.2551138257398 659.3044338223175 -0.12951171991608135
77 1 5726 698.456462866008 698.4459577440196 0.0260387906946562
78 1 5404 739.9888454232689 740.0555041628122 -0.1559438130025228
79 1 5101 783.9908719634984 784.0062720501764 -0.03400663645243185
80 1 4815 830.6093951598905 830.5647840531561 0.09298515222599235
81 1 4544 880.0 880.0880088008801 -0.17313206165272277
82 1 4289 932.3275230361796 932.4009324009324 -0.13630809512869746
83 1 4049 987.7666025122484 987.6543209876543 0.19680423180216167
84 1 3821 1046.5022612023945 1046.5724751439036 -0.11615138646993728
85 1 3607 1108.7305239074883 1108.6474501108648 0.12972094703764014
86 1 3404 1174.6590716696305 1174.7430249632894 -0.12372748009875068
87 1 3213 1244.5079348883237 1244.5550715619165 -0.06557054930635786
88 1 3033 1318.5102276514797 1318.3915622940012 0.15581733702128986
89 1 2862 1396.912925732016 1397.1358714634998 -0.27628096019179793
90 1 2702 1479.9776908465378 1479.8372179060304 0.16432888221606845
91 1 2550 1567.9817439269968 1568.012544100353 -0.034006636451522354
92 1 2407 1661.218790319781 1661.1295681063123 0.09298515222326387
93 1 2272 1760.0 1759.7888253409592 0.20773562200338347
94 1 2144 1864.6550460723593 1864.801864801865 -0.13630809512869746
95 1 2024 1975.5332050244967 1975.3086419753085 0.19680423180398066
96 1 1910 2093.004522404789 2093.144950287807 -0.11615138646993728
97 1 1803 2217.461047814978 2217.2949002217297 0.12972094703945913
98 1 1702 2349.3181433392597 2348.796241926013 0.38463665483141085
99 1 1606 2489.0158697766474 2489.110143123833 -0.06557054930271988
100 1 1516 2637.0204553029603 2636.7831245880025 0.15581733702492784
101 1 1431 2793.82585146403 2793.2960893854747 0.3283057576900319
102 1 1350 2959.9553816930757 2960.7698001480385 -0.47627576859486
103 1 1275 3135.963487853996 3134.796238244514 0.6445095584258524
104 1 1203 3322.43758063956 3322.2591362126245 0.09298515222508286
105 1 1135 3520.0 3521.1267605633802 -0.5540835537995008
106 1 1072 3729.3100921447212 3727.865796831314 0.6706059484076832
107 1 1011 3951.066410048991 3952.5691699604745 -0.6583373262456007
108 1 955 4186.009044809578 4184.100418410042 0.7895426174818567
109 1 901 4434.922095629956 4434.589800443459 0.12972094703945913
110 1 850 4698.636286678519 4700.352526439483 -0.632240936261951
111 1 803 4978.031739553295 4975.124378109453 1.0114024552967749
112 1 757 5274.0409106059205 5277.0448548812665 -0.9857811541060073
113 1 715 5587.65170292806 5586.592178770949 0.3283057576900319
114 1 675 5919.910763386151 5917.15976331361 0.8046965792036644
115 1 637 6271.926975707992 6269.592476489028 0.6445095584258524
116 1 601 6644.87516127912 6644.518272425249 0.09298515222326387
117 1 567 7040.0 7042.2535211267605 -0.5540835537976818
118 1 535 7458.6201842894425 7462.686567164179 -0.9435984100891801
119 1 505 7902.132820097982 7905.138339920949 -0.6583373262474197
120 1 477 8372.018089619156 8368.200836820084 0.7895426174818567
121 1 450 8869.844191259912 8869.179600886919 0.12972094704127812
122 1 425 9397.272573357039 9389.671361502347 1.4009173115864542
123 1 401 9956.06347910659 9950.248756218905 1.0114024552949559
124 1 378 10548.081821211841 10554.089709762533 -0.9857811541060073
125 1 357 11175.30340585612 11173.184357541899 0.3283057576882129
126 1 337 11839.821526772303 11834.31952662722 0.8046965792018455
127 1 318 12543.853951415984 12539.184952978056 0.6445095584258524

Tabelle 9.29-1: Umsetzung der Miditonhöhen mit Timer 1 oder 3 auf dem Arduino Micro

Tonhöhen mit Timer 0

midi N OCR f soll [Hz] f ist [Hz] Fehler [cent]
0 1024 477 8.175798915643707 8.172071129707113 0.7895426174806236
1 1024 450 8.661957218027254 8.661308203991132 0.1297209470395586
2 1024 425 9.177023997418987 9.169600938967136 1.4009173115884437
3 1024 401 9.722718241315029 9.717039800995025 1.0114024552968317
4 1024 378 10.300861153527185 10.306728232189974 -0.9857811541073147
5 1024 357 10.913382232281373 10.91131284916201 0.3283057576903161
6 1024 337 11.562325709738577 11.556952662721894 0.8046965792036644
7 1024 318 12.249857374429666 12.245297805642632 0.6445095584260798
8 1024 300 12.978271799373287 12.977574750830565 0.09298515222542392
9 1024 283 13.75 13.754401408450704 -0.5540835537989324
10 1024 267 14.56761754744031 14.575559701492537 -0.9435984100902033
11 256 1011 15.433853164253879 15.439723320158103 -0.6583373262453733
12 256 955 16.351597831287414 16.344142259414227 0.7895426174804925
13 256 901 17.32391443605451 17.322616407982263 0.12972094703945913
14 256 850 18.354047994837973 18.36075205640423 -0.6322409362617236
15 256 803 19.445436482630058 19.43407960199005 1.0114024552970022
16 256 757 20.60172230705437 20.613456464379947 -0.9857811541071442
17 256 715 21.826764464562746 21.82262569832402 0.3283057576900319
18 256 675 23.124651419477154 23.11390532544379 0.8046965792038918
19 256 637 24.499714748859333 24.490595611285265 0.6445095584260798
20 256 601 25.956543598746574 25.95514950166113 0.09298515222531023
21 256 567 27.5 27.508802816901408 -0.5540835537985913
22 256 535 29.13523509488062 29.151119402985074 -0.9435984100909991
23 256 505 30.867706328507758 30.879446640316207 -0.658337326245146
24 256 477 32.70319566257483 32.68828451882845 0.7895426174804925
25 256 450 34.64782887210902 34.645232815964526 0.12972094703945913
26 256 425 36.70809598967594 36.678403755868544 1.4009173115882732
27 256 401 38.890872965260115 38.8681592039801 1.0114024552967749
28 256 378 41.20344461410874 41.226912928759894 -0.9857811541073715
29 256 357 43.65352892912548 43.64525139664804 0.32830575768957715
30 256 337 46.24930283895431 46.22781065088758 0.8046965792041192
31 256 318 48.99942949771867 48.98119122257053 0.6445095584263072
32 256 300 51.91308719749315 51.91029900332226 0.09298515222462811
33 256 283 55.0 55.017605633802816 -0.5540835537985913
34 256 267 58.27047018976125 58.30223880597015 -0.9435984100896349
35 64 1011 61.735412657015516 61.758893280632414 -0.6583373262446912
36 64 955 65.40639132514966 65.3765690376569 0.7895426174804925
37 64 901 69.29565774421803 69.29046563192905 0.1297209470390044
38 64 850 73.41619197935188 73.44300822561692 -0.6322409362614962
39 64 803 77.78174593052023 77.7363184079602 1.0114024552972296
40 64 757 82.40688922821748 82.45382585751979 -0.9857811541069168
41 64 715 87.30705785825096 87.29050279329608 0.3283057576900319
42 64 675 92.49860567790861 92.45562130177515 0.804696579202755
43 64 637 97.99885899543735 97.96238244514106 0.6445095584267619
44 64 601 103.8261743949863 103.82059800664452 0.09298515222508286
45 64 567 110.0 110.03521126760563 -0.5540835537985913
46 64 535 116.5409403795225 116.6044776119403 -0.9435984100909991
47 64 505 123.47082531403103 123.51778656126483 -0.6583373262456007
48 64 477 130.8127826502993 130.7531380753138 0.7895426174809472
49 64 450 138.59131548843604 138.5809312638581 0.12972094703854964
50 64 425 146.83238395870382 146.71361502347418 1.4009173115891826
51 64 401 155.56349186104046 155.4726368159204 1.0114024552967749
52 64 378 164.81377845643496 164.90765171503958 -0.9857811541069168
53 64 357 174.614115716502 174.58100558659217 0.3283057576900319
54 64 337 184.99721135581723 184.9112426035503 0.8046965792036644
55 64 318 195.9977179908746 195.92476489028212 0.6445095584258524
56 64 300 207.65234878997262 207.64119601328903 0.09298515222599235
57 64 283 220.0 220.07042253521126 -0.5540835537985913
58 64 267 233.0818807590449 233.2089552238806 -0.9435984100909991
59 64 252 246.9416506280621 247.03557312252966 -0.6583373262446912
60 64 238 261.6255653005986 261.5062761506276 0.7895426174809472
61 64 224 277.1826309768721 277.77777777777777 -3.7131974989733862
62 64 212 293.66476791740763 293.42723004694835 1.4009173115891826
63 64 200 311.1269837220809 310.9452736318408 1.0114024552967749
64 64 189 329.6275569128699 328.94736842105266 3.576103037719804
65 64 178 349.228231433004 349.16201117318434 0.3283057576909414
66 64 168 369.99442271163446 369.8224852071006 0.804696579202755
67 64 158 391.9954359817492 393.0817610062893 -4.79108061819079
68 64 149 415.30469757994524 416.6666666666667 -5.668198364359341
69 64 141 440.0 440.14084507042253 -0.5540835537985913
70 64 133 466.1637615180898 466.4179104477612 -0.9435984100909991
71 8 1011 493.8833012561242 494.0711462450593 -0.6583373262428722
72 8 955 523.2511306011972 523.0125523012553 0.7895426174809472
73 8 901 554.3652619537442 554.3237250554324 0.12972094703945913
74 8 850 587.3295358348153 587.5440658049354 -0.632240936261951
75 8 803 622.2539674441618 621.8905472636816 1.0114024552985938
76 8 757 659.2551138257398 659.6306068601583 -0.9857811541069168
77 8 715 698.456462866008 698.3240223463687 0.3283057576909414
78 8 675 739.9888454232689 739.6449704142012 0.8046965792036644
79 8 637 783.9908719634984 783.6990595611285 0.644509558424943
80 8 601 830.6093951598905 830.5647840531561 0.09298515222599235
81 8 567 880.0 880.2816901408451 -0.5540835537967723
82 8 535 932.3275230361796 932.8358208955224 -0.9435984100909991
83 8 505 987.7666025122484 988.1422924901186 -0.6583373262456007
84 8 477 1046.5022612023945 1046.0251046025105 0.7895426174800377
85 8 450 1108.7305239074883 1108.6474501108648 0.12972094703764014
86 8 425 1174.6590716696305 1173.7089201877934 1.4009173115882732
87 8 401 1244.5079348883237 1243.7810945273632 1.0114024552967749
88 8 378 1318.5102276514797 1319.2612137203166 -0.9857811541096453
89 8 357 1396.912925732016 1396.6480446927374 0.3283057576918509
90 8 337 1479.9776908465378 1479.2899408284025 0.8046965792036644
91 8 318 1567.9817439269968 1567.398119122257 0.6445095584258524
92 8 300 1661.218790319781 1661.1295681063123 0.09298515222326387
93 8 283 1760.0 1760.5633802816901 -0.5540835537958628
94 8 267 1864.6550460723593 1865.6716417910447 -0.9435984100909991
95 8 252 1975.5332050244967 1976.2845849802372 -0.6583373262437817
96 8 238 2093.004522404789 2092.050209205021 0.7895426174800377
97 8 224 2217.461047814978 2222.222222222222 -3.7131974989715673
98 8 212 2349.3181433392597 2347.417840375587 1.4009173115864542
99 8 200 2489.0158697766474 2487.5621890547263 1.0114024552985938
100 8 189 2637.0204553029603 2631.5789473684213 3.576103037721623
101 8 178 2793.82585146403 2793.2960893854747 0.3283057576900319
102 8 168 2959.9553816930757 2958.579881656805 0.8046965792036644
103 8 158 3135.963487853996 3144.6540880503144 -4.791080618189881
104 8 149 3322.43758063956 3333.3333333333335 -5.668198364359341
105 8 141 3520.0 3521.1267605633802 -0.5540835537995008
106 8 133 3729.3100921447212 3731.3432835820895 -0.9435984100909991
107 1 1011 3951.066410048991 3952.5691699604745 -0.6583373262456007
108 1 955 4186.009044809578 4184.100418410042 0.7895426174818567
109 1 901 4434.922095629956 4434.589800443459 0.12972094703945913
110 1 850 4698.636286678519 4700.352526439483 -0.632240936261951
111 1 803 4978.031739553295 4975.124378109453 1.0114024552967749
112 1 757 5274.0409106059205 5277.0448548812665 -0.9857811541060073
113 1 715 5587.65170292806 5586.592178770949 0.3283057576900319
114 1 675 5919.910763386151 5917.15976331361 0.8046965792036644
115 1 637 6271.926975707992 6269.592476489028 0.6445095584258524
116 1 601 6644.87516127912 6644.518272425249 0.09298515222326387
117 1 567 7040.0 7042.2535211267605 -0.5540835537976818
118 1 535 7458.6201842894425 7462.686567164179 -0.9435984100891801
119 1 505 7902.132820097982 7905.138339920949 -0.6583373262474197
120 1 477 8372.018089619156 8368.200836820084 0.7895426174818567
121 1 450 8869.844191259912 8869.179600886919 0.12972094704127812
122 1 425 9397.272573357039 9389.671361502347 1.4009173115864542
123 1 401 9956.06347910659 9950.248756218905 1.0114024552949559
124 1 378 10548.081821211841 10554.089709762533 -0.9857811541060073
125 1 357 11175.30340585612 11173.184357541899 0.3283057576882129
126 1 337 11839.821526772303 11834.31952662722 0.8046965792018455
127 1 318 12543.853951415984 12539.184952978056 0.6445095584258524

Tabelle 9.29-2: Umsetzung der Miditonhöhen mit Timer 0 auf dem Arduino Micro

Chromatische Aufwärtsbewegung eines Dreiklangs

#include <avr/pgmspace.h>
#include<avr/interrupt.h>

//Einstellen von Miditonhöhen mit den Timern 1 und 3 im CTC-Mode.

//const unsigned int LOOKUP_OCR1[] = PROGMEM {
const unsigned int LOOKUP_OCR1[] = {
61155, 57723, 54483, 51425, 48539, 45814, 43243, 40816, 38525, 36363, 
34322, 32395, 30577, 28861, 27241, 25712, 24269, 22907, 21621, 20407, 
19262, 18181, 17160, 16197, 15288, 14430, 13620, 12855, 12134, 11453, 
10810, 10203, 9630, 9090, 8580, 64792, 61155, 57723, 54483, 51425, 
48539, 45814, 43243, 40816, 38525, 36363, 34322, 32395, 30577, 28861, 
27241, 25712, 24269, 22907, 21621, 20407, 19262, 18181, 17160, 16197, 
15288, 14430, 13620, 12855, 12134, 11453, 10810, 10203, 9630, 9090, 
8580, 8098, 7644, 7214, 6809, 6427, 6066, 5726, 5404, 5101, 
4815, 4544, 4289, 4049, 3821, 3607, 3404, 3213, 3033, 2862, 
2702, 2550, 2407, 2272, 2144, 2024, 1910, 1803, 1702, 1606, 
1516, 1431, 1350, 1275, 1203, 1135, 1072, 1011, 955, 901, 
850, 803, 757, 715, 675, 637, 601, 567, 535, 505, 
477, 450, 425, 401, 378, 357, 337, 318};


//const unsigned int LOOKUP_N1[] = PROGMEM {
const unsigned int LOOKUP_N1[] = {
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1};


//const unsigned int LOOKUP_OCR0[] = PROGMEM {
const unsigned int LOOKUP_OCR0[] = {
477, 450, 425, 401, 378, 357, 337, 318, 300, 283, 
267, 1011, 955, 901, 850, 803, 757, 715, 675, 637, 
601, 567, 535, 505, 477, 450, 425, 401, 378, 357, 
337, 318, 300, 283, 267, 1011, 955, 901, 850, 803, 
757, 715, 675, 637, 601, 567, 535, 505, 477, 450, 
425, 401, 378, 357, 337, 318, 300, 283, 267, 252, 
238, 224, 212, 200, 189, 178, 168, 158, 149, 141, 
133, 1011, 955, 901, 850, 803, 757, 715, 675, 637, 
601, 567, 535, 505, 477, 450, 425, 401, 378, 357, 
337, 318, 300, 283, 267, 252, 238, 224, 212, 200, 
189, 178, 168, 158, 149, 141, 133, 1011, 955, 901, 
850, 803, 757, 715, 675, 637, 601, 567, 535, 505, 
477, 450, 425, 401, 378, 357, 337, 318};

//const unsigned int LOOKUP_N0[] = PROGMEM {
const unsigned int LOOKUP_N0[] = {
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 
5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1};


//const unsigned int LOOKUP_FEHLER0 = PROGMEM {
const unsigned int LOOKUP_FEHLER0[] = {
8, 1, 14, 10, 10, 3, 8, 6, 1, 6, 
9, 7, 8, 1, 6, 10, 10, 3, 8, 6, 
1, 6, 9, 7, 8, 1, 14, 10, 10, 3, 
8, 6, 1, 6, 9, 7, 8, 1, 6, 10, 
10, 3, 8, 6, 1, 6, 9, 7, 8, 1, 
14, 10, 10, 3, 8, 6, 1, 6, 9, 7, 
8, 37, 14, 10, 36, 3, 8, 48, 57, 6, 
9, 7, 8, 1, 6, 10, 10, 3, 8, 6, 
1, 6, 9, 7, 8, 1, 14, 10, 10, 3, 
8, 6, 1, 6, 9, 7, 8, 37, 14, 10, 
36, 3, 8, 48, 57, 6, 9, 7, 8, 1, 
6, 10, 10, 3, 8, 6, 1, 6, 9, 7, 
8, 1, 14, 10, 10, 3, 8, 6};

int ZEIT=0;
bool ZUSTAND=false;

int TON=0;

ISR(TIMER4_COMPA_vect)
{
    if(ZEIT==4000) 
    {
      digitalWrite(0,ZUSTAND);
      ZUSTAND=!ZUSTAND;        
      ZEIT=0;
      
      TON++;
      TON%=25;
      
      setzeMidihoehe0(TON+48);  //Timer 3
      setzeMidihoehe1(TON+48+4);  //Timer 3
      setzeMidihoehe3(TON+48+7);  //Timer 3
      
    }  
    ZEIT++;
}

void initTimer4()
{
  //Vorteilung 2
  TCCR4B &= ~(1<<CS43);
  TCCR4B &= ~(1<<CS42);
  TCCR4B &= ~(1<<CS41);    
  TCCR4B |=  (1<<CS40);
 
  TIMSK4 |= (1<<OCIE4A); //Mode 4
  sei(); 
 
  //Andere Frequenzberechnung:   
  //f = fclk/(2*(OCR1A+1))
  //OCR1A = (fclk/(f*2*N))-1
  //OCR1A = 500000/440 - 1 ==  
  //OCR4B=268; 
  OCR4A=400; 
//  OCR4C=10; 
    
//OCR4B=268;     
//    OCR4A=2; 
//durch Interrupt gesteuert:
  pinMode(0,OUTPUT);    
}

void initTimer0()
{
  TCCR0B=0;
  TCCR0A=0;
  
  TCCR0B &= ~(1<<WGM02);
  TCCR0A |=  (1<<WGM01);
  TCCR0A &= ~(1<<WGM00);
    
  //Vorteilung 64
  TCCR0B &= ~(1<<CS02);
  TCCR0B |= (1<<CS01);
  TCCR0B |= (1<<CS00);
    
  //f = fclk/(2*N*(OCR1A+1))
  //OCR1A = (fclk/(f*2*N))-1
  //OCR1A = 125000/880 - 1 ==  141
  //KORRIGIERT:
  //********************************
  //OCR0A = 62500/440 - 1 ==  142
  //OCR0A = 16000000/(f*4*N) - 1 ==  142
  //********************************
  
  OCR0A=141;  
  
  //Toggle auf OC1A:
  TCCR0A &= ~(1<<COM0A1);
  TCCR0A |=  (1<<COM0A0);
  pinMode(11,OUTPUT);          //OC0A
}

void initTimer1()
{
  TCCR1B &= ~(1<<WGM13); //Mode 4
  TCCR1B |= (1<<WGM12);
  TCCR1A &= ~(1<<WGM11);
  TCCR1A &= ~(1<<WGM10);
    
  //Vorteilung 1: 16000000Hz
  TCCR1B &= ~(1<<CS12);
  TCCR1B &= ~(1<<CS11);
  TCCR1B |= (1<<CS10);
    
  //f = fclk/(2*N*(OCR1A+1))
  //OCR1A = (fclk/(f*2*N))-1
  //OCR1A = 8000000/440 - 1 ==  18181
  //KORRIGIERT:
  //********************************
  //OCR1A = 4000000/440 - 1 ==  9091
  //OCR1A = 16000000/(f*4*N) - 1 ==  9091
  //********************************
  OCR1A=9091;  //0,5Hz == 4 Schläge!
  
  //Toggle auf OC1A:
  TCCR1A &= ~(1<<COM1A1);
  TCCR1A |=  (1<<COM1A0);
  pinMode(9,OUTPUT);      
}

void initTimer3()
{
//  TCCR1B |= (1<<WGM13); //Mode 12
  TCCR3B &= ~(1<<WGM33); //Mode 4
  TCCR3B |= (1<<WGM32);
  TCCR3A &= ~(1<<WGM31);
  TCCR3A &= ~(1<<WGM30);
    
  //Vorteilung 1: 16000000Hz
  TCCR3B &= ~(1<<CS32);
  TCCR3B &= ~(1<<CS31);
  TCCR3B |= (1<<CS30);
    
  //f = fclk/(2*N*(OCR1A+1))
  //OCR1A = (fclk/(f*2*N))-1
  //OCR1A = 8000000/440 - 1 ==  18181
  OCR3A=18181/2;  //0,5Hz == 4 Schläge!
  
  //Toggle auf OC1A:
  TCCR3A &= ~(1<<COM3A1);
  TCCR3A |=  (1<<COM3A0);
  pinMode(5,OUTPUT);    //OC3A  
}




void setzeMidihoehe0(int midi)  //Timer 0
{
  TCCR0B &= 248; //unteren drei Bit löschen
  TCCR0B |= LOOKUP_N0[midi];
  OCR0A=LOOKUP_OCR0[midi];
}
void setzeMidihoehe1(int midi)  //Timer 1
{
  TCCR1B &= 248; //unteren drei Bit löschen
  TCCR1B |= LOOKUP_N1[midi];
  OCR1A=LOOKUP_OCR1[midi];
}
void setzeMidihoehe3(int midi)  //Timer 3
{
  TCCR3B &= 248; //unteren drei Bit löschen
  TCCR3B |= LOOKUP_N1[midi];
  OCR3A=LOOKUP_OCR1[midi];
}


void setup() 
{
    initTimer0();
    initTimer1();
    initTimer3();
    initTimer4();
}

void loop()
{
}

Code 9.29-1: Chromatische Aufwärtsbewegung eines Dreiklangs

Auslösen der Töne über digitale Ausgänge bei A3, A4, A5

#include <avr/pgmspace.h>
#include<avr/interrupt.h>

//Zuordnung Analog zu Digital
//A0 = D18
//A1 = D19
//A2 = D20
//A3 = D21
//A4 = D22
//A5 = D23
//A6 = D24
//A7 = D25
//A8 = D26
//A9 = D27
//A10 = D28
//A11 = D29

//Zuordnungen:
//Timer0: 11  A3 D21
//Timer1:  9  A4 D22
//Timer2:  5  A5 D23


//Einstellen von Miditonhöhen mit den Timern 1 und 3 im CTC-Mode.

//const unsigned int LOOKUP_OCR1[] = PROGMEM {
const unsigned int LOOKUP_OCR1[] = {
61155, 57723, 54483, 51425, 48539, 45814, 43243, 40816, 38525, 36363, 
34322, 32395, 30577, 28861, 27241, 25712, 24269, 22907, 21621, 20407, 
19262, 18181, 17160, 16197, 15288, 14430, 13620, 12855, 12134, 11453, 
10810, 10203, 9630, 9090, 8580, 64792, 61155, 57723, 54483, 51425, 
48539, 45814, 43243, 40816, 38525, 36363, 34322, 32395, 30577, 28861, 
27241, 25712, 24269, 22907, 21621, 20407, 19262, 18181, 17160, 16197, 
15288, 14430, 13620, 12855, 12134, 11453, 10810, 10203, 9630, 9090, 
8580, 8098, 7644, 7214, 6809, 6427, 6066, 5726, 5404, 5101, 
4815, 4544, 4289, 4049, 3821, 3607, 3404, 3213, 3033, 2862, 
2702, 2550, 2407, 2272, 2144, 2024, 1910, 1803, 1702, 1606, 
1516, 1431, 1350, 1275, 1203, 1135, 1072, 1011, 955, 901, 
850, 803, 757, 715, 675, 637, 601, 567, 535, 505, 
477, 450, 425, 401, 378, 357, 337, 318};


//const unsigned int LOOKUP_N1[] = PROGMEM {
const unsigned int LOOKUP_N1[] = {
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1};


//const unsigned int LOOKUP_OCR0[] = PROGMEM {
const unsigned int LOOKUP_OCR0[] = {
477, 450, 425, 401, 378, 357, 337, 318, 300, 283, 
267, 1011, 955, 901, 850, 803, 757, 715, 675, 637, 
601, 567, 535, 505, 477, 450, 425, 401, 378, 357, 
337, 318, 300, 283, 267, 1011, 955, 901, 850, 803, 
757, 715, 675, 637, 601, 567, 535, 505, 477, 450, 
425, 401, 378, 357, 337, 318, 300, 283, 267, 252, 
238, 224, 212, 200, 189, 178, 168, 158, 149, 141, 
133, 1011, 955, 901, 850, 803, 757, 715, 675, 637, 
601, 567, 535, 505, 477, 450, 425, 401, 378, 357, 
337, 318, 300, 283, 267, 252, 238, 224, 212, 200, 
189, 178, 168, 158, 149, 141, 133, 1011, 955, 901, 
850, 803, 757, 715, 675, 637, 601, 567, 535, 505, 
477, 450, 425, 401, 378, 357, 337, 318};

//const unsigned int LOOKUP_N0[] = PROGMEM {
const unsigned int LOOKUP_N0[] = {
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 
5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1};


//const unsigned int LOOKUP_FEHLER0 = PROGMEM {
const unsigned int LOOKUP_FEHLER0[] = {
8, 1, 14, 10, 10, 3, 8, 6, 1, 6, 
9, 7, 8, 1, 6, 10, 10, 3, 8, 6, 
1, 6, 9, 7, 8, 1, 14, 10, 10, 3, 
8, 6, 1, 6, 9, 7, 8, 1, 6, 10, 
10, 3, 8, 6, 1, 6, 9, 7, 8, 1, 
14, 10, 10, 3, 8, 6, 1, 6, 9, 7, 
8, 37, 14, 10, 36, 3, 8, 48, 57, 6, 
9, 7, 8, 1, 6, 10, 10, 3, 8, 6, 
1, 6, 9, 7, 8, 1, 14, 10, 10, 3, 
8, 6, 1, 6, 9, 7, 8, 37, 14, 10, 
36, 3, 8, 48, 57, 6, 9, 7, 8, 1, 
6, 10, 10, 3, 8, 6, 1, 6, 9, 7, 
8, 1, 14, 10, 10, 3, 8, 6};

int restdauer[] = {0,0,0};

int ZEIT=0;
bool ZUSTAND=false;

unsigned long int TON=0;

ISR(TIMER4_COMPA_vect)
{
    if(ZEIT==4000) 
//    if(ZEIT==32000) 
    {
      digitalWrite(0,ZUSTAND);
      ZUSTAND=!ZUSTAND;        
      ZEIT=0;
      
      TON++;
      TON%=49;
      
      setzeMidihoehe0(TON+36);  //Timer 3
      setzeMidihoehe1(TON+36+4);  //Timer 3
      setzeMidihoehe3(TON+36+7);  //Timer 3
      
    }  
    ZEIT++;

    if(restdauer[0]==0) 
    {
        pinMode(21,0);
        digitalWrite(21,0);
    }
    if(restdauer[1]==0) 
    {
        pinMode(22,0);
        digitalWrite(22,0);
    }
    if(restdauer[2]==0) 
    {
        pinMode(23,0);
        digitalWrite(23,0);
    }
    
    if(restdauer[0]>=0) restdauer[0]--;
    if(restdauer[1]>=0) restdauer[1]--;
    if(restdauer[2]>=0) restdauer[2]--;
}

void initTimer4()
{
  //Vorteilung 2
  TCCR4B &= ~(1<<CS43);
  TCCR4B &= ~(1<<CS42);
  TCCR4B &= ~(1<<CS41);    
  TCCR4B |=  (1<<CS40);
 
  TIMSK4 |= (1<<OCIE4A); //Mode 4
  sei(); 
 
  //Andere Frequenzberechnung:   
  //f = fclk/(2*(OCR1A+1))
  //OCR1A = (fclk/(f*2*N))-1
  //OCR1A = 500000/440 - 1 ==  
  //OCR4B=268; 
  OCR4A=400; 
//  OCR4C=10; 
    
//OCR4B=268;     
//    OCR4A=2; 
//durch Interrupt gesteuert:
  pinMode(0,OUTPUT);    
}

void initTimer0()
{
  TCCR0B=0;
  TCCR0A=0;
  
  TCCR0B &= ~(1<<WGM02);
  TCCR0A |=  (1<<WGM01);
  TCCR0A &= ~(1<<WGM00);
    
  //Vorteilung 64
  TCCR0B &= ~(1<<CS02);
  TCCR0B |= (1<<CS01);
  TCCR0B |= (1<<CS00);
    
  //f = fclk/(2*N*(OCR1A+1))
  //OCR1A = (fclk/(f*2*N))-1
  //OCR1A = 125000/880 - 1 ==  141
  //KORRIGIERT:
  //********************************
  //OCR0A = 62500/440 - 1 ==  142
  //OCR0A = 16000000/(f*4*N) - 1 ==  142
  //********************************
  
  OCR0A=141;  
  
  //Toggle auf OC1A:
  TCCR0A &= ~(1<<COM0A1);
  TCCR0A |=  (1<<COM0A0);
  pinMode(11,OUTPUT);          //OC0A
  pinMode(21,OUTPUT);          //A3 als Schalter
  digitalWrite(21,0);
}

void initTimer1()
{
  TCCR1B &= ~(1<<WGM13); //Mode 4
  TCCR1B |= (1<<WGM12);
  TCCR1A &= ~(1<<WGM11);
  TCCR1A &= ~(1<<WGM10);
    
  //Vorteilung 1: 16000000Hz
  TCCR1B &= ~(1<<CS12);
  TCCR1B &= ~(1<<CS11);
  TCCR1B |= (1<<CS10);
    
  //f = fclk/(2*N*(OCR1A+1))
  //OCR1A = (fclk/(f*2*N))-1
  //OCR1A = 8000000/440 - 1 ==  18181
  //KORRIGIERT:
  //********************************
  //OCR1A = 4000000/440 - 1 ==  9091
  //OCR1A = 16000000/(f*4*N) - 1 ==  9091
  //********************************
  OCR1A=9091;  //0,5Hz == 4 Schläge!
  
  //Toggle auf OC1A:
  TCCR1A &= ~(1<<COM1A1);
  TCCR1A |=  (1<<COM1A0);
  pinMode(9,OUTPUT);      
  pinMode(22,OUTPUT);          //A4 als Schalter
  digitalWrite(22,0);
}

void initTimer3()
{
//  TCCR1B |= (1<<WGM13); //Mode 12
  TCCR3B &= ~(1<<WGM33); //Mode 4
  TCCR3B |= (1<<WGM32);
  TCCR3A &= ~(1<<WGM31);
  TCCR3A &= ~(1<<WGM30);
    
  //Vorteilung 1: 16000000Hz
  TCCR3B &= ~(1<<CS32);
  TCCR3B &= ~(1<<CS31);
  TCCR3B |= (1<<CS30);
    
  //f = fclk/(2*N*(OCR1A+1))
  //OCR1A = (fclk/(f*2*N))-1
  //OCR1A = 8000000/440 - 1 ==  18181
  OCR3A=18181/2;  //0,5Hz == 4 Schläge!
  
  //Toggle auf OC1A:
  TCCR3A &= ~(1<<COM3A1);
  TCCR3A |=  (1<<COM3A0);
  pinMode(5,OUTPUT);    //OC3A  
  pinMode(23,OUTPUT);          //A5 als Schalter
  digitalWrite(23,0);
}




void setzeMidihoehe0(int midi)  //Timer 0
{
  TCCR0B &= 248; //unteren drei Bit löschen
  TCCR0B |= LOOKUP_N0[midi];
  OCR0A=LOOKUP_OCR0[midi];
  
  restdauer[0]=100;
  pinMode(21,OUTPUT);  
  digitalWrite(21,1);
}
void setzeMidihoehe1(int midi)  //Timer 1
{
  TCCR1B &= 248; //unteren drei Bit löschen
  TCCR1B |= LOOKUP_N1[midi];
  OCR1A=LOOKUP_OCR1[midi];
  restdauer[1]=100;
  pinMode(22,OUTPUT);  
  digitalWrite(22,1);
  
}
void setzeMidihoehe3(int midi)  //Timer 3
{
  TCCR3B &= 248; //unteren drei Bit löschen
  TCCR3B |= LOOKUP_N1[midi];
  OCR3A=LOOKUP_OCR1[midi];
  restdauer[2]=100;
  pinMode(23,OUTPUT);  
  digitalWrite(23,1);
}


void setup() 
{
    initTimer0();
    initTimer1();
    initTimer3();
    initTimer4();
}

void loop()
{
}

Code 9.29-2: Auslösen der Töne über digitale Ausgänge bei A3, A4, A5