6502.org
http://forum.6502.org/

[85] Tip of the day
http://forum.6502.org/viewtopic.php?f=7&t=342
Page 1 of 4

Author:  GARTHWILSON [ Sat Dec 16, 2000 5:40 am ]
Post subject:  [85] Tip of the day

Tip of the day, #1.  (I will try to give a tip every day as long as I can keep coming up with them.)

Note: Most of these tips, plus a lot more information, can be found in my website section, "6502 PRIMER: Building your own 6502 computer."

When you connect asynchronous SRAM (the kind of RAM usually used in small systems built by hobbyists in this forum), you can mix up the data lines and mix up the address lines too if it makes wiring or board lay-out easier.  As long as data lines go to data pins and address lines go to address pins, it will work fine.  You can do that for EPROM too, but you will have to make a programming adapter socket.  Don't mix up the lines for I/O ICs like the 6522 and 6551.

Author:  GARTHWILSON [ Sun Dec 17, 2000 4:15 am ]
Post subject:  [85.2] Tip of the day

Tip of the day, #2

When using I/O ICs that have a wire-OR IRQ\ output, typically a 3.3K resistor is recommended for the pull-up to Vcc. But with only this passive pull-up instead of an active one, the rising edge is quite slow when you clear the interrupt bit in the I/O chip, as illustrated below. Your interrupt-service routine (ISR) should clear the bit early to make sure the IRQ\ line is up by the time the ISR is finished and the μP allows interrupts again. Otherwise you'll get a false interrupt signal.

Image

Author:  GARTHWILSON [ Mon Dec 18, 2000 5:26 am ]
Post subject:  [85.3] Tip of the day

Tip of the day, #3

The 65c02 has a Schmitt-trigger reset input, so you can just use a capacitor and resistor to time the reset signal.  There is not much hysteresis though (although the amount may vary between brands) so electrical noise can keep you from getting a clean reset.  If you use an RC for reset, connect the capacitor right at the µP's (or its socket's) leads, keeping the capacitor leads as short as practical.  For the 6502 DIP package, put the capacitor directly from pin 1 to pin 40.

Edit:  Apparently not all brands have a Schmitt-trigger input for the reset; so you may need to verify for the brand you have.

There's more about reset circuits in the 6502 primer's chapter on it, at http://wilsonminesco.com/6502primer/RSTreqs.html .

Author:  GARTHWILSON [ Tue Dec 19, 2000 5:04 am ]
Post subject:  [85.4] Tip of the day

Tip of the day, #4

The 6522's synchronous serial port has seven modes of operation. For outputs that don't need the speed of PA or PB, connect this serial port to a chain of shift register (SR) IC's. For example, using 15 8-bit SR's, you get 120 output bits while leaving most of the 6522's pins free for other uses. Use mode 101 to clock the data out under control of T2, or mode 110 to clock it at half the phase-2 rate. You will typically use one of the 6522's parallel I/O bits to produce the strobe signal after shifting out the serial data stream. The 74HC164 and '595 are both 8-bit serial-in, parallel-out SR's, but the '595 has latches so the outputs don't change during the shifting-- they wait until you strobe the newly shifted data into the latches. To output other voltages (like for 12V control logic), use comparators like the LM339 for level translation to feed 4094 SR's running at the desired voltage. Allegro's UCN5821's outputs can drive relays directly, but it's cheaper to use driver transistors with one of the other SRs mentioned above. Don't reload the 6522's SR with a new byte before the last one is finished being sent out, or that next byte will be lost.

Image

There's more about using the 22's synchronous-serial port in the "circuit potpourri" page of the 6502 primer, at http://wilsonminesco.com/6502primer/potpourri.html .

Garth Wilson

Author:  GARTHWILSON [ Wed Dec 20, 2000 6:23 am ]
Post subject:  [85.5] Tip of the day

Tip of the day, #5

The 6522's SR can also be used in mode 100 (shift out free-running at T2 rate) to output a 9-level PWM (0 to 8 bits high), which when followed by an RC filter, is suitable for a 9-level D/A. I've used it to generate DTMF. This is slightly better than 3-bit resolution. Some talking toys only use 2-bit resolution!

Since it's free-running in this mode, it will keep putting out the same value over and over until you give it another value. Feeding
Code:
00000000 for 0, gives  .000V output;
00010000 for 1, gives  .625V output;
00100010 for 2, gives 1.250V output;
01010010 for 3, gives 1.875V output;
10101010 for 4, gives 2.500V output;
10101101 for 5, gives 3.125V output;
11011101 for 6, gives 3.750V output;
11101111 for 7, gives 4.375V output; and
11111111 for 8, gives 5.000V output.


Image

Simplest 6522 serial port D/A converter output filter, with -3dB point at 4kHz. For driver code, go to http://wilsonminesco.com/6502primer/potpourri.html#DAC and scroll down a little bit.

Author:  GARTHWILSON [ Thu Dec 21, 2000 5:54 am ]
Post subject:  [85.6] Tip of the day

Tip of the day, #6

Without bit-banging, you can also use the 6522's synchronous serial port in mode 101 for limited, but relatively fast, RS-232 output (adding a line driver).  CB1 need not be connected for this.  Since T2 only uses its counter's low byte to control the baud rate, the slowest you can go at 2MHz is about 4800 bps.  To go slower, use mode 111, even if you use T1 and PB7 on the same 6522 to supply the external CB1 clock.  RS-232 goes out low bit first, so you'll have to reverse the bit order in software.

You could conceivably get all 8 data bits + start and stop (who uses parity?) by making a word extend across the boundaries of consecutive SR operations, but you'd probably add a 6551 if you really needed the full RS-232 complement.  Otherwise, since the 6522's SR only gives 8-bit frames and you need start and stop bits, you're left with 6 bits for data.  With this 40H range, you can still get every character you see on your keyboard (no lower case) by subtracting a 20H offset from the ASCII value.  If the receiving computer is set for 7 or 8 data bits, the last bit(s) will always be high because of the early stop bit.  Add 40H or C0H, plus your offset, to make the data conform to ASCII again.  If your offset excludes needed characters like CR and LF, you can substitute characters you don't need— maybe \ and _ .  The short word will usually require leaving a couple of bits' extra time before starting the next byte, to ensure that the receiving computer sees a valid stop bit.

Author:  GARTHWILSON [ Fri Dec 22, 2000 4:33 am ]
Post subject:  [85.7] Tip of the day

Tip of the day, #7

Similar to tip #4, you can use the 6522's SR for inputting hundreds of bits as well, typically using mode 001 or 010 and a daisy chain of something like the 74HC165 or '597. For input at a different voltage, you can use the LM339 comparator between a chain of 4021's and the 6522. Again, hundreds or even thousands of bits can be interfaced to a single 6522 this way.

Image

For more description, see the section of the potpourri page of my 6502 primer where you see the same diagram as above.

There is a bug in all brands of 6522 in mode 011 however. See my next tip.

Author:  GARTHWILSON [ Sat Dec 23, 2000 4:35 am ]
Post subject:  [85.8] Tip of the day

Tip of the day, #8

The 6522 has a bug in mode 011, shifting synchronous serial data in under control of external CB1 clock.  All brands have this bug.  If the edge on CB1 falls within a few nanoseconds of the falling edge of phase 2, the CB1 edge will be ignored, so you lose a bit.  Worse, you'll get framing errors on subsequent data.  To get around it, put the external clock signal into the D input of a 74HC74 flip-flop, run the flip-flop's Q output to the 6522's CB1 pin, and clock the flip-flop with phase 0 or phase 2.  I have used this to send data from one 6502 computer to another using CA2 for an extra handshake line.

Attachment:
SerBugFlipFlop.jpg
SerBugFlipFlop.jpg [ 28.48 KiB | Viewed 9220 times ]

The SPDT switch in the diagram is for direction (up for CB1=output and down for it being an input), and could of course be replaced with 74-family parts to control the switching with software, something like the following which comes from my SS22 interface article:

Attachment:
SS22halfDuplx2.jpg
SS22halfDuplx2.jpg [ 58.84 KiB | Viewed 9220 times ]

Edit, many years later:  Mode 111 (shift out under control of an external shift clock) is also affected by the same bug.  I had missed that earlier.

Edit, 1/18/24:  Forum member Andre Fachat posted some test results linked in his post at viewtopic.php?f=4&t=7937 (and my post here shows up in his video :D ).

Author:  GARTHWILSON [ Sun Dec 24, 2000 5:36 am ]
Post subject:  [85.9] Tip of the day

Tip of the day, #9

To get the 6522's T1 running in free-run mode, you must set bit 6 of the ACR before writing to the counters.  Then, write to T1's counters to get it started.  After that you can write to the latches.  (This requirement may not hold for all manufacturers.)  It took me a long time to get this going the first time since this information is not in the data books.  I finally got it by looking at a working program that an applications engineer at Rockwell sent me.

Author:  GARTHWILSON [ Mon Dec 25, 2000 4:55 am ]
Post subject:  [85.10] Tip of the day

Tip of the day, #10

When you're not using a 6551 ACIA for serial communication, you can use the RTS\ and DTR\ as extra output bits.  Be aware, however, that the 6551 ACIA needs a toggling signal at the XTAL 1 input for some internal operations, so don't just stop clocking it when you're not using the serial I/O.

Merry Christmas (It won't be Christmas here for a few more minutes)

Author:  GARTHWILSON [ Tue Dec 26, 2000 5:23 am ]
Post subject:  [85.11] Tip of the day

Tip of the day, #11

The MIDI (musical instrument digital interface) bit rate is 31,250bps, which is not a standard rate option for the 6551 ACIA with a 1.8432 MHz crystal.  To get it, set the 6551 for one-sixteenth of the XTAL clock input rate, and then feed it with 500kHz instead of 1.8432MHz.  Get the 500kHz off of a 6522's PB7 from its free-running T1.  If you have a 6522 put out a steady square wave on PB7 from T1, the frequency is:  f=Ph2/(2(n+2)), where Ph2 is the phase-2 system clock frequency, and n is the T1 latch value.

Similarly, you can get much higher bit rates from the ACIA, still under software control.  Hitting all the standard RS-232 speeds up to 115200 bps is shown 90% of the way down the page at http://wilsonminesco.com/6502primer/IO_ICs.html .

Author:  GARTHWILSON [ Wed Dec 27, 2000 6:43 am ]
Post subject:  [85.12] Tip of the day

Tip of the day, #12

The capacitors of approximately 15 to 22 pF from the XTAL terminals of the 6551 ACIA to ground are not just to make the crystal frequency more acurate.  If that were all they were for, you'd normally be close enough without them.  But if you don't have a capacitor at least on XTAL 1 (the input) when using a crystal connected from XTAL 1 to XTAL 2, spurious components on the internal crystal oscillator's waveform may keep the baud rate generator from working at all.

Author:  GARTHWILSON [ Wed Dec 27, 2000 6:43 am ]
Post subject:  [85.13] Tip of the day

Tip of the day, #12 (duplicate-- How did that happen? So I'll replace it with Tip 12-A, bringing it in from here)

Tip of the Day, #12-A For simple raster graphics using an analog oscilloscope in X-Y mode, you can built a circuit whose counter ICs are fed from the clock line of a 6522's synchronous-serial port, whose data line goes to the Z-axis input. Here's a photo:

Image

Here's a simplified schematic of it (just omitting some resistors and capacitors):

Image

It just takes three pins of the 6522: two for the serial interface and one to reset the frame to start. As you can see, you could make any character you want, any font, and monochrome binary graphics. The 6522 takes constant babysitting though, so to keep the display going while your processor does something else, one way would be to make a separate, very simple computer to take the data and buffer it and run the display.

I should probably interlace it to cut the perceived flicker when scanning a lot of rows at a rate that everything can handle. (The Z-axis input of this scope was not able to handle the data as quickly as the computer could send it out.) It would requiring switching a couple of wires and changing the software. The down side would be that the frame height in number of lines can't change on the fly. I'd have to put in a DIP switch.

Author:  GARTHWILSON [ Thu Dec 28, 2000 4:10 am ]
Post subject:  [85.14] Tip of the day

Tip of the day, #13

If using more than one 6551 ACIA without a dedicated external clock oscillator, you can drive them all off of a single 1.8432MHz crystal by connecting the XTAL 1 pin (input) of secondary 6551's to the XTAL 2 (output) pin of the primary one that has the crystal.  My workbench computer has 3 6551's, and one of them has a choice, selectable through DIP switches, of using either the 1.8432MHz, or VIA3PB7 for MIDI, as mentioned in tip #11.  Having 3 switches gives the option to use separate transmit and receive clocks.

Author:  GARTHWILSON [ Fri Dec 29, 2000 4:39 am ]
Post subject:  [85.15] Tip of the day

Tip of the day, #14

When servicing 6551 ACIA interupts for simultaneous transmission and reception, remember that reading the status register clears the interrupt, but the interrupt could have been caused by both TX register empty and RX register full at the same time.  If your ISR ends before finding all the interrupt causes, it may, for example, find the receive register full, service that, and then exit thinking it's done, when in actuality the transmit register emptied before you read the status register and it's waiting for the next byte.  Now the IRQ line is false and the issue will never be addressed, and transmission will come to a halt.  If more than one thing in the same IC could need service, make sure the ISR doesn't stop before the whole job is done.

Page 1 of 4 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/