View Full Version : A/D port results
JRobertson
08-03-00, 07:22 AM
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. <br>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 <br> <br>
JRobertson
08-03-00, 12:51 PM
Ok, this is an update of my progress. I've realized that I wasn't taking the 8 bit value but rather the 16 bit value, as well as the fact that my voltage divider was reversed. But even after I figured this out, I've had a problem. The voltage input into the pin has never been above 5 but for some reason I think i've shorted out the group of 4 pins. How could this happen??<p>jay
nmitech
08-03-00, 01:05 PM
Sound to me that you own a NMIX/T-0020 or NMIY-0020. If so then PortE bit 3 - 7 are using to read keypad data. Normally these 5 bits are pulled low by the keypad driver chip, 74C923. If your application does not require the keypad; all you have to do is removed the 74C923 chip to recover all 8-bit of portE for inputs.<br>
JRobertson
08-03-00, 02:06 PM
Thanks for the reply, but I'm using a NMIS-1022 board.<p>I'm using port E, the analog/digital input pins.
MLCarter
09-03-00, 06:58 PM
Hello, not related to your discussion but .. I can get a/d to work fine from 4th on a nmix 0020 board but I'm attempting to get faster readings using a machine code sub as follows :<p>I got it to go myself, the code below works<br>It would have been nice to use the Y register and BRCLR but I can not get any of the ,Y commands to work.<br>HEX<br>: IS CONSTANT ;<p>B030 IS ADCTL<br>B031 IS DATA1<br>B032 IS DATA2<br>B033 IS DATA3<br>B034 IS DATA4<p>1002 IS CHNL<br>1 CHNL C!<p>CODE-SUB ADA<br>CE C, 1003 , ( LDX $1003<br>B6 C, CHNL , ( LDAA the channel<br>B7 C, ADCTL , ( STAA @ ADCTL<br>B6 C, ADCTL , ( LDAA ADCTL<br>85 C, 80 C, ( BIT TEST #80<br>26 C, 2 C, (BNE branch 2 locs forward when bit 7 sets<br>20 C, F7 C, ( BRA go back 9 locs<br>( 26 C, F9 C, ( BNE branch -7 locs until bit 7 sets<br>08 C, ( INCX increment X<br>B6 C, DATA2 , ( LDAA a/d data2<br>A7 C, 00 C, ( STAA,X store @ X<br>8C C, 1020 , ( CPX do upto #1020<br>26 C, E6 C, ( BNE back 26 locs<br>39 C, ( RTS return from sub<br>END-CODE<p>The idea is to take a series of readings and put into RAM from $1004 by increamenting X. The result I get is the previous value in DATA2 written repeatedly in the RAM loc's $1004 to $1020 <br>Can someone see the problem ?<br>Thank You<p>
What Y-indexed instructions do you want to use? I haven't had any trouble along those lines; would you like to see some code that works for me? The Y register is the data stack pointer, and needs to be preserved. Could that be your trouble?<p>On an '0020, isn't $1002 RAM? Your "1002 IS CHNL" puzzles me.<p>Jerry<p>----------<br>Engineering is the art of making what you want from things you can get.<br>
MLCarter
09-07-00, 07:18 PM
Hello JYA,<br> I just store the channel(CHNL) in RAM so as part of a larger program can be easily changed.<br>I can not get any ,Y instructions to work. In this case I wanted to use BRCLR,Y to check when the A/D conversion is complete. <br>I see the Y instructions have 2 byte machine codes, is this part of the problem. A bit of<br>sample code would be great, <br>Thank You Mark.
Hello, ML.<p>The Y register serves as the data stack pointer, and must be preserved. That is, you can use it any way you like, provided you first save it, and then restore it. X is a free register for most purposes; you can alter it at will and Forth doesn't care. If you could save Y into X, you could just as well use X instead, so my code assumes that you can't. I also assume you want to test the two least-significant bits.<p>...<br>183C , ( PSHY ; could also be 18 C, 3C C,<br>( Somehow load Y with address to be tested.<br>181F , 0300 , ( BRCLR Y,3,0 ; could also be 18 C, 1F C, 03 C, 00 C,<br>...<br>1838 , ( PULY ; could also be 18 C, 38 C,<br>...<br>END-CODE<p>The code above would apply to the X register if '18' is omitted everywhere. That is,<br>1F C, 0300 , ( BRCLR X,3,0 . <br>However, as I wrote before, there is no need to save and restore X.<p>BRCLR Y takes 9 clocks; PUSHY and PULY together take 11 more. LDY immediate will bring the total to 24. The way you do it now may actually be faster. Randy Dumse wrote a nifty cycle timer that I use (in addition to one I wrote for myself). Let me know if you want copies.<p>Jerry<p>----------<br>Engineering is the art of making what you want from things you can get.<p><br>
MLCarter
09-10-00, 12:51 AM
Hi Jerry,<br> yes I see my mistake with the Y register and the stack pointer.<br>Yes I would like to have a copy of your cycle timer if thats OK<br>Thanks, Mark
Mark,<p>This is a word to always output in decimal, no matter what BASE is when I run the timer:<br>: U.D ( u -- ) BASE @ >R DECIMAL U. R> BASE ! ;<p>This is Randy Dumse's timer, with U.D instead of U. To time a single word (say, DUP), make sure that there's something on the stack, write TT DUP <enter>, and see '54 cycles'.<br>: TT ' CFA B00E @ 6 ! EXECUTE B00E @ 6 @ - 117 - U.D ." cycles " ;<p>These words let you time a word or group of words inside of a definition. Use them this way:<br>: MYWORD BLAH BLEH start FOO BAR mark POOH ;<br>Later, type .c and see the cycle count for FOO and BAR, but nothing else.<br>: start B00E @ 6 ! ;<br>: mark B00E @ 6 @ - 147 - 6 ! ;<br>: .c 6 @ U.D ." cycles " ;<p><br>Location 6-7 is a user variable in page zero reserved, but not used. <p>Enjoy.<p>Jerry<p>----------<br>Engineering is the art of making what you want from things you can get.<p>
vBulletin v3.0.7, Copyright ©2000-2012, Jelsoft Enterprises Ltd.