View Full Version : using A/D and floating point
JRobertson
08-01-00, 11:16 AM
Hi again, I'm trying to receive inputs on the A/D ports and manipulate the results using floating point words. When I output the results, i get data that is completely off the mark, and in addition, the output of the last value on the floating point stack results in a crash. Any ideas would be helpful, my code is below.<p>thanks,<br>Jay<p><br>_____________________________________________<br>HEX<p>: INIT-A2D 80 B039 C! ;<p>: GETVOLTAGE 0 B030 C! <br>BEGIN B030 C@ 80 AND UNTIL <br>B031 @ D>F ;<p>: GETPRESSURE 1 B030 C! <br>BEGIN B030 C@ 80 AND UNTIL <br>B032 C@ D>F 1.0 F- ;<p>: GETCURRENT 2 B030 C! <br>BEGIN B030 C@ 80 AND UNTIL <br>B033 C@ D>F .050 F/ 20.0 F* ;<p>DECIMAL<p>: GETLOAD GETCURRENT GETVOLTAGE / ; <br>: GETFLOW GETPRESSURE 8.35 F* .1679 F+ ;<p>: DOWNLOAD GETFLOW GETLOAD GETCURRENT GETPRESSURE GETVOLTAGE ;<br>: OUTPUT CR ." VOLTAGE " F. CR ." PRESSURE " F. CR ." CURRENT " F. CR<br>." LOAD " F. CR ." FLOW " F. CR ;<br>: GO! DOWNLOAD OUTPUT ;<br>_____________________________________________<br>
nmitech
08-01-00, 12:14 PM
You are using wrong floating format,<p>DECIMAL<br>: GETFLOW GETPRESSURE 8.35 F* .1679 F+ ;<p>Try this,<br>DECIMAL<br>: GETFLOW GETPRESSURE 835E-2 F* 1679E-4 F+ ;<p>
Also you need to have two entries on the stack to use D>F ( d -- ) (F: -- r ). So instead of:<p>: GETVOLTAGE 0 B030 C! <br>BEGIN B030 C@ 80 AND UNTIL <br>B031 @ D>F ;<p>: GETPRESSURE 1 B030 C! <br>BEGIN B030 C@ 80 AND UNTIL <br>B032 C@ D>F 1.0 F- ;<p>: GETCURRENT 2 B030 C! <br>BEGIN B030 C@ 80 AND UNTIL <br>B033 C@ D>F .050 F/ 20.0 F* ;<p>Try:<p>: GETVOLTAGE 0 B030 C! <br>BEGIN B030 C@ 80 AND UNTIL <br>B031 @ 0 D>F ;<p>: GETPRESSURE 1 B030 C! <br>BEGIN B030 C@ 80 AND UNTIL <br>B032 C@ 0 D>F [ DECIMAL ] 1.0E F- ;<p>HEX<br>: GETCURRENT 2 B030 C! <br>BEGIN B030 C@ 80 AND UNTIL <br>B033 C@ 0 D>F [ DECIMAL ] .050E F/ 20.0E F* ;<p> I also corrected the floating point words with the appending of E. Also, know that floating point numbers can only be entered when in DECIMAL radix. That is why I switched to DECIMAL in the middle of the word.<p>Rob
JRobertson
08-02-00, 11:29 AM
Thanks for the replies. I've been trying just to read in a voltage on the A/D port and can't find anything in the Max-forth documentation or the 68hc11 docs about what is actually returned to the result registers. <p>I'm measuring voltages between 0 - 24 volts, and I'm using 1k and 4.3k resistors as a voltage divider. For testing purposes, I'm just attaching the lines to a variable source. When I read the data in the register, I get either -209 (for voltage over 5 out of the source) or somewhere around 25000 (for voltages under 5). <p>Can anyone think of a reason why I'm not getting good numbers?<p>These microprocessor and forth manuals aren't very clear about much of anything.<p>Thanks,<br>Jay
Since you are getting negative numbers and numbers like 25000, you are reading more than a byte. Use C@ to access 8 bit wide registers and you will only get unsigned 8 bit values. There are several sources for A/D on the web as well as in the Motorola literature. Sometimes it just takes patience to read the highly condensed technical documents but usually the information is there.
vBulletin v3.0.7, Copyright ©2000-2012, Jelsoft Enterprises Ltd.