kopia lustrzana https://github.com/dgatf/Oscilloscope
Update
rodzic
9a957e0077
commit
195803eb1a
|
@ -1,6 +1,6 @@
|
|||
# Oscilloscope Serial
|
||||
|
||||
A simple oscilloscope application that reads the values in the serial that generated by an Arduino board based on the value of the analog pin A0
|
||||
A simple oscilloscope application that reads the values at serial port generated by an Arduino board and based on the value of the analog pin A0
|
||||
|
||||
<p align="center"><img src="./images/img1.png" width="600"><br>
|
||||
<i>Main window</i><br><br></p>
|
||||
|
|
|
@ -1,31 +1,27 @@
|
|||
//uint8_t val = 5;
|
||||
#define FREQ 100 // HZ
|
||||
#define DUTY 0.5 // %/100
|
||||
|
||||
#define MS_TO_COMP(SCALER) (F_CPU / (SCALER * 1000.0))
|
||||
|
||||
void setup() {
|
||||
pinMode(A0, INPUT);
|
||||
Serial.begin(1000000);
|
||||
//DDRB |= _BV(DDB3);
|
||||
//TCCR2A = _BV(COM2A1) | _BV(COM2A0) | _BV(WGM21) | _BV(WGM20);
|
||||
//TCCR2B = _BV(WGM22) | _BV(CS22)| _BV(CS21) | _BV(CS20);
|
||||
//OCR2A = 120;
|
||||
|
||||
DDRB |= _BV(DDB2);
|
||||
TCCR1A = _BV(WGM11) | _BV(WGM10);
|
||||
TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS11); // scaler 8
|
||||
|
||||
TCCR1A |= _BV(COM1B1);
|
||||
OCR1A = 10 * MS_TO_COMP(8);
|
||||
OCR1B = 0.5 * OCR1A;
|
||||
|
||||
pinMode(A0, INPUT);
|
||||
Serial.begin(1000000);
|
||||
|
||||
// PWM 100Hz, 50% DUTY, PIN B2
|
||||
DDRB |= _BV(DDB2);
|
||||
TCCR1A = _BV(WGM11) | _BV(WGM10);
|
||||
TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS11); // scaler 8
|
||||
TCCR1A |= _BV(COM1B1);
|
||||
OCR1A = 1000 / 100 * MS_TO_COMP(8);
|
||||
OCR1B = 0.5 * OCR1A;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
static uint16_t ts = 0;
|
||||
if ((uint16_t)micros() - ts > 100)
|
||||
{
|
||||
ts = micros();
|
||||
uint8_t val = analogRead(A0) >> 2;
|
||||
Serial.write(val);
|
||||
}
|
||||
static uint16_t ts = 0;
|
||||
if ((uint16_t)micros() - ts > 100)
|
||||
{
|
||||
ts = micros();
|
||||
uint8_t val = analogRead(A0) >> 2;
|
||||
Serial.write(val);
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue