kopia lustrzana https://github.com/dgatf/Oscilloscope
Update
rodzic
195803eb1a
commit
7fb759369c
18
README.md
18
README.md
|
@ -4,3 +4,21 @@ A simple oscilloscope application that reads the values at serial port generated
|
||||||
|
|
||||||
<p align="center"><img src="./images/img1.png" width="600"><br>
|
<p align="center"><img src="./images/img1.png" width="600"><br>
|
||||||
<i>Main window</i><br><br></p>
|
<i>Main window</i><br><br></p>
|
||||||
|
|
||||||
|
<p align="center"><img src="./images/img2.png" width="300"><br>
|
||||||
|
<i>Settings</i><br><br></p>
|
||||||
|
|
||||||
|
Flash oscilloscpe.ino to an arduino board. In the Oscilloscope gui settings select the serial port with correct properties. By default 1000000bps, 8bits, no paraty, 1 stop bot and no flow control and an interval of 100ms between analog readings.
|
||||||
|
|
||||||
|
For ATmega based boards there is a PWM signal at pin B2(OC1B). To test the Oscilloscope app connect pin B2 to pin A0
|
||||||
|
Adjust PWM signal with PWM_FREQ and PWM_DUTY. Default is 100Hz, 50% duty.
|
||||||
|
|
||||||
|
Pin B2 location:
|
||||||
|
- Uno, Leonardo: pin 10
|
||||||
|
- ATmega2560: pin 12
|
||||||
|
|
||||||
|
To build the Oscilloscope app:
|
||||||
|
- install qt
|
||||||
|
- cd to src/qt folder
|
||||||
|
- qmake
|
||||||
|
- make
|
||||||
|
|
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 44 KiB |
|
@ -1,24 +1,37 @@
|
||||||
#define FREQ 100 // HZ
|
/* Interval between analog readings. It has to be the same as defined in the Oscilloscope settings */
|
||||||
#define DUTY 0.5 // %/100
|
#define INTERVAL 100// microseconds (us)
|
||||||
|
|
||||||
|
/* PWM signal properties */
|
||||||
|
#define PWM_FREQ 100 // HZ
|
||||||
|
#define PWM_DUTY 0.5 // %/100
|
||||||
|
|
||||||
#define MS_TO_COMP(SCALER) (F_CPU / (SCALER * 1000.0))
|
#define MS_TO_COMP(SCALER) (F_CPU / (SCALER * 1000.0))
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(A0, INPUT);
|
pinMode(A0, INPUT);
|
||||||
Serial.begin(1000000);
|
Serial.begin(1000000);
|
||||||
|
|
||||||
// PWM 100Hz, 50% DUTY, PIN B2
|
#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328PB__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega32U4__)
|
||||||
|
/* PWM signal is available at pin B2(OC1B). To test the Oscilloscope app connect pin B2 to pin A0
|
||||||
|
Adjust PWM signal with PWM_FREQ and PWM_DUTY
|
||||||
|
Pin B2:
|
||||||
|
Uno, Leonardo: pin 10
|
||||||
|
ATmega2560: pin 12
|
||||||
|
PWM 100Hz, 50% DUTY, PIN B2
|
||||||
|
*/
|
||||||
DDRB |= _BV(DDB2);
|
DDRB |= _BV(DDB2);
|
||||||
TCCR1A = _BV(WGM11) | _BV(WGM10);
|
TCCR1A = _BV(WGM11) | _BV(WGM10);
|
||||||
TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS11); // scaler 8
|
TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS11); // scaler 8
|
||||||
TCCR1A |= _BV(COM1B1);
|
TCCR1A |= _BV(COM1B1);
|
||||||
OCR1A = 1000 / 100 * MS_TO_COMP(8);
|
OCR1A = 1000 / PWM_FREQ * MS_TO_COMP(8);
|
||||||
OCR1B = 0.5 * OCR1A;
|
OCR1B = PWM_DUTY * OCR1A;
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
static uint16_t ts = 0;
|
static uint16_t ts = 0;
|
||||||
if ((uint16_t)micros() - ts > 100)
|
if ((uint16_t)micros() - ts > INTERVAL)
|
||||||
{
|
{
|
||||||
ts = micros();
|
ts = micros();
|
||||||
uint8_t val = analogRead(A0) >> 2;
|
uint8_t val = analogRead(A0) >> 2;
|
||||||
|
|
Ładowanie…
Reference in New Issue