Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
karudu
/
Scope
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
beb6ac6c
authored
Nov 03, 2022
by
karudu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ekraanitäie mõõtmise režiim, sakkide näitamine, peatamise nupp
parent
17d365e7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
15 deletions
scope.ino
scope.ino
View file @
beb6ac6c
#define PIN_BUTTON_1 5
#define PIN_BUTTON_1 5
// BUTTON_RANGE_DN
#define PIN_BUTTON_2 4
#define PIN_BUTTON_2 4
// BUTTON_RANGE_UP
#define PIN_BUTTON_3 3
#define PIN_BUTTON_3 3
// BUTTON_FREQ
#define PIN_BUTTON_4 2
#define PIN_BUTTON_4 2
// BUTTON_SHUTDOWN
#define PIN_ADC 7 // A7
#define PIN_ADC 7 // A7
#define BUTTON_RANGE_DN 0
#define BUTTON_RANGE_DN 0
#define BUTTON_RANGE_UP 1
#define BUTTON_RANGE_UP 1
#define BUTTON_FREQ 2 // Change frequency
#define BUTTON_FREQ 2 // Change frequency
#define BUTTON_
RUNSTOP
3
#define BUTTON_
SHUTDOWN
3
#define PERIOD_10MS 0
#define PERIOD_10MS 0
#define PERIOD_1MS 1
#define PERIOD_1MS 1
...
@@ -16,22 +16,36 @@
...
@@ -16,22 +16,36 @@
#define PERIOD_100MS 4
#define PERIOD_100MS 4
#define PERIOD_1S 5
#define PERIOD_1S 5
/* Configuration options */
// Cursor values in format xx.x
// Cursor values in format xx.x
#define CURSOR_1 "5.0"
#define CURSOR_1 "5.0"
#define CURSOR_2 "0.0"
#define CURSOR_2 "0.0"
// Uncomment to run in oneshot mode
//#define ONESHOT_MODE
// Period to measure in
#define ONESHOT_PERIOD PERIOD_1MS
// How many points to measure before stopping (Serial Monitor display is 49 points wide)
#define ONESHOT_POINTS 49
// https://www.gammon.com.au/adc
// https://www.gammon.com.au/adc
/
/ Globals
/
* Globals */
char
G_PrintfBuf
[
32
];
char
G_PrintfBuf
[
32
];
char
G_CursorBuf
[
5
+
1
+
5
+
1
+
1
];
char
G_CursorBuf
[
5
+
1
+
5
+
1
+
1
];
char
G_MeasureFreq
;
char
G_MeasureFreq
;
char
G_TimeCounter
;
#define TIME_L_VALUE '0'
#define TIME_H_VALUE "0.5"
#ifdef ONESHOT_MODE
int
G_OneshotPoints
;
#endif
// ReadButton globals
// ReadButton globals
unsigned
long
G_LastDebounceTime
[
4
];
unsigned
long
G_LastDebounceTime
[
4
];
int
G_ButtonState
[
4
];
int
G_ButtonState
[
4
];
int
G_PrevButtonState
[
4
];
int
G_PrevButtonState
[
4
];
#define DEBOUNCE_DELAY_MS 25
#define DEBOUNCE_DELAY_MS 25
// Flash data
/* Flash data */
extern
const
char
FLASH_VoltageTable
[
1024
*
3
]
PROGMEM
;
extern
const
char
FLASH_VoltageTable
[
1024
*
3
]
PROGMEM
;
byte
ReadButton
(
int
Button
)
byte
ReadButton
(
int
Button
)
...
@@ -53,6 +67,21 @@ byte ReadButton(int Button)
...
@@ -53,6 +67,21 @@ byte ReadButton(int Button)
return
0
;
return
0
;
}
}
// Restore peripherals to default state and stop the program
void
Stop
()
{
TCCR1A
=
0
;
TCCR1B
=
0
;
// Stop the timer
Serial
.
end
();
Serial
.
begin
(
9600
);
ADCSRA
=
bit
(
ADEN
);
ADCSRA
|=
bit
(
ADPS2
)
|
bit
(
ADPS1
)
|
bit
(
ADPS0
);
// Prescaler 128
ADMUX
=
bit
(
REFS0
)
|
PIN_ADC
;
ADCSRB
=
bit
(
ADTS0
);
for
(;;)
{}
}
// Error occured, light the onboard LED and stop the program
// Error occured, light the onboard LED and stop the program
void
Error
()
void
Error
()
{
{
...
@@ -141,9 +170,23 @@ ISR(ADC_vect)
...
@@ -141,9 +170,23 @@ ISR(ADC_vect)
Serial
.
write
(
'.'
);
Serial
.
write
(
'.'
);
Serial
.
write
(
pgm_read_word_near
(
FLASH_VoltageTable
+
P
+
1
));
Serial
.
write
(
pgm_read_word_near
(
FLASH_VoltageTable
+
P
+
1
));
Serial
.
write
(
pgm_read_word_near
(
FLASH_VoltageTable
+
P
+
2
));
Serial
.
write
(
pgm_read_word_near
(
FLASH_VoltageTable
+
P
+
2
));
if
(
G_MeasureFreq
!=
PERIOD_100US
)
{
Serial
.
write
(
'\t'
);
G_TimeCounter
--
;
if
(
G_TimeCounter
==
0
)
{
G_TimeCounter
=
10
;
Serial
.
write
(
TIME_H_VALUE
);
}
else
Serial
.
write
(
TIME_L_VALUE
);
}
Serial
.
write
(
'\r'
);
Serial
.
write
(
'\r'
);
Serial
.
write
(
'\n'
);
Serial
.
write
(
'\n'
);
#ifdef ONESHOT_MODE
G_OneshotPoints
++
;
if
(
G_OneshotPoints
==
ONESHOT_POINTS
+
1
)
Stop
();
#endif
//Serial.println(micros() - tstart);
//Serial.println(micros() - tstart);
}
}
...
@@ -158,15 +201,22 @@ void setup()
...
@@ -158,15 +201,22 @@ void setup()
pinMode
(
PIN_BUTTON_4
,
INPUT_PULLUP
);
pinMode
(
PIN_BUTTON_4
,
INPUT_PULLUP
);
Serial
.
begin
(
2000000
);
Serial
.
begin
(
2000000
);
#ifndef ONESHOT_MODE
SetTimerPeriod
(
PERIOD_10MS
);
SetTimerPeriod
(
PERIOD_10MS
);
G_MeasureFreq
=
PERIOD_10MS
;
G_MeasureFreq
=
PERIOD_10MS
;
#else
SetTimerPeriod
(
ONESHOT_PERIOD
);
G_MeasureFreq
=
ONESHOT_PERIOD
;
G_OneshotPoints
=
0
;
#endif
InitADC
();
InitADC
();
for
(
int
i
=
0
;
i
<
4
;
i
++
)
G_LastDebounceTime
[
i
]
=
0
;
for
(
int
i
=
0
;
i
<
4
;
i
++
)
G_LastDebounceTime
[
i
]
=
0
;
for
(
int
i
=
0
;
i
<
4
;
i
++
)
G_PrevButtonState
[
i
]
=
HIGH
;
for
(
int
i
=
0
;
i
<
4
;
i
++
)
G_PrevButtonState
[
i
]
=
HIGH
;
sprintf
(
G_CursorBuf
,
"%s
\t
%s
\t
"
,
CURSOR_1
,
CURSOR_2
);
// Precalculate the cursor string
sprintf
(
G_CursorBuf
,
"%s
\t
%s
\t
"
,
CURSOR_1
,
CURSOR_2
);
// Precalculate the cursor string
G_TimeCounter
=
10
;
}
}
int
lstate
=
LOW
;
int
lstate
=
LOW
;
...
@@ -189,15 +239,12 @@ void loop()
...
@@ -189,15 +239,12 @@ void loop()
if
(
ReadButton
(
BUTTON_FREQ
)
==
1
)
if
(
ReadButton
(
BUTTON_FREQ
)
==
1
)
{
{
G_MeasureFreq
++
;
G_MeasureFreq
++
;
if
(
G_MeasureFreq
==
PERIOD_10US
+
1
)
G_MeasureFreq
=
PERIOD_10MS
;
if
(
G_MeasureFreq
==
PERIOD_100US
+
1
)
G_MeasureFreq
=
PERIOD_10MS
;
//if(G_MeasureFreq == PERIOD_1S + 1) G_MeasureFreq = PERIOD_10MS;
SetTimerPeriod
(
G_MeasureFreq
);
SetTimerPeriod
(
G_MeasureFreq
);
}
}
if
(
ReadButton
(
BUTTON_
RUNSTOP
)
==
1
)
if
(
ReadButton
(
BUTTON_
SHUTDOWN
)
==
1
)
{
{
if
(
lstate
==
LOW
)
lstate
=
HIGH
;
Stop
();
else
lstate
=
LOW
;
digitalWrite
(
LED_BUILTIN
,
lstate
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment