Showing posts with label RS232. Show all posts
Showing posts with label RS232. Show all posts

Monday, March 19, 2012

MFC Control Complete

Today I finished implementing control over my mass flow controllers from Alicat.  I now have the capacity to drive two MFCs via analog voltage or serial from our custom Arduino shield.  Everything works directly from MATLAB.

This is our Arduino-based olfactometer control module connected to two Alicat MFCs.
The output works at high frequencies with the MFCs being able to follow up to 3 Hz well.  I doubt that this performance will be maintained with long downstream tubing, but I hope to be able to do at least 1 Hz at output.

I had to work out a kink to get switching between serial and analog control to work.  The Alicat documentation says that A$$W20=16384 should enable analog set point. However, I found that this does not work.  Reading register 20 after setting analog set point from the front panel, however, showed that the correct value is actually 17408.

The Arduino will start by default in analog control mode. To switch modes:

[mode] = {0: SERIAL_OUT, 1: ANALOG_OUT}
olf.funcALIMode([mode]);

I tested the whole setup using my handy dandy flowmeter and things work very well so far.  Here is the code I used for my current test setup:


olf = OlfactometerDriver_SerialInterface('COM10'); pause(12);


% proportional control var
olf.funcALIMessage('A$$W21=500')
% differential control var
olf.funcALIMessage('A$$W22=10')


olf.funcALISin(1,1,0.5);
olf.funcALISin(0,1,0.5);


Next step: connect the MFCs to the olfactometer, determine the right parameters for sinusoids, and verify output via PID.


Thursday, March 15, 2012

My Awesome Test Setup

Here's a picture of my setup.  On top of the Arduino is our custom valve driver shield.  Attached to the shield DB9 port is my hastily soldered inverter.  That connects to the Alicat MFC.  The Arduino is also connected to the PC by its USB port.

PC (MATLAB) --> Arduino --> MFC


Below is what interacting with the MFC looks like from MATLAB.


Wednesday, March 14, 2012

Why is RS232 so Backwards??

Ah the beauty of old conventions.  I could not understand why RS232 treated -ive voltages as 1s and +ive voltages as 0s.  But, I got a bit of an explanation from a tech support person and then wikipedia:

http://en.wikipedia.org/wiki/RS-232

Turns out RS232 was created in the days of teletype machines (YEAH!).  In those days trasmitted data was stored as holes punched onto moving tape. These holes were then read as 1s and no holes were read as zeros. So the translation was that a hole (i.e. lack of paper and bit value 1) makes sense as a -ive voltage and no hole (i.e. still paper and bit value 0) makes sense as a +ive voltage.

This all reminds me of that story as to how the wheel spacing of Roman chariots set constraints for getting rocket ships onto the launch pad.

http://www.astrodigital.org/space/stshorse.html

Makes perfect sense now!
Just resolved sending also and I got my first serial port comm between Arduino and the MFC.  In the end, I simply inverted both the transmit and receive signals.

In the light of the morning

In the light of the morning, answers come:
http://www.sparkfun.com/tutorials/215

It looks like the MFC is using an RS232 standard but the Arduino is using TTL serial standard.  These two protocols differ in two main ways:

1. TTL is high for 1 and low for 0, whereas RS232 is the opposite
2. The voltages on TTL and RS232 can be wildly different

However, I happen to know that the voltages one the two devices are ok, so for me its just a matter of inverting the signal.  I can in principle just get a signal inverter, however, I will also order a RS232 to Serial converter:

RS232 Shifter SMD
http://www.sparkfun.com/products/449

Update, I added a simple voltage inverter circuit in front of the receive on the Arduino and MAGIC, it now reads the signals from the MFC just fine!  Now all that is left is sending...