News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_m_dr_m

How to make an optic pen?

Started by m_dr_m, 10:38, 09 December 23

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Brocky

#25
SMH.. youre right darkhalf, i didnt look at the timing diagrams!  :picard:

i still wonder if a pure digital signal is needed to trigger it, im measuring <1.8v when against the screen (phosphor glow), and over 2v when the electron beam hits, and clamped to 5v max. i guess 1.8v maybe to high to trigger it back to a low tho... altho an interrupter switch/button on the photodiode line itself would let the voltage drop to 0v.. (press button to allow the voltage through the photodiode)

i currently have the arduino sketch reading the voltage value via an analog input with limit clamp on the low side... it would be quite easy to use force a digital low when clamped below 2v and digital high when > 2v, but it would be really nice to use less hardware!

darkhalf

I would be using something similar that light pen circuit that dodogildo posted. Transistor would  control logic levels. They use an NPN and photo transistor.  No option for variable adjustment in that circuit. However something doesn't look right in the schematics so will need to check it over. 

Would like to make my current Amstrad pen trigger the LPEN instead of joystick port

Checked out parts on the Dart circuit board and its got 74 series logic chips including shifters, counters etc on it. Fair bit of stuff. Looks like standard NPN transistors
CPC464/GT64, CPC464 Plus/CTM640, 2 x CPC6128/CTM644

darkhalf

Attached is an 'enhanced' version of the DK'Tronics light pen circuit and some traced out schematics. Photo resistor goes via a transistor with various resistors to the LPEN input on the expansion port

The other part is the 27C128 EPROM which uses 74LS27 to NOR the inputs (/IORQ, /WR) and maybe A8? Some of the traces are impossible to track without the actual board.

Seems to then trigger a flipflop along with A15 via 74LS74 which enables ROMDIS and /CE similar to the other external ROM boards schematics I've looked at today. The D0-D3 lines are configurable via jumper holes in the middle of the board. Looks like D2 might be the only one enabled for this ROM. From the wiki page:
Quote
    A15=0 doesnt't trigger the Gate Array (which would also require A14=1)A13=0 does trigger Upper ROM Bank Number

So next step is to load the DK'Tronics ROM from a normal ROM expansion board

https://www.cpcwiki.eu/index.php/Dk%27tronics_Lightpen

Then try the ROM software to write/read #BC00/#BF00 as #1C00/#1F00 using the Amstrad Magazine #8 pen
CPC464/GT64, CPC464 Plus/CTM640, 2 x CPC6128/CTM644

darkhalf

Okay so here is the Amstrad LP-1 lightpen inside
https://www.cpcwiki.eu/index.php/Amstrad_LP-1_light_pen

As you can see it is just a photo diode with a 3.3K resistor between the legs inside a plastic case

Pin 2 JOY DOWN (white) is the light sensor output
QuoteKeyboard.Row9.Bit1 (aka Joystick Down) (0=Light, 1=No Light)

Pin 8 COMMON (red) is the ground
QuoteKeyboard.Row9 is constantly held LOW during lightpen access
(AY) PSG.Ext.PortA configured as inputs would pickup the corresponding column for the Joy Down input

I've had this for a while (got it from a friend) but not really used it much. The included software I've converted to DSK and loaded up. English Manual would be helpful, but the CPC wiki one was French only. I've converted it OCR and then google translate through it. Output is somewhat readable

The software uses square boxes to let you select through menus. Screen needs to be colour and brightness up. If your flyback isn't putting out enough brightness - it will not work

Basically to draw anything with this pen, you have to press SPACE to get the screen to flash white. It then grabs the current cursor point. Then you have to move the pen to the next location, and SPACE again to get the next point. It takes several seconds to do each point drawing with this method and is very cumbersome.
CPC464/GT64, CPC464 Plus/CTM640, 2 x CPC6128/CTM644

darkhalf

QuoteAlso the lightpen on the 50pin port has the fantastic benefit of it getting directly attached to the CRTC and you can then just read the CRTC lightpen register to understand where it actually has hit the screen. So I think it cannot get better than that
CRTC only can measure at character positions. This is the DK'Tronics and other implementations. Poll the CRTC to get the position and convert to X,Y

QuoteThere also exist Joystickport versions, but you then have to do the calculation yourself and also time will go by until you read it, and I am not sure how it should work as the joystick port is only getting checked every 1/50s second
This is the Trojan/Amstrad Joystick implementation. Needs screen to be 'white' to calculate the location in software from what I've seen so far. Can calculate pixels but there is a longer delay in calcualting. There is code for the LP-1 on CPCwiki which explains how to use it

Quotehttps://archive.org/details/06_Schneider_CPC_International_1985-08
This article explaining what I wrote above reviewed a German joystick version lightpen and Light Painter software (which looks impressive compared to the Amstrad version)

QuoteHere is the wiki entry: https://www.cpcwiki.eu/index.php/Happy_Computer_Light_Pen
@GUNSHED had a look on archive.org but could not find it in the text
=firstTitle%3AH]https://archive.org/search?query=%22happy+computer%22&sort=title&and%5B%5D=firstTitle%3AH

Lots of Happy Computer, but assume we want the 'Schneider Sonderheft versions'. They have 2,4,6,7,8 there. Assuming its one of the missing ones which has the article
CPC464/GT64, CPC464 Plus/CTM640, 2 x CPC6128/CTM644

GUNHED

http://futureos.de --> Get the revolutionary FutureOS (Update: 2023.11.30)
http://futureos.cpc-live.com/files/LambdaSpeak_RSX_by_TFM.zip --> Get the RSX-ROM for LambdaSpeak :-) (Updated: 2021.12.26)

darkhalf

Thanks. Looks similar to the other magazine diagram posted but different resistor values, and slight change in arrangement


From LHS to RHS I think we have:
blue/grey/brown 680 ohm
blue/grey/brown 680 ohm
grey/red/orange? 82K ohm?
orange/grey/brown? 18K ohm?

Please let me know if I have the colours wrong. Assuming cap is 0.1uf

If the transistor is a BC547 (similar to the other circuit) then the order is 1 = collector, 2 = base, 3 = emitter (which goes to negative)  and that makes the brown wire negative, and blue positive (once again correct me if wrong)

The phototransistor however in this circuit connects between directly to the 5V rail, and then to the 680 ohm to negative rail. Still has a cap between the transistor base and the phototransistor 
CPC464/GT64, CPC464 Plus/CTM640, 2 x CPC6128/CTM644

darkhalf

Attachment with joined photo (inverted reverse side for clarity). Will use a veroboard and MX4 connector to build this one up and post results
CPC464/GT64, CPC464 Plus/CTM640, 2 x CPC6128/CTM644

darkhalf

#33
I've attached the original magazine schematics with values attached. Whilst drawing this up I found an error (doesn't match their track layout). The linkage from 680k to both collector and base is incorrect. I've removed this

Also hand drawn are the Happy Computer (GUNSHED - top) from the above board and the Amstrad Mag (below).

Assume 1nf capacitor (0.1uf) after rereading and SP201 as a suitable substitute phototransistor since BPW42 are not available

From what I'm understanding so far, the Happy Computer may be using a positive bias instead of negative bias with using the phototransistor?

[Update - 1nF on Amstrad mag should be on lightpen side. Cannot update attachment]
CPC464/GT64, CPC464 Plus/CTM640, 2 x CPC6128/CTM644

darkhalf

Updated (rough) schematics for DK'Tronics and Amstrad Magazine attached. 

Note that the schematic is almost identical between both, apart from some minor resistor value updates (620ohm vs 670ohm pull up on LPEN line, and 22K vs 15K pull down on photo transistor line)

Other differences. DK'Tronics had a 2.2 ohm resistor to the phototransistor and Amstrad mag instead has 1nf cap 

Going to try this with a breadboard first due to the variances, and I only have the LP-1 phototransistor here to experiment with currently
CPC464/GT64, CPC464 Plus/CTM640, 2 x CPC6128/CTM644

darkhalf

#35
Slight adjustment on above Amstrad Mag circuit (2.2K resistor should be on lightpen side of capacitor). This effectively puts 5V at the light transistor via this resistor.

Built the circuit on breadboard and only applied external 5V power and measured the LPEN output. Conclusion - photo transistor from the LP-1 didn't like this circuit. Need to find/try the proper photo transistor (SP201)

Only positive note so far is DK'Tronics ROM boots and runs fine in external ROM slot 1. Just needs a working light pen circuit to use it
CPC464/GT64, CPC464 Plus/CTM640, 2 x CPC6128/CTM644

Bryce

Quote from: darkhalf on 12:20, 27 December 23
QuoteAlso the lightpen on the 50pin port has the fantastic benefit of it getting directly attached to the CRTC and you can then just read the CRTC lightpen register to understand where it actually has hit the screen. So I think it cannot get better than that
CRTC only can measure at character positions. This is the DK'Tronics and other implementations. Poll the CRTC to get the position and convert to X,Y

How do you mean "at character positions"? If that was the case, then no pixel level graphics would be possible (or maybe I've mis-understood what you mean).
The DK'Tronix lightpen is triggering on the light of the CRT ray scanning the screen and is exact to the pixel.

Bryce.

darkhalf

#37
QuoteHow do you mean "at character positions"?
Just from what I read here:
https://archive.org/details/06_Schneider_CPC_International_1985-08

Translated from Page 11:
QuoteThe Schneider CPC owns the expansion Port at pin 47 Light pen connection. A precise processing of the values received there takes place in the kernel ROM. Because of the peculiarity of the CPC video controller But it is only possible to have one to achieve character-by-character resolution.

This is enough for positioning and for Menu controls completely off. Want However, you can get high-resolution  graphics create with the lightpen, that's how it comes you can only move on with a trick. The Lightpen connects to the joystick port or any data line of the bus system connected and then the switching states are queried.

For this purpose you color it Screen black if possible and creates a bright Sign. Now the light pen hits this sign. a signal is present and the corresponding address of the  Bus line is switched to the logical one Potential set to  high". This is how you leave it the screen character in a radius of 1 character (character). rotate and move on its own axis the lightpen in the desired one Direction. Every time. if the rotating Sign a signal to the Lightpen sends. will be the current one Position raised to base position and the process repeats itself. This The method has the disadvantage that it... works very slowly, but is through an average calculation the drawing in high-resolution graphics possible.

As in the basics of Lightpen mentioned. you have it at the CPC two possibilities. a light pen to operate. Both have their flaws, although the more serious one clearly when connecting to the expansion Port is located. For this reason the manufacturers of the LightpenPainter probably also for the connection decided the joystick port. this means Lwas a somewhat unusual one and slow processing, however through the advantage of drawing in HRG can as well as an excellent one Software, is balanced. The program is mainly for graphical purposes Thought to work, but can also as a menu control for your own User programs are used.

A demo disk shows how something built into basic programs becomes. In addition to the main program and there is another one in the demo RSX extension named .,Picture" on the disc containing the Lightpen creates images conveniently in your own programs are recorded can do that. The real highlight, however, is the May program, that all contains functions. with that too inexperienced draftsman is able to create his ownto create images
CPC464/GT64, CPC464 Plus/CTM640, 2 x CPC6128/CTM644

darkhalf

QuoteThe DK'Tronix lightpen is triggering on the light of the CRT ray scanning the screen and is exact to the pixel.
Not from what I'm reading: MC6845.PDF Data Sheet

QuoteLPEN High (R16) and Low (R17)
These registers together comprise a 14-bit register whose contents is the light pen strobe position, in terms of the video display address at which the strobe occurred. When the lPEN Input changes from low to high, then, on the next negative-going edge of CClK, the contents of the internal scan counter is stored in registers R16 and R17

R16 = Light Pen Reg (H) (5..0)
R17 = Light Pen Reg (L) (7..0)
(Also noted that R14/R15 are a 14-bit cursor register with same calculations)

Light pen register R16/R17 = Refresh memory address value. DK'Tronics reads these by setting register address in 1C00 and reading value from 1F00

Refer Section 13 DK'Tronics_Graphics_Lightpen_(ROM_Version)_Manual.pdf

Note: X ranges 0-39 and Y ranges 0-24 irrespective of mode

Calculations:
XYPos = R16 << 8 | R17 - 12292
YPos = XYPos / 40
XPos = XYPos - YPos * 40
CPC464/GT64, CPC464 Plus/CTM640, 2 x CPC6128/CTM644

darkhalf

Trying to find that Lightpen Painter software (no luck) but did find a youtube video for DK'Tronics light pen

https://www.youtube.com/watch?v=QG-WcZnpZuE

Around 5:40 he is commenting on the lack of accuracy (cursor is shaking) and you can see the draw results at 7:30 (pictured below). Perhaps DK'Tronics software attempts using some interpolation between squares?

You will note he is also drawing on a white background, to get the lightpen to respond. With DK'Tronics pen, fortunately you can continuously get updates on its (cursor based) position

Whilst the Amstrad (joystick port version) lets you position on a black screen, but then needs SPACEBAR press to trigger the read. Upon press, software knows only the pixel accurate Y position, and then draws a white block about 20 pixels high across until the light pen detects it. It uses this detection for pixel accurate X position. The process takes about 2-4 seconds per point (!)

To get something working better than either method I was thinking you could potentially combine them. 

1. Use the CRTC LPEN input to determine the immediate X,Y character position of the pen (against white background)

2. Push button to the pen (connected to joystick port Fire) to trigger light pen operation

3. Upon trigger, read the Y pixel position (via the DOWN arrow joystick read)

4. Start drawing vertical lines 8 pixels high at the X,Y character position to get the X pixel position

Obviously this would need updated drawing software to use a more accurate version of this pen, and some experimenting on correct resistor values for the photo transistor to both joystick and LPEN inputs
CPC464/GT64, CPC464 Plus/CTM640, 2 x CPC6128/CTM644

darkhalf

Doing some more reading of the LP-1 manual for the Amsoft package and you need to keep space held down for free draw to work properly

1. Whites the screen for pen detect
2. Upon detect will draw a horizontal bar
3. Then draws a pixel based on current X,Y pixel position (in black) 
4. Draws a box behind the pixel which follows the pen (whilst in the box) and draws pixels 

If the pen moves outside the box, you need to repeat the process. Movement is a bit jaggered, but the output at pixel resolution detection better than the character based from DK'Tronics demonstration
CPC464/GT64, CPC464 Plus/CTM640, 2 x CPC6128/CTM644

darkhalf

Attached are the BASIC and some slightly commented disassembly files for the Amstrad/Trojan software via joystick port. 

The 'draw' versions are cut down versions of the originals with more commenting

Some documentation on using the lightpen for menu cursor scanning, but if you are wanting to use the graphics parts then this is undocumented. Done some minor reverse engineering on this (haven't looked at Z80 in years) against the AY-3-8912, UpD-8255, CPC Firmware guide and Ins/outs of the Amstrad CPC464 book to get a start on this

Using the CRTC read method for the DK'Tronics unit is much easier than this
CPC464/GT64, CPC464 Plus/CTM640, 2 x CPC6128/CTM644

andycadley

You can see why these never really caught on, they're way too janky and the resolution is far too limited for drawing without hacky work arounds.

Character based accuracy was "good enough" for light gun style shooting games but that's not much cop if you then have to put the light pen right up against the screen...

darkhalf

Agreed. Reading the comments on YouTube etc confirms they were not as anticipated.  I remember the C64 Koala pad worked ok but limited uses on that computer. Would like to get this better but waiting on parts now and holidays almost over here
CPC464/GT64, CPC464 Plus/CTM640, 2 x CPC6128/CTM644

GUNHED

Darkhalf is right. On hardware level there is no pixel-precision. Only CRTC positions.

On a software level on the other hand some kind of sophisticated coding can simulate it. (Using the noise).
http://futureos.de --> Get the revolutionary FutureOS (Update: 2023.11.30)
http://futureos.cpc-live.com/files/LambdaSpeak_RSX_by_TFM.zip --> Get the RSX-ROM for LambdaSpeak :-) (Updated: 2021.12.26)

Brocky

nice investigation there @darkhalf i think im gonna leave this project on the back burner, it doesnt see to work as well as we all expected....

...maybe lightgun would be a better project..

darkhalf

@Brocky I'm still going to give it a shot when the parts arrive, but yeah the output doesn't look that promising for the DK'Tronics version. There are some other types of software such as Electric Studio etc which may work better, but overall having character resolution input isn't that great

If there was a way to use the CTRC and joy input together, and output that as a more accurate 'CRTC like' output then this would be a better solution and still would work with existing CPC software. So I'm not going to shelve it just yet but could be a bit of effort
CPC464/GT64, CPC464 Plus/CTM640, 2 x CPC6128/CTM644

andycadley

Quote from: darkhalf on 07:46, 03 January 24If there was a way to use the CTRC and joy input together, and output that as a more accurate 'CRTC like' output then this would be a better solution and still would work with existing CPC software. So I'm not going to shelve it just yet but could be a bit of effort

Theoretically, I don't see why not. Use the CRTC method to get the character position, the flash a bunch of white rectangles inside that character to locate the actual pixel position. Having two wires coming from the pen (one to the expansion port, the other the joystick port) would make it even more cumbersome to use however. Although I guess there is no reason you couldn't do something similar via another IO port.

darkhalf


QuoteHaving two wires coming from the pen (one to the expansion port, the other the joystick port) would make it even more cumbersome to use however.
Agreed. However compared to the amount of other peripherals coming out of my CPC, it probably won't matter!

Quote Although I guess there is no reason you couldn't do something similar via another IO port.
Stopped digging too far into the Dart circuitry in the first posts, but do wonder if they did something like that. There is a fair bit of 74 series logic going on there. Software link here. Some article in French too

https://www.cpc-power.com/index.php?page=detail&num=5853
CPC464/GT64, CPC464 Plus/CTM640, 2 x CPC6128/CTM644

Powered by SMFPacks Menu Editor Mod