PDA

View Full Version : A/D ISSUES


eds
07-07-00, 12:57 PM
Tech, Thanks for the code requested; Going through it has helped me bridge many gaps between Forth and Assembly languages. I do have a few questions though:<p>1) The code line for the BCD conversion:<p>DECIMAL<p>: BCD S&gt;F 5E0 F* 255E0 F/ BASE @ DECIMAL F. BASE ! ;<p>HEX<br>is very confusing. I cannot find meaning for the words: S&gt;F, F*, or F/ and the line in general does not mean anything to me. Please explain how this line works.<p>2) The code itself resulted in non-practical results. I thus modified it, usind the three steps in the NMI manual and got decent results. Strangely, for any given channel, the results will be very good for a few readings, then very bad (almost 2 volts off) for the next few readings. I've looked for signal errors and have tried masking schemes, but still the same fluctuations. I did find a relationship between P and Q, when adjusting them to certain values, yields a pattern; ie. 4 good results followed by 4 bad ones (or 1 and 1 with different P,Q). Is this a calibrations problem a code problem. I have yet to calibrate, but the logic doesn't seem to lead to that. Here's the modified code:<p>COLD<p>HEX<p>404 DP !<br>B030 CONSTANT ADCTL<br>B031 CONSTANT ADR1<br>B032 CONSTANT ADR2<br>B033 CONSTANT ADR3<br>B034 CONSTANT ADR4<p>B00E CONSTANT TCNT<br>B023 CONSTANT TFLG1<br>B01E CONSTANT TOC5<p>DECIMAL 50000 HEX CONSTANT Q<br>DECIMAL 239 HEX CONSTANT P<p>VARIABLE CNT<p>: COMPARE-SUCCESS? BEGIN TFLG1 C@ 8 AND 0= NOT UNTIL ;<br>: CLEAR-FLAG 8 TFLG1 C! ;<p>: INIT<br> 0 CNT !<br> TCNT @ 1000 + TOC5 !<br> CLEAR-FLAG<br>;<p>DECIMAL<p>: BCD S&gt;F 5E0 F* 255E0 F/ BASE @ DECIMAL F. BASE ! ;<p>HEX<p>: READ-ANALOG<br> CR<br>10 ADCTL C!<p>07 BE00 C!<br>00 BF00 C!<br>BF00 C@ 2 * BCD<p>06 BE00 C!<br>F0 BF00 C!<br>BF00 C@ 2 * BCD<p>05 BE00 C!<br>0F BF00 C!<br>BF00 C@ 2 * BCD<p>04 BE00 C!<br>FF BF00 C!<br>BF00 C@ 2 * BCD<p>14 ADCTL C!<p>0B BE00 C!<br>FF BF00 C!<br>BF00 C@ 2 * BCD<p>0A BE00 C!<br>FF BF00 C!<br>BF00 C@ 2 * BCD<p>09 BE00 C!<br>FF BF00 C!<br>BF00 C@ 2 * BCD<p>08 BE00 C!<br>FF BF00 C!<br>BF00 C@ 2 * BCD<br>;<p><br>: RUN<br> CR .&quot; Starting A/D conversion...&quot; CR<br> INIT<br> BEGIN<br> BEGIN<br> COMPARE-SUCCESS?<br> Q TOC5 @ + TOC5 !<br> CLEAR-FLAG<br> CNT 1+!<br> CNT @ P =<br> UNTIL<p> COMPARE-SUCCESS?<br> Q TOC5 @ + TOC5 !<br> READ-ANALOG<br> 0 CNT !<br> ?TERMINAL<br> UNTIL<br> ABORT<br>;<br>RUN<p>Thanks,<br><p>----------<br>Ed Seng<br>

nmitech
07-07-00, 02:35 PM
You are using the A/D sample program of the HC11 built-in 8 bit A/D for the 12-bit A/D board.<p>Here is the sample program for 12-bit A/D,<p>( Reading 8-CHANNEL 12 BIT A/D )<p>HEX <br> <br>400 DP !<br> <br>: DELAY1 2000 0 DO LOOP ;<br>: DELAY2 100 0 DO LOOP ;<br>: READ-A/D<br> CR<br> BEGIN<br> 7 BE00 C! 0 BF00 C! DELAY2 BF00 @ 10 / FFF AND U.<br> 6 BE00 C! 0 BF00 C! DELAY2 BF00 @ 10 / FFF AND U.<br> 5 BE00 C! 0 BF00 C! DELAY2 BF00 @ 10 / FFF AND U.<br> 4 BE00 C! 0 BF00 C! DELAY2 BF00 @ 10 / FFF AND U.<br> B BE00 C! 0 BF00 C! DELAY2 BF00 @ 10 / FFF AND U.<br> A BE00 C! 0 BF00 C! DELAY2 BF00 @ 10 / FFF AND U.<br> 9 BE00 C! 0 BF00 C! DELAY2 BF00 @ 10 / FFF AND U.<br> 8 BE00 C! 0 BF00 C! DELAY2 BF00 @ 10 / FFF AND U.<br>CR DELAY1<br>?TERMINAL UNTIL KEY DROP <br>;<p>Forth on line URL,<br>http://www.ee.ualberta.ca/~rchapman/MFwebsite/V50/Alphabetical/Brief/index.html<p>You can also order a hardcopy of UMMAX (HC11 maxforth manual), price:$30. Please email to: nmisales@newmicros.com<p>If you are new to FORTH, I would recommend you a good FORTH book for beginner from,<br>http://theforthsource.com<p><p>

eds
07-10-00, 11:14 AM
To let you/everyone know. The random errors in my A/D conversions was due to the lack of a COMMON GROUND!