PIC 18F4550 conversor AD para 8 canales

 

- page last update april 2011- (página en catellano)
 

 

General description:

The actual project is the successor of the already made unit “PAD to MIDI”. The old unit, made view years ago, uses a PIC16F877. The source code was written in assembling (ASM) uff ... but it works (still) very fast.
The code for the new PIC18F4550 is written in C (BoostC) and it can be downloaded with all other files (electrical schematics, descriptions) at the very end of this page.
Compared to the huge code of the 16F877 the new code for the 18F4550, written in C, is much simpler.
While the “firmware” of the 16F877 project reads 8 analog inputs and converts the results to a MIDIprotocol the new code for the 18F4550 only reads the 8 analog inputs and sends the results to its USART to a MAX232 (level shifter) connected by a cable to the RS232 port of the computer.
In case to not have any more a RS232 input (all Laptops) there are cables (RS232 to USB) or one can make a small PCB using a FT232 USART to USB converter. (see FT232). The reason to use a PIC184550 was principal to have a PIC with the ability to connect the PIC directly to a USB port using the its internal register. Still I didn't program the source code to have this ability of the PIC.
For further use of the incoming (raw) data sent from the PIC, I use Pure Data (the download file includes a patch). With Pd one has a lot of possibilities to interpret the events. They can be used as MIDI, or OSC events to manage other programs (SuperCollider, Resolume) or one can send the data with [netsend] to another computer. Interesting is the use of tables, [tablewrite], [tableread] to change incoming data in may different ways.
If you prefer to program in Prozessing or SuperCollider environment instead of Pure Data one can obtain the results of course.
The firmware of the PIC18F4550 works indeed very fast. One can adjust the sliders in Pd to avoid that Note Off messages are sent. With a simple Midi interpreter (MIDI_OX for example) one can generate 30 MIDI Note-On messages with only one stroke. This is a tremendous sound cloud achieved only with a simple Midi tool.

 
Block-Scheme of the circuitry:
18F4550 8 AD converters
The above Block-Scheme shows the signal flow of one channel, but of course there is only one PIC18F4550 and one Level-Shifter (MAX232).

 

The differential pre-amplifier (for one channel)
Balanced Preamp
Balanced Preamp

The LF356 is a low price, widely distributed JFET op-amp. To amplify a signal of a piezoelectric transducer with a narrow frequency range of approx. 100Hz to 6kHz the IC is a good joice.
The gain of the circuit is 4,7 (G = Rf/Rin). To powering up a condesator microphone or, as I do
commonly, to powering a small Pcb with a (FET preamp) to buffer the piezo transuder a voltage though R7 of 4K7 is applied to the “hot” input 2 of the cannon plug. (Phantom power).

 
Interface made by Martin Hug
Balanced Preamp made by Martin Hug
16 Cannon plugs and 8 differential pre-amps. The sound is very clean and nice.
 
The envelope follower (for one channel)
Envelope Follower Martin Hug

The original design of the envelope follower you find here. I added a potentiometer (R20) to get the ability to adjust the output voltage, pin 7, of the LM324. The “free” IC3C I use to have a visual event indicator with LED1. The indicator could be designed significantly simpler with only one resistance of 1k and a LED connected to pin 8 of the IC3C.
Together with the differential pre-amplifier I get quit good results. It is a good idea to put a 100 ohm resistance with a 5,1V Zener diode to the output (pin 7) of the IC3B to protect the input of the 18F4550. (the reason is the to high +15V, -15V of the envelope follower for the inputs of the PIC).

 
 
PCB envelopw follower Martin Hug The 8 envelope follower units are designed for easy plug into a base PCB. (see photo).

Each unit is connected using “very” old computer plugs. I got a lot of them without even paying them, but for my purpose they work good enough.
The envelope followers are made with SMD devices.

 

 
The PCB with the PIC184550
PIC18F4550 & xBee by Martin Hug
PCB with the 18F4550 and the socket to put and xBee module if there is a need.
schematics  18F4550 8 channel AD
schematics 18F4550 by Martin hug

When I designed the PCB I put view connectors without use to the PCB. With this connectors one could connect a xBee unit or a serial LCD to the I2C bus of the PIC.
What we really need for the project is only J6 for 8 analog inputs, J1 to connect a PIC programmer and the 3 LED's to have some visual control. I use a ICD2 clone to program the PIC18F4550.

8 channel AD converter by Martin Hug
PW filter & PCB18F4550 by Martin Hug
Open unit (Rack standart) with 8 audio pre-amplifiers, 8 envelope followers, 8 audio outputs & 1 power supply filter to get a clean audio signal.

 

Extract of the PIC18F4550 firmware

Cristal externo de 20MHz.
// init function for RX/TX
void init_TX_RX()
{
char dump; // aux Var to empty RX_buffer
rcsta = 10000000b; // set SPEN bit,serial port enabled & CREN disabled.
txsta = 00100100b; // TXEN enabled, BRGH = 1, TX9 8-bit, Async mode.
baudcon = 010001000b; // BRG16 = 1 (010001000).
spbrg = 42; // 42 for 116,279Kbaud)
dump = rcreg; // empty RX_buffer.
dump = rcreg; // empty RX_buffer.
}
//La función de un canal (canal 3) para enviar los datos mediante el USART del PIC.
//Solo si las condiciones de la primera línea están evaluado en verdad (true) la función envía los datos al USART.
if ((!test_bit (on_off,3)) && (Vel_3 >= TH_3) || (Vel_3 >= aux_3 + TH_3))
{
del_3 = del_3 + 1;
if (del_3 >= del_On_3) // short delay to adjust the envelpoe knee at the beginning.
{
set_bit (portc,1); // white_LED on.
aux_3 = Vel_3; // aux_3 used to re-trigger Note. if value is higher than Vel_3.
set_bit (upper_3,4); // select Ch_3: 10000b = 16.
init = 0x00; // init byte, sets in Pure Data the gate_object.
txreg = init; // 1st byte =0x00 initialize Pure Data.
while(!trmt);
txreg = upper_3;
while(!trmt);
txreg = lower_3;
set_bit (on_off,3); // indicates that data is sent.
del_3 = 0;
clear_bit (portc,1); // white_LED off.
Vel_3 = 0x00;
return;
}

Uff … it looks weird but it isn't …

The function shows how 10bits of channel 3 are sent. The transmission includes in total 3 bytes: The init byte, always 0x00, the bytes upper_3 and lower_3.
The 6 unused bits of the upper byte of the 10bit AD conversion are used for direction purpose. So, locking at the code above the “set_bit (upper_3,4)” writes the address, so that Pure Data (or Prozessing) can extract the address included in the upper_3 byte and assign the corresponding channel.
To determinate an event a forth byte is sent, As soon as the 18F4550 reads a 0V at the analog input a byte with its corresponding channel address is sent.
In this way I avoid that the PIC sends permanently data as soon the voltage rises above 0V. The effect is similar to a MIDI-Keyborad: on pressing a key its correspond

The source code is written in C (BoostC) and is included in the download-ZIP at the bottom of the page.
AD converter for 8 channels with 18F4550 by Martin Hug
All the circuitry is mounted in a standard 19inch chassis. The unit can be screwed into a Rack for easy transport.
 
 
 
MAX232 level shifter
MAX232 PCB by Martin Hug I made a small print to convert the data from the 18F4550 to a RS232 format. The PCB is done using a MAX232.
I reused the PCB with the MAX232 because I had it ready mad from another project.

But I recommend using a newer design with a FT232RL to connect directly to an USB port of the computer. FTP232

 
schematics MAX232 by Martin Hug
schematics MAX232 by Martin Hug
schematics FT232 by Martin Hug

 

 

audio pre-amplifier

The schematics is really simple. The gain can be adjusted with the potentiometer of 10k between 2,7 minimum and 57 maximum. The pot. Is connected to pin 2 of the IC2. The LED1 is an event indicator of the input values.

schematics  pre-amplifier by Martin Hug

 

 

Pure Data patch

With the program of Pd one can adjust several parameters of the 18F4550.
Adjustable are:
TH: minimum voltage that generates events. (like Trash Hold)
NoteOff: below this voltage a final byte is sent.
On delay: after how may program cycles a data package is sent?
MIDI ON/OFF: not activated.

Pure Data Pd partch 18F4550 8 channel AD by Martin Hug

 

open related links in new window. (only Internet Explorer)

 

 

 

download the 18F4550_AD files