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>F 5E0 F* 255E0 F/ BASE @ DECIMAL F. BASE ! ;<p>HEX<br>is very confusing. I cannot find meaning for the words: S>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>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 ." Starting A/D conversion..." 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>