State machine used inter character spacing behaving better now
This commit is contained in:
parent
ea53f98cc8
commit
1547262a80
70
documentation/Morse_reception_state_diagram.tex
Normal file
70
documentation/Morse_reception_state_diagram.tex
Normal file
@ -0,0 +1,70 @@
|
||||
\documentclass{article}
|
||||
|
||||
% Language setting
|
||||
% Replace `english' with e.g. `spanish' to change the document language
|
||||
\usepackage[english]{babel}
|
||||
|
||||
% Set page size and margins
|
||||
% Replace `letterpaper' with `a4paper' for UK/EU standard size
|
||||
\usepackage[letterpaper,top=2cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}
|
||||
|
||||
% Useful packages
|
||||
\usepackage{amsmath}
|
||||
\usepackage{graphicx}
|
||||
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
|
||||
\usepackage{tikz}
|
||||
\usetikzlibrary{automata, positioning, arrows}
|
||||
|
||||
\title{Morse reception state machine}
|
||||
\author{R.P. Clark}
|
||||
|
||||
\begin{document}
|
||||
\maketitle
|
||||
|
||||
\begin{abstract}
|
||||
Your abstract.
|
||||
\end{abstract}
|
||||
|
||||
\section{Introduction}
|
||||
|
||||
State machine for morse rt decoding.
|
||||
\begin{itemize}
|
||||
\item 0: IDLE --- start state
|
||||
\item 1: KEY\_DN --- Morse KEY is DOWN
|
||||
\item 2: DIT --- Morse DIT element registered
|
||||
\item 3: DAH --- Morse DAH element registered
|
||||
\item 4: END\_CHAR --- One morse character registered i.e. (A-Z0-9)
|
||||
\item 5: SPACE --- One SPACE between characters registered
|
||||
\end{itemize}
|
||||
The relationships between these states is shown in figure~\ref{fig:morse_rt_reception},
|
||||
the time $\tau$ is 50mS for 20 characters per minute Morse code.
|
||||
\begin{figure}
|
||||
\centering
|
||||
\begin{tikzpicture}
|
||||
|
||||
\node[state, initial] (q0) at (2,12) {0:IDLE};
|
||||
\node[state] (q1) at (4,9) {1:KEY\_DN};
|
||||
\node[state, accepting] at (10,6) (q2) {2:DIT};
|
||||
\node[state, accepting] at (8,6) (q3) {3:DAH};
|
||||
\node[state, accepting] at (4,3) (q4) {4:END\_CHAR};
|
||||
\node[state, accepting] at (2,0) (q5) {5:SPACE};
|
||||
|
||||
\draw (q0) edge[->>,right] node{key down} (q1)
|
||||
(q1) edge[->>,right] node{KEY\_UP $\tau \approx 1$} (q2)
|
||||
(q1) edge[->>,left] node{KEY\_UP $\tau \approx 3$} (q3)
|
||||
(q2) edge[->>,right] node{$\tau \approx 3$} (q4)
|
||||
(q3) edge[->>,left] node{$\tau \approx 3$} (q4)
|
||||
(q4) edge[->>,left] node{$\tau > 4$} (q5)
|
||||
(q5) edge[->>,right, bend left, left=4.3] node{key down} (q1)
|
||||
(q4) edge[->>,left, bend left, left=4.3] node{key down} (q1)
|
||||
;
|
||||
\end{tikzpicture}
|
||||
\caption{State diagram for morse real time reception}
|
||||
\label{fig:morse_rt_reception}
|
||||
\end{figure}
|
||||
|
||||
|
||||
%\bibliographystyle{alpha}
|
||||
%\bibliography{sample}
|
||||
|
||||
\end{document}
|
51
main.py
51
main.py
@ -14,6 +14,9 @@ rtc.setDate(16, 7, 2022)
|
||||
rtc.setTime(12, 10, 0)
|
||||
rate = 50 # 20 wpm
|
||||
|
||||
# 0=IDLE 1=KEYDN 2=DIT 3=DAH 4=SPACE
|
||||
morse_state = 0
|
||||
|
||||
#sec = 0
|
||||
#f = open(logFileName, 'a')
|
||||
#f.write("# Data Logging: Date, Time, Temperature, Pressure, Humidity, AirQuality, CO2\n")
|
||||
@ -41,7 +44,7 @@ def ButtonA_f_IRQHandler(pin):
|
||||
print (" IRQ button A" + str(rate))
|
||||
|
||||
def ButtonB_f_IRQHandler(pin):
|
||||
global last_pv, last_tt, spurious, mindex
|
||||
global last_pv, last_tt, spurious, mindex, morse_state
|
||||
pv = pin.value()
|
||||
tt = time.ticks_ms()
|
||||
#print("button B IRQ", tt, pv)
|
||||
@ -51,7 +54,12 @@ def ButtonB_f_IRQHandler(pin):
|
||||
else:
|
||||
#b=buttonEvent(time.ticks_ms(),pv)
|
||||
d = tt - last_tt
|
||||
if pv:
|
||||
if pv: # MORSE BUTTON DOWN
|
||||
|
||||
if ( morse_state == 4 ):
|
||||
if d > rate*7:
|
||||
printm(' ')
|
||||
|
||||
#print(" duration of inter-m space ", d)
|
||||
if d < rate*3:
|
||||
print (" ")
|
||||
@ -60,14 +68,17 @@ def ButtonB_f_IRQHandler(pin):
|
||||
mindex += 1;
|
||||
beeper.playTone(600)
|
||||
button_state = 1
|
||||
else:
|
||||
morse_state = 1 # button down
|
||||
else: # MORSE BUTTON RELEASED
|
||||
#print(" duration of press ", d)
|
||||
if d > rate*3:
|
||||
morse.append("-");
|
||||
print ("DAH")
|
||||
#print ("DAH ms=", morse_state)
|
||||
morse_state = 3
|
||||
else:
|
||||
morse.append(".");
|
||||
print ("DIT")
|
||||
#print ("DIT ms=", morse_state)
|
||||
morse_state = 2
|
||||
beeper.stopTone()
|
||||
button_state = 0
|
||||
last_pv = pv
|
||||
@ -213,27 +224,17 @@ def decode_morse():
|
||||
return ("9")
|
||||
return("?")
|
||||
|
||||
|
||||
last_was_space = 0
|
||||
last_sp = 0
|
||||
def process_morse():
|
||||
global last_tt, morse, last_was_space, last_sp
|
||||
tt = time.ticks_ms()
|
||||
if (button_state == 0):
|
||||
if (tt - last_tt) > rate*6:
|
||||
# morse chacter complete
|
||||
if (len(morse) > 0):
|
||||
#print(morse)
|
||||
printm(decode_morse())
|
||||
morse = []
|
||||
last_was_space = 0
|
||||
last_sp = last_tt
|
||||
|
||||
if (tt - last_sp) > rate*22 : # and last_not_space == 0:
|
||||
if last_was_space == 0:
|
||||
printm(" ");
|
||||
last_was_space = 1 # dont keep repeating inter word spaces
|
||||
last_sp = last_tt
|
||||
def process_morse():
|
||||
global last_tt, morse, morse_state
|
||||
tt = time.ticks_ms()
|
||||
if ( morse_state == 2 or morse_state == 3):
|
||||
if (tt - last_tt) > rate*3:
|
||||
# morse chacter complete
|
||||
printm(decode_morse())
|
||||
morse = [] # clear for next character to rxd
|
||||
morse_state = 4
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user