Categories

VMAC PiHat v2 DTMF

WIKI:

One of the VMAC PiHat v2 features is the well known, on-board, 8870 DTMF decoder, which takes its audio input to the 6 way header, so you can connect where required, such as wire back to one of the matrix inputs or outputs.

The DTMF decoder binary logic output is connected directly to the Pi header for a variety of software control functions.

All logic levels are at 3V3 (D0-D3 and DINT).

High impedance line level audio input.

See other Wiki pages for additional Sample I/O code.  For simplicity, you can use Thonny to run and edit the Python code. This application is included within Raspbian and also available for Windows and MAC users.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

As all VMAC PiHat I/O’s are at 3v3 levels, the board uses a special 3v3 version of the decoder, namely the MITEL MT88L70AS, which performs very well on testing and certainly compares well with the original more widely available 5v version,  CM8870.

In our test lab, the decode audio levels were fine down to around 70mV and up to 3V (with input 100k trimmer pot at maximum).  Ideally in the real world, you will be using something approaching line level 1V.

DTMF decode was reliable right down to a minimum tone length of 10 ms and 1ms off time (between tones).  This makes the decoder nice and sensitive but robust too.

Fast strings of DTMF Symbols were decoded 100%, using the above minimum values.  These were both from the test box, via audio files played on the Pi and locally over radio.

Control of the decoder is via the Pi Header and the following GPIO:

Binary Data lines (These lines go high on decoding a DTMF tone)

D0 = GPIO 26
D1 = GPIO 19
D2 = GPIO 13
D3 = GPIO 6

StD Latch Output (This goes high when successfully decoding a DTMF tone)

DINT = GPIO 5

AUDIO TEST FILES

Three audio WAV test files are provided. Each are different timing and quality.  One file has the same 0 multiple times in order to test double digits.

Depending what you use to play the files, you may need to set the Pi audio path, from within terminal, as it may default to HDMI, rather than the 3.5mm jack socket.

Audio socket terminal command:

amixer -c 0 cset numid=3 1

Audio HDMI terminal command:

amixer -c 0 cset numid=3 2

 

HAMKit DTMF Test Sequence 0_1_2_3_4_5_6_7_8_9_#___A_B_C_D.wav decodes to the below:

 DTMF Value: 10 Symbol: 0
 DTMF Value: 01 Symbol: 1
 DTMF Value: 02 Symbol: 2
 DTMF Value: 03 Symbol: 3
 DTMF Value: 04 Symbol: 4
 DTMF Value: 05 Symbol: 5
 DTMF Value: 06 Symbol: 6
 DTMF Value: 07 Symbol: 7
 DTMF Value: 08 Symbol: 8
 DTMF Value: 09 Symbol: 9
 DTMF Value: 12 Symbol: #
 DTMF Value: 11 Symbol: *
 DTMF Value: 13 Symbol: A
 DTMF Value: 14 Symbol: B
 DTMF Value: 15 Symbol: C
 DTMF Value: 00 Symbol: D

HAMKit DTMF Test Sequence 0123456789ABCDps.wav decodes to the below:

DTMF Value: 10 Symbol: 0
 DTMF Value: 01 Symbol: 1
 DTMF Value: 02 Symbol: 2
 DTMF Value: 03 Symbol: 3
 DTMF Value: 04 Symbol: 4
 DTMF Value: 05 Symbol: 5
 DTMF Value: 06 Symbol: 6
 DTMF Value: 07 Symbol: 7
 DTMF Value: 08 Symbol: 8
 DTMF Value: 09 Symbol: 9
 DTMF Value: 13 Symbol: A
 DTMF Value: 14 Symbol: B
 DTMF Value: 15 Symbol: C
 DTMF Value: 00 Symbol: D
 DTMF Value: 12 Symbol: #
 DTMF Value: 11 Symbol: *

HAMKit DTMF Test Sequence 00000000000000000000.wav decodes to the below. Note only one entry due to duplicated tone.

DTMF Value: 10 Symbol: 0

 

CODE 

The two basic Python test code examples are provided that allow you to check the DTMF decoder, display the binary output (displayed in decimal), and then also decode the symbols using a lookup.

In essence, the required Pi GPIO are setup as inputs and then monitored in a tight loop.  Upon the StD Latch Output going high, the inputs are decoded and displayed. The second code example takes the decoded decimal value and using a lookup table, displays the actual DTMF Symbol.

HAMKit VMAC PiHat | Test Example Code to Setup the DTMF Decoder (Decimal) v1.1

# HAMKit VMAC PiHat | Test Example Code to Setup the DTMF Decoder (Decimal) v2.0
# Test code is suitable for PiHat PCB revision 2.0
# When testing decoder, audio input can be between 70 mV and 3V. Ideally line level 1V.
# This version of test code displays the binary value as decimal of the decoded DTMF Tone.
# Dave Williams G8PUO, January 2018

#!/usr/bin/python

import RPi.GPIO as GPIO

#====== GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.cleanup()

#Define GPIO Inputs
GPIO_D0 = 26
GPIO_D1 = 19
GPIO_D2 = 13
GPIO_D3 = 6
GPIO_DINT = 5

#Define Variables
DValueStore = 0

#Setup Inputs with pull-ups enabled
GPIO.setup(GPIO_D0, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(GPIO_D1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(GPIO_D2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(GPIO_D3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(GPIO_DINT, GPIO.IN, pull_up_down=GPIO.PUD_UP)

#Loop
while True:
    
    #Read 8870 StD Latch Output
    DINT = GPIO.input(GPIO_DINT)
    
    #Check for High Pulse from the 8870 StD Latch Output
    if DINT == True:
        
        #Only Check GPIO if 8870 Data Bits have changed 
        D0 = GPIO.input(GPIO_D0)
        D1 = GPIO.input(GPIO_D1)
        D2 = GPIO.input(GPIO_D2)
        D3 = GPIO.input(GPIO_D3)
        DValue = D0+(D1*2)+(D2*4)+(D3*8)
        
        #Only Display if DTMF Value has changed
        if DValueStore != DValue:
            DValueStore = DValue
        
            #Print Output
            print ("DTMF Value = " + str(DValue))

HAMKit VMAC PiHat – Test Example Code to Setup the DTMF Decoder (Symbols) v1.1

# HAMKit VMAC PiHat | Test Example Code to Setup the DTMF Decoder (Symbols) v2.0
# Test code is suitable for PiHat PCB revision 2.0
# When testing decoder, audio input can be between 70 mV and 3V. Ideally line level 1V.
# This version of test code displays the binary value and Symbol lookup of the decoded DTMF Tone.
# Dave Williams G8PUO, January 2018

#!/usr/bin/python

import RPi.GPIO as GPIO

#====== GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.cleanup()

#Define GPIO Inputs
GPIO_D0 = 26
GPIO_D1 = 19
GPIO_D2 = 13
GPIO_D3 = 6
GPIO_DINT = 5

#Define Variables
DValueStore = 0

#Setup Inputs with pull-ups enabled
GPIO.setup(GPIO_D0, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(GPIO_D1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(GPIO_D2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(GPIO_D3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(GPIO_DINT, GPIO.IN, pull_up_down=GPIO.PUD_UP)

#Define DTMF Symbols
DTMFLookup = ["1","2","3","4","5","6","7","8","9","0","*","#","A","B","C","D"]

#Loop
while True:
    
    #Read 8870 StD Latch Output
    DINT = GPIO.input(GPIO_DINT)
    
    #Check for High Pulse from the 8870 StD Latch Output
    if DINT == True:
        
        #Only Check GPIO if 8870 Data Bits have changed 
        D0 = GPIO.input(GPIO_D0)
        D1 = GPIO.input(GPIO_D1)
        D2 = GPIO.input(GPIO_D2)
        D3 = GPIO.input(GPIO_D3)
        DValue = D0+(D1*2)+(D2*4)+(D3*8)
        
        #Only Display if DTMF Value has changed
        if DValueStore != DValue:
            DValueStore = DValue
        
            #Print Output
            print ("DTMF Value: %02d \tSymbol: " % (DValue) + DTMFLookup[DValue - 1])

 

Leave a Reply

This site uses User Verification plugin to reduce spam. See how your comment data is processed.