ECE 4760: Laboratory 2
You will construct a standard Dual Tone Multi-Frequency (DTMF) generator like those used on any tonch-tone or cell phone. As you press the buttons, the system will play the correct frequencies. The system will record up to 12 digits, then play them back through the DAC to simulate redial. To do this you will have to use Direct Digital Synthesis sampling at a fairly high rate to a DAC, then route the DAC output to speakers.
You will use a keypad to make a DTMF dialer with audio output to a speaker. Analog output will be through a SPI controlled DAC.
The analog signal will
be DTMF sine wave bursts generated using Direct Digital Synthesis
(DDS) technique one one channel of the DAC. An example on the Dev board page (example DAC/DDS example) shows how you might implement
a DDS, with the SPI DAC. Your DDS unit must resolve 256 table entries. For this lab, you will need to modulate the amplitude, and you will need to run two simultaneous DDS units and sum them. The sine wave table will need to be scaled to prevent overflow. For high quality audio synthesis, you are going to need to generate audio samples in an ISR based on a timer interrupt running at high rate. You probably will not have time in the ISR to use floating point arithmetic. Note that this example toggles the RA0 line to time the ISR rate. You need to omit that feature, if you attach the keypad to RA0!
- The SPI DAC you will use is the MCP4822.
The SPI connections are supplied on the Big Board, as long as you connect the DAC_CS jumper.
The DDS example above shows the logical SPI setup.
- You will need to get user input from a keypad, as explained below.
Keypad setup and keyboard scanner code for the Big Board is in the Keypad example on the development board page.
More keypad wiring information is available on the TFT/keypad page.
- Possible pin assignments for keypad, DAC and keypad on the Big Board.
- TFT uses
pins 4,5,6, 22 and 25 (RB0, RB1, RB2, MOSI1, SCLK1)
SCK1: connected to RB14 on the PIC
MOSI (SDO1): PPS output group 2 connected to RB11 on the PIC
CS: connected to RB1 on the PIC
SDCS: left unconnected as I'm not using the microSD card for this
RST: connected to RB2 on the PIC
D/C: connected to RB0 on the PIC
- DAC SPI channel 2 uses
pin 26, RB15
SDO2 (MOSI) is in PPS output group 2, could be connected to RB5 which is
pin 14, but remember to set
#pragma config JTAGEN = OFF, DEBUG = OFF
CS (chip select) connected to RB4,
pin 11, but remember to set
#pragma config JTAGEN = OFF, DEBUG = OFF
- Keypad -- need 7 i/o lines (see schematic on the TFT/keyboard page)
If you use RA0 to RA3 and RB7 to RB9 then my keypad scanner works.
RA0 to RA3 must have the 300 ohm resistor in series! you can see these here.
In this lab and every lab, make sure you are running Protothreads 1_2_1.
I suggest organizing the code as:
- Protothreads maintains the ISR-driven millisceond-scale timing.
- Timer ISR running at the DDS sample rate to update the DDS and the DAC.
(Lecture explaining the keypad scanner, debouncer, and DDS sample rate, Another lecture on DDS)
- Main sets up peripherials and protothreads then just schedules tasks, round-robin.
- Keypad Thread
- scans the keypad
- runs the debounce state machine you will need a state machine that debounces all 12 keys.
(Lecture explaining the keypad scanner, debouncer, and DDS sample rate)
(state machine pseudocode for ONE button, but use the state machine explained in the lecture)
- places valid keypresses into a digit buffer and triggers tone burst production
- handles erase/start commands
- detects test mode. see below.
- waits for 30 mSec.
- sets the DDS parameters for two sine waves (if any) which are playing.
- Starts/stops the play back
- Write a Protothreads C program which implements a DTMF generator with the following
- The keypad will be used to enter up to 12 digit telephone numbers.
As each digit is pressed, the two sine waves in the table below will be generated and added together, then modulated.
You must debounce the keypad.
- Pressing the
* button erases the entire stored phone number.
- When the
# button is pressed, the DTMF signal for each entered digit is produced for at least 65 millseconds to simulate dialing of the digits.
Each digit pressed implies that two sine waves play at the same time, as shown in the table below.
There should be at least 65 millseconds of silence between each digit.
- Each tone burst (sum of two sine waves) should ramp up to full amplitude over a time of about 5 milliseconds and ramp down again in about the same amount of time. Ramping the amplitude will decrease the broad band Fourier components which tend to add an annoying click to the sounds. The ramp need not be linear, but could be.
Example matlab code.
- Frequency accuracy should be +/-1.5% (as per DTMF spec) Generate sinewaves using DDS. The sinewaves should be built from
8-bit samples (taken from a 256 entry table and scaled to 12 bits for the DAC).
- Implement a test mode in which each of 7 DTMF frequencies can be individually measured for frequency accuracy.
Add a button button on the white board to trigger the frequency test mode. During test mode,
pressing the buttons 1 through 7 should produce one of seven single-frequency sine waves for as long as you hold the buttons.
You will need to display the FFT of the 7 frequencies to show that all spurous frequencies are lower than -20 db from main tones.
A table of DTMF frequencies:
- Connect the circuit to a speaker audio input (green phone plug) and listen
the output. This will aid in debugging and is required for the demo.
- Demo this program to a staff member. Show that all specifications are met
by verifying frequencies with an oscilloscope.
- At no time during the demo should you need to press RESET.
- Your written lab report should include the sections mentioned in the policy page, and :
- How you generated the freqencies (DDS resolution, etc) and an measurement
of how accurate they are.
- Oscilloscope capture of typical waveforms.
- Oscilloscope capture of FFT to show that harmonic distortion meets the DTMF spec
- How you generated the various time intervals required by this project.
- A diagram of the state machine you used to debounce. One of the TAs (Shiva) recommends drawing FSM with fizzim.
- Other design aspects of the assignment, such as the conversion from
user input frequency in Hz to DDS increment.
- A heavily commented listing of your code.
Copyright Cornell University
July 2, 2018