Created
September 8, 2014 11:25
-
-
Save aki-lua87/63b30838e39bf7f6d300 to your computer and use it in GitHub Desktop.
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
#include<TimerOne.h> | |
#define INPUT_PIN 7 | |
#define LED_PIN 13 | |
#define MAX 500 | |
volatile int i = 0; | |
volatile int temp[MAX+25]; | |
volatile int mk[127]; | |
void ber() | |
{ | |
temp[i++] = digitalRead(INPUT_PIN); | |
} | |
void setup() | |
{ | |
pinMode(INPUT_PIN,INPUT); | |
pinMode(LED_PIN,OUTPUT); | |
Serial.begin(115200); | |
int x,y,input = 0,BitError = 0; | |
//M系列生成 | |
mk[0] = 1; | |
mk[1] = 1; | |
mk[2] = 1; | |
mk[3] = 1; | |
mk[4] = 1; | |
mk[5] = 1; | |
mk[6] = 1; | |
for(int b = 7;b < 127;b++) | |
{ | |
mk[b] = mk[b-7]^mk[b-1]; | |
} | |
digitalWrite(LED_PIN,HIGH); //スタート | |
Timer1.initialize(25); //クロック(25us) | |
Timer1.attachInterrupt(ber); //割り込み | |
while(1) //割り込み終了 | |
{ | |
if(i >= MAX-1) | |
{ | |
Timer1.detachInterrupt(); | |
break; | |
} | |
} | |
digitalWrite(LED_PIN,LOW); //エンド | |
//頭出し | |
for(int a = 0;a < MAX;a++) | |
{ | |
if(temp[a] == 1 && temp[a+1] == 1 && temp[a+2] == 1 && temp[a+3] == 1 && temp[a+4] == 1 && temp[a+5] == 1 && temp[a+6] == 1) | |
{ | |
x = a; | |
break; | |
} | |
} | |
int b = 0; | |
for(int a = x;a < MAX;a++) | |
{ | |
Serial.print(a-x); | |
Serial.print(":::"); | |
if(b == 127) | |
{ | |
if(0 == temp[a]){input++;} | |
else{input++; BitError++;} | |
Serial.print("000"); //デバック用 | |
b = 0; | |
} | |
else | |
{ | |
if(mk[b] == temp[a]){input++;} | |
else {input++; BitError++;} | |
Serial.print(mk[b]); | |
b++; | |
} | |
Serial.print(":::"); | |
Serial.println(temp[a]); | |
} | |
Serial.print(" InputBit -> "); | |
Serial.print(input); | |
Serial.print(" BitError -> "); | |
Serial.print(BitError); | |
Serial.print(" BER -> "); | |
Serial.println(100*BitError/input); | |
} | |
void loop() | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment