Author Topic: Universal Serial Interface for Amstrad CPC  (Read 1192 times)

0 Members and 1 Guest are viewing this topic.

Offline Etegar

  • CPC464
  • **
  • Posts: 5
  • Liked: 0
Re: Universal Serial Interface for Amstrad CPC
« Reply #25 on: 19:46, 12 January 19 »
Hi Ikonsgr,


Very interesting project. I would like to order 1 board if it's available with the edge connector adapter.

Thanks

Offline Dandare

  • CPC664
  • ***
  • Posts: 54
  • Country: es
  • Liked: 115
Re: Universal Serial Interface for Amstrad CPC
« Reply #26 on: 18:16, 13 January 19 »

Nice project,

I'm curious: at 32Mhz, a pic16 runs one instruction each 125ns.
Given that you need to identify the port, whether it's read or write, and either capture the bus or put the right response back in the bus (and take it out before the next instruction), I would say the timing is almost impossible to get right, considering you have less than 1us (8 pic asm instructions) to do it all.


Congratulations on the achievement. I can't imagine how you do it unless you are inserting wait states like there's no tomorrow  :)
(Does that pause switch gives a hint about this?)

« Last Edit: 18:23, 13 January 19 by Dandare »

Offline ikonsgr

  • CPC6128
  • ****
  • Posts: 199
  • Country: gr
    • ikonsgr 80's Home Micros WorkBench
  • Liked: 108
Re: Universal Serial Interface for Amstrad CPC
« Reply #27 on: 23:50, 13 January 19 »

Nice project,
I'm curious: at 32Mhz, a pic16 runs one instruction each 125ns.
Given that you need to identify the port, whether it's read or write, and either capture the bus or put the right response back in the bus (and take it out before the next instruction), I would say the timing is almost impossible to get right, considering you have less than 1us (8 pic asm instructions) to do it all.
Congratulations on the achievement. I can't imagine how you do it unless you are inserting wait states like there's no tomorrow  :)
(Does that pause switch gives a hint about this?)


You are right, there is NO way all these to be done in less than 1uS, unless you have a PIC running at 200Mhz... :D 

So, of course amstrad need to be paused when circuit is activated (you just force "READY" signal to low and Amstrad can freeze.... for ever!),although the hole code execution for each sent/received byte is done in a few microseconds!
Now, apart from the need of instant activation of the curcuit and pausing of amstrad (which in the end ,was done using a logic gate chip, it was really impossible to do it using the pic and software routine, as they were too slow even @32Mhz),the most difficult part, was the correct reading of a  byte from serial port! The precise latch/unlatch of PIC's data port to amstrad's data bus, seemed to be impossible to achieve!
At some stage of development,i was so frustrated of not being able to sync everything right, that i thought the only way to do it, was using an extra octal 3state buffer chip (which is as big as the PIC itself ::)  ), between cpc's 8bit data bus and pic's data port, and enable it by IORQ signal (so the buffer would "automatically" make the correct "latch/unlatch" of pic's port to cpc's data port).
But then suddenly...an idea "hits me": studying in detail how Z80's is reading a byte from a port and combining this knowledge with the way Amstrad allows access of I/O buses to Z80, i managed to resolve this, by using only a small rudimentary "sample & hold" circuit (just a small diode and a capacitor) of the READY signal that fed a pic's input pin! You see,i discover that in the proccess of reading a byte from a port, i can ensure that the byte was "downloaded" correctly to accumulator when the 1st high pulse of ready signal occured AFTER unpausing amstrad. So what i did, was, unpause amstrad for 0.25uS (e.g. 1cycle @4mhz, exactly the clock of Z80 ;) ) and then repause it again. If in this time, the "sample & hold" pin was High, it means that byte was taken, and i could proceed to unlatching Pic's data port from amstrad's data bus and unpause amstrad completely! If not, then i issue again a 0.25uS cycle of "unpause/pause"  and do the same check! That way, i managed to "bit bang"  pic's port at exactly the correct time and with the minimum ovehead ,the hole check of "sample & hold" code, each time amstrad is paused, executes in only 0.5us!

I began to deal with this project since summer of 2017, and have spent literally many 100's of hours on this! In the process, i got involved with assembly programming (i even developed a code
for fast read/write files byte by byte using firmware, because of this project!), DELPHI programming on the PC, PIC programming, basic programming on CPC, learn to configure and use bluetooth modules, wifi modules, usb to serial interfaces,and ofcourse  design the schematics and the pcb board for the circuit...

To get an idea, i began with this:
https://www.dropbox.com/s/g1zvz97hb67oql6/DSCN0752.JPG?dl=0
Which is evolved to this :
https://www.dropbox.com/s/dv9fo1zi7k6cpij/PROTOTYPE2.JPG?dl=0\
And finally end up to the pcb board shown in the 1st post...


Surely, it was a lot of trouble but, i did it  *mostly* as a hobby, a fun of making something creative,  and in the end,  sharing any knowledge and achievement with the community!


Long live Amstrad CPC! :)  
« Last Edit: 00:37, 14 January 19 by ikonsgr »

Offline Dandare

  • CPC664
  • ***
  • Posts: 54
  • Country: es
  • Liked: 115
Re: Universal Serial Interface for Amstrad CPC
« Reply #28 on: 11:00, 14 January 19 »
Very nice,
just a hint for future projects you may get yourself involved with: (Maybe you already know about it)
PICs with a Parallel Slave Port will save you a lot of trouble and will let you interface with the CPC without wait states.


Downside is you'll have to go to a 40pin package at least to get that peripheral.


Offline ikonsgr

  • CPC6128
  • ****
  • Posts: 199
  • Country: gr
    • ikonsgr 80's Home Micros WorkBench
  • Liked: 108
Re: Universal Serial Interface for Amstrad CPC
« Reply #29 on: 21:24, 14 January 19 »
That's really very nice feature! Sadly, microchip doesn't provide this feature to the parametric search list ,so it's difficult to find what models have this feature.
Anyway, if the "smallest" pic with such feature is with 40pins, i'm afraid it's way too large, bulky and with "overkill" pincount  (and probably much more expensive at least newer models with internal 32Mhz clock) for this project.
My first priority when i was looking for a suitable PIC, was to be able to operate at least @32Mhz (with internal osc), have 1Kb RAM, Hardware Uart, and have the minimum pin count for my needs (20 or 28 at most). Besides 16F1579, there is another  "pin compatible" and with similar features PIC ,16F1459 which operates at 48Mhz. I haven't tested yet, but i believe it can work directly (just with a different Hex file ofcourse) on the same board, and so you can have a "Turbo" version of the serial interface ,+50% faster!


Offline ikonsgr

  • CPC6128
  • ****
  • Posts: 199
  • Country: gr
    • ikonsgr 80's Home Micros WorkBench
  • Liked: 108
Re: Universal Serial Interface for Amstrad CPC
« Reply #30 on: Yesterday at 10:42 »
I just add a new "half price" purchase option (pcb board+PIC flashed with program).
With this, anyone can easily build the board by himslef, needing only a soldering iron!   ;)
« Last Edit: Yesterday at 10:45 by ikonsgr »

Offline LambdaMikel

  • 6128 Plus
  • ******
  • Posts: 941
  • Country: us
    • Homepage
  • Liked: 474
Re: Universal Serial Interface for Amstrad CPC
« Reply #31 on: Yesterday at 17:14 »
Hi John,
I'd like to order 2 - assembled, if possible  :) Please send me PM for payment instructions.
CheersMichael

Offline krusty_benediction

  • CPC664
  • ***
  • Posts: 125
  • Country: fr
  • Liked: 93
Re: Universal Serial Interface for Amstrad CPC
« Reply #32 on: Today at 10:05 »
Nice project@Duke: do you think it can be used in association with the M4 in order to debug a CPC runing application from the PC ?. The M4 read memory from the CPC and send it to the PC through this interface