6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Mon Oct 07, 2024 3:26 am

All times are UTC




Post new topic Reply to topic  [ 27 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Wed May 09, 2007 11:35 pm 
Offline

Joined: Mon Apr 16, 2007 6:04 am
Posts: 155
Location: Auckland, New Zealand
Hi, I have been lurking for a little while and reading a load of very interesting posts. It encouraged me to start my own project which I need to explain somewhat I think. Excuse the rambling description - this does take some explaining!

Basically I am on a Bender. As in the robot kind. From Futurama. I am building a full sized Bender robot with a beer brewing barrel inside him. That was simple enough but never being content with nice, easy projects I decided it would be cool to make him talk. I decided it would be even cooler and in keeping with a joke on the show if Benders 'brain' was 6502 based.

I have built a small circuit which is basically a binary counter hooked into some ROM chips programmed with audio samples. I am using 27c2001/27c020s. The counter counts up through the ROMs address lines clocking out the data which is then fed into a latch and finally a 8 bit R2R D to A. All very crude but actually fairly effective. I built the circuit such that I can test it seperately with a 555 providing clock pulses. This works now and I can play audio from the chip.

The next step is making all this micro controlled. I could make a 6502 SBC from scratch to drive it but as I have a 1541 disk drive here (that someone gave me over 10 years ago) I decided to hack that instead to see if the idea will work. What I have done is make an adaptor that plugs in where the 6522 VIA that controls the drive mechanism goes (UC2 which is at 1C00h). This adaptor allows through all the pins except all the port A and B pins and the CA1/2 CB1/2 pins. Those are then broken out and wired through to my circuit.

My idea is to reprogram the 1541 ROM and control the VIA to drive my circuit. I use the VIAs onboard timer to generate the clock signal I need to clock my audio circuit (at 16khz). I use 4 bits on one of the ports to drive the top four address bits of each of my memory chips. Using 4 bits this way means I can access the audio in one second blocks. I use the other four bits to do chip selection of each of my audio ROM chips. Clocking audio at at 16kHz allows me 16 seconds of audio per chip and I can have up to 10 chips (using a 1 into 10 decoder for the chip select).

I was going to get clever and have lookup tables in the audio chips so I could read them to see what samples there were and where but as the audio ROM isn't hooked to the data bus (only the latch) I decided against that. I will just hardcode the starting addresses of the samples into the controlling program. Once I get the thing working I can't see wanting to change the samples anyway.

I am currently trying to get a simple program running on the hacked drive board just to get my head around 6502 programming and to see if I can setp the VIA how I need it. I am using 27c64 ROMS in place of the drives 2364 using a pin adaptor. There may be something odd about these ROMS. They are a Fujitsu part and need a 21v programming level. They might be a 6 volt part and that may be causing my problems. I did also use one of the 27c2001s though (ignoring the upper address pins) as a test and get the same results.

Basically I have written a little program that should simply loop around setting and resetting the VIA port pins. I have a small handheld scope that is good enough to show me pins wiggling up and down (but not much more). What seems to be happening is my code is running I think. I can see the address lines on the ROM changing and also see the data being switched out. I have no way to telling what the data is of course, just that it is there. When I look at the 1-10 chip select on the 1541 though it isn't selecting the VIA at all. Only the output for number 1 is changing. I expect to see the CS2 chip select pins on the VIA toggling but I don't.

I am new to 6502 coding although I have played with PICs in the past (in fact I have made the same circuit before using a PIC as the controller and that worked fine). I am using the Kowalski 6502 simulator/assembler to write and test the code. In the simulator it works fine. I can see the memory at 1C00h and 1C01h toggle.

If I am understanding the 1541 circuit and disassembly correctly the ROM chip I am replacing is at address E000h to FFFFh. This is UB4 on the board (closest to the heatsink). The VIA is UC2 and at address 1C00h.

I am not sure of my code so I have included it here. Once assembled I save it as a binary take the hex code and open it in Visual Studio. I remove all the blanks at the start (0000h to DFFFh) so the code starts at 0000h and the reset vector is at 1FFCh and I program this into my ROM chip. Once on the board everything should then match up fine (code starting at E000h and reset at FFFCh).

I can't understand why I am not seeing the VIA chip being selected. If the addresses are clocking through OK as they do on the simulator then the VIA ports should be alternating 1 and 0s. I am sure I have missed something blindingly obvious or am doing something silly which is why it isn't working. I just need someone to slap me on the head and point it out!

I may in the mean time start building a new board from scratch and just use the chips off the 1541 in that. Be a lot neater and smaller but using the 1541 is a good test for now.

Simon

Here is the code (formatting probably messed up posting it here):

rom_start = $E000
reset = $Fffc
via = $1c00
via_b = via + 0
via_a = via + 1
via_bdir = via + 2
via_adir = via + 3

.ORG rom_start

LDA #$FF ; Load acc with FFh
STA via_bdir ; Set port b all output
STA via_adir ; Set port a all output
loop
LDA #$AA ; Data
STA via_b ; Load data on port b
STA via_a ; Load data on port a
LDA #$55 ; Data
STA via_b ; Load data on port b
STA via_a ; Load data on port a
JMP loop


.ORG reset ; Reset vector
.WORD rom_start


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu May 10, 2007 3:32 pm 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
Are you positive the chip is actually being selected at the hardware level?

Also, you mention making an adapter that breaks out the 6502 bus interface of the old VIA socket. Are you sure that the signals arriving at the 6522 are clean and noise-free? Is each signal connected to the correct corresponding pin on the 6522?

The software looks impeccable -- the problem has to be hardware at this point.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu May 10, 2007 6:47 pm 
Offline

Joined: Mon Apr 16, 2007 6:04 am
Posts: 155
Location: Auckland, New Zealand
Damn! I was hoping someone would spot a nice, simple software bug or a problem with how I get it onto the ROM!

I have checked all the connection and they are wired to the correct places. As for them being reliable well, I have my doubts. Trying to plug daughter boards into IC sockets doesn't really work too well. I need a proper scope really to be able to see how noisy things are. At the 74LS42 chip select all I see is each of the input lines have data on them but only the 0 output ever goes low. So it is never even selecting the chip as far as I can see. I should test that chip perhaps. The other thing I should have mentioned is I have no way to test the drive itself. I am just assuming it works! When powered up the light comes on and the motor spins for a couple of seconds then stops. All the descriptions I have say that is correct. I never actually owned a C64. I went straight from Vic 20 to Apple 2s!

I am actually going to cannibalise the drive board for parts I think. Everything is socketed except the 2016 RAM which I will need to desolder carefully. I am going to build my own SBC with the parts using the same circuit as in the drive more or less with my own added clock circuit (that Harry the Bastard one) and my own reset circuit. It will be simple since it only has to do the one job. One 32k ROM, the 2016 RAM and one VIA. As I say the audio part of the circuit is built and tested and works well. I just need the logic signals to drive it! I could use a PIC easily of course but the whole purpose of this project is to use the 6502.

Will be getting the SBC parts today and construction will begin this weekend.

Simon


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat May 12, 2007 11:25 pm 
Offline

Joined: Mon Apr 16, 2007 6:04 am
Posts: 155
Location: Auckland, New Zealand
An update. I built a whole new board based on the 1541 circuit and fired that up. I was basically having the same result. The circuit seemed very unstable and eventually I traced that to not having a big enough cap on the power supply and sagging battery voltages. I switched to a plug in power supply but in a fit of stupidity (this was at 11pm after a day of solding all those damn wires) I plugged in my 20+ volt one instead of the 5 volt one. There was a small FIZZZZT! and everything died. Half the logic ships were bad and the rest are probably suspect. The 2016 RAM is definitely fried. I will have to work out getting some more somewhere (maybe from more old C64 drives) or ordering online. I am sure there is nowhere in NZ I can just go to get some. The processor seems OK oddly enough but the VIA is suspect. Actually I had my doubts about them to start off with! I have replaced all the logic and this time used LS instead of HC chips. The original board used LS of course. I thought you could substitute HC for LS but maybe I am wrong there. Hey, I'm a software engineer, not hardware :) Anyway, with all the small logic replaced it is working a bit better. I can see the chip select for the VIA toggling now. I really wish I had a decent scope or logic analyser! But the VIA pins aren't toggling I think. They may be but perhaps my silly handheld scope is stopping it? I shall try hooking a buffer and an LED up to it and slowing down the loop a lot.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun May 13, 2007 5:11 am 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
HC and LS logic are not generally interchangable except in all but the absolute simplest of circuits. Since you're working with NMOS parts from the early 80s, I recommend staying with LS logic. Use HC or AC components only on newer parts, like the 65C22 and 65C02 chips.

Sorry to hear about the overvoltage issues. I always build my logic circuits with a 7805-type regulator just to be safe. Although I now require at least 7V of input voltage (I usually use 9V to 12V), it ensures that I always have the right votlage on the parts. (If, at a later time, you see fit to upgrade to 1.8V or 3.3V logic, proper regulation becomes even more critical!)

What frequency does your handheld scope go up to? If you can see the _CS line of the VIA toggling, you should be able to see the PA or PB pin states too. Best case, PA/PB can never toggle more than thalf as fast as Phi2, so if you're running at 1MHz, and your scope can see a 500kHz signal, you should be able to see something, even if it's a distorted sine wave on the display.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun May 13, 2007 6:16 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8522
Location: Southern California
Quote:
I thought you could substitute HC for LS but maybe I am wrong there.
You can substitute it in many cases, but various things must be kept in mind to stay out of trouble. A couple of past topics you might be interested in are viewtopic.php?t=195 and viewtopic.php?p=909#909 . To get most directly to the point, a cut-and-paste of part of the latter is:
Quote:
Fairchild's applications note 319 at http://www.fairchildsemi.com/an/AN/AN-319.pdf compares the LS and HC logic families.
Ap. note 368 at http://www.fairchildsemi.com/an/AN/AN-368.pdf discusses HCT and TTL.
AN375 at http://www.fairchildsemi.com/an/AN/AN-375.pdf and AN377 at http://www.fairchildsemi.com/an/AN/AN-377.pdf may be helpful in matters of noise at the inputs and I/O levels.
AN314 at http://www.fairchildsemi.com/an/AN/AN-314.pdf also addresses interfacing between TTL and CMOS.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun May 13, 2007 6:33 am 
Offline

Joined: Mon Apr 16, 2007 6:04 am
Posts: 155
Location: Auckland, New Zealand
Thanks for the comments and the links guys. I will check them out now. The circuit is working much better with LS parts now although I am afraid it seems my 6522 VIA has gone to integrated circuit heaven too! Without the VIA in the circuit everything works as I would expect. I can see things toggling and the chip select working as I would expect. I will probably just order known good parts off the net and go from there.

The scope I am using is a little Velleman handheld. It is a 1Mhz thing but really it isn't that good. Enought to get some idea of what's happening. Better than nothing certainly!

As for the regulators I did have one in there but the supply I hooked up was over it's maximum voltage. I thought they had overvoltage protection built in but I guess not? If the couple of volt overhead needed to run them is a pain you can get the low dropout versions. LM2904 from memory? They only need a half volt or so overhead to regulate.

Simon


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jun 14, 2007 10:03 am 
Offline

Joined: Mon Apr 16, 2007 6:04 am
Posts: 155
Location: Auckland, New Zealand
Well, an update. I finally got my replacement ICs from the states so I could continue with this project and I also bought myself a simple dual channel scope which has proved incredibly useful so far. Basically I am stuck now. I just can't get this thing to work. Here is where I am at now.

I very carefully checked all the wiring again. This time not only making sure the pins were all connected to each other correctly but also making sure they weren't connecting where they shouldn't be. I found two shorts! Those are fixed now.

I made myself a little NOP ROM plugin and have been playing with that. I can use my scope to trigger on the A15 line and then monitor whats happening on the other lines in relation to that. As far as I can see everything is working fine. My circuit is based on the 1541 drive circuit with one 6522 VIA at 1800h. I can see this being selected fine (actually it gets selected 4 times per cycle due to the way the addressing is done). I can see it cycling up through the addresses nicely. And I can see the other chip selects toggling at what looks like the right times.

However when I put in my ROM (with the code above) and the other chips the behaviour is really odd. I can see something happening as in the address lines are toggling but the wrong chip select lines are selected. Also the signals don't look too clean to me. I am starting to wonder if there is something wrong with the actual ROMS I am using. They are used MBM27C64-30s. I think they are really old since they need a 21volt programming voltage. The do program and veryify fine so they are programmed correctly. But might it be that they aren't working correctly in my circuit for some reason?

Tomorrow I shall go get some different 27C64 ROMS and try them I guess. But is it possible the physical ROM chips I have could cause the problems I am seeing?

Simon


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jun 14, 2007 4:01 pm 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
The 1541 was designed without CMOS logic, IIRC, and unless you also replaced all intervening logic to use CMOS as well, this _might_ be a problem.

Steps I'd try, in the order I'd try them:

1) Program the EPROMs you have with all NOPs, with a JMP instruction at the end to prevent execution outside the ROM address range. If this doesn't work, then,

2) Program some new EPROMs with all NOPs + tail JMP instruction. If it does work, then there was something wrong with the old EPROM chips. Otherwise, if it still doesn't work, ...

3) Try to acquire a 2764 chip from around the same time period the 1541 was introduced (1979 to 1982 IIRC) and which isn't CMOS. As I recall, Commodore's products all used 23xx series ROMs, which are not EPROMs, but which may use a different kind of logic (NMOS perhaps).


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jun 14, 2007 9:14 pm 
Offline

Joined: Mon Apr 16, 2007 6:04 am
Posts: 155
Location: Auckland, New Zealand
Funnily enough I was trying step 1 this morning before work. Actually the first time I tried I forgot to put the JMP in so all sorts of weirdness would have been happening! With the jump so it just cycles the ROM I again get weird behaviour. Something is happening but measuring the address lines on my decode chip (A10, A11 and A12) they all have the same signal on them. A15 seems to be all over the place too when I think it should be high if I am just cycling my ROM at E000h.

Onto step 2 now I think. I can get a Microchip 27C64 today. They are faster than the old ones I have and use a 12.5 volt programming voltage. So I shall see how one of them goes. Getting a non CMOS part could be tricky around here. Probably need to get them from the US too.

Will let you know how things go with the Microchip part. Thanks for the suggestions!

Simon


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jun 14, 2007 9:47 pm 
Offline

Joined: Tue Jul 05, 2005 7:08 pm
Posts: 1041
Location: near Heidelberg, Germany
kc5tja wrote:
1) Program the EPROMs you have with all NOPs, with a JMP instruction at the end to prevent execution outside the ROM address range. If this doesn't work, then,


Remember to put in the RESET vector at the end, so the CPU does not jump elsewhere right at the start.

André


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jun 14, 2007 11:21 pm 
Offline

Joined: Mon Apr 16, 2007 6:04 am
Posts: 155
Location: Auckland, New Zealand
Hi André, yep I made sure I did that. I am using the 6502 assembler/simulator to write and assemble the code then opening the binary in Visual Studio and shifting everything so it is burnt to the start of the EPROM and the reset vector is in the correct place.

Simon


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Jun 16, 2007 11:02 pm 
Offline

Joined: Mon Apr 16, 2007 6:04 am
Posts: 155
Location: Auckland, New Zealand
OK, finally success! It was my ROM chips but not how I though. I tried my older chips with the exact same result as before. Lots of weird outputs going on. Pretty much the sort of thing you get when you have floating inputs. Ah-ha! That was it. My circuit used the 27C64 ROMS instead of the original 2364. Obviously there are some pin differences between the two. I was very careful to make sure I had all the pins wired correctly, which they were, but I overlooked one thing. My PGM pin (pin 27 - active low) was left floating. I tied that high and Bingo! everything works. My 6522 is outputtig nice square waves finally! Now I can go on to using my new working SBC to control the audi part of Bender's brain!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jun 17, 2007 2:09 am 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
You realize, in exchange for all the help we've offered, we simply must have pictures of this thing when it's done . . . ;D


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jun 17, 2007 2:39 am 
Offline

Joined: Mon Apr 16, 2007 6:04 am
Posts: 155
Location: Auckland, New Zealand
kc5tja wrote:
You realize, in exchange for all the help we've offered, we simply must have pictures of this thing when it's done . . . ;D


Absolutely! I just finished the last of the wiring of inputs/outputs between the SBC and the audio boards an am just about to work on the code to interface them. I was just thinking I really need to document all this and throw it up on a web page. Mainly so I can remember how the hell it all works in 6 months time!

Simon


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 27 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 49 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: