12,500Hz 구형파에서 펄스를 계산하여 출력을 트리거하려고했습니다. 여기까지 내가 가진 코드가 있습니다. Arduino가 재설정되면 25ms 샘플에서 315를 직렬로 인쇄합니다. 315 x 40 = 12600. 그것은 완벽하게 작동하는 것 같습니다.
내 유일한 문제는 보드를 재설정 할 때이 번호를 한 번만 반환한다는 것입니다. 이제 동일한 코드를로 아래로 이동하면 void loop연속적으로 계산 되어 불변의 수익을 얻습니다.
루프 섹션에 넣을 내용을 이해하지 못하므로 일정 기간 동안 입력 핀의 토글 수를 반복적으로 정확하게 계산할 수 있으므로 12,500의 존재 여부에 따라 출력에 무언가를 할 수 있습니다 Hz 신호 또는 아닙니다.
volatile int IRQcount;
int pin = 2;
int pin_irq = 0; //IRQ that matches to pin 2
void setup() {
// Put your setup code here, to run once:
Serial.begin (9600);
attachInterrupt(pin_irq, IRQcounter, RISING);
delay(25);
detachInterrupt(pin);
Serial.print(F("Counted = "));
Serial.println(IRQcount);
}
void IRQcounter() {
IRQcount++;
}
void loop() {
// Put your main code here, to run repeatedly:
}
위의 코드를 사용하여 재설정 버튼을 누를 때마다 직렬 창에 한 줄이 표시됩니다.
Counted = 441
Counted = 442
Counted = 441
Counted = 441
Counted = 441
이제 동일한 결과를 원하지만 반복해서 반복하고 싶습니다. 그렇게하면 신호가 끊어지면 출력을 끌 수 있습니다 (LOW). 신호가 있으면 출력이 높아집니다.
내 시도는 첨부 인터럽트를 아래로 이동하여 void loop반복되었습니다. 그 모습은 다음과 같습니다.
volatile int IRQcount;
int pin = 2;
int pin_irq = 0; //IRQ that matches to pin 2
void setup() {
// Put your setup code here, to run once:
Serial.begin (9600);
}
void IRQcounter() {
IRQcount++;
}
void loop() {
// Put your main code here, to run repeatedly:
attachInterrupt(pin_irq, IRQcounter, RISING);
delay(25);
detachInterrupt(pin);
Serial.print(F("Counted = "));
Serial.println(IRQcount);
}
내가 얻는 수익은 자체 업데이트이지만 매번 0에서 시작하는 대신 "count"는 이전 카운트에서 시작합니다. 그래서 점점 커집니다. 12500Hz 신호를 나타내는 상수 값을 반환하여 출력 만 트리거하도록하려고합니다.
Counted = 442
Counted = 886
Counted = 1330
Counted = 177
Counted = 2221
Counted = 2667
Counted = 3112
Counted = 3557
Counted = 4002
Counted = 4448
Counted = 4893
Counted = 5338
Counted = 5784
Counted = 6229
Counted = 6674
Counted = 7120
Counted = 7565
Counted = 8010
Counted = 8456
Counted = 8901
Counted = 9347
Counted = 9792
Counted = 10237
Counted = 10683
Counted = 11130
Counted = 11576
Counted = 12022
Counted = 12469
Counted = 12915
Counted = 13361
Counted = 13808
Counted = 14254
Counted = 14700
Counted = 15147
Counted = 15593
Counted = 16040
Counted = 16486
Counted = 16932
Counted = 17378
Counted = 17825
Counted = 18271
Counted = 18717
Counted = 19164
Counted = 19610
Counted = 20056
Counted = 20503
Counted = 20949
Counted = 21395
Counted = 21842
Counted = 22288
Counted = 22735
Counted = 23169
Counted = 23616
Counted = 24062
Counted = 24508
Counted = 24955
Counted = 25401
Counted = 25730
Counted = 25756
Counted = 26200
Counted = 26646
Counted = 27093
Counted = 27539
Counted = 27985
Counted = 28432
Counted = 28878
Counted = 29324
Counted = 29770
Counted = 30217
Counted = 30663
Counted = 31110
Counted = 31556
Counted = 32002
Counted = 32449
Counted = -32641
Counted = -32195
Counted = -31748
Counted = -31302
Counted = -30855
Counted = -30408
Counted = -29962
Counted = -29515
Counted = -29069
Counted = -28622