Pada pagi hari ini, saya akan menjelaskan mengenai bagaimana cara men-sampling tegangan DC atau sinyal yang berbentuk sinus agar terdeteksi nilai Vp / nilai puncaknya, biasanya ini yang membuat kebanyakan orang bingung bagaimana cara menentukan dan mendapatkan nilai tegangan DC sinus, sebenarnya cara untuk mendapatkannya cukup mudah yaitu dengan mensampling data sekecil mungkin dan data sampling bisa disimpan sebanyak mungkin, ini diperuntukkan agar nilai tertinggi dapat diketahui dan dideteksi setiap kali proses sampling dilakukan, saya mencoba pakai Arduino UNO dengan frekuensi sampling 8,9 KHz / 50KHz namun data yang tersimpan hanya 100 data, namun jika Arduino Mega dapat menyimpan lebih banyak lagi hingga mencapai 300 data, maka dari itu saya sarankan untuk menggunakan Arduino Mega untuk sinyal sinus yang rentang nya besar. Berikut adalah program untuk mencari nilai tertinggi dari 300 data yang disampling.
1. Program Arduino
// Arrays to save our results in
unsigned long start_times[300];
unsigned long stop_times[300];
unsigned long values[300];
// Define various ADC prescaler
const unsigned char PS_16 = (1 << ADPS2);
const unsigned char PS_32 = (1 << ADPS2) | (1 << ADPS0);
const unsigned char PS_64 = (1 << ADPS2) | (1 << ADPS1);
const unsigned char PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);
// Setup the serial port and pin 2
void setup() {
Serial.begin(9600);
// set up the ADC
ADCSRA &= ~PS_128; // remove bits set by Arduino library
// you can choose a prescaler from above.
// PS_16, PS_32, PS_64 or PS_128
ADCSRA |= PS_128; // set our own prescaler to 64 / 128 / 32 / 16
}
void loop() {
unsigned int i;
unsigned int z;
z = 0;
// capture the values to memory
for(i=0;i<300;i++) {
start_times[i] = micros();
values[i] = analogRead(0);
if (values[i] >= z) {
z = values[i];
}
stop_times[i] = micros();
}
// print out the results
Serial.println("\n\n--- Results ---");
for(i=0 ; i<300 ;i++ ) {
Serial.print(values[i]);
Serial.print(" ");
Serial.print(z);
Serial.print(" ");
Serial.print(" ");
Serial.print(" elapse = ");
Serial.print(stop_times[i] - start_times[i]);
Serial.print(" us\n");
}
z = 0;
}
unsigned long start_times[300];
unsigned long stop_times[300];
unsigned long values[300];
// Define various ADC prescaler
const unsigned char PS_16 = (1 << ADPS2);
const unsigned char PS_32 = (1 << ADPS2) | (1 << ADPS0);
const unsigned char PS_64 = (1 << ADPS2) | (1 << ADPS1);
const unsigned char PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);
// Setup the serial port and pin 2
void setup() {
Serial.begin(9600);
// set up the ADC
ADCSRA &= ~PS_128; // remove bits set by Arduino library
// you can choose a prescaler from above.
// PS_16, PS_32, PS_64 or PS_128
ADCSRA |= PS_128; // set our own prescaler to 64 / 128 / 32 / 16
}
void loop() {
unsigned int i;
unsigned int z;
z = 0;
// capture the values to memory
for(i=0;i<300;i++) {
start_times[i] = micros();
values[i] = analogRead(0);
if (values[i] >= z) {
z = values[i];
}
stop_times[i] = micros();
}
// print out the results
Serial.println("\n\n--- Results ---");
for(i=0 ; i<300 ;i++ ) {
Serial.print(values[i]);
Serial.print(" ");
Serial.print(z);
Serial.print(" ");
Serial.print(" ");
Serial.print(" elapse = ");
Serial.print(stop_times[i] - start_times[i]);
Serial.print(" us\n");
}
z = 0;
}
2. Hasil sampling 100 data
549 716 elapse = 116 us
558 716 elapse = 112 us
566 716 elapse = 116 us
573 716 elapse = 116 us
580 716 elapse = 116 us
587 716 elapse = 116 us
592 716 elapse = 116 us
598 716 elapse = 116 us
603 716 elapse = 120 us
609 716 elapse = 112 us
616 716 elapse = 112 us
622 716 elapse = 112 us
628 716 elapse = 112 us
636 716 elapse = 112 us
642 716 elapse = 112 us
648 716 elapse = 112 us
654 716 elapse = 112 us
658 716 elapse = 112 us
664 716 elapse = 120 us
669 716 elapse = 116 us
675 716 elapse = 116 us
679 716 elapse = 116 us
683 716 elapse = 116 us
688 716 elapse = 116 us
690 716 elapse = 116 us
693 716 elapse = 112 us
696 716 elapse = 124 us
699 716 elapse = 116 us
701 716 elapse = 116 us
705 716 elapse = 116 us
707 716 elapse = 116 us
710 716 elapse = 116 us
712 716 elapse = 116 us
713 716 elapse = 116 us
713 716 elapse = 120 us
714 716 elapse = 112 us
714 716 elapse = 112 us
714 716 elapse = 112 us
715 716 elapse = 112 us
716 716 elapse = 112 us
716 716 elapse = 112 us
716 716 elapse = 112 us
714 716 elapse = 112 us
712 716 elapse = 120 us
709 716 elapse = 116 us
705 716 elapse = 116 us
702 716 elapse = 116 us
698 716 elapse = 116 us
694 716 elapse = 116 us
690 716 elapse = 116 us
686 716 elapse = 116 us
682 716 elapse = 120 us
678 716 elapse = 112 us
674 716 elapse = 116 us
670 716 elapse = 116 us
666 716 elapse = 116 us
661 716 elapse = 116 us
657 716 elapse = 116 us
653 716 elapse = 116 us
648 716 elapse = 116 us
643 716 elapse = 124 us
637 716 elapse = 120 us
630 716 elapse = 116 us
624 716 elapse = 116 us
618 716 elapse = 116 us
611 716 elapse = 116 us
605 716 elapse = 116 us
598 716 elapse = 116 us
591 716 elapse = 116 us
583 716 elapse = 116 us
576 716 elapse = 112 us
568 716 elapse = 112 us
559 716 elapse = 112 us
549 716 elapse = 112 us
541 716 elapse = 112 us
532 716 elapse = 112 us
525 716 elapse = 112 us
518 716 elapse = 116 us
511 716 elapse = 116 us
503 716 elapse = 116 us
496 716 elapse = 116 us
488 716 elapse = 116 us
481 716 elapse = 116 us
472 716 elapse = 116 us
465 716 elapse = 116 us
457 716 elapse = 116 us
449 716 elapse = 116 us
442 716 elapse = 116 us
436 716 elapse = 116 us
430 716 elapse = 116 us
423 716 elapse = 116 us
418 716 elapse = 116 us
412 716 elapse = 116 us
406 716 elapse = 116 us
400 716 elapse = 120 us
392 716 elapse = 112 us
385 716 elapse = 112 us
378 716 elapse = 112 us
373 716 elapse = 112 us
367 716 elapse = 112 us
558 716 elapse = 112 us
566 716 elapse = 116 us
573 716 elapse = 116 us
580 716 elapse = 116 us
587 716 elapse = 116 us
592 716 elapse = 116 us
598 716 elapse = 116 us
603 716 elapse = 120 us
609 716 elapse = 112 us
616 716 elapse = 112 us
622 716 elapse = 112 us
628 716 elapse = 112 us
636 716 elapse = 112 us
642 716 elapse = 112 us
648 716 elapse = 112 us
654 716 elapse = 112 us
658 716 elapse = 112 us
664 716 elapse = 120 us
669 716 elapse = 116 us
675 716 elapse = 116 us
679 716 elapse = 116 us
683 716 elapse = 116 us
688 716 elapse = 116 us
690 716 elapse = 116 us
693 716 elapse = 112 us
696 716 elapse = 124 us
699 716 elapse = 116 us
701 716 elapse = 116 us
705 716 elapse = 116 us
707 716 elapse = 116 us
710 716 elapse = 116 us
712 716 elapse = 116 us
713 716 elapse = 116 us
713 716 elapse = 120 us
714 716 elapse = 112 us
714 716 elapse = 112 us
714 716 elapse = 112 us
715 716 elapse = 112 us
716 716 elapse = 112 us
716 716 elapse = 112 us
716 716 elapse = 112 us
714 716 elapse = 112 us
712 716 elapse = 120 us
709 716 elapse = 116 us
705 716 elapse = 116 us
702 716 elapse = 116 us
698 716 elapse = 116 us
694 716 elapse = 116 us
690 716 elapse = 116 us
686 716 elapse = 116 us
682 716 elapse = 120 us
678 716 elapse = 112 us
674 716 elapse = 116 us
670 716 elapse = 116 us
666 716 elapse = 116 us
661 716 elapse = 116 us
657 716 elapse = 116 us
653 716 elapse = 116 us
648 716 elapse = 116 us
643 716 elapse = 124 us
637 716 elapse = 120 us
630 716 elapse = 116 us
624 716 elapse = 116 us
618 716 elapse = 116 us
611 716 elapse = 116 us
605 716 elapse = 116 us
598 716 elapse = 116 us
591 716 elapse = 116 us
583 716 elapse = 116 us
576 716 elapse = 112 us
568 716 elapse = 112 us
559 716 elapse = 112 us
549 716 elapse = 112 us
541 716 elapse = 112 us
532 716 elapse = 112 us
525 716 elapse = 112 us
518 716 elapse = 116 us
511 716 elapse = 116 us
503 716 elapse = 116 us
496 716 elapse = 116 us
488 716 elapse = 116 us
481 716 elapse = 116 us
472 716 elapse = 116 us
465 716 elapse = 116 us
457 716 elapse = 116 us
449 716 elapse = 116 us
442 716 elapse = 116 us
436 716 elapse = 116 us
430 716 elapse = 116 us
423 716 elapse = 116 us
418 716 elapse = 116 us
412 716 elapse = 116 us
406 716 elapse = 116 us
400 716 elapse = 120 us
392 716 elapse = 112 us
385 716 elapse = 112 us
378 716 elapse = 112 us
373 716 elapse = 112 us
367 716 elapse = 112 us
No comments:
Post a Comment