Skip to content

Commit 7105d07

Browse files
committed
Merge remote-tracking branch 'github/develop' into feature/119-serial-interface-connect-protocol-with-actual-data
2 parents 7c92e38 + 4bf500a commit 7105d07

61 files changed

Lines changed: 2240 additions & 484 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/generate-documentation.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: generate and deploy documentation
22

33
on:
4-
push:
5-
branches-ignore:
6-
- 'gh-pages'
4+
workflow_run:
5+
workflows: [Cleanup GitHub Pages Branch Workflow]
6+
types: [completed]
77

88
permissions:
99
contents: write
@@ -13,6 +13,11 @@ jobs:
1313
runs-on: ubuntu-latest
1414

1515
steps:
16+
- name: Install tools for generation of documentation
17+
run: |
18+
sudo apt-get install doxygen graphviz
19+
sudo apt-get install texlive-base perl # necessary for citing bib files
20+
1621
- name: Checkout code
1722
uses: actions/checkout@v2
1823

@@ -25,9 +30,9 @@ jobs:
2530
echo "DOC_OUTPUT_DIR=$output_dir" >> "$GITHUB_ENV"
2631
2732
- name: generate documentation
28-
uses: mattnotmitt/doxygen-action@v1.9.5
29-
with:
30-
additional-packages: texlive perl # necessary for citing bib files
33+
run: |
34+
wget https://github.com/plantuml/plantuml/releases/latest/download/plantuml.jar
35+
(echo "PLANTUML_JAR_PATH = ."; cat Doxyfile) | doxygen -
3136
3237
- name: deploy documentation
3338
uses: peaceiris/actions-gh-pages@v3

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
.vscode/extensions.json
77
doc/html/
88
doc/latex/
9+
.vscode/settings.json

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ To get in touch with us you may contact a [contributor](https://github.com/Task-
2929

3030
Before submitting to this repository, please:
3131

32+
* Familiarize yourself with the
33+
[software architecture documentation](<\ref software_architecture> "software architecture documentation")
34+
and the
35+
[design decisions](<\ref doc/decisions> "design decisions").
3236
* Test your contribution.
3337
* Make sure your code does not introduce warnings or errors.
3438
* Your proposition may be reviewed based on state of the art coding standards (for example [C++ Core Guidelines](https://isocpp.github.io/CppCoreGuidelines/) or [C++ Super FAQ](https://isocpp.org/faq)).

Doxyfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ EXTRACT_STATIC = YES
77
CITE_BIB_FILES = doc/bibliography
88
INPUT = .
99
RECURSIVE = YES
10+
EXAMPLE_PATH = doc/debouncing/
1011
IMAGE_PATH = doc/
1112
USE_MDFILE_AS_MAINPAGE = ./README.md
1213
HTML_FILE_EXTENSION = .xhtml

README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,30 @@ Since version 2.1.0 it uses VS Code's built-in terminal instead.
7171
That terminal does not provide a prompt for entering, reviewing and modifying a message before sending it.
7272
See also [this issue report](https://github.com/wokwi/wokwi-features/issues/698).
7373

74-
Serial port forwarding is enabled for the simulator.
75-
Thus a Telnet client can be used to connect to the serial port of the simulator.
74+
The simulator also [provides a RFC2217 TCP server](https://docs.wokwi.com/vscode/project-config#serial-port-forwarding) as an alternative.
75+
Serial port forwarding is enabled for the simulator per configuration.
76+
This can be used to connect via a Telnet client to the serial port of the simulated device.
7677

77-
For example one can use the [PuTTY](https://www.putty.org/) SSH Client in Telnet mode with `localhost` as host and `4000` as port.
78+
For example one may use a [PuTTY](https://www.putty.org/) SSH Client with the following settings:
79+
80+
- Host Name: `localhost`
81+
- Port: `4000`
82+
- Connection type: Telnet
83+
84+
For testing with the Task Tracker App (or any other programm which supports a serial interface),
85+
one can forward the RFC2217 TCP connection to a pseudo terminal.
86+
For example using [socat](http://www.dest-unreach.org/socat/):
87+
88+
socat -d -d pty,raw,echo=0,link=/tmp/tcp_tty tcp:localhost:4000
89+
90+
Now you can connect to the serial terminal using these settings:
91+
92+
- path to serial line: `/tmp/tcp_tty`
93+
- speed: `115200` baud
94+
- data bits: `8`
95+
- stop bits: `1`
96+
- parity: none
97+
- flow control: none
7898

7999
### Debugging
80100

doc/debouncing.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Debouncing Approaches {#debouncing_approaches}
2+
3+
Obtaining the state of switches and buttons generally requires to debounce the input signal because of contact bouncing.
4+
The waveform of an input may be smoothed physically using a low-pass filter.
5+
Coping with bouncing programmatically may allow a simplified circuit thus reducing complexity and material cost.
6+
7+
Debouncing in software follows in general one of these approaches:
8+
9+
1. steady sampling of the signals and waiting for either
10+
1. an average value to cross a threshold
11+
2. a sequence of continuous states to reach a minimum length
12+
2. observing processor interrupts triggered by state changes of digital inputs
13+
1. after a state change, ignore further changes for a specified time before adopting the next change
14+
2. after a state change, wait for the state to be stable for a specified time before adopting that change
15+
16+
Steady sampling has disadvantages:
17+
18+
- if the sample rate is too low, the reaction may be significantly delayed
19+
- if the number of samples is too low, a state change may be prematurely detected (state changes while still bouncing)
20+
- constantly polling the state
21+
- may bind processing time
22+
- may require context switching
23+
- may be solved (more) efficiently using the processor's hardware timers and counters (availability depends on the MPU)
24+
25+
Interrupt based sampling only consumes processing time if actual changes occur.
26+
This is especially advantageous with buttons, which are seldomly actuated, compared to other activities.
27+
28+
Also interrupt based sampling is not flawless.
29+
The specific disadvantages depend on the chosen approach and the concrete implementation.
30+
31+
In any case it must be considered that detecting a steady state change of a button should probably be executed with a higher priority than the execution of the processing of that event.
32+
For example periodically sampling or reacting on an digital input should interrupt time-insensitive processing.
33+
But the actual processing of a finally adopted state change may take longer and should take place with lower priority.
34+
Thus some kind of synchronization mechanism (or interrupt masking) will usually be necessary.
35+
36+
Hereafter two different approaches based on hardware interrupts will be discussed.
37+
38+
39+
## Interrupt based Debouncing
40+
41+
Interrupts called by the processor as a reaction on a change of a digital input may be used to detect state changes of switches and buttons.
42+
In contrast to debouncing approaches which sample with fixed periods, interrupt based debouncing usually uses the time relative the the last state change to detect steady states.
43+
Either by discarding changes which occur shortly after a previously adopted state change.
44+
Or by waiting for the last change to prevail long enough.
45+
46+
47+
### Post-change delay
48+
49+
Approaches which ignore changes which occur in a short period after a previously accepted change are easy to implement.
50+
One simply has to compare the timestamp of the last accepted change with the current time.
51+
If that difference is below a threshold, the state change will be ignored.
52+
53+
\include{doc} bouncing-classic-normal.puml
54+
55+
The timing diagram above shows how, when the button is pressed, a rising edge will be detected.
56+
But also bouncing will occur for some time.
57+
A threshold defines a window (highlighted section) beginning with the first event in which following state changes will be ignored.
58+
After that window, if the button is released the falling edge, and therefor the state change, will immediately be detected.
59+
60+
The debounced signal will be active for the time between button pressed and released.
61+
62+
\include{doc} bouncing-classic-too-short.puml
63+
64+
A problem arises in case the button press (the pulse) is too short.
65+
The first state change will be detected.
66+
But if bouncing finishes within the window for ignoring changes, the final state (released) will not be detected.
67+
The debounced state will remain "active" until further state changes.
68+
69+
As the time a button bounces may differ on each actuation, defining a threshold value totally avoiding this problem may not be possible.
70+
71+
72+
### Pre-change delay
73+
74+
A different interrupt based approach waits for the input signal to be stable before adopting its change.
75+
This can be achieved with a delay which will be restarted each time a state change occurs.
76+
If the delay elapses without further changes the state is considered as stable.
77+
The current state is then read to check for a state change.
78+
79+
The duration of the delay can be much shorter than the window in which state changes will be ignored from the previous approach.
80+
In contrast to defining the expected time after which a signal will be stable it defines the minimum time a signal may not change to be accepted as stable.
81+
Thus the duration is more a requirement then a heuristic.
82+
83+
\include{doc} bouncing-delay-normal.puml
84+
85+
In the timing diagram above is shown that the debouncer will wait while the digital input bounces.
86+
After bouncings stops the delay time will elapse.
87+
Only then the state of the digital input is read to detect the state change.
88+
89+
The debounced signal will be active for a duration which depends on the bouncing while releasing the button.
90+
If bouncing takes the same time while pressing and releasing, the active duration will be the same as the pressed duration.
91+
92+
The debounced state will be delayed by the bouncing time and the defined startup delay.
93+
94+
\include{doc} bouncing-delay-too-short.puml
95+
96+
An advantage to the previous approach can be seen with short pulses.
97+
If the button is pressed and then released while still bouncing (or withing the delay), no state change will be adopted.
98+
Too short button presses do not lead to adopt only one of two (or more) state changes.
99+
This is the safer approach.
100+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@startuml
2+
title debouncing by post-event filtering: not too short
3+
caption debouncing normal pulse
4+
hide time-axis
5+
scale 1 as 250 pixels
6+
binary "digital input" as D
7+
binary "debounced signal" as B
8+
9+
@0
10+
D is low
11+
note top of B : debounced
12+
B is low
13+
@+1
14+
D is {low,high}
15+
note bottom of D : button pressed
16+
D@+0 <-> @+0.8 : bouncing
17+
D -> B : rising edge detected
18+
highlight +0 to +1 : state changes ignored
19+
B is high
20+
@+0.8
21+
D is high
22+
@+0.5
23+
D is {low,high}
24+
note bottom of D : button released
25+
D -> B : falling edge detected
26+
D@+0 <-> @+0.8 : bouncing
27+
highlight +0 to +1 : state changes ignored
28+
B is low
29+
@+0.8
30+
D is low
31+
32+
33+
@enduml
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@startuml
2+
title debouncing by post-event filtering: too short
3+
caption too short pulse leads to wrong state
4+
hide time-axis
5+
scale 1 as 250 pixels
6+
binary "digital input" as D
7+
binary "debounced signal" as B
8+
9+
@0
10+
D is low
11+
note top of B : debounced
12+
B is low
13+
@+1
14+
D is {low,high}
15+
D@+0 <-> @+0.9 : bouncing
16+
D -> B : rising edge detected
17+
highlight +0 to +1 : state changes ignored
18+
B is high
19+
@+0.9
20+
D is low
21+
D -> B : state change ignored
22+
23+
@enduml
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
@startuml
2+
title debouncing based on delay: not too short
3+
caption debouncing normal pulse
4+
hide time-axis
5+
scale 1 as 250 pixels
6+
binary "digital input" as D
7+
binary "debouncer waiting" as W
8+
binary "debounced signal" as B
9+
10+
@0
11+
D is low
12+
note top of B : debounced
13+
B is low
14+
@+1
15+
D is {low,high}
16+
W is high
17+
note bottom of D : button pressed
18+
D@+0 <-> @+0.8 : bouncing
19+
@+0.8
20+
W@+0 <-> @+0.1 : delay
21+
D is high
22+
@+0.1
23+
W is low
24+
W -> D : read state
25+
W -> B : rising edge detected
26+
B is high
27+
@+0.5
28+
note bottom of D : button released
29+
D is {low,high}
30+
W is high
31+
D@+0 <-> @+0.8 : bouncing
32+
@+0.8
33+
D is low
34+
W@+0 <-> @+0.1 : delay
35+
@+0.1
36+
W is low
37+
W -> D : read state
38+
W -> B : falling edge detected
39+
B is low
40+
41+
@enduml
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@startuml
2+
title debouncing based on delay: too short
3+
caption too short pulse will be completely ignored
4+
hide time-axis
5+
scale 1 as 250 pixels
6+
binary "digital input" as D
7+
binary "debouncer waiting" as W
8+
binary "debounced signal" as B
9+
10+
@0
11+
D is low
12+
note top of B : debounced
13+
B is low
14+
@+1
15+
D is {low,high}
16+
W is high
17+
D@+0 <-> @+0.9 : bouncing
18+
@+0.9
19+
D is low
20+
W@+0 <-> @+0.1 : delay
21+
@+0.1
22+
W -> D : read state
23+
W is low
24+
note top of B : state has not been adopted
25+
26+
@enduml

0 commit comments

Comments
 (0)