Page 1 of 4
Beginner in digital circuitry
Posted: Tue Feb 01, 2011 3:25 am
by ioncannon
Always wanted to do digital circuitry, and the current course I am taking in university has a lot to do with it (I am doing a CompSci major). I understand a lot of the hardware (if that's the right word) about microprocessors and various digital logic devices, but nothing about electrical engineering. However I would like to do some real world projects.
I began by desoldered a 6502 variant from the original Nintendo (Only thing with a 6502 I can part with, it's broken). The instruction set is the same, and you get a few bonus built in features.
-I wired VCC to 5v, and Grn to ground.
-I wired all the data bus pins to grn for a no-op instruction
-Wired VCC/Grnd to a ossilator, and wired the clock output, to the 6502's input.
-I grounded NMI and IRQ, and put the first 4 address lines through leds.
Reset is my biggest issue. I don't have a button on me right now, but would manually switching the wire between high, to low, back to high work?
I tried doing this, but if RESET is 5v, all lines are active, and if grounded all lines are low.
Is this because the CPU is cycling too fast to see, or is it not working properly?
Just a note, the NES 6502 divides clockspeed by 12, so this may also be an issue, since I have a 5.37mhz oscillator, it's running at around 448khz.
Re: Beginner in digital circuitry
Posted: Tue Feb 01, 2011 3:58 am
by BigDumbDinosaur
Always wanted to do digital circuitry, and the current course I am taking in university has a lot to do with it (I am doing a CompSci major). I understand a lot of the hardware (if that's the right word) about microprocessors and various digital logic devices, but nothing about electrical engineering. However I would like to do some real world projects.
I began by desoldered a 6502 variant from the original Nintendo (Only thing with a 6502 I can part with, it's broken). The instruction set is the same, and you get a few bonus built in features.
Welcome to the wacky world of 6502s and to the forum.
-I wired VCC to 5v, and Grn to ground.
-I wired all the data bus pins to grn for a no-op instruction
Actually, all zeros on the data bus results in a BRK instruction, not NOP. The opcode for NOP is $EA, or %11101010 in binary. So, to get NOP, wire the data bus as follows:
D0 - low
D1 - high
D2 - low
D3 - high
D4 - low
D5 - high
D6 - high
D7 - high
-Wired VCC/Grnd to a ossilator, and wired the clock output, to the 6502's input.
Presumably you used a TTL can oscillator. It's also possible to use a crystal, or even an R-C circuit.
-I grounded NMI and IRQ, and put the first 4 address lines through leds.
IRQ and NMI should both be high. IRQ is level sensitive and if continuously held low, causes the MPU to get stuck in an IRQ loop. Also, IRQ takes the MPU through the vector at $FFFE-$FFFF, which has to point to valid code. NMI causes a jump through $FFFA-$FFFB.
Reset is my biggest issue. I don't have a button on me right now, but would manually switching the wire between high, to low, back to high work?
After a fashion. However, you should have a short delay upon the transition from low to high. A simple R-C circuit will suffice.
I tried doing this, but if RESET is 5v, all lines are active, and if grounded all lines are low.
See above comments.
Just a note, the NES 6502 divides clockspeed by 12, so this may also be an issue, since I have a 5.37mhz oscillator, it's running at around 448khz.
It could be. NMOS MPUs have a minimum clock speed below which they won't function.
Posted: Tue Feb 01, 2011 5:22 am
by GARTHWILSON
All good answers from BDD, but I think he's mostly thinking about the CMOS 6502. I don't think the NMOS one had a Schmitt-trigger input for RST\, so it needed a clean edge with a quick rise time. I can't find anything about it in the Rockwell or Synertek data sheets right now though. I do know that the NMOS ones had a die-heating problem with leaving the RST line down more than a tenth of a second or so. 50ms was what a lot of RST circuits were made to deliver. You will need more than just a switch, since the switch will produce a lot of bouncing instead of a clean RST signal. If the last low time is at least a few clock cycles long, you might be in luck, if the rise time is fast enough. Use a CMOS one and you won't have to worry about it.
The NMOS 6502 also required an external oscillator, unlike the CMOS one which could use an RC hung off the clock pins.
The NMOS 6502 was not guaranteed to work below 100kHz. The CMOS ones can be stopped without losing data from the registers, meaning you can even single-clock it with a button (with a debouncing circuit of course) so you can probe all the lines at each clock cycle if you want.
The NMOS 6502 had several bugs and quirks that got fixed in the CMOS one. The latter has more instructions and addressing modes too, so for anyone just starting out, I would definitely recommend going straight for the CMOS one. The exception is if someone wants to start programming on a Commodore 64 for example, since it used a 6502 variation that was never available in CMOS.
Re: Beginner in digital circuitry
Posted: Tue Feb 01, 2011 7:28 am
by kc5tja
I began by desoldered a 6502 variant from the original Nintendo (Only thing with a 6502 I can part with, it's broken). The instruction set is the same, and you get a few bonus built in features.
I believe the NES CPU lacks decimal mode, however, so software performing BCD arithmetic won't run.
Re: Beginner in digital circuitry
Posted: Tue Feb 01, 2011 3:45 pm
by ioncannon
Always wanted to do digital circuitry, and the current course I am taking in university has a lot to do with it (I am doing a CompSci major). I understand a lot of the hardware (if that's the right word) about microprocessors and various digital logic devices, but nothing about electrical engineering. However I would like to do some real world projects.
I began by desoldered a 6502 variant from the original Nintendo (Only thing with a 6502 I can part with, it's broken). The instruction set is the same, and you get a few bonus built in features.
Welcome to the wacky world of 6502s and to the forum.
-I wired VCC to 5v, and Grn to ground.
-I wired all the data bus pins to grn for a no-op instruction
Actually, all zeros on the data bus results in a BRK instruction, not NOP. The opcode for NOP is $EA, or %11101010 in binary. So, to get NOP, wire the data bus as follows:
D0 - low
D1 - high
D2 - low
D3 - high
D4 - low
D5 - high
D6 - high
D7 - high
-Wired VCC/Grnd to a ossilator, and wired the clock output, to the 6502's input.
Presumably you used a TTL can oscillator. It's also possible to use a crystal, or even an R-C circuit.
-I grounded NMI and IRQ, and put the first 4 address lines through leds.
IRQ and NMI should both be high. IRQ is level sensitive and if continuously held low, causes the MPU to get stuck in an IRQ loop. Also, IRQ takes the MPU through the vector at $FFFE-$FFFF, which has to point to valid code. NMI causes a jump through $FFFA-$FFFB.
Reset is my biggest issue. I don't have a button on me right now, but would manually switching the wire between high, to low, back to high work?
After a fashion. However, you should have a short delay upon the transition from low to high. A simple R-C circuit will suffice.
I tried doing this, but if RESET is 5v, all lines are active, and if grounded all lines are low.
See above comments.
Just a note, the NES 6502 divides clockspeed by 12, so this may also be an issue, since I have a 5.37mhz oscillator, it's running at around 448khz.
It could be. NMOS MPUs have a minimum clock speed below which they won't function.
Thanks for the information. I thought 00000000 was NOOP because I was using a 8085 guide as a reference. Thought some of the instructions (at least noop) would be the same. Will try the new wiring when I get home.
All good answers from BDD, but I think he's mostly thinking about the CMOS 6502. I don't think the NMOS one had a Schmitt-trigger input for RST\, so it needed a clean edge with a quick rise time. I can't find anything about it in the Rockwell or Synertek data sheets right now though. I do know that the NMOS ones had a die-heating problem with leaving the RST line down more than a tenth of a second or so. 50ms was what a lot of RST circuits were made to deliver. You will need more than just a switch, since the switch will produce a lot of bouncing instead of a clean RST signal. If the last low time is at least a few clock cycles long, you might be in luck, if the rise time is fast enough. Use a CMOS one and you won't have to worry about it.
The NMOS 6502 also required an external oscillator, unlike the CMOS one which could use an RC hung off the clock pins.
The NMOS 6502 was not guaranteed to work below 100kHz. The CMOS ones can be stopped without losing data from the registers, meaning you can even single-clock it with a button (with a debouncing circuit of course) so you can probe all the lines at each clock cycle if you want.
The NMOS 6502 had several bugs and quirks that got fixed in the CMOS one. The latter has more instructions and addressing modes too, so for anyone just starting out, I would definitely recommend going straight for the CMOS one. The exception is if someone wants to start programming on a Commodore 64 for example, since it used a 6502 variation that was never available in CMOS.
Ahh so it wasn't just me, whenever RST was grounded, the chip would heat up significantly. Should 500khz clock be ok? I read it's due to DRAM data inside the CPU degrading if the chip is not clocked fast enough.
Re: Beginner in digital circuitry
Posted: Tue Feb 01, 2011 3:47 pm
by ioncannon
I began by desoldered a 6502 variant from the original Nintendo (Only thing with a 6502 I can part with, it's broken). The instruction set is the same, and you get a few bonus built in features.
I believe the NES CPU lacks decimal mode, however, so software performing BCD arithmetic won't run.
Yea, I did some NES programming, I remember that one quirk. For now I just want to see if I can get a proper running cpu.
Posted: Tue Feb 01, 2011 10:20 pm
by GARTHWILSON
Should 500khz clock be ok? I read it's due to DRAM data inside the CPU degrading if the chip is not clocked fast enough.
Yes. Just don't drop it below 100kHz unless it's CMOS. Current-production WDC 65c02's can have the clock stopped in either phase, whereas Rockwell, CMD, Syntertek, and other 65c02's could only stop with phase 2 high. NMOS ones can't stop at all without losing the data.
Posted: Wed Feb 02, 2011 2:51 am
by ioncannon
Well, wired it correctly, and it still just outputs 1s on the address bus.
Got a 20mhz clock (So we are running at 1.6mhz)
Wired the Reset through this circuit to debounce
http://www.all-electric.com/schematic/dbounce4.gif
Wired the data bus correctly
NMI and IRQ are wired to 5v
I am not too sure about resistors (again never did electric engineering), but maybe I need to use them instead of wires (in certain areas)?
Update: Put LEDs on the last 6 Address lines and I am seeing activity!!!! Seems it just just to fast to notice a change. However I popped a cable out by accident and now my reset is working backwords

. Probably a cable to my not gate somewhere.
Update2: IT WORKS!!!! Problem was VCC fell out of a not gate. So cool seeing the leds count in binary. Big smile on my face.
Also means CPU isn't fried.
Now two things, for some reason the speed slows down after a while, and pressure on the cpu causes it to flicker/go fast again/pause. I am right now clocked around 450khz, maybe that's why? Going to put it back to 1.6mhz.
Update3:
Fixed the random flickering when cpu pressed, by placing the faster clock. Still have slow clock problems though.
Weird putting my hand even near (but not touching) the clock wire speeds up the clock (I AM GOD).
Have had it running for 10min now, CPU is really hot. How hot should they get normally?
Posted: Wed Feb 02, 2011 9:53 am
by flaith
Hi,
as i'm really interested by how you wired things, is it possible to have a draw of it ?
because i'm just starting to learn electronics for fun (with an Arduino)
Thanks

Posted: Wed Feb 02, 2011 5:24 pm
by BigDumbDinosaur
Put LEDs on the last 6 Address lines and I am seeing activity!!!!
You need to invest in a logic probe. You can get a
reasonably good one at a reasonable price.
BTW, now that you seem to have some activity with your Frankenstein circuit, you should try to create a simple computer out of it. There is no shortage of examples around here, some that are very simple and some that aren't.

Posted: Wed Feb 02, 2011 6:52 pm
by ioncannon
Put LEDs on the last 6 Address lines and I am seeing activity!!!!
You need to invest in a logic probe. You can get a
reasonably good one at a reasonable price.
BTW, now that you seem to have some activity with your Frankenstein circuit, you should try to create a simple computer out of it. There is no shortage of examples around here, some that are very simple and some that aren't.

That's what my next step is

! Blew my left over cash on components and new tools, but getting payed on Friday, so will buy some SRAM and a ROM. Going to need a eprom programmer though =\. Expensive.
Was also thinking of turning it into a small NES synthesizer. Trying to understand the schematic (
http://www.freeinfosociety.com/electron ... tendo4.jpg), prof. of mine says the two pins output to a filter of some kind.
I am guessing wiring a speaker to said pins won't work...
Update: Seems the lines are literally the direct output. Saw a few "stereo sound" guides, and people tap the two pins and feed wires to two RCA ports. Going to be an interesting project

.
Posted: Thu Feb 03, 2011 5:34 pm
by BigDumbDinosaur
Going to need a eprom programmer though =\. Expensive.
Not necessarily. If all you are going to do is program EPROMs go to eBay and look for a TOP853. They sell for around 50 bucks. I have one here, and once you get past the comical English in the software, it's not bad. I use it all the time to burn EPROMs.
Posted: Mon Feb 14, 2011 2:42 pm
by ioncannon
Hmm seems I may have done a little mistake. Was wiring the buses lines to a empty breadboard for better organization, and now the CPU seems to be dead. No output is coming from the address lines. The cpu isn't outputting anything. Do you think it's dead? Might have to go to value village and grab another NES lol.
Also, thanks Dino, got that eprom programmer you mentioned.
Posted: Sun Feb 20, 2011 6:47 pm
by ioncannon
Figured out, the clock line was messed up a bit. All works now. Got the address decoder circuit wired up and it's working correctly

!!!
Address Space is setup like this for now:
$0000-$1FFF ROM (8kb)
$2000-$3FFF RAM (8kb)
I am thinking of wiring a 7 segment display up to one address so I can output for now.
Now I have a question, on the NES CPU the RESET vector is at:
$FFFC–$FFFD 2 bytes Address of Power on reset handler routine
Will my ROM have to be positioned in that space? so instead of $2000-$3FFF it would be $E000-$FFFF? Is this the same on normal 6502's?
Posted: Sun Feb 20, 2011 7:42 pm
by BigEd
Yes, you pretty much need ROM at the top of memory to cover the vectors and RAM at the bottom to cover zero page and the stack.
If you do a partial address decode then either or both devices can be mirrored many times over. Perhaps ROM would cover everything from $8000 to $ffff and RAM cover everything from $0000 to $7fff. The advantage is that the address decode is simpler (or minimal) - there's not much difference to the software, if you're writing your own. But it might help fit in with the expectations of software you inherit.
(As an extreme case, the Atari 2600 had just 128bytes of RAM which was mirrored in both zero page and page one for the stack.)