DL4YHF's Audio-Utilities:
A/D converter for the serial port

Last updated: October 14, 2015.
Full web address: http://www.qsl.net/dl4yhf/soundutl/serpicad.htm

Main Site: www.qsl.net/dl4yhf

A/D Converter Hardware

This hardware connects directly to your PC's serial port. Two analog input channels are available. The sampling rate for both channels is exactly 2500 samples/second, if the clock is exactly 10 MHz. The baudrate for the serial interface is also derived from the clock frequency; for fclk=10MHz it is 115200 bits / second. See notes below.

(schematic diagram)

Interface between PIC and Computer ("COM1" or "COM2"):

The RS232 specification requires a line voltage of at least +/- 3 Volts, but most PC accept 0 and 5 Volts as valid  H/L input levels. If not, you can add a non-inverting level converter to the circuit.

Connections between ADC(PIC) and PC:

ADC side
(PIC board)
PC side (COM1, COM2)
 9-pole SUB-D
Remarks
Ground Pin 5 (GND)
TXD Pin 2 (RxD) serial data PIC -> PC
RXD Pin 3 (TxD) serial data PC -> PIC

The connection from PC to PIC is not really required, so you can use an "omnidirectional" connection, possibly via a single optocoupler or a cheap wireless receiver+transceiver ("ISM", with TTL-input to the transmitter and TTL output from the receiver). The plan is to use this serial link from PC to PIC for configuration purposes in future firmware versions.

Analog inputs and anti-aliasing filters

The PIC's analog inputs (here: GP0 and GP1) accept voltages from 0...Vdd (here: +5 V). Vdd is also used as reference voltage, so you must use a stabilized voltage source. THE PIC CANNOT HANDLE NEGATIVE INPUT VOLTAGES,  so you may have to add an OPAMP to amplify the input signal and add some DC bias. In contrast to a PC soundcard, the PIC's analog input is DC-coupled so there is no lower frequency limit.

The source impedance at the PIC's analog input ports should not exceed 2.5 kOhms. More about this can be found in the PIC's datasheet, search for "PIC12F629/675 Datasheet" or "DS41190" at http://www.microchip.com.

To avoid aliasing effects, you may have to add some filters before the PIC's analog input. Cut off all frequencies above half the sampling rate (here: 2500 Hz / 2 = 1250 Hz). If the source of the analog signals (which may be an "analog front-end") does not contain such frequencies, you can leave the filters away.

Short description of the PIC firmware

The PIC digitizes two channels with a sampling rate of 2500 sample pairs / second. The resolution is a little over 10 bit, because 4 ten-bit-values are added before the PIC sends them to the PC (the presence of weak noise helps a bit here to keep the the least significant bit moving).

COM port settings

This is only important if you want to write your own "driver" software on the PC side. The Serial Input Tool which will be described later makes all required COM port settings automatically.

  • 115200 bits/second,
  • 1 startbit, 8 databits, 1 stopbit
  • no parity, no handshake (neither hard nor soft)

Format of serial data frame

The analog values are sent  from PIC to the PC in a 4-byte frame. There are 2500 frames per second, which is close to the maximum a standard COM port can handle. The first byte (=byte[0]) is mainly used for synchronisation, the receiver can easily detect the begin of a 4-byte frame.

Note: The PC's async serial interface transmits the least significant bit in a BYTE (LSB,"bit 0") first, the most significant bit (MSB, "bit 7") last.

Byte[0] = Sync/Status
Usually 0xFF which looks like a "STOP BIT" to the receiver. Used for frame sync, but also for BYTE sync if receiver was turned on too late. (and you should turn the ADC on *after* booting the PC, at least under Windoze (XP, 7, 8.1) you can get funny results if the plug-and-play system thinks the A/D converter is a mouse (!!) ). Under Windows 8.1, those strange effects could be cured by de-activating a device named 'Serial Microsoft BallPoint' somewhere in the deep swamps of the system control. It seems to be a bad habit of windows to detect all kinds of devices (on any serial port) as 'Microsoft BallPoint', including GPS receivers, just google for 'Windows detects USB GPS as Serial Ballpoint'.
In future firmware versions, the PIC will be react on commands (which are sent from PC to PIC), then the "Sync/Status" byte will carry a response code like 0xFE. In that case, byte[1] .. byte[3] may have different meanings.
Byte[1] = I-channel, LSB
Least significant bits of 1st analog input channel (bits I7..I0).
Byte[2] = Q-channel, LSB
Least significant bits of 2nd analog input channel (bits Q7..Q0).
Byte[3] : Most significant bits, combined
Bits 3..0 = Most significant bits of  1st channel (I11..I8),
Bits 7..4 = Most significant bits of 2nd hannel (Q11..Q8).

More info can be found in the documentation of the PIC firmware, which is part of the PIC firmware archive (see links at the end of this document).
To use the A/D converter as an input device for DL4YHF's Spectrum Lab, copy the string (format specification) shown below into the 'Params' field on SL's Audio Settings tab, after setting the 'Input Device' to the COM port to which the ADC is connected on your system:
Input device / Stream:   COM3 (replace the '3' with your COM port's number)
Params:                         115200,8-N-1,IQ12
Nominal Sample Rate:   2500

If the PC's serial port is in fact a USB <-> RS-232 adapter, the COM port number will most likely be 3 or higher, because Windows still seems to reserve "COM1" and "COM2" for real on-board serial ports.

Serial Input Utility

To use the A/D converter for some windows programs (including Spectrum Lab), the "Serial Input Utility" program (serinput.exe) can be used. It receives a data stream from the serial port (COM1 or COM2 of your PC). The received data frames are decoded and written into a file which can be accessed using standard disk I/O operations.

One of the parameters when starting serinput is the name of the communication port, which is usually COM1 or COM2.

More info: See download links for the audio utilities at the end of this document.

You can automatically launch the Serial Input Utility from SpectrumLab by entering this on the configuration tab "AD / DA Server":

  • (<checked>) consume ADC file:  audio.dat
    (this is the name of the file produced by SERINPUT and consumed by SpecLab)
  • to start A/D server: serinput.exe /port=COM2
    (assuming you copied "serinput.exe" into the Spectrum Lab directory, and the PIC-based A/D converter is connected to COM2)

Links...

Some links only work if this page was loaded from www.qsl.net/dl4yhf !

PIC12F675 firmware for the "Serial PIC ADC"
(absolute web link: http://www.qsl.net/dl4yhf/soundutl/serpicad.zip)
Contains programmable HEX file and firmware manual, including the serial frame format.
Description and download site for the audio utility programs
(absolute web link: http://www.qsl.net/dl4yhf/snd_utl1.html)
General information about the audio utility programs, and how to use them in your own application.
A simple PIC programmer for the serial port
(absolute web link: http://www.qsl.net/dl4yhf/winpicpr.html)
Can be used to put the firmware into the PIC12F675. A simple interface for the serial or parallel is all you need.

master copy: c:\\pic\SerialAD\serpicad.htm

 Back to the Software Overview