Using MAXQ and MAC for Control and Digital Signal Processing

Publisher:luanzgcLatest update time:2011-03-01 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Introduction to MAXQ

The MAXQ series of microcontrollers are high-performance 16-bit RISC devices designed for low-noise operation and are ideal for battery-powered mixed-signal applications. MAXQ integrates high-precision analog functions with digital components to reduce the number of chips in the design. MAXQ uses the Harvard memory structure to arrange data, code and register space on different buses. The main advantage of this memory structure is that it has flexible word lengths, and system and peripheral registers can be 8 or 16 bits. Since the instruction word of MAXQ is 16 bits, microcontrollers usually have a 16-bit instruction bus. Another advantage of the Harvard structure is that registers are always used to access memory, so that peripherals such as analog-to-digital converters (ADCs) and hardware coprocessors can be accessed in a direct access manner. MAXQ2000 is the first product in the MAXQ series of microcontrollers. It integrates a 16-bit CPU, 64KB flash memory, 2KB SRAM and a 4 36-segment LCD controller.


Challenges that arise when both control applications and digital signal processing are required

Traditional microcontrollers (MCUs) and digital signal processors (DSPs) are generally considered to be two incompatible machines in the field of microcomputers. MCUs are suitable for control applications that require low-latency response to asynchronous processes, while DSPs excel in high-intensity mathematical calculations. Of course, MCUs can also be used to perform complex arithmetic operations, but because the arithmetic logic unit (ALU) of most MCUs performs one operation at a time, its operation speed is much slower than that of DSPs. Similarly, DSPs are not suitable for control applications due to their internal architecture.

As more and more applications are added to control applications with small amounts of signal processing, choosing between DSPs and traditional MCUs becomes increasingly difficult. In such applications, the solution of embedding DSP code into the MCU is attractive. However, with this approach, most of the application time is spent executing DSP functions, and the control application has to sacrifice. The emergence of the MaxQ architecture solves this problem. In the modular MaxQ architecture, the multiply-accumulate unit (MAC) can be easily integrated. With the use of hardware MAC, 16 16-bit multiply-accumulate operations can be implemented in a single cycle without affecting the task execution on the control processor. The following example shows how to use the MAC module in the MaxQ microcontroller to solve a practical problem.


The mac module is used in conjunction with maxq

For DSP, the most basic application is to filter analog signals. In filtering applications, the appropriately modulated analog signal is provided to the ADC, and the sampled data stream is filtered in the digital domain. The execution process of a conventional filter can be implemented by the following formula:

Where Bi and Ai are the characteristic values ​​of the system feedforward and feedback responses, respectively. According to the values ​​of Ai and Bi, digital filters can be divided into two categories: finite impulse response (FIR) filters and infinite impulse response (IIR) filters. When the system does not contain any feedback elements (that is, all Ai = 0), the filter is of FIR type, and its equation is:

When the elements of Ai and Bi are not 0, the filter is of IIR type.

From formula (2), we know that the main mathematical operation of the FIR filter is to multiply each sample input by a constant, and then accumulate each product, which is performed n times in total. It can be explained by the following C language program segment:

y[n]=0;
for(i=0;i小于n;i++)
y[n]+=x[i]*b[i]

For a microprocessor with a multiplier unit, it can be implemented according to the following pseudo code:

move ptr0, #x ;primary data pointer -> samples
move ptr1, #b ;secondary dp -> coefficients
move ctr, #n ;loop counter gets number of samples
move result, #0 ;clear result register

acc_loop:

move acc, @ptr0 ;get a sample
mul @ptr1 ;multiply by coefficient
add result ;add to previous result
move result, acc ;...and save the result back
inc ptr0 ;point to next sample
inc ptr1 ;point to next coefficient
dec ctr ;decrement loop counter
jump nz, acc_loop ;jump if there are more samples
end

Thus, even though there is a multiplier, the multiplication and accumulation loop requires 12 instructions and (assuming a single-cycle unit and multiplier) 4+ 8n cycles. The same operation is done in the multiplication-accumulation unit of the maxq, the code space is reduced from 12 words to 9 words, and the running time is reduced from 4+ 8n cycles to 4 +5n cycles. The code implementation is as follows:

move dp[0], #x ; dp[0] -> x[0]
move dp[1], #b ; dp[1] -> b[0]
move lc[0], #loop_cnt ; lc[0] -> number of samples
move mcnt, #init_mac ; initialize mac unit

mac_loop:

move dp[0], dp[0] ; activate dp[0]
move ma, @dp[0]++ ; get sample into mac
move dp[1], dp[1] ; activate dp[1]
move mb, @dp[1]++ ; get coeff into mac and multiply
djnz lc[0], mac_loop

It is important to note that in the MAXQ multiply-accumulate unit, when the second operand is loaded into the unit, the requested operation is automatically performed and the result is stored in the MC register. It should also be noted that the length of the MC register is 40 bits, which allows a large number of 32-bit multiplication results to be accumulated before overflow, which is an improvement over the traditional method, where overflow detection must be performed after each basic operation. To illustrate how to use MAC efficiently in the signal processing flow, a simple application for a dual-tone multi-frequency (DTMF) transceiver is listed.


dtmf Overview

DTMF (Dual Tone Multitre-Quency) is a signaling technology used in telephone networks to transmit address information from network terminals (telephones or other devices) to switches. The mechanism is to use two groups of four independent tones, each with no harmonic correlation between them, such as a "low frequency group" (below 1 kHz) and a "high frequency group" (above 1 kHz). Each digit on the telephone keypad can be represented by exactly one tone in the low frequency group and one tone in the high frequency group. Figure 1 shows the distribution of these tones.

Tone encoder for dtmf transceiver

The encoder portion of the dtmf transceiver is straightforward and requires two digital sine oscillators, each of which can be tuned to one of four low-frequency group frequencies or high-frequency group frequencies.

There are many ways to solve the problem of digitally synthesizing a sine wave.

One way to generate a sine wave is to avoid the digital synthesis problem completely and just filter the square wave generated by the port pin strongly. Although this method is effective in many applications, the technique does not meet the Bellcore (Bell Communications Research Institute) requirements for the spectral purity of the sine wave. The second method is to use a lookup table to generate the sine wave. In this method, 1/4 of a sine wave is stored in a ROM table, which generates the required waveform based on pre-calculated interval sampling. However, it takes a lot of memory to generate a 1/4 sine table with high enough resolution to meet the spectral requirements, so this method is not usually used. Another relatively good method is to use a recursive digital resonator to generate a sine wave.

The sine wave generated by the recursive digital resonator is shown in Figure 2. The resonator is implemented as a two-pole filter and can be described by the following difference equation:



Where k is a constant defined as:

Since the DTMF dial requires only a small number of tones, the eight values ​​of k can be precomputed and stored in ROM. For example, the constant required to produce a 770 Hz line frequency tone at an 8 kHz sampling rate is:

There is also a value that must be calculated, namely the initial pulse required to start the oscillator. Obviously, if xn-1 and xn-2 are both 0, each subsequent xn will be 0. To start the oscillator, set xn-1 to 0 and xn-2 to:

In this example, assuming that a unit sine wave is required, equation (6) can be simplified to:

It is easy to express the above process in code: Initialize two intermediate variables x1 and x2. x1 is initialized to 0, and x2 is loaded with the initial excitation value (calculated in equation (7) above) to start oscillation. Perform the following operations to generate a single sample of the sine wave:

x0=k*x1-x2;
x2=x1;
x1=x0;

Each new sine value is calculated using a multiplication and a subtraction. Using the single-cycle hardware MAC on the MAXQ microcontroller, a sine wave can be generated with the following code:

move dp[0], #x1 ; dp[0] -> x1
move mcnt, #init_mac ; initialize mac unit
move ma, #k ; ma=k
move mb, @dp[0]++ ; mb=x1, mc=k*x1, point to x2
move ma, #-1 ; ma=-1
move mb, @dp[0]-- ; mb=x2, mc=k*x1-x2, point to x1
nop ; wait for result
move @--dp[0], mc ; store result at x0

Detection of dtmf tones

Since only a small number of frequencies need to be detected, a modified Goertzel algorithm can be used. This Goertzel algorithm is more efficient than the general DFT (Discrete Fourier Transform) mechanism and provides reliable detection of signals within the frequency band. Figure 3 is a schematic diagram of the Goertzel algorithm implemented with a simple second-order filter.

In order to detect a tone of a specific frequency using the Goertzel algorithm, the constant k must be calculated first. For the DTMF detector, this constant can be calculated at compile time, and all tone frequencies are explicitly specified. The value of k can be calculated according to formula (4).

First, the three intermediate variables (d0, d1 and d2) are initialized to 0. Now, for each sample value x received, the following formula is calculated:

After obtaining a sufficient number of samples (usually 205 if the sampling rate is 8 kHz), use the newly calculated D1 and D2 to calculate the following formula:

So that P contains the square power of the test frequency in the input signal x (D12 and D22). In order to decode all four columns of DTMF, each sample will be passed through 8 filters. Each filter will have its own K value and a set of intermediate variables. Since each variable is 16 bits, the entire algorithm will require 48 bytes of intermediate storage.

Once the p values ​​of different tone frequencies are calculated, one tone in the high-frequency group and the low-frequency group will be more than twice the value of the other tones, and usually its amplitude is one order of magnitude higher. Figure 4 is the sampled input signal provided to the decoder, and the values ​​of x are 852 Hz and 1336 Hz respectively. Figure 5 shows the detection results of the Goertzel algorithm. If the signal spectrum does not meet this standard, there are two possible situations, either there is no DTMF energy in the signal, or the noise is too large to block the signal.

A spreadsheet illustrating the algorithm and example code for a MAXQ processor equipped with a MAC are available at www.maxim-ic.com/MAXQ_DTMF.

in conclusion

The MaxQ microcontroller combined with its MAC unit builds a bridge between the traditional MCU and DSP, and effectively solves the technical problem of coexistence of control applications and systems that require a small amount of signal processing. With the addition of a hardware MAC, the MaxQ microcontroller takes the signal processing capabilities of the previous 16-bit microcontroller to a new level. The single-cycle MAC also provides commonly used functions, making real-time signal processing possible.

Reference address:Using MAXQ and MAC for Control and Digital Signal Processing

Previous article:Using time-interleaved ultra-high-speed analog-to-digital converters at the PCB level
Next article:Design and application of RF source control signal simulator

Latest Analog Electronics Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号