You are on page 1of 22
Jonathan W. Valvano 128 Chapter 12 Solutions 66811 Solution 12.1. A 6811 is used to implement the data acquisition system that measures pressure. Part a) The built-in 8 bit A/D of the 6811 is used. Since the transducer and amp are linear, the precision (number of distinguishable alternatives) at each stage will be the same. The pressure precision is 100 alternatives, so an A/D with 8 bits (256 alternatives) will satisty the specifications. Part b) Gain required is SV/10mV=500. Use an instrumentation amp because 1) large gain, 2) differential signal, 3) good Zin, 4) good CMRR. Use an AD620 single chip instrumentation amp because of its simple design and superior performance over the 3 op amp implementation. Gain equation for the AD620 is Rf=49.4k2/(G-1)=98.8@ . For a 2 pole Butterworth LPF R=10k2, the C's are 70.7pF/(2x100)0 113uF, and 141 4yF/(2x100)=0225uF. Scale to Re1IKQ, CO IF, 0.2nF. +12 _ instrumentation amp Buttepyorth fe=100 Hz, nk sil ET O.1pF OnE HL Reseae -12¥ gain=500 Part) Show the ritual unsigned char Pressure void Ritual (void) ( asm(" sei") U1 Powerup A/D 11 continuous scan channed 7 “/ 244.14 He real tine interrupt {7 axm real time interrupt 17 clear RITE asme" oli") ;) Part d) Show the interrupt handler. To optimize for speed 1) use continuous A/D mode; 2) write the handler in asicanbly language 3) as real ine iterpt instead of euput compare seteteeuteangwer letereerterin, Co ¥pragna interrupt_hendlex RTThandlez () void Rithandler(void){ __// many cycles to do it the easy way "ressures (200*RDRI) /258; TELG2r0x40; } 11 clear RITE, acknowledge interrupt _RMInandier: | // code generated by ICci1 version 3.5 lay #255 4 psby ia aes cira 2 9d, 4 aa #100 3 gsr _mulu G12 pay 6 3sr divi 64100 Stab “pressure 4 dab #84 2 stab 413304 tox 3 eel 2 = 278 cycles Jonathan W. Valvano 126 Solutions Manual for Real Time Embedded Systems, 2 Edition answer 2°07 irareeesinl canonnirees Rethandler: #85 cycles to do it right daa 021032 * read A/D result 4 cycles laab #100 + Pressure=(100*ADR1)/255 2 cycles mul Reg D-100¥ADRI 10 cycles idx #255 + Eressure=(100*ADRI) /255 3 cycles idiv * Reg X=(100*A0RI)/255 41 cycles xsd + Reg B=(100*ADR1) /255 3 cycles Stab Pressure + save calculation 4 eyeres daa #0x40 + 2 cycles staa 0x1025 * acknowledge Real Time Int 4 cycles Hel * 12 cycle: seaesersenetansvor Qeeteereeeenersin ansomblyteenereretes Rizhandler: + 38 cycles to get close daa 0x1031 * read A/D result 4 cycles Ada #100 * 2 cycles mul + Reg AR100*RDRI/256 30 cycles staa Pressure Pressure=(100*ADR1) /256 4 cycles Idea #0%40 * 2 cycles ‘staa 0¥1025 + acknowledge Real Tine Int 4 cycles rel {6812 Solution 12.1. A 6812 is used to implement the data acquisition system that measures pressure Part a) Same as the 6811 solution Part b) Same as the 6811, except, connect analog signal to 6812 PAD?. arto) Show the ritual. unsigned char Pressures void Ritual (void) { asm eet ‘AEDCTL2 = 0x80; // Powerup A/D AIDcTLa = 0x05; // B-bit resolution RIDCTES = OxA7; — // continuous scan channel 7 GRGINT = 0x80; // RTZE*1 enable ti RIZCTL = 0x60; // 4,096ns, sample faster than Nyquist rate asa cli} art d) Show the interrupt handler. To optimize for speed 1) use continuous A/D mode; 2) write the handler in assembly language; 3) use realtime interrupt instead of output compare Jfranevinterinhaver Ietearssesin Geeshenteee void" interrupt. 7 RTTHan void) ( Pressure = (100*ATOORO) /255; RITFLG = 0x80: 1) Reknowledge by clearing RITE ) Jevtessevenosanever 2utreeeaeeeniesn aszenblyterretnseonnens Rithandler: + 36 cycles to do it right daa ATDOROL + read A/D result 3 cycles laab #100 + Pressures (100%RDRI) /255. 1 cycles mul * Reg De100*ADRI 3 cycles lex 4285 + Pressures (100*ADRI}/255 2 cycles saiv + Reg X=(100°ADR1}/255 12 cycles xgdx + Reg Be(100*ADRL| /255 3 cycles Stab Pressure * save calculation 3 cycles daa #360 * 3 cycles ‘stan RITFLAG + acknowledge Real Time Int 2 cycles Fei . 2 cycles siesvensvansansuer geettevereesresin agnemblytientettrens Razhandlers ¥ 21 cycles to get close daa ATDDROL » read A/D result 3 oycles deb #100 + Pressures (100*ADRI}/285 1 cycles aol + Reg D=100*apa1 3 eycies ‘tea Pressure «+ ‘Pressure=(1O0*ADRL)/256 3 cycles dea 4580 : i cycles ‘tea RITFLAG + acknowledge Real Time Int 2 cycles red * & cycles Jonathan W. Valvano 127 (6811 Solution 12.2. Part a) The full scale bridge output is 100 um times 100 V/m, which is 0.01 V. To match the full scale range of the AID, we need a gain of 5/001, which is $00. An instrumentation amplifier is used A 1 Hz HPF will remove the ‘unwanted low frequency signal. A 200 Hz LPF is added to prevent aliasing and remove high frequency noise. The ‘sampling rate will be 480 Hz. ,PB1~Go, PBO=S/H, PD4=Done, PD3-0=D11-8, PC50=D7-0 +5 high pass filter OTK Tow pass filter 141. 4ur 628-200, “011HF pF Ste 70.16 uF 1414kQ. Part b) The A/D resolution is 10V/4096 = 2.4 mV. The maximum allowable droop tate for the S/ETis the A/D resolution (2 4 mV) divided by the A/D conversion time (501s), which is 49 Vises. Part) Since the system i linear, the displacement resolution isthe range (200m) divided by the precision (4096), which is 0.05 pm. art d) Nyquist Theorem requires the sampling rate to be stctly greater than 400 Hz. A sampling rate of 480 Hz will simplify the digital filter design. The analysis ofthe digital filter to remove the 60 Hz can be found in Chapter 15, (0) = (x(n) + x(0-4)72 The Z transform, and arough sketch of its gain versus frequency response i as follows. H@)= (1+ ayn Gain 0 60 120 180 240 Frequency (Hz) Parte) Show the ritual subroutine which initializes the necessary microcomputer devices define Rate 4167 fdetine ocs 0x08 unsigned short index: // index into ¥ represents the current sample short x(5]: 7/ wacg of 12-bit signed sanples -2088 to +2047 void ritual (void) ( unsignea short a7 Jonathan W. Valvano 128 Solutions Manual for Real Time Embedded Systems, 2™ Edition asm(" sei"): 1 make atomic // Port is an output A/D Go 4s PBI, S/H hold is BO PORTE=07 DDRD= 0x0 JJ RJD Done is PD4, A/D D1I-D8 is PD3-PDO DDRC=0x00; V7 B/D DI-D0 is BCT-2CO for(i=0;ie5;4+4). x{d]=07 TuSK1|=0C57// Ara output compare § index = 07 Dawte= TFLG1=008; J) rnitianty clear OCsE ocseroNr‘nater // First one asm(" cli"); } Part) The ISR which samples, filters and saves the filter outputs in the buffer Y. faetine Done 0x10 define HOLD 2 define GO 1 void Wait (unsigned short delay) { unsigned short starttime = TCNT: while ((TCNT-startTime) o- 10. 7406 Tesi o e120 Vg (volts) Part 6) The 1.7k0 resistor will generate the 25V, 15mA operating with light in the cable. The 74HIC14 provides hysteresis for noise rejection. Jonathan W. Valvano 130 Solutions Manual for Real Time Embedded Systems, 2™ Edition 45 7 sv a Va ie with light = (ms) 1s * : ons L7ka optic - 7 cable Scents Vq_ (volts) Part c) Nyquist Theorem says the slowest possible sampling rate, f, i 10 Hz. We will implement this system using ‘the 30.517 HRT interrpt ‘Past d) The squarewave V2(tis attached to input capture ICI, 681) Port A PA2 Pat e) Show global data structure required to implement the digital filter unsigned char x7 // current raw tenperature, resolution 1 F unsigned char yi // current filtered temperature, resolution 1 F Part {) Show the ritual and interrupt handlr(s). Given the $00 ns Eelock, the period in $00 ns units, P~20+T, where ‘Tis temperature in F. Thus T=P/20, andthe range is 10s = P<2-ms, or 30

void interrupt 7 Rtthandier(void)( // 30.517 Hz real time interrupt CRGFIG = 0:80; // acknowledge by clearing RIZE x = Poriod/240; // temperature in F Y= GH)/2; | 17 TAR Filter y(nyety(a-2)4x (n) )/2 ’ (6811 Solution 12.4 arta) With a Gain of 392, a force of 200 dynes converts directly into an A/D output of 200, To pass 0 to 10 Hz we will havea 100Hz LPF. We will handle the offset adjustment in software, (dynes) Vy (mV) PEI(V) AD owt 0 0 0 0 i 0s 002 1 200 10 3.92 200 ‘Any low power, low noise op amp can be used to build the LPF 14) 4k 45 49.40 ae Part b) Design the distributed network ‘Subpart b1) Show the hardware interface between a single chip 6811 slave and the network All unused 6811 inputs must be connected to ground or +S. slave 6811 } slave 6811 | [ slave 6811 | open collector [master a asynchronous PD1pDO |{ PDI PDO |[ PDIPDO | feitGupiex LPDIPDO 4, all grounds are connected Jonathan W. Valvano 132 Solutions Manual for Real Time Embedded Systems, 2™ Edition ‘Subpart b2) The maximum baud rate fora 2 MHz 6811 is 125,000 bits/sec, the bit time is 8 us. Each frame is 1 start, 9 data bits and I stop. Each frame requires 88us to transmit, IFBit §=1 then the frame is an address from master to slave otherwise itis a data from slave to master. address=$31 data=$43 san0.12345 67 8siop sat0 12345 67 8x0p U1 U iLT Perea ake ero | Partc) Include all the software tht will exist in each slave ‘Subpart c1) Show the software that goes inthe RAM (uninitialized on (+ wrsszaeein REM i8 stack, local variables**¥*+© ‘Subpart 2) Show the software that goes in the EEPROM (can be different for each slave). [+ mosvas7in EEPROM are constanter#*t¥e%+/ unsigned char Offset-0; /* easily changed to calibrate each system*/ unsigned char Address-0x34; ‘Subpattc3) Show the software that goes inthe ROM (must be the same for each slave). [+ sTitressin ROM As exeeutable progran™**/ define Re 0x80 fdefine w 0x10 Fdetine RIE 0x20 Faetine 1 0x08, define RE 0x04 fpragea interrupt_handler sctitan() /* Interrupts on Zeceive data */ void Sci#lan (void) { unsigned char datar Af(SccR1aRS) {if (ScDRe=Address) SCORFADRIGOEFset:) /* Send force */ else dataescor /* Read and ignore data frames */ , void Ritual (void) ( i") 7% Make ritual atomic */ ScoRI=M: 74 9 bit data with T6=0 meaning data */ SCCR2-RIEHTEWRE; /* Enable SCI, interrupt on RORE */ /+ 125000 bits/sec */ 7+ enabig 3/0 7/ 7+ Continuous scan of channel 1 */ ‘7+ Diowe1 open collector PDL */ asm(" cli") :) void main(void) { Ritual ( wie) (6812 Solution 12.4 Part a) Same as 6811, except analog signal is connected to 6812 PADI Part b) Design the distributed network Subpart bl) Show the hardware intecface between a single chip 6812 slave and the network All unused 6812 inputs must be connected to ground or #5 slave 6812 || slave 6812 || slave 6812] open collector [master 6812 asynchronous psifixD || psitxD || PSUTxD | falrduptex bPSUTxD all grounds are connected Jonathan W. Valvano 133 Subpart b2) The maximum baud rate for a 4 MHz 6812 is 250,000 bits/sec, the bit time is 4 us. Each frame is 1 start, 9 data bits and 1 stop. Each frame requires 44us to transmit. If Bit 81 then the frame is an address from master to slave otherwise iti a data from slave to master address=$31 data=$43 sant. 12345 67 8stop sand 12345 67 8sop Se eee — us —> 1 4us Parte) Include athe software that will exist in each slave ‘Subpart eI) Show the software that goes inthe RAM (uninitialized on power up) fo bassstienry Ratt 4s stack, Local varsableat*tsrvstsesesse/ Subpart 2) Show the software that goes inthe FEPROM (can be diferent foreach slave) Js Nesssvesein EEPROM ate constanter*"*"#+*/ mned char Ofssee=07 /* easily changed to calibrate each systen*/ unsigned char Adcreass0x347 ‘Subpart c3) Show the software that goes in the ROM (must be the same for each slave). [x Masssnesayn som 49 executable progzaa™™*/ fectine Ro 0x80 Seetine Looes O30 Aeotine Wms) Ox40 fdetine w——ox10 Hdetine RIE 0x20 Wdefine 72 0x08 define RE 0x04 /* Interrupts on receive data */ void interrupt 20 SCiHian(void) { unsigned char data; LE (SCIDRHERE) ( Sf (SCIDRI==Address) SCIORL = ALDDRO‘OFEeet: /* Send @-bit force */ ) else data = scroat; J Road snd Sgnoze data frames */ i void Ritual (void) ( aan set J+ Nake ritual atomic */ ‘SCTCRI = LOOPS+NoNSrM; /* half duplex, 9 Bit data with Té-0 meaning data */ SCICR? = RIETECRE; /* Enable SCI, interrupt on RORE SCIED = 1, 7+ 300000 bite/see */ ATDCTL2 = 03807 /* Powerup A/D */ ATDerEA = Oxe5. Yo Bebie ROC */ AIDCTES = OxAl? 7+ Continuous scan of channel 1 */ asm cli} void main(voia) [ Ritual (7 while) , {6811 Solution 12.8. Data acquisition alarm system. Part a) Resistors are 1% metal film, capacitors are ceramic or polystyrene (high quality, nonpolarized), the filters are 2 pole Butterworth, Jonathan W. Vaivano 134 ‘Solutions Manual for Real Time Embedded Systems, 2™ Edition instrumentation amp 100 Hz HPF microphone] : 7 art b) Design the interface between the 6811 signal BO and the EM relay. a wa : @s sit 7406 Eww \] 1R0VAc BO is eee Part c) Show interface between the keypad and the 6811. SK 1 ‘: ‘Subpart dL) Show the software thet goes in the RAM (uninitialized on power up), ‘Subpart 42) Show the software that goes in the EEPROM. 7] alarm threshold unsigned char codeLength=3; 71 cam change secret code length unsigned char secret (3)=(3,1,2)7 // Keye which disable alarm, reverse order Jonathan W. Valvano 135 void main(void)( unsigned int iz ‘sum=0; DDRC=0; 1/ remember unused CMOS Inputs must be grounded key-none: for (J40;iccodebength; i++) code (s}=none? count=0; (OP 108=02807 17 enable A/D ADOTL*0x217 / continuous sampling of channel 2 IMSKI=0x387 11 arm both O04 and OCS TocsetcNTe100; —// start right avay ‘rocéerowr+100; TELGL=0x18; J] initially clear flags asa(" c1i"):) Subpart 44) Show the 1 kHz DAS interrupt handler: void DAShandler (void) { int sample=ApR1-128; // ~128 vo 127 sun-sunesanple*sampley ocs=7005+2000; /7 2000 £ cycles in 1 ms TFLGI~0x08; 11 acknoledge OCS Af (eount++==1000) ( count=0, Lf (sum>threshold) PORTB*1; // start alarm ‘sun=07)) Subpart d5) Show the keypad periodic poling interupt handler void Keyhandler (void) { unsigned int maton, i7 yoct=10c4+40000;// #0000 £ cycles in 20 me ‘TELGI=0x10; 17, acknoledge Océ Lf (reysenone) { 11 no key pressed last interrupt AE(PORTC!*0x08)( // ignore if none last time and none this tine ‘swatch (PORZC) ( ‘ease 0x0! ; breaks case 0x0! break; case 0x08 breaks case 0x0" breaks default: breaks) for (imcodenength=1)4>0;i--) code(i)=code (1-2): code (0) key? mat cheTRUE? for (imO7i0;i--) code(i)=code 4-1) ‘code [0] = Key? atch = TRUE? for (107 i $00 Hz Temperanre(C) ResitmnceQ) Vi Gols) VeVa(oalt) Yooh) —-ADowipt 2 20 cisen 0 ° ° 3001 5001 iaie7s banooxt ms 3 0 Oiemm — Oowtst $ foes 49.4K0 Sgt =02 ur 5.00V, ae = [aDsea 47011 = 106 oe |REFO2 500 define Cce 0x80 unsigned short WindDirection(vold) ( unsigned short directions ADCTL = 7; // Start A/D while ((ADCTL @ CCE) == 0)()7 Gizection = (ADRI"45+16)/32;// max 2554541565535 // the +16 creates the proper xounding return (direction); , (6812 Solution 12.10. Design a wind direction measurement instrument using the 10-bit A/D converter. Part a) Show the analog interface between the transducer and the A/D port channel 7 45 0 define sce 0x2000 unsigned short WindDirection (void) { unsigned short direction: ‘RIDCTLS = 0x97 // Staxt B/D channel 7 while ((ATDSTAT ¢ SCE) == 0) (J; Gizection = (ATDDRO*4S#64) /12% 17 max 45*1023464<65835 17 the +64 creates the proper xounding return/direction); } ‘Solution 12.11. Design a postion DAS using a sensor, analog electronics and a 6811/6812 Part a) y~0.1Vinmex. The sensitivity, whichis the slope of the y=f(x) response, is 0.1 V/mm. Part b) We wish to map y=-0,1V into z1=0 and y=+0.1V into 215. The transfer equation is Se(y+0.1)=25ey +25 ‘We could also map y=-0.1V into 21=+5 and y=40.1V into 21=0. This transfer equation is 21=25 -25ey Past c) We want the maximum allowable noise for our analog circuit to be less than the resolution at that point Assuming the A/D is the limiting factor, the resolution aty is 0 2V/256 or 781 nV. Adding a safety factor of 1/2, we ‘want the amplifier noise to be less than 390 wV refered to its input. Part d) Nyquist Theorem states any sampling rate strictly greater than 2 Hz. would be appropriate Parte) We could have implemented the transfer relation, 21= 25 -2Sey, with just one cp amp. Rather, we will se a noninverting amplifier so the the input impedance of the circuit will be large. The op amps will need to be powered with +12 and -12 volts because the intermediate signal, 50-y, can range from -5 to +5 volts. The bandwidth of the first stage is 8 kH¥z and the second stage 400 kHz, o the combined bandwidth is about 8 kHz, well above the specifications, All resistors are 1% metal film. 6 +5.00 F 0k 10k0 +1297] Our =p [REFO2 z1=2.5-25¢y gain=50 Part ) You could scale the capacitors to standard values 0.1 and 02uF by changing the 10k resistors to 112.5, Since the exact cutoff of 10 He isnot crtcal, you covld use a 100k resistor making he cutoff about L1H ll resistors are 1% metal film, and capacitors ae polystyrene, polypropylene or Teflon. Part g) Assuming the A/D is the i willbe 2/256-0.0078 mm ing factor, the system resolution Sohution 12.12. Design an electronic sale Parts) Whats the bridge output (VI-V2)? What gain is required? Vie5.00-101/200=2 525V V2-5 0099/2002 475V VIAV2+0,05V Gain-5/0 05-100 Partb) Design the pre-amp. Part ¢) Design the two pole LPF with a cutoff of 20 Hz All resistors are 1% metal film, and capacitors are polystyrene, polypropylene or Teflon. To make agin of 100, we set Ry = 49400 £2/9949902 Jonathan W. Valvano 140 Solutions Manual for Real Time Embedded Systems, 2" Edition ‘You could scale the capacitors to standard values 0.1 and 0.2uF changing the 10K resistors to 56K. Patt d) The system resolution is 1 Kg divided by 256 or 39g. Part e) The sampling rate should be above 20 Hz because of the Nyquist Theorem. Extra Question 12.13. The objective of this question is to design the analog electronics to interface a distance ‘ansducer to the 0 to +5V builtin 10-bit ADC of the 9812C32. The transducer output isa single voltage (relative to ‘ground, not differentia) with a range of 0.5 to 1.0 volts. Distance(m) —_Tranducer Vol ADC input vol 0 0 50 25 100 3 Part a) What i the éxpected resolution ofthis data acquisition system in mele Part b) Choose the most appropriate decimal fixed-point resolution. Eg, select from these 100,10, 10.1, or 0.01 m. Part c) Derive a linear equation that maps the full-scale transducer output to the fll-scale ADC input Part d) Build this circuit with one rail-to-rail op amp and a REFOS 2 SOV analog reference. You do not need to show ‘the power connections or include an analog low pass filter Part e) Write a function that samples the ADC, and retums the distance as a decimal fixed-point number. Extra Solution 12.13, Part a) 100m/1024 = 0.098m Part b) This is approximately equal to 0.1m, A= 10" m. art ) Voge 5*(Vin-B5) ot Vou S*Vin2.S Part d) Add Vac=2.5V. Vou= 5*VieVee Add V_= GV, to make sam of gains equal to 1 Vou = 5*Via Vou 3*Ve (Chose Re 150 KO, asthe least common multiple ofS, 1,3. Build oy 30K Parte) Needs 32-bit math unsigned Short Distance(votd) { unsigned long 4; ‘ATDCTLS = 03807 // Stazt A/D channel 0 while ((ATOSIAT @ SCE) == 0) 1}; d= (ATDDRO*125+64) /128; // max 1023°125+6465535 1/ the +64 creates the proper rounding retuzn dy } Jonathan W. Valvano 141 Extra Question 12.14. Design a data acquisition system using a accelerometer and the 10-bit ADC of the 9812C32 ‘channel 5. The transducer converts acceleration to voltage. The fiequencies of interest are 0 to 20 Hz. The ‘transducer output is a differential voltage, which constrained to -0.1V< (V,-V;) <0.1V, The ADC range is 0 10 45V. Acceleration (m/sec*) _Tranducer Voltage V.-V_ (V) ADC input voltage (V) =100 “01 0 0 0 25 +100 401 3 Part a) What is the expected resolution of this data acquisition system in m/sec"? Pat b) Choose the the eget bt appropiate binary fiaed-pont resolution E g, sles fom one ofthese values 4, 21,2", 250,2425, 20007" mise Fu) Design the analog interace Add an anti-aliasing LPE filter. There ar two inputs Vs and Va, and one output eu such tht Vor = 25¢CV-¥a)e2. This means the ouput vole wl be constaned io O10 SV. The tansdacer requires the first stage ofthe analog circuit has an input impedance larger than 10 MC You must build this interface tlh TLC2274s and oe REFS, using jut +5V power ‘Part d) Write a function that samples the ADC, and retums the acceleration asa binary fixed-point number. Pat) What the slowest sampling rae that cts te Nyquist hearer Ext Solton 12.14 Part) Since we ar iterested into 0H, we need a sampling rat of 402 Pattd) 200 miseT1024 = 0.198 mse Part) The largest resolutioin, whichis smaller than 0.195, i 0.125. A= 2° mised? ‘Acceleration msec?) ADC input voltage CV) ‘ADC Fedo meee) “100 0 0 ~800 0 25 siz ° +100. s 41023 800 Part d) We wse an instrumentation amp, because ofthe differential nature and the input Rnpedance. We add a 23V to the ground signal of the amp to scale the signals near 2 SV. Gain of 25 is calculated as (SOK/1OK}(1+2*20K/I0k) The filter is designed with LPF xls first design step iso select he cutot fei)” 20 ‘this in RAGokm) 10 same a inital R CIAW 1125228 ie ALAC) COAG) 0.562613 is TO.) 0 O5:C1A second design step isto choose convenient Capacitor values felts) 20 sume a previous fe RB (ohm) 112523 new value to maich exact © CIBGR Oi sil isin C2BGE) 005 is 054C1B third design step isto choose a convenient resistor valve fe(Ha) “” 22,50451 new coutoff based on these convenient values RC (rob) 100.000 fill his value in cia t same as CIB. CHR) 005 sameas 2B vi Gain=10 Jonathan W. Valvano 142 Solutions Manual for Real Time Embedded Systems, 2 Edition Parte) 16-bit math is ok short Acceleration (void) { short a: RIDCTLS = 0335; U/ Stat a/D channel 5 while ((ATDSTAY & SCF) == 0) ()7 2 = ((AFODRO-512)*25)/16;// max 12*25<32768 return a7} Extra Question 12.15. A data acquisition system measures position with a range of -20 to 20 m, using an external 4-bit ADC. What number system (integer, binary fixed-point, decimal fixed-point, or floating point) would you ‘propose to represent these positions ifthe system required extensive mathematical calculations and very litle human ‘input/output? For full credit, give the value to be stored in memory when the position is $ m. Give units for the number system, Extra Solution 12.15, First, determine the measurement resolution, which is 40 m divided by the ADC precision of 16384. This system can resolve position differences of 0.00244 m Binary fixed-point is selected because multiple calculations will be required. 1/0.0244=410, The next larger power of 2is 512. A 16-bit signed binary fixed-point ‘number system with a resolution of 1/512 m will be able to represent all measured values. The range is -64 to 64 m. Possible 16-bit signed binary fixed-point solutions are resolution=1/512 m 6410 64m —_$ mstored a5 2560 321032m S$ mstored a8 $120 Extra Question 12.16. Time-jiter, 5, isthe difference between when a periodic task is supposed to be run, and ‘when itis actually run. The gol ofa real-time DAS is to start the ADC ata periodic rate, At Lett, be the nh time the ADC is stated. In particular, the goel to make t.~tqi = At. The jitter is defined as the constant, St, such that atst65535 1/ the 432 creates the proper rounding return a) Extra Question 12.19. Design a flowmeter using the 12-bit Max1247 ADC shown in Figure 7 44. The transducer converts blood flow into voltage. The blood flow range is 0 to 16 L/min. You will design the analog electronics to interface this transducer to the 0 to +2:5V extemal ADC The transducer output is a single voltage (relative to round, not differential), with a range of 2 to 3 vols. Flow(Limin) _Tranducer Vol ADC Input vol 0 2 0 8 225 125 16 25 25 Parts) What isthe &:pacied resohaton o this daa aequisifon system fa Tin Part 5) Choose the lgest, but appropriate binary fixed-point resolution Eg, select a resolution that is a power of two... 2,2,1,2", 23,2°,. Limin, Parte) Deve a linear equation that maps the fll scale transducer output tothe fl-seale ADC inpet Part) Buld this ciruit with one op amp and a REFOI 10 0V analog reference. You do not need to show the power connections. You do nat ned to ince en analog low pass fier, Parte) Write a funeton that sampies the 12-bit ADC, and returns the blood flow as a binary fixed-point mamber ‘You may assume the ADC is initialized (Program 7 6) and you may call he existing Program 7.7 Extra Solution 12.19. Part) Range/preision = 16L/min/4096 = 0 00390625 Linin Jonathan W. Valvano 144 ‘Solutions Manual for Real Time Embedded Systems, 2 Edition Part b) The largest resolution less than 0.00391 is 1/256. A = 2* L/min Flow(Limin ‘ADC input vo ‘Ade Fad Pot Ua) 0 0 0 ° 8 12s 2048 2048 16 25 5095, 4095 Parte) Van= 5 Vin-10 Part d Step one, rewrite with reference chip voltage shown a third input Van =5 VayVog ‘Step two, adda ground asa third input, with again such that the sum of the gains is 1. Veg" 3 Via~Vae~3 Ve Step three, choose a feedback resistor which is a common multiple of 13,5. R150 Step four, select four input resistors to get the desired gains Rin Patt e) unsigned short BloodFlow (void) ( // no conversion necessary return ADC_in(ch0) ; 1 Program 7.7 ) Extra Question 12.20. Design a pressure deta acquisition system it ADC. The transducer converts pressure into voltage. The input range is 0 to 4 dynes/om’. The objective ofthis question isto design the analog ‘electronics to interface a transducer to the 0 to +5V IL-bit ADC. The tansducer ourput, Vis a single voltage ing an 11- (relative to ground, not differential), with a range of 0.5 to I volts. Pressure (dynesfem®) — Tranducer Voltage V, "ADC input voliage W, 0 050 0 2 075 25 4 1.00 s Part a) What isthe expected resolufion of this data acquisition system in dynes/om art b) Choose the the largest, but appropriate decimal fixed-point resolution E g., select from these 1000, 100, 10, 1, 0.1, 001, of 0.001 dynesiem? Part c) Derive a linear equation that maps the full-scale transducer output tothe full-scale ADC input. at d) Build this interface with one op amp and a REFO3 2 SOV analog reference. You do not need to show the ‘power connections. You do not need to include an analog low pass filter Parte) Write a function that samples the 11-bit ADC, and returns the pressure as a decimal fixed-point number. You may assume the ADC is initialized and you may call an existing program ADC_In() to get the 11-bit unsigned sample (002047). Extra Solution 12.20. Paita) 4 dynes/en#/2048 = 0.00195 dyneslen? Part b) The largest resolution less than 0.00195 is 0.001. A= 10° dynesicm’. ina ee ° ° @ 2 102 2000 4 2047 ‘00 Patt o) Vip = 10V;-5 Part d) Step one, rewrite with reference chip voltage shown asa third input Vap= 10, Step two, add a ground asa third input, with a gain such that the sum of the gains is. Van ‘Step three, choose a feedback resistor which is @ common multiple of 2,7,10. R= TOKO ‘Step four, elect three input resistors to get the desired gains. Ve 10 Vs-2Veet-7 Ve Jonathan W. Valvano 145 Part o) unsigned short Pressure(void)( unsigned short data unsigned long ps data = ADC_tn()7 1/9 to 2047 P= (data*i25+32)/64; —// max 20477125+32>65535 return pi | 7/ the #32 cxeates the proper rounding Extra Question 12.21. The objective ofthis question isto design the analog electonics to interface a transducer to the 0 to+5V built-in ADC ofthe 6812. The transducer output, Vi single voltage (relative to ground, not differential, witha range of 05 t0 0.75 volt. Van ™=20V,~ 10 Part 2) Build this interface with one op amp and a REFO3 2.50V analog reference. You do not need to show the power connections. Yeu do not need to include an analog low pss filter Pb) What is the voltage resolution referred to input V,,of the system if the ADC has 12 bts? Extea Solution 1221. Vay =20V;~ 10 Part a) Step one, rewrite with reference chip voltage shown as a tird input Van 20 V; AVowr Step two, ad a ground as atird input, with again such that the sum of the gains is 1. Vap= 20 V,-4Vir-15 Vy Step thre, choose a feedback resistor which is a common multiple of 4,15 20. Ry= 6ORQ. Step four, sles three input resistors to get the desired gains Part b) The voltage resolution, calculated as range/precision, i 0.25V/4096 ~ 61V Extra Question 12.22, A transducer has th following quadtatic relationship ‘T= 0.0083*R?~ | 2465°R + 6632 ‘here T is the temperature in °C and Ris the resistance in KO. In the computer, I and R are implemented as decimal fixed point numbers with resolutions of 0.01 °C and 0.1 KO respectively. Write a C function using fixed-point math (integer calculations) that takes R as an input and gives T 2s an output DO NOT IMPLEMENT TABLE-LOOKUP. WITH LINEAR INTERPOLATION. Implement the quadratic equation directly. The domain of R is 20.0 to 640 KO, and the range of Tis 20.00 to 45.00 °C. Extra Solution 12.22, First convert resistance and temperature to fied point, T= 7/100, R= &R/10. 49/100 ~0.0083*(4R/10) ~ 1-2465*iRV10 + 66.32 P= 0,00834R'— 12 465°AR + 6632 Convert constants to integers Jonathan W. Valvano 146 Solutions Manual for Real Time Embedded Systems, 2"! Edition ‘T= (83*R*RY/10000 ~ (12465*RY/1000 + 6632 Use signed long math because 83¥R*R will exceed 16 bits Must be signed because 83*R*R<124650°R short Convert (short ){ long bigt,bigR; igh = (long)R? —_// pronote to 32-bits DAgT © (83zAbigRtbign~224650L*bLgR) /10000+6632 return (short) big?s) // denote ‘You could use unsigned long math if you rearange the terms to keep the intermediate calculations positive unsigned short Convert (unsigned chort R)( unsigned long Big, DigR = (unsigned long) Ry 71 pronote £0. 32-bits igh = (663200001+83EDigR*bigh-124650L*bigR) /100007 return (unsigned short) BisT:) // denote Extra Question 12.23. Design en analog circuit used to measure force F. The input range is 0 0 100 dynes. The frequencies of interest are 0 to 10 He, The transducer is comprised of four resistors, which you should place in resistance bridge. Increasing te force will ease two resistors o reduce in value, while the other two will increase in value Ry = 1000 -0.1°F y= 1000+0.1°F y= 1000+0.15F R= 1000-0.1°F ‘where the resistances are given in ohms and the foree in dynes. The ADC range is 0 to +10V and the precision is 12 bits. Give chip mumbers but not pin numbers. Show how the four resistors are connected and how the bridge is Powered. Specify all resistor values. You may use +12 and ~12V analog supply voltages. Include the proper analog filter Extra Solution 12.23. First you caleulate the range of resistance. Ry and Rp range from 1000 to 1010 ohms and Ry and Ry range from 1000 to 990 ohms. Next, you place the 4 resistors in a bridge and use 2 low-noise REFO2 +5.00V. voltage reference to power the bridge, Vs is equal to S*Ry(R, + Ra). Since (Ry + Rs) is a constant, V; is equal 10 'Ry/400. The voltage Vs ranges fiom 2 5 192.525 V. Vz is equal t S*Rg(Rs + Ry). Since (Ry + Ry) i a constant, Vs 4s equal to Ry400. The voltage Va ranges from 2 5 to 2.475 V. The difference (Vr-V3) ranges from 0 100.05 V. AR instrumentation amp with again of 10/005~200 will ereate an ouput, Vs, which matches the 0 to +10V ADC range. The AD620 is a good high-quality low-cost instrumentation amplifier. The R, resistor is chosen to create the 200 ‘gain R,= 49 1k/199 = 2470 The LPF cuts at 10Hz. Using LPF xis ( Fist design step sto select the eutoft : fede) 10 *illthisin RA Giohm) 10. same ss inital R CIAGR) 22505 is 141.4iaemfo) CAGE) 11252 _ is 7.7m) or SCI second design step ist choose convenient Capacitor values fed) 10 same as previous fe RB (koh) 225.045 new value to match exact fe CGR Oi ‘fillthisin CBU 0056 0C1B ‘third design step is to choose a convenient resistor value fez) 10229 new couofTdasedon these convenient values RC (koh) 220.000 fill this vale i CIC@F) Of sameas CIB C2CGF) 005 sameas C28 +5.00V R3 Ref02 RL

You might also like