GPIO ports on SXB boards..

Building your first 6502-based project? We'll help you get started here.
User avatar
GARTHWILSON
Forum Moderator
Posts: 8775
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: GPIO ports on SXB boards..

Post by GARTHWILSON »

Collen wrote:
drogon wrote:
The timing constraints are well inside that of a 6502 - the shortest time you need to pulse the line low for is in the order of 6µS.
[...] also are the I/O ports protected or can they handle a bit bang ? (output a bit/pulse, while a bit/pulse is coming in)
if i shorten them because the timing is off, do i wreck my SXB board ?
The amount of time Gordon was saying there is for the 1-Wire interface if understood him right. 1-Wire and I²C use and open-drain (or open-collector) pull-down and passive resistor pull-up. The way to do that with the 65c22 is to leave a 0 in the applicable output register bit, and then change the data-direction register bit in DDRA or DDRA to 1 for output when you want to pull the line down, or 0 for input when you want to let it float up, or to read the line to see if another device is pulling it down. That way there's never any bus contention. If you do make a mistake and have contention (like make it try to actively pull up when something else is pulling down), there's a small possibility of damage if it's left that way for long enough, but definitely not if it's on the order of microseconds. It will be the same kind of thing with many other ICs as well, not just the 65c22.
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?
User avatar
drogon
Posts: 1671
Joined: 14 Feb 2018
Location: Scotland
Contact:

Re: GPIO ports on SXB boards..

Post by drogon »

GARTHWILSON wrote:
Collen wrote:
drogon wrote:
The timing constraints are well inside that of a 6502 - the shortest time you need to pulse the line low for is in the order of 6µS.
[...] also are the I/O ports protected or can they handle a bit bang ? (output a bit/pulse, while a bit/pulse is coming in)
if i shorten them because the timing is off, do i wreck my SXB board ?
The amount of time Gordon was saying there is for the 1-Wire interface if understood him right. 1-Wire and I²C use and open-drain (or open-collector) pull-down and passive resistor pull-up. The way to do that with the 65c22 is to leave a 0 in the applicable output register bit, and then change the data-direction register bit in DDRA or DDRA to 1 for output when you want to pull the line down, or 0 for input when you want to let it float up, or to read the line to see if another device is pulling it down. That way there's never any bus contention. If you do make a mistake and have contention (like make it try to actively pull up when something else is pulling down), there's a small possibility of damage if it's left that way for long enough, but definitely not if it's on the order of microseconds. It will be the same kind of thing with many other ICs as well, not just the 65c22.
One wire, as it's name suggests is a two wire bus (ho ho - signal and ground), however it works better with 3 wires - power - otherwise the remote device have to work in what's known as parasite power mode - they can work fine, but work better with active power. (And to supply power - use a spare GPIO pin - they only need a few mA, but then you can effectively power cycle the bus).

You need to be able to change the direction of the pin you use to communicate with the devices.

Each device has a unique 64 bit address, so the first thing you do is send the address - so wire in output mode, hold low for 500µS which is a bus reset (also powers down all devices in parasite power mode), then pull the bus high again...

To send a 1, you pull the bus low for anywhere between 1 and 15µS, then pull the bus high for the remainder of the time-slot which is in the order of 64µS. To send a 0, you pull it low for 60µS, then let it go high for a few more µS, and so on, until you send the device address, then you send the command-code to the device, then you can read data back - to read data back, you send a short pulse low (15µS max) then turn the bus into read mode and see what you get inside the next 60µs. You need to keep sending a high pulse to keep parasite powered devices powered-up - another reason to use 3 wires and provide active power. Devices typically implement CRCs so you can check that to make sure you get the right thing back.

Just looked up the SXB - it's 8Mhz and has VIA/PIAs on-board, so with that in-mind, then the 1-wire protocol ought to be very achievable. I do it in C on an ATmega running at 8Mhz so I'd hope there is plenty of scope for 65c02 ASM at the same speed.

The down-side of 1-wire is that you need to know the devices address - and each device is unique - by design. There is a mechanism to discover a devices address (and a network of devices on one bus master), but it's complex and ugly. Some devices have the address stamped onto them, but reading it off a TO92 size package can be challenging... (so cheat and plug it into a Raspberry Pi as that has 1-wire built into the kernel and just look at the 1-wire virtual filesystem)

Anyway, that's 1-wire. I've just ordered up some PCBs for my SBC project and stuck a 6522 on it, so I might have a go at it myself over the xmas period as I quite like 1-wire sensors and I don't think it would be that challenging to re-write my ATmega C code into 6502...

-Gordon
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/
whartung
Posts: 1004
Joined: 13 Dec 2003

Re: GPIO ports on SXB boards..

Post by whartung »

drogon wrote:
Just looked up the SXB - it's 8Mhz and has VIA/PIAs on-board, so with that in-mind, then the 1-wire protocol ought to be very achievable. I do it in C on an ATmega running at 8Mhz so I'd hope there is plenty of scope for 65c02 ASM at the same speed.
The chip is capable of 8Mhz, but the boards available from WDC are at 3.6864 MHz.
Chromatix
Posts: 1462
Joined: 21 May 2018

Re: GPIO ports on SXB boards..

Post by Chromatix »

Which makes each cycle about 271ns, for constructing timing loops.
User avatar
BitWise
In Memoriam
Posts: 996
Joined: 02 Mar 2004
Location: Berkshire, UK
Contact:

Re: GPIO ports on SXB boards..

Post by BitWise »

whartung wrote:
drogon wrote:
Just looked up the SXB - it's 8Mhz and has VIA/PIAs on-board, so with that in-mind, then the 1-wire protocol ought to be very achievable. I do it in C on an ATmega running at 8Mhz so I'd hope there is plenty of scope for 65c02 ASM at the same speed.
The chip is capable of 8Mhz, but the boards available from WDC are at 3.6864 MHz.
It depends on the board. The 65C265 and 65C134 SXBs are 3.6864MHz but the 65C02 and 65C816 SXBs are 8MHz. The '02 and '816 have ACIA, PIA and VIA support chips. The '134 and '265 are the microcontroller version of the chips with embedded peripherals.
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
User avatar
Collen
Posts: 20
Joined: 27 Nov 2018
Location: Netherlands..
Contact:

Re: GPIO ports on SXB boards..

Post by Collen »

drogon wrote:
GARTHWILSON wrote:
Collen wrote:
drogon wrote:
The timing constraints are well inside that of a 6502 - the shortest time you need to pulse the line low for is in the order of 6µS.
[...] also are the I/O ports protected or can they handle a bit bang ? (output a bit/pulse, while a bit/pulse is coming in)
if i shorten them because the timing is off, do i wreck my SXB board ?
The amount of time Gordon was saying there is for the 1-Wire interface if understood him right. 1-Wire and I²C use and open-drain (or open-collector) pull-down and passive resistor pull-up. The way to do that with the 65c22 is to leave a 0 in the applicable output register bit, and then change the data-direction register bit in DDRA or DDRA to 1 for output when you want to pull the line down, or 0 for input when you want to let it float up, or to read the line to see if another device is pulling it down. That way there's never any bus contention. If you do make a mistake and have contention (like make it try to actively pull up when something else is pulling down), there's a small possibility of damage if it's left that way for long enough, but definitely not if it's on the order of microseconds. It will be the same kind of thing with many other ICs as well, not just the 65c22.
One wire, as it's name suggests is a two wire bus (ho ho - signal and ground), however it works better with 3 wires - power - otherwise the remote device have to work in what's known as parasite power mode - they can work fine, but work better with active power. (And to supply power - use a spare GPIO pin - they only need a few mA, but then you can effectively power cycle the bus).

You need to be able to change the direction of the pin you use to communicate with the devices.

Each device has a unique 64 bit address, so the first thing you do is send the address - so wire in output mode, hold low for 500µS which is a bus reset (also powers down all devices in parasite power mode), then pull the bus high again...

To send a 1, you pull the bus low for anywhere between 1 and 15µS, then pull the bus high for the remainder of the time-slot which is in the order of 64µS. To send a 0, you pull it low for 60µS, then let it go high for a few more µS, and so on, until you send the device address, then you send the command-code to the device, then you can read data back - to read data back, you send a short pulse low (15µS max) then turn the bus into read mode and see what you get inside the next 60µs. You need to keep sending a high pulse to keep parasite powered devices powered-up - another reason to use 3 wires and provide active power. Devices typically implement CRCs so you can check that to make sure you get the right thing back.

Just looked up the SXB - it's 8Mhz and has VIA/PIAs on-board, so with that in-mind, then the 1-wire protocol ought to be very achievable. I do it in C on an ATmega running at 8Mhz so I'd hope there is plenty of scope for 65c02 ASM at the same speed.

The down-side of 1-wire is that you need to know the devices address - and each device is unique - by design. There is a mechanism to discover a devices address (and a network of devices on one bus master), but it's complex and ugly. Some devices have the address stamped onto them, but reading it off a TO92 size package can be challenging... (so cheat and plug it into a Raspberry Pi as that has 1-wire built into the kernel and just look at the 1-wire virtual filesystem)

Anyway, that's 1-wire. I've just ordered up some PCBs for my SBC project and stuck a 6522 on it, so I might have a go at it myself over the xmas period as I quite like 1-wire sensors and I don't think it would be that challenging to re-write my ATmega C code into 6502...

-Gordon
Ah, so i can damage the 265sxb if i short it by accident.. can i protect it a little more
by putting a resistor on the data line ?!

to GARTHWILSON, i was in the same thinking process as you described.. thx for confirming it for me :D

and Gordon, looks like where gonna do the same with Xmas.. except for me it's more about testing and learning
the 1wire, spi and those ADC's .. xmas is to short for more... :)

Chromatix wrote:
Which makes each cycle about 271ns, for constructing timing loops.
Thx, this makes coding a little bit easier regarding the timings (delay loops ect).. i do use the 3.6864 MHz 286sxb version..
User avatar
GARTHWILSON
Forum Moderator
Posts: 8775
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: GPIO ports on SXB boards..

Post by GARTHWILSON »

Collen wrote:
Ah, so i can damage the 265sxb if i short it by accident.. can i protect it a little more
by putting a resistor on the data line ?!
Don't be too paranoid about it. In all the years I've been using the 65 family, I think the only time I've damaged any of them was when I let a tool roll under the wire-wrapped board and short things when it was powered up. Even then, it was probably from shorting the ±10V for RS-232 and my op amps for the analog section to something, not shorting +5V or ground to data pins. I never did try to figure out what was damaged. I just replaced the ICs and kept going. That was over 20 years ago.
Quote:
and Gordon, looks like where gonna do the same with Xmas.. except for me it's more about testing and learning
the 1wire, spi and those ADC's .. xmas is to short for more... :)
Note that 1-Wire is only for really slow things, like temperature sensors which can't change much in even a tenth of a second. There are far more SPI and I²C ICs on the market than 1-Wire. There are even more Microwire ICs on the market than 1-Wire. Microwire is National Semi's baby, basically a subset of SPI. SPI and I²C don't have any timing requirements like 1-Wire does, as long as the controller doesn't overrun the speed the devices can go, which you probably won't have to worry about (especially for SPI) if you're bit-banging with a 3.6864MHz '02.
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?
Post Reply