# What's the difference between a DSP and microcontroller?

What are the core attributes that make a DSP and microcontroller different from each other?

I have in mind a machine vision device that needs to run image processing algorithms but also control some networking and hardware I/O. How good would the DSP be at controlling hardware output pins, and how well can microcontrollers run image processing algorithms?

• Can I please ask if this is homework? – A_A Feb 12 '17 at 10:16
• This is not homework. I'm starting to experiment with the Atmel chip on an Arduino and wondering what this platform is best at doing vs a DSP. – Phillip Ngan Feb 13 '17 at 6:25
• You may want to ask what is the differences between a micro-controller based DSP vs FPGA based DSP vs Matlab DSP? – Tay Wee Wen Feb 13 '17 at 6:50
• I've put more specifics in the question to hopefully narrow the answer set. – Phillip Ngan Feb 16 '17 at 19:30
• Phillip, i am pretty sure that a DSP like a modern SHArC can control output pins "pretty good". you can map practically any peripheral (and there are several of them) to any pin you want and you can explicitly control the pin as input/output/high/low/high-impedace, whatever. and there are hundreds of pins on the chip. not all of them are GP I/O. – robert bristow-johnson Feb 19 '17 at 3:35

a Digital Signal Processor is one that has, in its instruction set, some instructions and addressing modes that are optimized for processing digital signals.

usually these optimizations can be shown around what is needed to perform the dot-product needed for an FIR filter.

$$y[n] = \sum\limits_{i=0}^{L-1} h[i]\,x[n-i]$$

to do this in, say, $L$ instructions, a DSP must be able to do in one instruction:

1. multiply $h[i]$ and $x[n-i]$ together.
2. accumulate that product into an existing sum.
3. fetch the next $h[i+1]$ and $x[n-i-1]$ in anticipation of the next multiply-accumulate. since these are two numbers to fetch, a DSP will use something called a Harvard architecture that has at least two separate memory spaces for $h[i]$ and $x[n]$ so the DSP can fetch these two numbers simultaneously.
4. addressing $x[n]$ must be in a circular queue. a DSP will perform the modulo (or "wrap around") arithmetic on the index or address of $x[n]$ necessary without additional instructions.
5. the result $y[n]$ will eventually go to an output DAC or fixed-point stream and there is some way to saturate the value of $y[n]$ against some $\pm$ maximum without additional instructions. if the DSP is a fixed-point DSP, then this accumulator register will have width in bits that is the sum of the bitwidth for $h[i]$ and the bitwidth for $x[n]$ plus a few more bits on the left as "guard bits".

a general purpose CPU can do all of these, but not likely in a single instruction cycle and things like modulo arithmetic and saturation will need their own specific instructions in a general-purpose CPU.

a DSP may also have some instructions and an addressing mode that facilitates the operations of the Fast Fourier Transform (FFT). this may include instructions necessary to perform an FFT "butterfly" in as few as four instruction cycles (or two instruction cycles if SIMD is operational).

They are not disjoint sets, as some contemporary microcontrollers SOCs contain DSPs. The DSP cores are usually designed to execute certain computational algorithms with deterministic latencies and less transistors. Not so for many contemporary high-performance CPU cores. In the olden days when fabs couldn't fit that many transistors on a chip (even one entire microcontroller), there was a bigger difference, such as DSPs being implemented out of multiple (hundreds to thousands) of chips (or discrete transistors, or perhaps even vacuum tubes).

Robert Bristow-Johnson's very fine answer discusses the attributes of a DSP. But it contrasts those attributes with a General Purpose CPU. The OP asked about the differences between a DSP and a microcontroller. So, since we already have an excellent description of a DSP, I will concentrate on the microcontroller part.

From wikipedia:

A microcontroller (or MCU for microcontroller unit) is a small computer on a single integrated circuit. In modern terminology, it is a System on a chip or SoC. A microcontroller contains one or more CPUs (processor cores) along with memory and programmable input/output peripherals.

So a microcontroller is a CPU and other perperials that are neccesary to allow the CPU to be useful in the real world. There are in fact DSP chips that are microcontrollers, and there is also a lot of blending of the general purpose CPU and the DSP in modern devices.