13.07.2015 Views

An Integrated, Modular Simulation System for Education ... - Cal Poly

An Integrated, Modular Simulation System for Education ... - Cal Poly

An Integrated, Modular Simulation System for Education ... - Cal Poly

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

*/static void mdlDerivatives(SimStruct *S){}#endif /* MDL_DERIVATIVES *//*-------------------------------------------------------------------------*/void PCLabCardInit(struct PCLabCard *card){/* dCard = new DACCard(12, card->da1Low, 0.0, 5.0, 2, 0.0);if (!dCard) printf("PCLabCard: Unable to allocate memory <strong>for</strong> DAC\n"); */outportb(card->gainCtrl, 0x00);outportb(card->modeCtrl, 0x01);}/*-------------------------------------------------------------------------*/float doConversion(struct ADCChannel *Chan, struct PCLabCard *Card){float value;unsigned short bHigh, bLow, flag = 1;if (Chan->cNumber >= Card->nADChannels)printf("PCLabCard: <strong>An</strong>alog channel %d is out of range\n", Chan->cNumber);outportb(Card->muxCtrl, Chan->cNumber);outportb(Card->softAD, 0xff);delay(1);while (flag) {bHigh = inportb(Card->adHigh);bLow = inportb(Card->adLow);flag = bHigh & 0x10;}}Chan->adcount= (bHigh gain*(float)Chan->adcount + Chan->offset;return value;/*-------------------------------------------------------------------------*//* Source code <strong>for</strong> ADCChannel class *//*-------------------------------------------------------------------------*/void ADCChannelInit(struct ADCChannel *chan, struct PCLabCard *card){float value;chan->adcount=0;if (chan->minV == chan->maxV) {chan->minV = card->minADVoltage;chan->maxV = card->maxADVoltage;}}chan->gain = (chan->maxV - chan->minV)/(float)(card->maxADCount);chan->offset = chan->minV;value = chan->gain*(float)chan->adcount + chan->offset;/* Function: mdlTerminate =====================================================* Abstract:* No termination needed, but we are required to have this routine.136

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!