This week H-A-D featured an article with a home-built racing sim. While watching the video I have seen that the author did many connections on an Arduino board just inserting the wires on the pin header.
I have seen that before on a considerable amount of projects. It's not something I would rely on for a long term operation circuit, then I realized that there is room for a screw terminal shield. (Eagle Files):
The Expert is a Brazilian manufactured in the 80's and it is compatible with MSX standard. It uses a detachable keyboard but it lacks the Caps Lock LED on the keyboard because the 13 pin connector used ran out of pins (even the shield is used as a 14th conductor for GND).
One day I heard about that issue on my favorite podcast, and just for fun I have designed a Caps Lock cartrige for the Expert. Some time later I have added another feature to the cartridge that is not implemented on the computer: a RESET button.
I have designed PCBs for the MSX cartriges before, like the MSXDOS2 cartride that contains a ROM with the MSXDOS2 kernel with some glue logic to perform the bankswitching (the circuit was not designed by me though). Such cartridge allows the Expert - an MSX1 machine - to run MSXDOS2 without a Memory Mapper.
On this sunday afternoon I have merged the two projects and created the Ultimate MSX Caps Lock cartridge:
The PCB and schematics files are available on Github. I have just routed the board, not assembled the circuit yet, sou use it at your own risk.
A 100% of the CD and DVD drives that I have from LG suffered from an annoying aging problem. After few months of use the CD/DVD fails to load the media and eject the disc. At first it occurs oftenly and gets worse with time up to the point the it fails everytime.
I needed to reinstall the operating sytstem on an old machine and the drive - an LG unit was at the point that it failed all the times.
Then I've took off the covers of the DVD player to figure out what was happenning and I have found that the loading mechanism required good force at the end of its course.
Such mechanism is driven by a belt that I found that was too loose - in the sense that it lacked tension - to provide the necessary friction.
To fix the problem I used a sillicone band torn in two (as it was too wide to fit). Though the perimeter of the sillicone band was much smaller than the original belt, it supported the tensioning very well and it restablished the DVD player.
Worth to mention that the belt can be replaced without openig the drive as the belt is reachable (using a tweezer) with the DVD with its door opened.
One of the participants of the MSX.org reported that the Digi:Arka worked very well with Arkanoid 1 but it did not worked with Arkanoid 2. One of the possibilities is that the rom might not have code to read the paddles, just like in the first title, and indeed it is possible to find two versions of the game with the differences pointing to corroborate this hypothesis:
But the user that reported me the problem have the original paddle controller that was bundled with the game and such controller works in both titles (Arkanoid I and II).
The idea for this project occurred to me while I was implementing the PC Joystick adapter for #Control Freak , and the user @Dave's Dev Lab mentioned that he had 300 IBM PC jr joysticks and I started to wonder if I could use the cheap Digispark instead of the Arduino Micro.
The PC jr joystick, as most of the early PC controllers provides only a couple of axes and two buttons. In other words only 4 I/Os are necessary and that is exactly what Digispark provides.
I could reuse some of the experience acquired during the development of support for paddles in the Atari adapter for my #AVeRCADE board, as long as I did some work to adapt the "raw" environment of V-USB+GCC to the Arduino "framework" used by Digispark.
First thing done was to synchronize the potentiometer reading to the USB interrupts. That can be achieved by putting the CPU to sleep(), and the timing loop will always run after the CPU wake up to service an interrupt. The header is required though.
Second thing to do is ti turn off Timer1. It took me some time to realize that the Timer 1 (instead of Timer 0) was generating unwanted interrupts, waking the micro controller at the wrong time. Some Arduino functions rely on this timer and therefore will not work, most notably the delay( )and therefore theDigispark.delay( ).
Main loop code:
voidloop() {
sleep_enable(); // Prepare CPU to sleep
power_timer1_disable(); // turn housekeeping off
sleep_cpu();
sleep_disable();
if (++interval > 3) { // run once in row of a three
interval = 0;
for (i = 0; i < 150; i++); // 100us delay
doNewSample();
populateValues();
DigiJoystick.update();
}
}
And the result:
Main loop continues right after the interrupts
As the USB interrupts occur 8 ms apart, it is easy to count how many times the CPU woke up and run the loop at the desired sample rate, but the least time interval that I could make it work was 1 out 3 which means 24ms.
The sampling loop was written to run as fast as possible. Inside the loop it is necessary to test if the capacitors have charged and each iteration must take exactly the same time. That was achieved without the use of assembly and the test is performed without the use of the "if" statement. The trick is simple: A variable is initialized at 0 (zero) and added to the state of the bit being tested at each iteration. It is necessary to invert the state of the input bits, though. While the capacitor is being charged and the voltage at its terminals is under the positive threshold voltage, reading the pin will result into Zero which inverted and mask will become 1 and the variable increments. After the voltage exceeds Vih, the variable will be added to 0 and will not increment anymore until the end of the counting cycle. Code is simple as that:
And the result is a counting loop of mere 300us (microseconds)!
The last piece of the puzzle is the calculation of the timing capacitor. The following parameters shall be considered: Charging time: ~310us Potentiometer Resistance for maximum charging time: 100k Ohms Supply Voltage (Vcc): 5Volts Input threshold voltage: Vih = 2.5Volts
The calculation formula is well known
The number crushing can be easily done with the aid of Wolfram Alpha
The closest capacitor value is 4.7nF
Buttons The only two pins left for the buttons are pin 1 and pin 5 and both will require some attention to make them work as button inputs. Refer to the diagram below:
On Digispark boards, digital Pin 1 is pulled down by a 1k Ohm resistor (R2) in series with an LED (D2). One option would be to rework the board and remove the LED or the resistor but another option, less invasive is to use a pull up resistor that provides a resulting voltage above Vih (2.5 as we have seen before) . Tests were performed with 1K and 560 Ohms resistors...
I have just added support for LED status on Digispark Keyboard library.
Now to get the LED status is just a matter of calling the function
DigiKeyboard.getLEDs()
DigiKeyboard.getLEDs()
and test for one of the 3 contants:
NUM_LOCK
CAPS_LOCK
SCROLL_LOCK
Just like in the example
// USB Caps Lock Led gizmo - Danjovic 2020
// Use modified version of DigiKeyboard library// https://github.com/Danjovic/DigistumpArduino/tree/master/digistump-avr/libraries/DigisparkKeyboard#include"DigiKeyboard.h"voidsetup(){
pinMode(1,OUTPUT); // Digistump BuiltIn LED as output
}
voidloop(){
// Check the state of Caps Lock and change led accordinglyif (DigiKeyboard.getLEDs() & CAPS_LOCK)
digitalWrite(1, HIGH);
else
digitalWrite(1, LOW);
DigiKeyboard.delay(10);
}
The modified version of the libraries are available at:
This is another method for providing analog position to Atari 5200 that does not depend upon internal calibration.
The analog controller information is measured by Pokey chip that measures the time a capacitor takes to increase its voltage from near zero to a given value. This time varies with the resistance of the potentiometer axis.
Many videogames and computers, like ATari 2600, PC gameport, Apple][ gameport usually discharges the capacitors right before start a new reading cycle. On these systems is just a matter of waiting for the capacitors to discharge to know when to push the line high to provide a desired position (timing) information.
But in Atari 5200 that is not so easy because Pokey chip keeps the capacitors discharged by until the next sampling cycle that depends upon the game loo, therefore the discharge moment can not be used as a time reference.
The experiments that I have done consisted in:
polarize one of the pot inputs with a resistor that provides a low counting, e.g. 10KOhms and detect the voltage increase before it reaches ~1.9V that is the input threshold voltage of POT pins in Pokey Chip.
Then the line is forced LOW by the time enough to provide the desired counting in Pokey chip.
Finally the line is pushed high to exceed the threshold voltage and that makes pokey capture the exact counting.
Worth to mention that this method does not depend upon internal calibration of Vac voltage (at pin 9).
The links [1][2] are for two videos with the first experiments. The tests have been performed on a AVR (Arduino board) together with the #Atari 5200 Controller Port Emulator
MegaPlay adapter lets you play Atari 5200 using a 6 button Sega Genesis controller yet providing full keypad control.
The circuit can be built using an Arduino Nano and two analog multiplexers. Interface with analog joystick can be borrowed from "Low Priced MasterPlay clone adapter".
Keypad presses can be emulated by activating a pair of analog multiplexers. This scheme allow the simulation of 1 (one) keypress at a time, but frees the software from critical timing.
The Atari 5200 controllers are well known by its low reliability. Many alternatives to the original controllers have rose along the time from when the sytem was being sold on stores up to present days when it is possible to find adapters being produced and sold by members of Atari Age community forums. The adapters found today can be either:
a) analog - based on digital potentiometers or
b) digital - based on switched resistors.
Both change resistance in a RC network that is used by the console to convert a time measurement into positional information.
There are other ways to do it, though:
Applying a variable voltage on a fixed resistor. The charging time depends upon the RC constant for a given potential difference (voltage). That is pretty much how the trackball works.
Detecting the moment the timing capacitor start to charge and hold the voltage low until the correct timing has passed. On the 5200 it is a tricky task, because the capacitors do not receive a pulse (of known time) to discharge. Instead they are held discharged until the CPU generates a pulse internally that releases the charge.
I have figured out the methods above after went through plenty of technical information such as datasheets, books and forum posts. In the meantime I have worked on the design of some alternative controller adapters:
Norris: Adapater for Wii Nunchuck controller.
Provides vertical/horizontal movement plus 2 buttons. - Keypad functions are provided by tactile switches. - Body composed by 3 PCBs stacked on top of each other
Built-in Wii Nunchuck connector on PCB
Wire bridges on PCB to hold game faceplates
Hunter: Adapter for Playstation Dualshock controller.
Provides vertical/horizontal movement plus 2 buttons - Analog sticks can work together or expand to a second connector (for Robotron)
Directional D-PADs work behave like digital controller on Masterplay adapter
Numeric Pad emulated by the controller by pressing L2. Worth to mention that emulating the keyboard can be somewhaty tricky too.
Can emulate behavior of trackball, behaving like the Trackpoint on Thinkpads
Stingray: Adapter for Wii Nunchuck Classic controller
Basically the same functionality of the Hunter
Numeric Pad emulated by the controller by pressing ZL
Built-in Wii Nunchuck connector on PCB
Concept board for StingRay
Second controller (for dual stick games) is connected through P2 Jack. If necessary GND connection wire can be used for one of the triggers of the second controller.
So far the controller adapters I have seen for the Atari 5200 and that can provide analog control use a used a digital potentiomenter (and extra capacitance).
This is certainly a nice solution but there are other alternatives, though:
1) Keep series resistor constant, vary the voltage applied to charge the capactor (just like the trackball do)
That can be done with a PWM providing 0-5V and some resistors in a network to match the desired voltage range. This method is used on the CX-53 trackball.
2) Detect when capacitors start to charge and hold the line down until the desired count, then push the line to +5V
It is a pity that the architecture of the Pokey Chip, used by the Atarti 5200 to read the potentiometers do not discharge the capacitors at the beginning of the sampling cycle but at the end. The only mark of the beginning of the charge is that the voltage over the capacitor starts to ramp up and that can be done by the analog comparator of a microcontroller set to a voltage that is below the minimum Vih (1.9V). Luckly there is plenty of time to react to that, as the pokey counts in Hsync lines (64us ).
I have acquired recently a Hypershot controller for Famicon model JE506. Such controller comes in a pair and share the DB-15 connector to be attached on expansion port.
Given the state of the buttons I wonder if the previous owners were Wolverine and Sabertooth...
Nevertheless I got some reading on NesDev Wiki that pointed that the Hypershot controllers should be read by the console as single switches instead of a stream of data. Such information were confirmed with a multimeter.
The measurements performed were compared with the information presented on the wiki about the JE506 controller. The results show some difference from the JE506 information presented elsewhere on the wiki, considering the pinout of the expansion port presented elsewhere on the wiki. The Common pins for controllers (Out 1 and Out 2) are exchanged, as well as the JUMP/RUN function for both controllers.
After spent some time unsuccessfully looking for precise information about the Mouse protocol used by MSX computers I got a subrom binary to disassemble and take a look.
Mouse reading is performed by NEWPAD subroutine at address 0x1ad but the reading effectively occurs after addres 0x3509:
The Mouse routine reads 6 nibbles (0..5) in sequence, cadenced by the (toggling of) pin 8. Small delay loops are inserted between readings. Both the Mouse and the Trackball reset their internal counters after one edge of the Pulse signal.
The 5h nibble read might be the High order nibble for the Mouse or the delta Y value for a trackball.
Given the typical DPI resolution of the MSX mouse no displacement above 16 steps should be observed, then the expected value for the 5th nibble should be 0b0000 for positive displacement or 0b1111 for negative displacement.
The trackball is a much less resolution device and uses solely 4 bits, nevertheless as the mouse only a small amount of displacement should be observed (zero or one count up/down).
One of the curious aspects of the trackball is that it uses an inverted sign bit, which means "0" displacement is represented by 0b1000, and that is the key for the NEWPAD routine to differentiate a trackball from a mouse.
; Nibble 5: Trackball: Delta Y, inverted Sign bit
; (7) 0111 (-1) minus one
; (8) 1000 ( 0) zero
; (9) 1001 (+1) one plus
;
; Mouse: Delta X high nibble, normal sign bit
; ( 0) 0000 ( 0) Zero
; (15) 1111 (-1) Minus one
xor 08h ; Turn values 7, 8, 9 into 15, 0 and 1
sub 02h ; Turn 15, 0 and 1 into 13, 14 and 15
cp 0dh ; Trackball should greater or equal 13
jr c,returnMouse ; values less than 13
;
returnTrackBall:
....
The brief positive pulse issued after the 6th nibble is read has the purpose of reset the internal Y counter of a mouse, as registers should be read in pairs (4 nibbles).
Sinclai ZX computers (ZX81/Spectrum) don't ship with a joystick port but they can count on the ubiquitous Kempston interface to provide 4 directional lines plus 3 buttons and that is more than enough to connect a Sega Master System HPD-200 paddle controller.
Paddle detection and reading code provided by SMS POWER. I/O address changed to match Kempston (0x1F), though.
A simple hardware adapter is necessary in between the Kempston interface and the HPD-200 paddle
An alternative for the HPD-200 is to build a DIY SMS/MarkIII paddle controller by Raphaël Assénat. In such case the wiring can be modified to route the signals from pins 5,7 and 9 thus dispensing the use of the adapter.
Example code (work still in progress) available at my github repository.
I believe it is possible to add a backporch for ZX97 (original) using three available gates from U25.
D11 discharges the capacitor at each negative horizontal pulse coming from /CSYNC and causes pin 11 of IC25 to go LOW, which blanks the video output signal at U25C.
After the sync pulse leaves R4 start to charge the capacitor. While the voltage is below positive threshold of U25 inputs the video stays blank, thus generating the backporch level. After that the output of U25D goes HIGH and the video content coming from U5B pin 8 can reach the output.
It might be necessary to fiddle with the value of R24 according with the technology of U25 (LS, HC, HCT, etc)
The resistors R1,R2,R3 were calculated to provide full compatibility with RS170: 1Vpp @ 75 Ohms load, 70% Video, 30% sync, DC coupling at output (the latter is a de facto standard).
This circuit have not been tested yet on the ZX97 but works like a charm on TK85 (a ZX81 clone)
One of the users at msx.org tech forums asked if was possible to use Atari 7800 joypads in MSX.
The 7800 controllers are very similar to 2600 and therefore to MSX. The main difference is that to maintain compatibility with 2600 joysticks whilst providing two buttons, the 7800 used active high buttons on pins 5 and 9 which are used in 2600 for paddle inputs.
The straightforward solution is to invert the signals and that can be accomplished by a pair of NPN transistors.
Controller and adapter schematics, side by side, for better understanding.
My version of PCB for "SD2IEC Revisited" from Retrohax (https://www.retrohax.net/sd2iec-revisited/). Hand routed, has basically the same dimensions and can be even built by tone transfer (no vias under components).
Board shared at OSHPARK (link) and at Github (link)
My collection of homemade projects stuffed inside Tic Tac boxes.
From left to right: Pickit2 clone, USBAsp, TicTacX, Arinc429 Sniffer, 32 Shades of GreyPICKit2 cloneUSBAsp Tic Tac XArinc 429 sniffer/analyzer32 Shades of GreyAnother view of the collection
Inspired by #Linear RGB LED Clockby Jan I decided to build my version. Instead of RGB LED addressable strip I'll be using regular LEDs and shift registers.
As I am planning to use the cheap chinese Digispark boards and a minimal of components. Since RESET pin is not available as I/O in most of the cheap boards I have only 5 pins to spare.
Two pins are for I2C communication with the RTC module
Browsing had.io pages I've stepped on the amazing #Zorkduino project wich implements a Z-Machine to play text adventure games (like Zork!).
The original project is very cool but it was build upon some ready made modules and a proto-board, so I've decided to route an specific board for the project named ZorkShield.
The board was designed to allow the assembly of both SD or MicroSD card slots and also allow the assembly of either a P2 stereo jack or a dual stacked RCA female for audio and video.
The video output have been slightly modified so the voltage and output impedance follow the RS-170 standard (like #VGA Blinking Lights). As a late time improvement I've added a RESET button.
Despite the board is a double layer It can be etched at home using tone transfer.
The layout was uploaded to OSHPARK but soon I'll upload it to github.
Today I have received a Microchip news with AVRs on it. That's the first time I ever seen Microchip advertising AVR microcontrollers. Despite the acquisition of ATMEL by Microchip is old news now this ad still blows my mind, lol!!!
Composite video standard defines a signal with 1Vpp amplitude under a 75 Ohms. From that signal 70% (0.7V) is the amplitude of video information which stands above a 0.3V pedestal, while the synchronism information (sync tip) corresponds to the remaining 30% of the total amplitude or 0.3Volts below the pedestal.
Many projects of video
generation for microcontrollers provide video signals that may work
but don't respect the video standard, thus the signal generated might
not be properly displayed depending upon the monitor used.
But generating a video signal with correct amplitude and impedance can be easily accomplished with the aid of resistors and some math.
Consider the circuit topology below where pin named VBIAS generates Sync signals, while VCOLOR pin generates video signals.
With two pins for
generating the Sync and Video information we can have four possible
combinations from which only three are expected: Sync level, Black
(pedestal) and White Level.
We need then to
calculate the value of the resistors wich can provide the following
voltages
Black Level 0.3 Volt @ 75 Ohms
White Level 1.0 Volt @ 75 Ohms
Sync Level 0 Volt @ 75 Ohms
First thing to consider
are the Voh and Vol from the microcontroller. Taking a PIC16F688 as
example such levels can be in the range from VDD-0.7Volts to Voh and
0.6Volts to Vol. It means that our Sync level might be slightly
biased to 0,3Volts under 75 Ohms load (0.6Volts without load).
Our amplitudes must
then be corrected to compensate for the biased Sync level while
maintaining the total amplitude in 1Vpp
Black Level 0.6 Volt @ 75 Ohms
White Level 1.3 Volt @ 75 Ohms
Sync Level 0.3 Volt @ 75 Ohms
Considering the
resulting internal impedance of 75 ohms such values shall be doubled
when no load is present.
Now we have the
necessary information to calculate the resistors. Let us use
Kirchoff's current law: “At any node (junction) in an electrical
circuit, the sum of currents flowing into that node is equal to the
sum of currents flowing out of that node”
Then we have
Considering the
voltages involved we have now the generic circuit equation:
Let us use Conductance
instead of Resistance to make the math easier to deal with
Then for RL=75Ohms,
VOL=0,6Volts e VOH=4,7Volts (PIC Vdd @ 5,4Volts) the equation for
the three possible video levels are:
On the absence of load,
RL = infinity, which means the Conductance is zero. Then we have the
equations for the unloaded circuit.
The 6 equations can be
written as a product of matrices
Using Scilab we can
easilly get the resulting conductances.
Which can be converted
to resistances, resulting in
>x.^-1
Then using the most close
commercial values we have:
Let's now do the
oposite way and check which are the theoretical values we can achieve
using commercial value resistors. Rewriting the equations in terms of
Vout we have:
Then solving for the
possible output levels we have:
Level Vsync Vvideo V Out(@75R) V Out (no load)
Black 4,7 0,6 0,64 1,29
White 4,7 4,7 1,35 2,71
Sync 0,6 0,6 0,17 0,35
Let us now estimate the
output impedance by the ratio of voltages with and without the 75
Ohms load.
Vopen/Vload = 2,71/1,35 = 2,01
Then from Thèvenin:
In plain numbers we
have ri=75 * (1,01) = 75,75 Ohms. Good enough!
The figure below shows
the circuit with final values.
For calculating the resistor values for other microcontrollers and logic gates (TTL, CMOS) it is possible to use the general matrix system below. The green lines correspond to the voltage levels with 75Ohms load while the blue lines are the voltages with open circuit (no load).
Notes:
It is necessary to notice that the pins that drive the resistor must me able to source and sink currents around 25mA, which many microcontrollers can handle. On devices with...
Following a suggestion from [tekkieneet] to rotate the microcontroller 90 degrees and move the push-button to the right edge of the board I have redesigned the layout this time also using Kicad.
I've posted a remark on the article "Creating a PCB in Everything" endorsing the design of single sided PCBs for DIY projects since they are far easier to replicate at home using techniques like toner transfer.
I've then started from original Nanite board and designed a single sided board for it, tinier as possible, using only PTH components.