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
837bf1e0
authored
Oct 26, 2022
by
karudu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Kiirem saatmine ~100us jaoks, mõõtesageduse muutmine
parent
6b68f03d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
37 deletions
adc_vtable.ino
scope.ino
adc_vtable.ino
0 → 100644
View file @
837bf1e0
This diff is collapsed.
Click to expand it.
scope.ino
View file @
837bf1e0
...
@@ -4,21 +4,36 @@
...
@@ -4,21 +4,36 @@
#define PIN_BUTTON_4 2
#define PIN_BUTTON_4 2
#define PIN_ADC 7 // A7
#define PIN_ADC 7 // A7
#define BUTTON_
1
0
#define BUTTON_
RANGE_DN
0
#define BUTTON_
2
1
#define BUTTON_
RANGE_UP
1
#define BUTTON_
3 2
#define BUTTON_
FREQ 2 // Change frequency
#define BUTTON_
4
3
#define BUTTON_
RUNSTOP
3
// Cursor values
#define PERIOD_10MS 0
#define CURSOR_1 "5.00"
#define PERIOD_1MS 1
#define CURSOR_2 "0.00"
#define PERIOD_100US 2
#define PERIOD_10US 3
#define PERIOD_100MS 4
#define PERIOD_1S 5
// Cursor values in format xx.x
#define CURSOR_1 "5.0"
#define CURSOR_2 "0.0"
// https://www.gammon.com.au/adc
// https://www.gammon.com.au/adc
// Globals
char
G_PrintfBuf
[
32
];
char
G_CursorBuf
[
5
+
1
+
5
+
1
+
1
];
char
G_MeasureFreq
;
// 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
extern
const
char
FLASH_VoltageTable
[
1024
*
3
]
PROGMEM
;
byte
ReadButton
(
int
Button
)
byte
ReadButton
(
int
Button
)
{
{
const
int
ButtonPins
[
4
]
=
{
PIN_BUTTON_1
,
PIN_BUTTON_2
,
PIN_BUTTON_3
,
PIN_BUTTON_4
};
const
int
ButtonPins
[
4
]
=
{
PIN_BUTTON_1
,
PIN_BUTTON_2
,
PIN_BUTTON_3
,
PIN_BUTTON_4
};
...
@@ -56,12 +71,6 @@ void InitADC()
...
@@ -56,12 +71,6 @@ void InitADC()
ADCSRA
|=
bit
(
ADATE
);
// Enable auto trigger
ADCSRA
|=
bit
(
ADATE
);
// Enable auto trigger
}
}
#define PERIOD_10MS 0
#define PERIOD_1MS 1
#define PERIOD_100US 2
#define PERIOD_10US 3
#define PERIOD_100MS 4
#define PERIOD_1S 5
// Set timer 1 to a specified measuring interval
// Set timer 1 to a specified measuring interval
void
SetTimerPeriod
(
int
Period
)
void
SetTimerPeriod
(
int
Period
)
{
{
...
@@ -69,7 +78,7 @@ void SetTimerPeriod(int Period)
...
@@ -69,7 +78,7 @@ void SetTimerPeriod(int Period)
TCCR1A
=
0
;
TCCR1A
=
0
;
TCCR1B
=
0
;
// Reset TCCR
TCCR1B
=
0
;
// Reset TCCR
TCNT0
=
0
;
// Reset the counter
TCNT0
=
0
;
// Reset the counter
// http://www.8bit-era.cz/arduino-timer-interrupts-calculator.html
// http://www.8bit-era.cz/arduino-timer-interrupts-calculator.html
switch
(
Period
)
switch
(
Period
)
{
{
...
@@ -115,24 +124,23 @@ void SetTimerPeriod(int Period)
...
@@ -115,24 +124,23 @@ void SetTimerPeriod(int Period)
sei
();
sei
();
}
}
volatile
int
results
[
100
];
volatile
int
resultNumber
=
0
;
char
G_PrintfBuf
[
32
];
// ADC complete ISR
// ADC complete ISR
ISR
(
ADC_vect
)
ISR
(
ADC_vect
)
{
{
//int tstart = micros();
//unsigned long tstart = micros();
// Range is 0-4.8 V
//Serial.println((ADC / 1023.0) * 4.8);
// TODO the printing here needs to be faster
Serial
.
write
(
G_CursorBuf
);
sprintf
(
G_PrintfBuf
,
"%s
\t
%s
\t
"
,
CURSOR_1
,
CURSOR_2
);
volatile
unsigned
int
Value
=
ADC
;
Serial
.
print
(
G_PrintfBuf
);
int
P
=
Value
*
3
;
Serial
.
println
((
ADC
/
1023.0
)
*
4.8
);
Serial
.
write
(
pgm_read_word_near
(
FLASH_VoltageTable
+
P
+
0
));
//Serial.println(5);
Serial
.
write
(
'.'
);
Serial
.
write
(
pgm_read_word_near
(
FLASH_VoltageTable
+
P
+
1
));
//sprintf(G_PrintfBuf, "%d\n", micros() - tstart);
Serial
.
write
(
pgm_read_word_near
(
FLASH_VoltageTable
+
P
+
2
));
//Serial.println(G_PrintfBuf);
Serial
.
write
(
'\r'
);
Serial
.
write
(
'\n'
);
//Serial.println(micros() - tstart);
}
}
EMPTY_INTERRUPT
(
TIMER1_COMPB_vect
);
EMPTY_INTERRUPT
(
TIMER1_COMPB_vect
);
...
@@ -147,22 +155,45 @@ void setup()
...
@@ -147,22 +155,45 @@ void setup()
Serial
.
begin
(
2000000
);
Serial
.
begin
(
2000000
);
SetTimerPeriod
(
PERIOD_100US
);
SetTimerPeriod
(
PERIOD_10MS
);
G_MeasureFreq
=
PERIOD_10MS
;
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
}
}
int
lstate
=
LOW
;
void
loop
()
void
loop
()
{
{
for
(
int
i
=
0
;
i
<
4
;
i
++
)
if
(
ReadButton
(
BUTTON_RANGE_UP
)
==
1
)
{
{
byte
State
=
ReadButton
(
i
);
if
(
lstate
==
LOW
)
lstate
=
HIGH
;
if
(
State
==
1
)
else
lstate
=
LOW
;
{
digitalWrite
(
LED_BUILTIN
,
lstate
);
sprintf
(
G_PrintfBuf
,
"Button %d is %d
\n
"
,
i
,
State
);
}
Serial
.
println
(
G_PrintfBuf
);
}
if
(
ReadButton
(
BUTTON_RANGE_DN
)
==
1
)
{
if
(
lstate
==
LOW
)
lstate
=
HIGH
;
else
lstate
=
LOW
;
digitalWrite
(
LED_BUILTIN
,
lstate
);
}
if
(
ReadButton
(
BUTTON_FREQ
)
==
1
)
{
G_MeasureFreq
++
;
if
(
G_MeasureFreq
==
PERIOD_10US
+
1
)
G_MeasureFreq
=
PERIOD_10MS
;
//if(G_MeasureFreq == PERIOD_1S + 1) G_MeasureFreq = PERIOD_10MS;
SetTimerPeriod
(
G_MeasureFreq
);
}
if
(
ReadButton
(
BUTTON_RUNSTOP
)
==
1
)
{
if
(
lstate
==
LOW
)
lstate
=
HIGH
;
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