| Author | Topic: Hummer ADC read code--successful (Read 1,755 times) |
gmoon Wizard's Apprentice
     member is offline
![[avatar]](http://home.earthlink.net/~dgdtv/images/jaw.jpg)
Joined: Mar 2006 Gender: Male  Posts: 876 Location: Ohio, USA
|  | Hummer ADC read code--successful « Thread Started on Apr 27, 2006, 12:40pm » | |
I dusted off some old brain cells (and old 65xx books) and wrote a ML routine for reading the Hummer's ADC/Pot.
You can find it here:
http://home.earthlink.net/~dgdtv/
Thanks to those who identified the ADC correctly, as this wouldn't be possible without that knowledge.... 
You can use this routine from BASIC, instructions are on the page.
| |
|
David Murray Moderator
     member is offline
![[avatar]](http://galaxy22.dyndns.org/david-avatar.jpg)
Joined: Dec 2004 Gender: Male  Posts: 1,561 Location: Kennedale, TX
|  | Re: Hummer ADC read code--successful « Reply #1 on Apr 27, 2006, 4:58pm » | |
Hey, thats great. This is the first usefull piece of information that has been posted here in a while.
I wonder if it would be possible to use that ADC on multiple different sources. For example, use the lines from the user-port and do a scanning routine to sample several different sources.
Maybe the DTV could be a good temperature sensing device after all.
| |
|
gmoon Wizard's Apprentice
     member is offline
![[avatar]](http://home.earthlink.net/~dgdtv/images/jaw.jpg)
Joined: Mar 2006 Gender: Male  Posts: 876 Location: Ohio, USA
|  | Re: Hummer ADC read code--successful « Reply #2 on Apr 27, 2006, 6:04pm » | |
One thing that comes to mind is something like a cmos 4066--the quad bilateral switch. These work with analog or digital signals, and you can switch in and out the voltages you need to sample with the ADC.
I think there are several similar chips which should work well with 5V (the DTV may be 3.3v, but the userport's designed to interface with TTL), if cmos does not. Use another userport line, maybe w/one of your shift registers to control the switch bank.
Durn shame the other 7 channels on the ADC aren't broken out...But that's the same old DTV refrain--why complain about what's missing on a $20 toy that does so much?
| |
|
David Murray Moderator
     member is offline
![[avatar]](http://galaxy22.dyndns.org/david-avatar.jpg)
Joined: Dec 2004 Gender: Male  Posts: 1,561 Location: Kennedale, TX
|  | Re: Hummer ADC read code--successful « Reply #3 on Apr 27, 2006, 8:24pm » | |
Hey.. even better, I didn't even realize it was an 8-channel ADC. Hmmm.. well, we know what the chip is. If you already have code that works, and it is 8-channels. I could just try to find the chip in DIP packaging and hook it to my user-port. (after all, I already cut the traces on mine, except for one unit that is still in the hummer game case)
But back to the user-port for a moment. I imagine the ADC runs at 3.3V right? I think you could hook the user-port as the ground and the ADC to the positive (so to speak) and you could theoretically sample 8 devices in this manner. I don't think any extra circuitry would be needed. I've heard of this being done with the built-in POT lines on the C64 using the user port. So it should be do-able here.
But still.. if that chip can sample 8 sources, that is plenty for me and it would only use 3 user-port lines.. May have to go hunt one of these things down. I still haven't tried your code yet.. Need to do that soon. maybe tonight.
| |
|
David Murray Moderator
     member is offline
![[avatar]](http://galaxy22.dyndns.org/david-avatar.jpg)
Joined: Dec 2004 Gender: Male  Posts: 1,561 Location: Kennedale, TX
|  | Re: Hummer ADC read code--successful « Reply #4 on Apr 27, 2006, 8:44pm » | |
Oh.. one more thing.. I plagerized your website and added all the relevant information on mine. Hope you don't mind. I added 2 links to your site, though.
| |
|
gmoon Wizard's Apprentice
     member is offline
![[avatar]](http://home.earthlink.net/~dgdtv/images/jaw.jpg)
Joined: Mar 2006 Gender: Male  Posts: 876 Location: Ohio, USA
|  | Re: Hummer ADC read code--successful « Reply #5 on Apr 27, 2006, 9:34pm » | |
No problem. And thanks for the credit...
Good idea about connecting an external ADC to the same userport lines and getting the extra channels. Be much less involved than switching inputs on the existing ADC.
For power you'd connect the ADC to the +3.3V and the board gnd. The same three userport lines (2-0) could be used for IO. There would be other connections, too--like a voltage reference for the ADC--you'd connect that to the +3.3v, or use a couple resistors to set the voltage you want. All 8 channels would be read from the same three lines. The read routine would need to accomodate the extra channels, but it did that originally, anyway--didn't know what channel the Hummer used. It would be easy to change it back.
I wonder how much harder it would be to implement TWI (I2C) or SPI serial on the DTV? That would open up using the userport with a host of microcontrollers....
| |
|
David Murray Moderator
     member is offline
![[avatar]](http://galaxy22.dyndns.org/david-avatar.jpg)
Joined: Dec 2004 Gender: Male  Posts: 1,561 Location: Kennedale, TX
|  | Re: Hummer ADC read code--successful « Reply #6 on Apr 27, 2006, 9:59pm » | |
Yeah, we've been discussing some of that very topic over on uHacking on this same board. That was actually my current plan up until an hour ago when I read that post. I was planning on using a PicAxe with 4 ADC's attached. Then communicating with the hummer via user-port. However, this new idea seems simpler, faster, and more cost-effective.
I looked over your code. I did not realize that you were reading all 8 channels at one point, but I could see the line:
Code:| adccmd = %00000001 ; includes channel # (6 bits total) |
|
And I figured that is what that was for.. But it could use some more documentation.. when you say includes the channel#, what else do those 8 bits signify? What channel are you currently reading?
| |
|
David Murray Moderator
     member is offline
![[avatar]](http://galaxy22.dyndns.org/david-avatar.jpg)
Joined: Dec 2004 Gender: Male  Posts: 1,561 Location: Kennedale, TX
|  | Re: Hummer ADC read code--successful « Reply #7 on Apr 27, 2006, 10:08pm » | |
Oh one more thing...
I just tried it on my unmodified hummer (well, slightly modified)
It works, but it doesn't work. Or maybe I don't understand it completely.
When I run the program it reads 255 constantly. If I turn the steering wheel to the left, it counts down to zero when I turn it all the way. But when I turn it to the right, it stays at 255.
I have 2 theories for this.
Theory 1: Maybe the ADC needs some kind of sensitivity variable programmed into it on initilization?
Theory 2: Maybe they used a different channel on the ADC for each direction of the wheel?
| |
|
gmoon Wizard's Apprentice
     member is offline
![[avatar]](http://home.earthlink.net/~dgdtv/images/jaw.jpg)
Joined: Mar 2006 Gender: Male  Posts: 876 Location: Ohio, USA
|  | Re: Hummer ADC read code--successful « Reply #8 on Apr 27, 2006, 10:28pm » | |
Looking at the timing diagram, an ADC READ cmd is (after all the START and CLOCK, etc.):
Three bits: 100 (all the cmds are three bits) followed by a three bit channel number: 000 (chan #0)
So these 6 bits need to be sent to the ADC: 100000
Since DIO is userport bit 0, the easiest way to do this is to store the bits in memory or a register, and then shift them, left-to-right. This means they are stored backwards-- %00000001 is:
two unused bits (00) the channel # (000) the ADCcmd (001)
After each write, the byte is LSRed (logical shift right--I don't want a carry bit added [not that it would matter in this case]) and the next bit is now in position at bit 0.
So it's essentially a queue--after the first bit leaves the queue, it looks like: 00000000. An empty bit was placed in bit 7 by the LSR.
The data is held in memory rather than the Y Reg because the routines originally included a delay loop--Y was the delay counter and X was the # of bits to send.
So the channel # is now hard-coded into the routine. I just need to define a memory location you can POKE before calling. This was the original way I set it up--but it worked correctly the first time! I never needed to change the channel.
I see your bug report, I get to that separately...
| |
|
gmoon Wizard's Apprentice
     member is offline
![[avatar]](http://home.earthlink.net/~dgdtv/images/jaw.jpg)
Joined: Mar 2006 Gender: Male  Posts: 876 Location: Ohio, USA
|  | Re: Hummer ADC read code--successful « Reply #9 on Apr 27, 2006, 10:39pm » | |
Quote:| When I run the program it reads 255 constantly. If I turn the steering wheel to the left, it counts down to zero when I turn it all the way. But when I turn it to the right, it stays at 255. |
|
Hmmm...
A couple things: I still haven't flashed my kernal (I've been looking at the source for the save bug--I'd like to save as much of the original Hummer code as possible.)
So I only tested the code with the bad DTVLOAD timing. But it seems to read the ADC just like the 'TEST' program.
But wait--you're using a stock kernal, aren't you--same as me.
Could you check and make sure the pot handle wasn't turned halfway when you reassembled the beast?
Hopefully we can get feedback from other Hummers, too.
| |
|
David Murray Moderator
     member is offline
![[avatar]](http://galaxy22.dyndns.org/david-avatar.jpg)
Joined: Dec 2004 Gender: Male  Posts: 1,561 Location: Kennedale, TX
|  | Re: Hummer ADC read code--successful « Reply #10 on Apr 27, 2006, 10:48pm » | |
No, the POT is aligned correctly because I can still play the hummer game, and their test program works.
So what does it do on your unit?
| |
|
gmoon Wizard's Apprentice
     member is offline
![[avatar]](http://home.earthlink.net/~dgdtv/images/jaw.jpg)
Joined: Mar 2006 Gender: Male  Posts: 876 Location: Ohio, USA
|  | Re: Hummer ADC read code--successful « Reply #11 on Apr 27, 2006, 11:07pm » | |
I get the full 8-bit range of values, but they top-out (and bottom-out) before the full pot rotation. So probably about 10 degrees on the low end reads 0 and 15 degrees on the high end reads 255. But these seem to be the same readings I get from the TEST prog (a little hard to compare without the steering wheel as a reference.)
Since it's pretty much centered on mine, I assumed that was normal behavior--I've tested pots with game ports before, and they all needed to be calibrated. That, and the fact that the Hummer game doesn't seem to need even a fraction of that.
Well, it was too good to be true that this worked right the first time (I haven't used assembly lang in years.)
I'd be more comfortable if our results were the same (even if they were bad)--it's disconcerning that two hummers with minimal mods give such different results.
First thing I'm going to do is check the output, and make sure I'm getting a full range of even & odd numbers--if I'm not then the data's getting shifted too far.
--added--
When I get a chance later today, I'll reinsert the delay loop--if the READ happens too early, there's a chance that the first bit is always set. That would be effectively throwing away half of the resolution.
Don't know why our machines respond differently, but it could be variations in the ADC itself....
| |
|
gmoon Wizard's Apprentice
     member is offline
![[avatar]](http://home.earthlink.net/~dgdtv/images/jaw.jpg)
Joined: Mar 2006 Gender: Male  Posts: 876 Location: Ohio, USA
|  | Re: Hummer ADC read code--successful « Reply #12 on Apr 28, 2006, 11:09am » | |
I can verify that at least on my Hummer it functions exactly as the TEST prog. Indeed, it's working at near ideal levels.
At close inspection, the Hummer steering wheel only travels 180 degrees--hence the fact that the ADC readings only cover 180 degrees.
![[image]](http://home.earthlink.net/~dgdtv/images/potrange.gif)
And after rebooting and running TEST, the hex values were identical to the output I was getting from the routine. I.E., if I left the pot in place reading '8', when I rebooted and ran TEST, it still showed '8'. (which is comforting, since I didn't know if the ADC bits were sent in reverse order.)
So I'm getting a full 8-bit range of odd and even values, right up to the limits of the 180 degree range.
Now, we need a more forgiving routine that works on all Hummers. Anyone else with a Hummer try this?
(David--I'll have another test routine for you this evening. At some point, you could compare the routine output with the TEST output--that would be helpful.)
| |
|
gmoon Wizard's Apprentice
     member is offline
![[avatar]](http://home.earthlink.net/~dgdtv/images/jaw.jpg)
Joined: Mar 2006 Gender: Male  Posts: 876 Location: Ohio, USA
|  | Re: Hummer ADC read code--successful « Reply #13 on Apr 28, 2006, 4:13pm » | |
David, try this one:
http://home.earthlink.net/~dgdtv/dtv/adc/ADCV12.PRG
I've included the timing loops, which might slow it down enough to make it work with all the Hummers.
Also, you can change some constants (each is one byte) by a poke in the following memory locations:
49290 -- channel # -- (0-7) 49291 -- general delay count (default= 4 -- delay for each 1/2 of CLOCK cycle) 49292 -- delay-after-START count (default= 8 -- delay before clock starts)
The counts are count indexes, and will count down for the delay (DON'T set them to 0 unless you want a LONG delay, as they are decremented before each test--a zero byte will rollover to a 255--I.E., 0 is the MAX delay amount.)
No other channel than 0 works--you'll get differing output, but not the POT values (don't set it to 8, 'cause that's just %1000--or zero.)
| |
|
David Murray Moderator
     member is offline
![[avatar]](http://galaxy22.dyndns.org/david-avatar.jpg)
Joined: Dec 2004 Gender: Male  Posts: 1,561 Location: Kennedale, TX
|  | Re: Hummer ADC read code--successful « Reply #14 on Apr 28, 2006, 5:39pm » | |
NEW INFORMATION - this should help
I experimented some more with the same program I tried last night. I went into the hummer test program and found that it worked perfectly, from $00 on the left to $FE on the far right. I tried your program again and got the same results as yesterday. In fact, paying more attention I realized that only a 45 degree angle is represented. The far left is 00 (using your program) and about 45 degrees to the left is 255. So 25% of the total movement is represented, the other 75% shows 255.
Next thing I tried.. Instead of turning the power off (as I usually do) I just hit the reset button when comming out of the hummer test program, then ran your program. Now it works fine. Reads 0 on the far left, 255 on the far right.
My theory is that the ADC needs some kind of initialization to set some kind of sensitivity or something like that.
Just for kicks, I'll try your new version later when I get home from the movies (or tommorow morning) You might try it on yours with using the reset and/or powering on/off and see what happens.
| |
| |
|