Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 22:31 29 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PicoMite: PicoGAME VGA development

     Page 23 of 31    
Author Message
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6820
Posted: 09:59pm 20 Jun 2022
Copy link to clipboard 
Print this post

There were a couple of "preferred" pins that I wanted to stick with for the prototype - and some that I had no choice about. Obviously, all the VGA and PS/2 pins are fixed. I preferred to stick with GP6 and GP7 for the audio to keep compatible with Peter. So, I had GP0-GP5 to play with then GP8 and GP9 were used by the PS/2. GP10-GP13 were in a good position for the SD card. The ADC pins had to be connected to the paddle/analogue stick pins. I needed a COM port on Port B... It all got a bit tangled. :) I'm afraid PIO possibilities and SPI connections were completely ignored.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4262
Posted: 11:09am 21 Jun 2022
Copy link to clipboard 
Print this post

Hi Tom,

Please find below code for PIO1 to read the 2 NES controllers from A and B ports (K8 and K7). The code is experimental, and I only have time to check the performance later this week. So if you are pressed for time, load it into your platform and run it.

The code is very basic, non optimized, and runs 2 state machines, one for each connector K8 (PIO1 state machine 0) and K7 (PIO1 state machine 1).

I have set the frequency of the PIO at 100kHz(=10us) which is quite low, but in line with the 12us pulse you use in your basic program. I have tested yesterday that 1us (1MHz) also works on my hand build NES controller. But your mileage may vary.
You can change the PIO frequency by changing the variable "f". But currently you get 400 updates per second on the NES controller keys.

'test for PIO SPI for NES controller
'VGApicomiteGAME board revision 1.4

'pin asignment K8/sm0 K7/sm1
'clk (out) gp1 gp4
'latch (out) gp2 gp5
'data (in) gp3 gp22

'PIO1 execute frequency
f=100000

'reserve pins for PIO1 sm0
SetPin gp1,pio1
SetPin gp2,pio1
SetPin gp3,pio1

'reserve pins for PIO1 sm1
SetPin gp4,pio1
SetPin gp5,pio1
SetPin gp22,pio1

'pio definition PIO1 sm0
s0=0                             'default with shift direction left
p0=Pio(pinctrl 0,2,0,GP3,,GP1,)  'GP3=IN base, GP1+GP2=SET

'pio definition PIO1 sm1
s1=0                             'default with shift direction left
p1=Pio(pinctrl 0,2,0,GP22,,GP4,) 'GP22=IN base, GP4+GP5=SET

'pio1 sm0 program, non optimized
'adr/instr/comment
'0 E083 'set pindir GP1, GP2, out
'1 E000 'set GP1, GP2 low
'2 E002 'gp2 high (latch)
'3 E000 'gp2 low

'4 E027 'load X with value 7
'5 A0C3 'mov NULL to ISR
'6 4001 'shift 1 bit GP3 into ISR
'7 E001 'GP1 high (clock)

'8 E000 'GP1 low
'9 0046 'JMP X-- to &h6
'A 8000 'push ISR
'B 0002 'jmp to &h2

'&h0C....&h0F not used

'pio1 sm1 program, non optimized
'10 E083 'set pindir GP4, GP5, out
'11 E000 'set GP4, GP5 low
'12 E002 'gp5 high (latch)
'13 E000 'gp5 low

'14 E027 'load X with value 7
'15 A0C3 'mov NULL to ISR
'16 4001 'shift 1 bit GP22 into ISR
'17 E001 'GP4 high (clock)

'18 E000 'GP4 low
'19 0056 'JMP X-- to &h16
'1A 8000 'push ISR
'1B 0012 'jmp to &h12

'&h1C...&h1F not used

'read the program from data statements into an array
Dim a%(7):For i=0 To 7:Read a%(i):Next i

'program and start the PIO1 state machines
PIO program 1,a%()      'program PIO1
PIO init machine 1,0,f,p0,,s0,0       'init sm0 from address &h00
PIO init machine 1,1,f,p1,,s1,&h10    'init sm1 from address &h10
PIO start 1,0                         'start PIO1 sm0
PIO start 1,1                         'start PIO1 sm1

Print "running"
h%=0

'read the FIFO's that contain the NES controller keys
Do
 PIO read 1,0,1,h% 'read from FIFO sm0
 Print Hex$(h%), 'print value
 PIO read 1,1,1,h% 'read from FIFO sm1
 Print Hex$(h%) 'print value
 Pause 100
Loop While Inkey$=""

End

'pio1 program in data statements
Data &hE000E002E000E083,&hE0014001A0C3E027,&h000280000046E000,0
Data &hE000E002E000E083,&hE0014001A0C3E027,&h001280000056E000,0


If you need to set IO pins to power the controllers, this has to be added.

@Mick

Your design has a 150ohm resistor to power the NES controller. I am not sure if I have this right, but the schematics I found on the web for the NES controller had 1k pullups to the switches (they use this low resistance to prevent high impedance wires that pickup noise when no key is pressed). When all keys are pressed there is 125 ohm load. And 150 ohm series. So the 4021 is powered from 1.4V where 3.3V was normal.
Maybe newer controllers have different pullup resistors. If not I think this resistor needs to be 10 ohm or so.
Edited 2022-06-21 21:20 by Volhout
PicomiteVGA PETSCII ROBOTS
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4047
Posted: 11:35am 21 Jun 2022
Copy link to clipboard 
Print this post

Wow, thanks Volhout, I look forward to testing and understanding your code ... when I have a PicoGAME 1.4 built, currently I only have the (red) prototype completed and the 1.4 is just populated with resistors - I meant to work on it last night but was distracted by Peter's latest firmware release and bug hunting.

> If you need to set IO pins to power the controllers, this has to be added.

Not sure what you mean, I believe the controllers "just work" (TM) on the PicoGAME.

  Quote  I am not sure if I have this right, but the schematics I found on the web for the NES controller had 1k pullups to the switches.


I think I've also seen it diagrammed with 10K pull-ups, my breadboarded one uses 4.7K pull-ups and my perfboard one uses 3.6K (SMD) pull-ups; it looks like there is a lot of wriggle room, but perhaps that is at 5V. The AliExpress controllers and my original old-stock clone Famicom controller have no discrete resistors:


New old-stock Famicom controller PCB - apologies that it's cropped I just grabbed a random photo from my archive.

Best wishes,

Tom
Edited 2022-06-21 21:43 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6820
Posted: 12:55pm 21 Jun 2022
Copy link to clipboard 
Print this post

The 150R value was found on test, using the controllers that I have. Originally it was lower (68R IIRC). It's there because there is a problem if you are using fire buttons on a switch joystick, which just happen to use the same pin as the NES controller uses for power. That resistor is all that prevents a heavy current being drawn from the 3V3 line when Fire is pressed. 150R seemed to work ok and kept the current low enough for both the available supply and for a tactile switch to be used as a fire button. IIRC I measured the controller load at about 3mA max.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4262
Posted: 02:51pm 21 Jun 2022
Copy link to clipboard 
Print this post

  thwill said  
> If you need to set IO pins to power the controllers, this has to be added.

Not sure what you mean, I believe the controllers "just work" (TM) on the PicoGAME.



This board revision you need to to make sure GP15 is set correctly.



Edited 2022-06-22 00:51 by Volhout
PicomiteVGA PETSCII ROBOTS
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4047
Posted: 03:04pm 21 Jun 2022
Copy link to clipboard 
Print this post

  Volhout said  This board revision you need to to make sure GP15 is set correctly.


We are definitely getting our "knickers in a twist"; that schematic is derived from the prototype board as it shows the bi-colour power/mode LED that isn't required by the v1.4 board - which IIRC also doesn't use GP15 to set the mode - I think Mick did something "clever"; possibly something you might consider "god damn awful" as a working professional .

Best wishes,

Tom
Edited 2022-06-22 01:06 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6820
Posted: 03:56pm 21 Jun 2022
Copy link to clipboard 
Print this post

If you have the Blue pcb (version 1.4) please don't even consider looking at the circuit for the red (prototype) one. They are different in many ways. That drawing is derived from the prototype circuit. The blue PCB doesn't have that transistor at all, just a simple resistor to light the LED from the supply.

Until I discover that controllers don't work with 150R supply resistors I'm unlikely to complicate things further - especially as it would mean controlling both sockets and I've no spare pins since I put a Fire button on Port B.  :) I think that reducing the value a little might be ok, but 10R (330mA) would sink the 3.3V supply completely with a single fire button. Two joysticks would stand no chance. I know it's not a great design, but it's simple and rugged - you can hold the fire buttons on both joysticks down all day at 44mA in total.

I tested the controllers by holding down all the buttons at once, just to prove that it would do it. It works.  :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4262
Posted: 04:57pm 21 Jun 2022
Copy link to clipboard 
Print this post

On my blue board, K8 is powered from GP14 that I set high. By doin that you power the NES through it's FETs 50 ohm. Better than 150 ohm, and you can use 10k pullup for the fire button....when GP14 is input.
PicomiteVGA PETSCII ROBOTS
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4262
Posted: 05:41pm 21 Jun 2022
Copy link to clipboard 
Print this post

@Tom,

The PIO for K7 (port B) does not work. Swapped data and clock.

Volhout
PicomiteVGA PETSCII ROBOTS
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6820
Posted: 05:42pm 21 Jun 2022
Copy link to clipboard 
Print this post

You can do that, it's fine. You shouldn't do it if someone is likely to (possibly unknowingly) plug an Atari joystick in though as it will short GP14 to ground when they press fire. How happy the Pico will be driving into a short circuit I don't know. It's not something I want to try. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4262
Posted: 06:32pm 21 Jun 2022
Copy link to clipboard 
Print this post

@Tom,

The PIO routine for K8 works now. For K8 I also swapped CLK and DATA pins.
The working version below.

For K7 I have to study. Currently I have no solution. GP22 is simply too far from GP5 to combine in PIO commands. I may have to do something with the side set range.
But today I have no solution yet. Needs a good night sleep I guess..

'test for PIO SPI for NES controller
'VGApicomiteGAME board revision 1.4

'pin asignment K8/sm0 K7/sm1
'data (in)     gp1    gp4
'latch (out)   gp2    gp5
'clk (out)     gp3    gp22

'PIO1 execute frequency
f=100000

'reserve pins for PIO1 sm0
SetPin gp1,pio1
SetPin gp2,pio1
SetPin gp3,pio1

'power the port K8
SetPin gp14,dout
Pin(gp14)=1

'pio definition PIO1 sm0
s0=0                             'default with shift direction left
p0=Pio(pinctrl 0,2,0,GP1,,GP2,)  'GP1=IN base, GP3+GP2=SET

'pio1 sm0 program, non optimized
'adr/instr/comment
'0 E083 'set pindir GP3, GP2, out
'1 E000 'set GP3, GP2 low
'2 E001 'gp2 high (latch)
'3 E000 'gp2 low

'4 E027 'load X with value 7
'5 A0C3 'mov NULL to ISR
'6 4001 'shift 1 bit GP1 into ISR
'7 E002 'GP3 high (clock)

'8 E000 'GP3 low
'9 0046 'JMP X-- to &h6
'A 8000 'push ISR
'B 0002 'jmp to &h2

'read the program from data statements into an array
Dim a%(7):For i=0 To 7:Read a%(i):Next i

'program and start the PIO1 state machines
PIO program 1,a%()      'program PIO1
PIO init machine 1,0,f,p0,,s0,0       'init sm0 from address &h00
PIO start 1,0                         'start PIO1 sm0

Print "running"
h%=0

'read the FIFO's that contain the NES controller keys
Do
PIO read 1,0,1,h% 'read from FIFO sm0
Print Hex$(255-h%)', 'print value
Pause 100
Loop While Inkey$=""

End

'pio1 program in data statements
Data &hE000E001E000E083,&hE0024001A0C3E027,&h000280000046E000,0
Data 0,0,0,0

PicomiteVGA PETSCII ROBOTS
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4262
Posted: 08:30am 22 Jun 2022
Copy link to clipboard 
Print this post

@Mick,

As to the 1.4 board. If you want to use K7 for serial communication (RS232) you should ground pin 5. Otherwise that won't work.

Volhout
PicomiteVGA PETSCII ROBOTS
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6820
Posted: 09:10am 22 Jun 2022
Copy link to clipboard 
Print this post

Pin 8 is already ground. I had no intention of making the connection standard for RS-232, it was just a "nice to have" feature,even if it needed a custom lead. Pin 5 would have had the second analogue input if another had been available on the PicoMite. Grounding it could, if someone was trying to use two paddle controllers or an analogue joystick on that port (as they can on Port A), cause a bit of a problem as it would connect a variable resistor directly between 3V3 and GND. Everything is compromises. lol

The Mini version is almost ready. At the moment the connections to the controller port are identical to those of Port A. Would there be any advantage to rearranging anything on there? It would break compatibility with version 1.4, but I may be able to keep it compatible with the new version of the full PicoGame.
Edited 2022-06-22 19:23 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4262
Posted: 09:41am 22 Jun 2022
Copy link to clipboard 
Print this post

Dear Tom,

Please find below PIO program for reading 2 NES controllers from port A(K8) and port B(K7) for the 1.4 board.

It took few braincells, and some googling, before I had a solution for the GP22 clock on the K7 connector. As a result there are 2 different state machine programs, and unless there are problems I would like to keep it this way.

The NES controller timing is more critical on the port B (K7) connector, so if you want to play with the speed (PIO frequency) make sure you check first on port B. I have confirmed both ports work at 1MHz (10x the current speed of 100kHz).

I hope you have any benefit from this work.

Regards,

Volhout

'test for PIO SPI for 2 NES controllers
'VGApicomiteGAME board revision 1.4

'-------------------------------------- IO pin configuration ----------------------------
'pin asignment K8/sm0 K7/sm1
'data (in)     gp1    gp4
'latch (out)   gp2    gp5
'clk (out)     gp3    gp22

'reserve pins for PIO1 sm0
SetPin gp1,pio1
SetPin gp2,pio1
SetPin gp3,pio1

'reserve pins for PIO1 sm1
SetPin gp4,pio1
SetPin gp5,pio1
SetPin gp22,pio1

'power the 2 ports K8 and K7 if needed
SetPin gp14,dout
SetPin gp15,dout
Pin(gp14)=1
Pin(gp15)=1

'---------------------------------------- PIO cofiguration ------------------------------
'PIO1 execute frequency
f=100000

'pio config PIO1 sm0
s0=0                             'default with IN shift left, OUT shift left
p0=Pio(pinctrl 0,2,0,GP1,,GP2,)  'GP1=IN base, GP3+GP2=SET

'pio config PIO1 sm1
s1=2^19                           'default with IN shift left, OUT shift right
p1=Pio(pinctrl 1,1,1,GP4,GP22,GP5,GP22) 'GP4=IN base, GP5=SET GP22=OUT/SIDESET

'-------------------------------------- PIO program (comment) ----------------------------
'pio1 sm0 program, non optimized
'adr/instr/comment
'0 E083 'set pindir gp2+3, out
'1 E000 'set gp2+3 low
'2 E001 'gp2 high (latch pulse)
'3 E000 'gp2 low

'4 E027 'load X with value 7
'5 A0C3 'mov NULL to ISR
'6 4001 'shift 1 bit GP1 into ISR
'7 E002 'GP3 high (clock pulse)

'8 E000 'GP3 low
'9 0046 'JMP X-- to &h6
'A 8000 'push ISR
'B 0002 'jmp to &h2

'&h0C....&h0F not used

'pio1 sm1 program, non optimized
'10 E081 'set pindir GP5, out      [side 0]
'11 E000 'set GP5 low              [side 0]
'12 A0EB 'MOV null inverted to OSR [side 0]
'13 6081 'OUT 1 bit OSR to pindirs [side 0] set GP22 out

'14 E001 'gp5 high (latch pulse)   [side 0]
'15 E000 'gp5 low                  [side 0]
'16 E027 'load X with value 7      [side 0]
'17 A0C3 'mov NULL to ISR          [side 0]

'18 4001 'shift 1 bit GP4 into ISR [side 0]
'19 1058 'JMP X-- to &h18          [side 1] this is the clock pulse GP22
'1A 8000 'push ISR                 [side 0]
'1B 0014 'jmp to &h14              [side 0]

'&h1C...&h1F not used
'----------------------------- END PIO program (comment) ---------------------------

'pio1 program in data statements
Data &hE000E001E000E083,&hE0024001A0C3E027,&h000280000046E000,0
Data &h6081A0EBE000E081,&hA0C3E027E000E001,&h0014800010584001,0

'read the program from data statements into an array
Dim a%(7):For i=0 To 7:Read a%(i):Next i

'program and start the PIO1 state machines
PIO program 1,a%()      'program PIO1
PIO init machine 1,0,f,p0,,s0,0       'init sm0 from address &h00
PIO init machine 1,1,f,p1,,s1,&h10    'init sm1 from address &h10
PIO start 1,0                         'start PIO1 sm0
PIO start 1,1                         'start PIO1 sm1


'------------------------------ MAIN level ----------------------------------------
Print "running"
h%=0

'read the FIFO's that contain the NES controller keys
Do
PIO read 1,0,1,h% 'read from FIFO sm0
Print Hex$(255-h%), 'print value
PIO read 1,1,1,h% 'read from FIFO sm1
Print Hex$(255-h%) 'print value
Pause 100
Loop While Inkey$=""

End


Edited 2022-06-22 19:49 by Volhout
PicomiteVGA PETSCII ROBOTS
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4047
Posted: 09:56am 22 Jun 2022
Copy link to clipboard 
Print this post

  Volhout said  I hope you have any benefit from this work.


Thanks Volhout I look forward to giving it a go.

I made some progress with my soldering last night but I need to wait for some new 22uF tantalum capacitors; the ones I had in stock look like they have been in storage since the 70's and don't test reliably with my shonky *Chinese* component tester.

Best wishes,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4047
Posted: 10:01am 22 Jun 2022
Copy link to clipboard 
Print this post

Mick,

I noticed last night that on the 1.4 board C9 has the silk-screen for a polarised elecrolytic capacitor but the BOM lists it as an unpolarised 100nF multilayer ceramic ?

Best wishes,

Tom
Edited 2022-06-22 20:02 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6820
Posted: 10:08am 22 Jun 2022
Copy link to clipboard 
Print this post

Wow... That's great! :)
Special thanks for the commented listing, it's much appreciated.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6820
Posted: 10:15am 22 Jun 2022
Copy link to clipboard 
Print this post

Tom:
Just use whichever you like. :) On the 1.4 that I'm using regularly I missed a few caps off either because I'd run out or because they were in an inconvenient place. As long as your power supply is reasonable - not dangled on the end of a 6ft Chinese USB extension lead for example - then you'll probably be ok. IIRC I might have put 1uF 50V (I know, it was a lousy choice) aluminium electrolytic in instead of 22uF and 100uF for C2 plus one or two of the 100nF (I ran out).
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2141
Posted: 12:52pm 22 Jun 2022
Copy link to clipboard 
Print this post

@thwill
"22uF tantalum capacitors; the ones I had in stock look like they have been in storage since the 70's and don't test reliably"

You may not want to bother with this but it may be possible to re-form the dielectric in the tantalums.
Stick them in a breadboard with a 10k resistor in series with each and apply a voltage a little under their rating and leave on overnight. Then measure the leakage current by measuring the voltage across the 10k. Any that are less than 10uA (100mV) are good.
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4047
Posted: 01:15pm 22 Jun 2022
Copy link to clipboard 
Print this post

  phil99 said  You may not want to bother with this but it may be possible to re-form the dielectric in the tantalums ...


I truly appreciate the "teaching moment" @phil99 but since I received them I've had my doubts and I can replace them (with less shonky looking, but no doubt still Chinese, capacitors) for a couple of quid.


A line-up of the suspects.

Best wishes,

Tom
Edited 2022-06-22 23:24 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
     Page 23 of 31    
Print this page
© JAQ Software 2024