6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 12:59 pm

All times are UTC




Post new topic Reply to topic  [ 58 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
PostPosted: Sat Jun 29, 2019 4:39 pm 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
railsrust wrote:
I'm trying to figure out how to use one of the UARTs to send Midi data to the synthesizer chip I'm using. Does anyone know where I can find resources on how to do it on the microcontroller?

You need to configure either timer 3 or 4 to generate the 31.25KHz baud clock (T3CL/T3CH or T4CL/T4CH plus enable in TER) and configure a serial port to use it (TCR) along with 8 data bits, one stop bit and no parity (ACSRx).
Code:
                lda     #($10<<UART)            ; Set UART to use timer 3
                trb     TCR
                lda     #<BRG_VALUE             ; And set baud rate
                sta     T3CL
                lda     #>BRG_VALUE
                sta     T3CH

                lda     #1<<3                   ; Enable timer 3
                tsb     TER

                lda     #%00100101              ; Set UART for 8-N-1
                sta     ACSR0+2*UART

The MIDI baud rate was design to be derived from nice round MHz clocks (1 or 2MHz). If you have a baud friendly CPU clock like the W65C265SXB's 3.86MHz there will be quite a bit of error.

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
PostPosted: Sat Jun 29, 2019 8:07 pm 
Offline
User avatar

Joined: Mon May 12, 2014 6:18 pm
Posts: 365
How hard would it be to run the system on one clock and MIDI or something similar on a second clock that was not a multiple if the first? I've thought about this in other contexts and I can't figure out how to do it. It seems like anything based on the first clock could never know if it was reading a stable or transitioning value from the second.


Top
 Profile  
Reply with quote  
PostPosted: Sun Jun 30, 2019 9:03 am 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
Druzyek wrote:
How hard would it be to run the system on one clock and MIDI or something similar on a second clock that was not a multiple if the first? I've thought about this in other contexts and I can't figure out how to do it. It seems like anything based on the first clock could never know if it was reading a stable or transitioning value from the second.

The '265 has two clock inputs one. The builtin ROM expects a baud friendly crystal for the fast clock (see extract from listing below) and a slow 32.767KHz slow one.
Code:
974 00:DFB5 SPEED .ds 1 ;MAIN XTAL SPEED
975 ;0 = 1.843200MHZ
976 ;1 = 2.457600MHZ
977 ;2 = 3.686400MHZ
978 ;3 = 4.915200MHZ
979 ;4 = 6.144000MHZ

The monitor's control of the system can be usurped at startup which would allow any speed up to allegedly 14Mhz but 8Mhz is probably more reasonable.

If you use an external 65C51 (or other brand of UART) then that could have its own timing crystal. The address and data bus are easily accessible and there are some predecoded chip selects you can use.

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 03, 2019 9:43 pm 
Offline
User avatar

Joined: Sun Mar 03, 2019 5:09 am
Posts: 22
Location: Texas
What if I'm trying to also run SPI and receive PS/2 keyboard commands with the Midi? Would all of that even be possible on the Uarts at the same time? I'm guessing this would nix any possibility of a serial port if I run Midi.


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 03, 2019 11:15 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8545
Location: Southern California
railsrust wrote:
What if I'm trying to also run SPI and receive PS/2 keyboard commands with the Midi? Would all of that even be possible on the Uarts at the same time? I'm guessing this would nix any possibility of a serial port if I run Midi.

"UART" stands for "universal asynchronous receiver/transmitter."  PS/2 (which is similar to I²C in coordinating bit transfers) and SPI are synchronous, not asynchronous, so they do not go through the UARTs.  Daryl (8BIT) was supplying his 65SPI IC which was a 65-bus-compatible SPI chip, but the CPLD he was using to make it has been discontinued, so he has been slowly working toward re-designing it to use another CPLD.  [Edit: It's at https://sbc.rictor.org/65spi2.html .]  The 6522's shift register can do some limited SPI but wasn't designed for that.  So the only way you can get SPI and PS/2 directly is to bit-bang them (which is really pretty easy; I have sample circuitry at http://wilsonminesco.com/6502primer/pot ... ITBANG_SPI, and sample code for it at http://wilsonminesco.com/6502primer/SPI.ASM ).  Otherwise you're pretty much stuck with using another microcontroller or external IC to get them.

"Synchronous" means the bit transfers are coordinated by a clock line whose edges tell when to change or latch the serial line's state, without regard to microseconds (as long as you don't exceed the speed abilities of either end of the connection).  There is no requirement for exact or consistent speeds.  In fact, the bit-banged transmission of a byte can be paused mid-byte to service an interrupt, then resumed later, without causing problems.

"Asynchronous" (like RS-232 normally is) is very picky about timing accuracy.  Instead of using a separate clock line, the only timing reference is the beginning of a start bit, and that starts the receiver's clock.  After that, the receiver can only use the amount of elapsed time from the beginning of the start bit to know when to trust that each data bit is valid.  Clearly then if there's more than a couple of percent difference in the transmitter's bit-sending rate and the rate the receiver expects, enough timing error will have accumulated by the end of the frame that you'll start getting errors.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 05, 2019 12:29 am 
Offline
User avatar

Joined: Sun Mar 03, 2019 5:09 am
Posts: 22
Location: Texas
I'm at the PCB layout and schematic phase currently. I want to do an RS232 serial port. Would I be better off just running the Midi off of a separate 65C51 and feed it a 500Khz crystal, or giving it even feeding it off the clock output of one of the Uarts?

As for the SPI lines, is there a specific set of pins I should wire them to? The same goes for the PS/2 lines. Google is my friend, but it's not being particularly friendly to me today.

The software side of things I'd like to figure out myself, but the hardware I'm having trouble with.


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 05, 2019 9:03 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8545
Location: Southern California
railsrust wrote:
I'm at the PCB layout and schematic phase currently. I want to do an RS232 serial port. Would I be better off just running the Midi off of a separate 65C51 and feed it a 500Khz crystal, or giving it even feeding it off the clock output of one of the Uarts?

The 65c22 offers the option to automatically toggle PB7 on T1 time-out without any software intervention after the initial setting up. I've used this to feed 500kHz to a 65c51 for MIDI, without a separate 500kHz oscillator (let alone crystal, which will probably be large and expensive). Without spending time in the '265 data sheet, I suspect it has a way to do this too. It is discussed in the 6502 primer, about 3/4 of the way down the page at http://wilsonminesco.com/6502primer/IO_ICs.html, with both hardware considerations and '02 software setup.

Quote:
As for the SPI lines, is there a specific set of pins I should wire them to? The same goes for the PS/2 lines. Google is my friend, but it's not being particularly friendly to me today.

SPI bit-banging hardware and software are discussed in the 6502 primer at http://wilsonminesco.com/6502primer/pot ... ITBANG_SPI . PS/2's hardware is similar to I²C which is similarly discussed in the 6502 primer at http://wilsonminesco.com/6502primer/pot ... ITBANG_I2C . PS/2's bits are a little different though, having 1 start bit, 8 data bits (LSB first), 1 parity bit (odd), 1 stop bit, [1 ack bit (if host-to-device)], closer to what RS-232 normally uses, so the software will partly be different from what you'd need to bit-bang I²C.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 05, 2019 10:00 pm 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
GARTHWILSON wrote:
Without spending time in the '265 data sheet, I suspect it has a way to do this too. It is discussed in the 6502 primer, about 3/4 of the way down the page at http://wilsonminesco.com/6502primer/IO_ICs.html, with both hardware considerations and '02 software setup.

The 265's four UARTs are clock from either Timer 3 or 4 which in turn are driven from the CPU's fast clock. The built in ROM expects a serial baud rate friendly clock speed (like the 3.6864MHz on the SXB) which won't divide nicely into a multiple of 31.25KHz. They will be a lot of error, for example for the SXB you set the timer counter to ..

N = 3686400 / (16 * 31250) - 1 = 6

.. which is really

Baud = 3686400 / (16 * (6 + 1)) = 32914

If you use a MIDI friendly crystal like 4Mhz you get no error

N = 4000000 / (16 * 31250) - 1 = 7

4000000 / (16 * (7 + 1)) = 31250

but then the built in monitor won't work

The '265 has two tone generators which can generate a programmable frequency using timers 2 & 3 but with a standard crystal you'd get big error -- its basically the same equation to derive the timer value (N = FCLK / (16 * FREQ) - 1)

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
PostPosted: Sat Jul 06, 2019 2:09 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
railsrust wrote:
As for the SPI lines, is there a specific set of pins I should wire them to?
No. You can choose any of the i/o pins not dedicated to a function you require. For example, the attached diagram highlights the pins used for the external address and data buses. Presumably, those are among the functions you'll require.

Attachment:
w65c265s uCtlr.gif
w65c265s uCtlr.gif [ 100.68 KiB | Viewed 1533 times ]

For SPI it's advantageous, though not necessary, to use pins mapped to bit 7, bit 6 and bit 0. In the article he linked, Garth notes, "You can use any I/O bits you want, but I chose the ones above because again bit 0 of a port is the easiest and quickest to pulse in software (using INC and DEC), and bit 6 or 7 of a port are easiest to test (using the BIT instruction)."

That said, not all bit-bang code derives an advantage from use of bit 6, so bit 6 is one I wouldn't sweat over. This post includes bitbang code which AFAIK is faster than anything out there, and its only preference, bit-wise, is for bit 7 and bit 0. (It's OK to use bit 6, but with this code it has no particular advantage.)

You asked also about the PS/2 lines. These can attach to any of the remaining I/O pins. The SPI interface is probably one you'll want to optimize for speed, and hence give first choice, bit-wise. But the PS/2 lines aren't especially critical.

Have fun, and keep us posted!

Jeff

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
PostPosted: Sat Jul 13, 2019 6:37 pm 
Offline
User avatar

Joined: Sun Mar 03, 2019 5:09 am
Posts: 22
Location: Texas
What would be a "baud-friendly" clock rate for the cpu to run at that's as close to 8Mhz as possible? I fully intend to use at least one Uart for a Serial port, but I want it to run fast as it can while doing so.


Top
 Profile  
Reply with quote  
PostPosted: Sat Jul 13, 2019 8:16 pm 
Offline

Joined: Sat Jan 02, 2016 10:22 am
Posts: 197
railsrust wrote:
What would be a "baud-friendly" clock rate for the cpu to run at that's as close to 8Mhz as possible? I fully intend to use at least one Uart for a Serial port, but I want it to run fast as it can while doing so.

7.3728 MHz maybe ?


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 17, 2019 12:11 pm 
Offline
User avatar

Joined: Sun Mar 03, 2019 5:09 am
Posts: 22
Location: Texas
At 7.3728 MHz would 55ns ram still be the correct one to use, or should it be a different speed? If I need a different speed ram/rom, what should I be using for that clock rate?


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 17, 2019 12:26 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
That frequency is a period of 135ns. So that's the slowest path you could expect to work, taking into account all delays: out from cpu, through glue, through RAM, over busses, into cpu. There's a good chance 55ns would be OK, but it depends on your glue.

Also, depending on your glue, the critical path might not be a full CPU cycle, but only one phase, in which case you have only 67ns. That's still more than 55ns, but doesn't leave much room for propagation delays.

(It will help somewhat that a 55ns RAM will usually run faster, because you won't have worst case power supply, temperature, or a worst-case chip.)


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 17, 2019 3:23 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
BigEd wrote:
a 55ns RAM will usually run faster, because you won't have worst case power supply, temperature, or a worst-case chip.
Yup. For hobbyist applications (ie, not life-support or rocket launches! :P ) you can assume the RAM is somewhat faster than specified. So, that's good news.

Quote:
Also, depending on your glue, the critical path might not be a full CPU cycle
This is the bad news -- and Ed has actually understated the case. You never get a full CPU cycle, even before the glue logic delays are considered. See my Visual Guide to 65xx CPU Timing


Attachments:
GIF09.gif
GIF09.gif [ 10.52 KiB | Viewed 1418 times ]

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 04, 2021 9:42 pm 
Offline
User avatar

Joined: Sun Mar 03, 2019 5:09 am
Posts: 22
Location: Texas
I'm thinking of using a W65C134s to control some secondary chips so as to offload the main cpu to give all of its grunt to the video chip.

Would it be possible to control the 8 bit MCU with the 16 bit one using one Parallel Interface Bus on each chip?

Would there be a particular set of pins I would need to connect on each, or would it matter?

The 65C02 MCU isn't really doing anything in parallel; it's really just meant to receive commands from the main processor and execute them.
Its only function is to control sound chips and deal with controller inputs. It's basically like the Z80 on a Sega Genesis/Megadrive.

I plan to use an Philips SAA1099 with a Yamaha YM3438 for sound. I have my own reasons for picking these two chips that would take FOREVER to go into here. Let's just say I went back and forth on how I wanted it to sound for a while. :lol:

The Uart will go to a Midi port. I'll be using a 65C22 for the controller inputs.

I'm thinking 16K of ram would be about right here.

I'm settling on a Yamaha V9958 for video, and the 65SPI V2 will be used to interface with any extra I/O I might need to connect.

I think I read that the V9958 doesn't like the way the 65C816 does "test passes" (if I read it right) under certain instructions. Is there any way I can use hardware to deal with this so I'm not blocking the use of some useful instructions?

I know it seems odd that it took forever for me to get to the point where I made these decisions, but I wanted to be absolutely sure of what I wanted in this pig. I've been looking at some other projects for inspiration, and I also picked from original machines as well. I think I have a few other things I'll be putting on, but that's mostly just stuff for interfacing a keyboard.

I think it's time to start drawing up a new block diagram and a schematic afterward.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 19 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: