Thursday, March 15, 2012

Outputting Functions to MFC

One of the thing I want to be able to do is to output arbitrary odor waveforms with my MFCs.  As a start, I implemented a Sin function to be output to the MFC (i.e. changing the flow rate at some set frequency).  I am hoping to put my MFCs into the setup to verify that they are working properly.

What I did was put a function that gets called on each loop of the Arduino which updates the flow rate at 100 msec intervals.

void loop()                     
{
  ...
  ALI.makeSin(); // ALI is my AlicatMFC object
}


void AlicatMFC::makeSin()

{
  float flow;
  unsigned int uiflow, flow_out;
  
  if (!_on) return;
  if ((millis()-_tL)<100) return;
  
  _tL = millis();
  
  flow = _mean + _ampl / 2.0 * sin( (float) (_tL - _t0) * 2.0 * 3.1415926536 * _freq / 1000.0 );


  if (flow > 1.0) flow = 1.0;
  if (flow < 0.0) flow = 0.0;
  
  uiflow = (unsigned int) ((float) ALI_MULTIPLIER * flow);
  
  setFlow('A',uiflow,&flow_out);  
}



No comments:

Post a Comment