Petscii Forums "PETSCII.COM"
« New Project--interfacing 2D, 3D controllers »

Welcome Guest. Please Login or Register.
Nov 20, 2009, 9:58pm




Petscii Forums "PETSCII.COM" :: General :: DTVHacking :: New Project--interfacing 2D, 3D controllers
Page 1 of 4 » Jump to page   Go    [Search This Thread][Send Topic To Friend] [Print]
 AuthorTopic: New Project--interfacing 2D, 3D controllers (Read 2,940 times)
gmoon
Wizard's Apprentice
*****
member is offline

[avatar]


[homepage]

Joined: Mar 2006
Gender: Male
Posts: 876
Location: Ohio, USA
 New Project--interfacing 2D, 3D controllers
« Thread Started on Jun 13, 2006, 7:52am »

Been working on a new project, interfacing an AVR micro to the Hummer.

http://home.earthlink.net/~dgdtv/cavr.html

I've successfully read analog joysticks and a 3D accelerometer with this hardware. The micro is cheap--an ATmega8L. The protocol uses three lines for data, so it's pretty fast.

As soon as I can borrow a digital camera with movie capabilites, I'll post some clips.
Link to Post - Back to Top  IP: Logged
David Murray
Moderator
*****
member is offline

[avatar]


[homepage]

Joined: Dec 2004
Gender: Male
Posts: 1,561
Location: Kennedale, TX
 Re: New Project--interfacing 2D, 3D controllers
« Reply #1 on Jun 13, 2006, 8:21am »

Hey.. Great job on the website. Those are some great pictures too, and I know how hard it is to get clear pictures of that kind of thing.

I will be making use of your project eventually. I need to order one of those AVRs.. but I want the bigger one with more inputs. How hard would it be for me to program the AVR?
Link to Post - Back to Top  IP: Logged
gmoon
Wizard's Apprentice
*****
member is offline

[avatar]


[homepage]

Joined: Mar 2006
Gender: Male
Posts: 876
Location: Ohio, USA
 Re: New Project--interfacing 2D, 3D controllers
« Reply #2 on Jun 13, 2006, 11:19am »

Thanks--I have a few strobes (flash units), and rarely use all of them, so I just setup a monolight (1000 watt-seconds) on a lightstand and leave it there. I bounce that off the white ceiling and it floods my small workshop with light (we're talkin' f/14 or f/16 @ ISO 160.) Add a supplemental closeup lens (I don't do enough macro work to justify a macro lens) and you can do decent closeups. And with strobes there is never any blur from camera movement, so I don't need a tripod.

Unfortunately, good digital SLRs can't do video, they have a real focal-plane shutter and a mirror that needs to pop up when you take photos--standard stuff for SLRs. So you sacrifice video for resolution, control and a fast shutter...

Guido Socher's article is the best to start with AVRs (I did):

http://www.linuxfocus.org/English/November2004/article352.shtml

It's very Linux oriented (and from your avatar I assume you're good with that.) I don't use his live-cd, I just installed the programs in Debian (then eventually moved to Ubuntu--Guido's version of avr-libc is getting a little old.)

But Atmel also has a freeware programming suite for Windows called "AVR Studio 4" and that integrates directly with avrgcc and avr-libc (but in Windows they are called 'WinAVR' instead of avrgcc.) It also has a good graphical simulator which Linux lacks.

There is, of course, a learning curve. First, you're hitting the hardward directly--something c64 programmers love, but modern 'C' programmers don't do much anymore. And there are several macros for setting/unsetting bits, etc. They actually take a little getting use to.

You need a way to transfer code to the AVR. I use the DAPA cable Guido describes in his article. It's very simple. The transfer prog is 'uisp'. The Windows suites use 'avrdude', which would also work under Linux. You just need to be sure that uisp or avrdude know which cable you're using.

One more thing--if you're planning on using an ATmega16, do what I did--order a couple ATmega8L chips. At $3.66 a pop (digikey), you'll be happier when you 'brick' one of those in the beginning, rather than the 16L ($6.56.)

Actually, it's probably not bricked, I think I just set the fuses wrong and it needs an external xtal....
Link to Post - Back to Top  IP: Logged
David Murray
Moderator
*****
member is offline

[avatar]


[homepage]

Joined: Dec 2004
Gender: Male
Posts: 1,561
Location: Kennedale, TX
 Re: New Project--interfacing 2D, 3D controllers
« Reply #3 on Jun 13, 2006, 3:29pm »


Quote:
It's very Linux oriented (and from your avatar I assume you're good with that.)


Actually, I used to be really into Linux for like 8 years. But when my daughter was born a little over 3 years ago I found I had less and less time for the things I used to do. So I started figuring out which things I was going to keep playing with and which things I wasn't. I decided Linux was going to be one I'd sacrifice. We always need Windows computers around the house. At the time I had about 20 computers around the house and after the baby it was reduced to 3. I kept Linux on my server (1 of those 3) for another year. But everytime I needed to update something I found it was taking longer and more work because i hadn't kept up with the scene and had to spend time figuring things out. So I eventually switched it to Windows also. So any AVR work I do would be under Windows.
Link to Post - Back to Top  IP: Logged
gmoon
Wizard's Apprentice
*****
member is offline

[avatar]


[homepage]

Joined: Mar 2006
Gender: Male
Posts: 876
Location: Ohio, USA
 Re: New Project--interfacing 2D, 3D controllers
« Reply #4 on Jun 14, 2006, 6:27am »

Well, I've had AVR Studio 4 and WinAVR installed (Windows) for several months, but hadn't touched them until yesterday.

When you create a new project, you get the choice of assembler or AVR GCC. I copied-and-pasted the source file in the new AVR GCC project--it compiled with only one warning, that the location of one include file had changed (WinAVR avr-libc is newer than avr-libc in Debian stable.) So any changes to the source were trivial.

There is more to it than that, as you still need to configure the ISP cable, set fuses, etc. But it would appear that using avr-gcc on Windows is easy.
Link to Post - Back to Top  IP: Logged
gmoon
Wizard's Apprentice
*****
member is offline

[avatar]


[homepage]

Joined: Mar 2006
Gender: Male
Posts: 876
Location: Ohio, USA
 Re: New Project--interfacing 2D, 3D controllers
« Reply #5 on Jun 14, 2006, 7:04am »

Video clips added of accelerometer and analog joystick:

http://home.earthlink.net/~dgdtv/cavr.html

(kind of crude, I borrowed the camera :) )

The accelerometer video is only a 2-axis demo, not all 3. But that's enough to emulate a joystick.
Link to Post - Back to Top  IP: Logged
pyrofer
Senior Member
****
member is offline





Joined: Jul 2005
Gender: Male
Posts: 263
Location: London
 Re: New Project--interfacing 2D, 3D controllers
« Reply #6 on Jun 14, 2006, 8:29am »

Thats so cool, do you have details on the accelerometer you used?
Link to Post - Back to Top  IP: Logged

Please visit my Project site at,
www.pyrofersprojects.com
David Murray
Moderator
*****
member is offline

[avatar]


[homepage]

Joined: Dec 2004
Gender: Male
Posts: 1,561
Location: Kennedale, TX
 Re: New Project--interfacing 2D, 3D controllers
« Reply #7 on Jun 14, 2006, 10:24am »


Quote:
(kind of crude, I borrowed the camera )


Yeah.. Since the framerate is so slow, it would have been better if you had moved the joystick slower, so we could see the smoothness (assuming it is smooth)

Still. Very good. I hope to make use of your work soon. I'm spending a little time re-doing some of my website for the new domain. But next on my list is to buy an AVR and see if I can get your code installed onto the AVR, and see if it will work for a multi-sensor input for me.
Link to Post - Back to Top  IP: Logged
gmoon
Wizard's Apprentice
*****
member is offline

[avatar]


[homepage]

Joined: Mar 2006
Gender: Male
Posts: 876
Location: Ohio, USA
 Re: New Project--interfacing 2D, 3D controllers
« Reply #8 on Jun 14, 2006, 11:01am »


Quote:
Thats so cool, do you have details on the accelerometer you used?


Thanks--there's a link to some info right below the video links, but here's a bit more... :)

It's an Analog Devices ADXL300, +/- 3g. Produces an output voltage proportional to the g-force applied on each axis (three outputs, coupled to three ADC pins on the AVR.)

One reason I chose the ADXL300 is it's 3.3v (as are both the DTV and the ATmega8L) and that simplifies interfaceing w/the other devices.

Specifically, I bought it on a breakout board:

http://www.sparkfun.com/commerce/product_info.php?products_id=692

At $30 USD, it's not really cheap, but I have other accelerometer/AVR projects in the works. If you're more skilled at SMD soldering than me, you can buy just the accelerometer ($11) and the bare board ($5.)

One note about sparkfun.com -- the first board had a small problem, and they were VERY responsive about sending a replacement.

I was left with a very positive impression of that company, and I'll order from them again (I have no connection to sparkfun, other than having ordered from them before.) They don't charge much for shipping, either.


Quote:
Since the framerate is so slow, it would have been better if you had moved the joystick slower, so we could see the smoothness (assuming it is smooth)


Well, I wanted to return the camera quickly, so I shot it and moved on.

In realtime, it's pretty smooth considering it's a sensitive device and there's no attempt yet to filter the output. Of course there is some jitter, just like the Hummer's ADC (and just try to hold an accelerometer completely still! :D)

Whatever is causing that interference band across the screen also regularly increases the jitter on the ADC (at 3 or 4 second intervals)--there is some noise in my setup, but that could be my 15 yr old 5V power supply, or not enough decoupling caps on the AVR. That noise is present w/o the accelerometer.

I haven't tried yet to power the setup off the Hummer's power regulator, so there's a 5v reg (main power), 3.3v reg on the hummer, and another 3.3v reg for the AVR/accel. This needs to be simplifed, eventually.
Link to Post - Back to Top  IP: Logged
David Murray
Moderator
*****
member is offline

[avatar]


[homepage]

Joined: Dec 2004
Gender: Male
Posts: 1,561
Location: Kennedale, TX
 Re: New Project--interfacing 2D, 3D controllers
« Reply #9 on Jun 14, 2006, 12:47pm »

A few more questions..

So is your routine currently still BASIC?

Do all ATMega8 chips have the ability to be programmed via two wires, or do only certain ones (For example, the PicAxe is just a regular PIC with a built-in program for receiving new code)

Are there any very affordable kits which include the needed cable, or am I better off building the cable myself? And do you have any links to a diagram of the cable?

Are you using any standardized protocol, or is it one you invented? I know you said it uses 3 bits (and 5 wires) How hard would it be for somebody like me to recode the thing to work off of 3 wires? (1-bit serial)
Link to Post - Back to Top  IP: Logged
gmoon
Wizard's Apprentice
*****
member is offline

[avatar]


[homepage]

Joined: Mar 2006
Gender: Male
Posts: 876
Location: Ohio, USA
 Re: New Project--interfacing 2D, 3D controllers
« Reply #10 on Jun 14, 2006, 3:35pm »

Duuude, you need to ask some easier questions (or I need to give briefer answers--this is a marathon post.) Good thing I'm running some batch files and I can revisit this on and off this afternoon...

1) Protocol's been converted to ML. The alpha source/target code is on the site. For more, see #4 below.


2) The AVR ISP (in-system programmer) spec requires 4 lines--but if you're careful, you can still use 3 of those for I/O (not RESET, tho.) Those lines shouldn't be jumping up/down right after a cold start.

All ISP-capable AVRs work with ISP cables/programmers without modification. But they can all be modified by power-users to operate via user-defined "bootloaders"-- difficult and unnecessary for must of us (i.e., you could create your own 'AVRaxe' if you were a god of microprogramming..) Some bootloaders let you prog via a 2-line serial cable.


3) Here's some cable info (REMEMBER--I don't do this in Windows, so I can't give first-hand advice):

If you buy one, make sure it's an ISP cable (there are others.) I've seen ISP cables online for $10-15. Might be a good bet. One type is called an "Atmel ISP Dongle."

NOTE: I didn't think the DAPA cable was usable in Windows/avrdude. But this may be incorrect, as Guido's site has avrdude instructions (and this explicity says it works in Windows):
http://shop.tuxgraphics.org/electronic/dapa.html?id=9fbab5
Link in previous post has article w/cable details (in table)

DAPA cable (different resistor values than Guidos, same otherwise):
http://www.ncfreak.com/cecilia/data/dapa.pdf

Good overview of other DIY cables that work with AVR Studio:
http://elm-chan.org/works/avrx/report_e.html

2 or 3 cable designs that work with Windows AVR Studio/AVRdude:

Graphic of buffered and unbuffered (do you feel lucky?) STK200 ISP dongles:
http://elm-chan.org/works/avrx/stk200.png

SP12 cable:
http://www.xs4all.nl/~sbolt/e-spider_prog.html

avrdude info and simple cable:
http://www.bsdhome.com/avrdude/



You could also consider running the whole shebang off of a Linux Live-CD, like what Guido offers--you wouldn't need an extra computer and you wouldn't need to reformat to Linux. Then the DAPA cable, Makefiles, etc. would all work, fersher.



4) Protocol doesn't follow any other standard, other than avoiding any absolute speed or timing references (the master can dictate whatever speed it wants.)

There really isn't any handshaking, but I've let my demos run for 2-3 hours without any sync loss. And handshaking could be added like other open-collector protocols (I2C, for instance) where the master releases the clock signal, then checks if the slave is holding it low.

This works because an open-collector 'HI' signal is basically ALL the devices on that line set to input (the line floats and a pull-up resistor pulls it 'HI'.) So the master can simultaneously float the line, and watch it at the same time to see if it actually does 'go HI'. If one device is holding clock 'LO', the master knows somebody isn't ready.

But that's not implemented, yet. And I was hoping this protocol would work on a stock c64, and I'm not certain the c64 userport is strictly open-collector.

I'm sure this can be adapted to any # of data lines you want. I don't think it would be too difficult, but then I wouldn't (since I've already done it, right?) ;)

For that initial development, BASIC turned out to be much more useful than I had expected. Since there's no timing reference, once the BASIC version worked it could be complied (austro-speed) and checked again for sync problems. By then I knew it had some 'robustness', and I could move on to ML.
« Last Edit: Jun 14, 2006, 3:51pm by gmoon »Link to Post - Back to Top  IP: Logged
David Murray
Moderator
*****
member is offline

[avatar]


[homepage]

Joined: Dec 2004
Gender: Male
Posts: 1,561
Location: Kennedale, TX
 Re: New Project--interfacing 2D, 3D controllers
« Reply #11 on Jun 14, 2006, 4:30pm »

I'm trying to decide between various different ways of expanding the I/O capabilities of the DTV. Actually, it has plenty of I/O for most uses. It is the fact that I need several analog inputs that constricts me. The AVR would give me that ability, and you've already done the work of making a communications protocol that works. However, using your method would require me to learn how to hook an AVR up to my PC and program it, possibily rewriting some of the code. But would have the advantage that I could use what I learned in future projects and also give me the ability to update my shuttlecraft's firmware in the future to do new things.

If I go with an off the shelf ADC, I would not need to program it, but I would have to master its communication protocols to make it work on the DTV.

So there really isn't an easy road for me. The AVR sounds like the best bet. Besides, as I already said.. once I learn to program one, the possibilities are endless as to what I could make with them.

It actually occurred to me you could make a small computer out of a couple of microcontrollers. A small one could create an NTSC video output (I've seen this done before) and the other could be the brain of the system reading input from PS/2 keyboard and mouse. The only real limitation is RAM. With most of the microcontrollers I see you wouldn't be able to surpase the processing power of a Vic-20.
Link to Post - Back to Top  IP: Logged
gmoon
Wizard's Apprentice
*****
member is offline

[avatar]


[homepage]

Joined: Mar 2006
Gender: Male
Posts: 876
Location: Ohio, USA
 Re: New Project--interfacing 2D, 3D controllers
« Reply #12 on Jun 14, 2006, 5:49pm »


Quote:
If I go with an off the shelf ADC, I would not need to program it, but I would have to master its communication protocols to make it work on the DTV.


Yeah, if someone else engineers it, at least that's one step you can skip. And it's twice as much work to design both sides of a protocol. But challenges are fun. :)


Quote:
So there really isn't an easy road for me. The AVR sounds like the best bet. Besides, as I already said.. once I learn to program one, the possibilities are endless as to what I could make with them.


Well, I like 'em so far. Those PICaxes are cool, but don't have the speed for low-level programming like this project (at least from a realtime-controller perspective.)

And I'd rather use 'C' than BASIC any day (plus it's easy to mix assembler in if you need to.) I'm already comfortable with the GCC way of doing things.


Quote:
The only real limitation is RAM. With most of the microcontrollers I see you wouldn't be able to surpase the processing power of a Vic-20.


If you haven't checked out avrfreaks.net, do so. There are AVRs coming soon that will have 8K of RAM and 256K of Flash. (OK, they won't be cheap...) But the power of these (and other uC, too) is amazing.

But seriously: Total size of the object code generated by avrgcc for the cAVR64 protocol and code to support the ADC reads, etc:

620 bytes. Out of 8K available. Sweet.
Link to Post - Back to Top  IP: Logged
jsaily
Full Member
***
member is offline





Joined: Feb 2006
Gender: Male
Posts: 221
Location: Finland
 Re: New Project--interfacing 2D, 3D controllers
« Reply #13 on Jun 19, 2006, 3:56am »

I think I need to stick my spoon into this soup also ;-)

One simple alternative for interfacing a DTV/Hummer to the outside world is the 1541-III device. It only needs a connection to the IEC-bus. If you look at Jan Derogee's website, this possibility is taken into account! The PIC source code can be easily modified to catch certain commands, execute the required tasks and return the data to C64. Also, RS-232/RS-485 connections are easily achieved this way.

For example, the PIC18LF2620 used in this project has 10 AD-channels , 4k SRAM and 64k flash-ROM.

Yeah, I prefer PICs over AVR... :-)
Link to Post - Back to Top  IP: Logged
gmoon
Wizard's Apprentice
*****
member is offline

[avatar]


[homepage]

Joined: Mar 2006
Gender: Male
Posts: 876
Location: Ohio, USA
 Re: New Project--interfacing 2D, 3D controllers
« Reply #14 on Jun 19, 2006, 6:11am »

This project should (I say should because it hasn't been benchmarked) be much faster than the IEC bus -- 3 data lines.

It could also easily be modified to use 4 data lines, like the original DTVLOAD routine (remember, the developers had a working IEC bus, but still added DTVLOAD.) Just use 4 bits of the userport for data, and substitute the CASSENCE line for overhead (CLK or ATTN.)

Any AVR ATmega device can utilize this code--32, 64, 128, etc. So don't fixate on the ablities/limitations of the ATmega8.

And to keep it simple (I knew other projects could do RS-232, etc.) use the internal oscillator (no crystal w/caps.)

Are you suggesting everyone should stop exploring other hacks and fun stuff to work on a single project?

Much prefer AVRs ;D
Link to Post - Back to Top  IP: Logged
Page 1 of 4 » Jump to page   Go    [Search This Thread][Send Topic To Friend] [Print]

Google
Webjledger.proboards.com
Click Here To Make This Board Ad-Free


This Board Hosted For FREE By ProBoards
Get Your Own Free Message Boards & Free Forums!