-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from TheBookThief/feature/tuner
Feature/tuner
- Loading branch information
Showing
9 changed files
with
519 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"board": "arduino:avr:nano", | ||
"configuration": "cpu=atmega328", | ||
"sketch": "main.ino", | ||
"port": "COM4", | ||
"output": "../ArduinoOutput" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Win32", | ||
"includePath": [ | ||
"D:\\Tools\\_development\\arduino-1.8.11\\tools\\**", | ||
"D:\\Tools\\_development\\arduino-1.8.11\\hardware\\arduino\\avr\\**" | ||
], | ||
"forcedInclude": [ | ||
"D:\\Tools\\_development\\arduino-1.8.11\\hardware\\arduino\\avr\\cores\\arduino\\Arduino.h" | ||
], | ||
"intelliSenseMode": "msvc-x64" | ||
} | ||
], | ||
"version": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Arduino", | ||
"type": "arduino", | ||
"request": "launch", | ||
"program": "${file}", | ||
"cwd": "${workspaceFolder}", | ||
"MIMode": "gdb", | ||
"targetArchitecture": "arm", | ||
"miDebuggerPath": "", | ||
"debugServerPath": "", | ||
"debugServerArgs": "", | ||
"customLaunchSetupCommands": [ | ||
{ | ||
"text": "target remote localhost:3333" | ||
}, | ||
{ | ||
"text": "file \"${file}\"" | ||
}, | ||
{ | ||
"text": "load" | ||
}, | ||
{ | ||
"text": "monitor reset halt" | ||
}, | ||
{ | ||
"text": "monitor reset init" | ||
} | ||
], | ||
"stopAtEntry": true, | ||
"serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware", | ||
"launchCompleteCommand": "exec-continue", | ||
"filterStderr": true, | ||
"args": [] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//Credits: http://www.breadboarding.de/frequenzmessung-arduino/ | ||
|
||
int zaehler; | ||
unsigned long timer; | ||
unsigned long timerOld; | ||
unsigned long startzeit; | ||
unsigned long messzeit = 1000000; | ||
|
||
void setup(){ | ||
|
||
Serial.begin(9600); | ||
|
||
|
||
} | ||
|
||
|
||
void loop(){ | ||
if ((micros() - startzeit) >= messzeit) | ||
{ | ||
float f = timer; //Datentyp 'float', wegen untenstehender Division | ||
f = 1000000/f; //Aus Periodendauer Frequenz berechnen | ||
detachInterrupt(0); | ||
if(f >= 300){ | ||
Serial.print("Zaehler: "); | ||
Serial.println(zaehler); | ||
} | ||
else if(f < 300 && f >= 30){ | ||
Serial.print("Messung: "); | ||
Serial.println(f, 1); | ||
} | ||
else if(f < 30 && f >= 3){ | ||
Serial.print("Messung: "); | ||
Serial.println(f, 3); | ||
} | ||
else if(f < 3){ | ||
Serial.print("Messung: "); | ||
Serial.println(f, 5); | ||
} | ||
attachInterrupt(digitalPinToInterrupt(2), Messung, RISING); | ||
zaehler = 0; //Frequenzzähler zurücksetzen | ||
startzeit = micros(); //Zeitpunkt der letzten Ausgabe speichern | ||
} | ||
} | ||
|
||
void Messung() | ||
{ | ||
zaehler++; | ||
timer = micros() - timerOld; | ||
timerOld = micros(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "tuner.h" | ||
#include "Arduino.h" | ||
|
||
|
||
int zaehler,zAvrg=0; | ||
unsigned long timer, timerOld; | ||
unsigned long startzeit; | ||
unsigned long messzeit = 1000000/4; | ||
float frqColl[5]; | ||
|
||
// 0 1 2 3 4 5 6 | ||
char notes[7] = {'C','D','E','F','G','A','B'}; | ||
float freq[27][2] = { | ||
{27.5, 5}, | ||
{30.9, 6}, | ||
{32.7, 0}, | ||
{36.7, 1}, | ||
{41.2, 2}, | ||
{43.7, 3}, | ||
{49.0, 4}, | ||
{55.0, 5}, | ||
{61.7, 6}, | ||
{65.4, 0}, | ||
{73.4, 1}, | ||
{82.4, 2}, | ||
{87.3, 3}, | ||
{98.0, 4}, | ||
{110.0,5}, | ||
{123.4,6}, | ||
{130.8,0}, | ||
{146.8,1}, | ||
{164.8,2}, | ||
{174.6,3}, | ||
{196.0,4}, | ||
{220.0,5}, | ||
{246.9,6}, | ||
{261.6,0}, | ||
{293.7,1}, | ||
{329.6,2}, | ||
{349.2,3} | ||
}; | ||
|
||
|
||
void Messung() | ||
{ | ||
zaehler++; | ||
timer = micros() - timerOld; | ||
timerOld = micros(); | ||
} | ||
|
||
|
||
float getAvrgFreq(float fA){ | ||
if(zAvrg>=5)zAvrg=0; //Zähler zurücksetzen | ||
if(isinf(fA))fA=0; //um fehlerhafte Kalkulation zu vermeiden | ||
frqColl[zAvrg] = fA; | ||
zAvrg++; | ||
|
||
float avrg=0.00f; | ||
for (int i=0; i < 5; i++){ | ||
avrg = avrg + frqColl[i]; | ||
} | ||
return (avrg/5); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef TUNER_H | ||
#define TUNER_H | ||
|
||
extern int zaehler; | ||
extern unsigned long timer; | ||
extern unsigned long timerOld; | ||
extern unsigned long startzeit; | ||
extern unsigned long messzeit; | ||
|
||
extern void Messung(); | ||
extern float getAvrgFreq(float); | ||
|
||
extern char notes[7]; | ||
extern float freq[27][2]; | ||
|
||
#endif /* TUNER_H */ | ||
|
||
|
Oops, something went wrong.