Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ARDUINO-PositionGaugeServer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CLEAR
ARDUINO-PositionGaugeServer
Commits
b908c34a
Commit
b908c34a
authored
4 years ago
by
Kyrre Ness Sjobaek
Browse files
Options
Downloads
Patches
Plain Diff
Add timeout for SPC data reading
parent
a467e7bd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
PositionGaugeServer.ino
+18
-2
18 additions, 2 deletions
PositionGaugeServer.ino
with
18 additions
and
2 deletions
PositionGaugeServer.ino
+
18
−
2
View file @
b908c34a
...
...
@@ -53,6 +53,7 @@ IPAddress subnet(255, 255, 0, 0);
// ***** OTHER CONFIG ***************************
const
unsigned
long
update_interval
=
1000
;
//[ms]
const
unsigned
long
SPC_timeout
=
5
;
//[ms] 260 us per 4-bit word, 13 words, plus some buffer
// ***** GLOBAL VARIABLES ***********************
...
...
@@ -260,6 +261,8 @@ void loop() {
void
readSPCinstrument
(
uint8_t
ch
)
{
unsigned
long
SPC_timeout_time
=
millis
();
digitalWrite
(
pinREQ
[
ch
],
HIGH
);
byte
spcdata
[
13
];
// The raw data sent by instrument
...
...
@@ -273,8 +276,18 @@ void readSPCinstrument(uint8_t ch) {
for
(
uint8_t
j
=
0
;
j
<
4
;
j
++
)
{
//WARNING: If instrument is not connected,
// the Arduino may become unresponsive.
while
(
digitalRead
(
pinCLK
[
ch
])
==
LOW
)
{
}
// hold until clock is high
while
(
digitalRead
(
pinCLK
[
ch
])
==
HIGH
)
{
}
// hold until clock is low
while
(
digitalRead
(
pinCLK
[
ch
])
==
LOW
&&
millis
()
<
SPC_timeout_time
)
{
}
// hold until clock is high
while
(
digitalRead
(
pinCLK
[
ch
])
==
HIGH
&&
millis
()
<
SPC_timeout_time
)
{
}
// hold until clock is low
if
(
millis
()
>=
SPC_timeout_time
)
{
Serial
.
print
(
"SPC timeout on ch="
);
Serial
.
print
(
ch
);
Serial
.
print
(
", i="
);
Serial
.
print
(
i
);
Serial
.
print
(
", j="
);
Serial
.
println
(
j
);
return
;
}
bitWrite
(
k
,
j
,
(
digitalRead
(
pinDAT
[
ch
])
&
0x1
));
...
...
@@ -350,6 +363,9 @@ void readSPCinstrument(uint8_t ch) {
measDataIsMm
[
ch
]
=
isMM
;
measDataFresh
[
ch
]
=
true
;
}
return
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment