Probably a couple years ago, I tried to
learn FPGA, but didn't get very far, even with high end FPGA boards.
But now, with TinyFPGA, thinking I'll have better luck starting from
scratch with this bare board.
Where to go next? Could do look-ahead
adder. But, looking at some CPU verilog, people just seem to do simple
math for their ALU. So, that 4-bit adder code can be replaced with
just a couple lines of verilog with something like output = input1 + input
2.
Ok, yes this works and is MUCH simpler.
Here are the files. Note: You
may need to add JustAdd.v back into the project for some reason, not
sure what happened, but seems it was removed from project when zipped
up.
Next, we clean up the code by moving
everything to main .v file, removing the counter, and deleting must
unused lines. Files for Step5
here.
Next step is to implement the 74181 in Verilog.
This has been done before, so there is code
to borrow from.
There are some design decisions though.
Think we'll use active high logic (instead of the real ones active low).
Maybe we'll implement all the functions, not just the ones used by
Nibbler.
Ok, going from some C source code on Github,
have implemented the full 74181 in
Verilog. It's really amazing how close Verilog is to C.
Was able to use the P2 to verify that the C code and FPGA are giving the
same output. The original code was using active low logic I/O, but
was fairly easy to switch to active high (except for the carries).
Figured out that since this is all
combination logic, we don't what the outputs to be registers, don't
need an always block, and want to use blocking assignments (using
"=") instead of "non-blocking assignments (using "<="), as is always
the case for combinational logic. See
here for more info.
Next step is to figure out how to the 74173 4-bit
register chips.
One issue is that, apparently, you don't do
tristate inside of FPGA, just at the I/O pins. So, need to use a
4-bit multiplexer to say which chip is driving the bus.
While getting the OUT ports to work,
found an error in the 74173 code regarding the gate enable.
Figured out that the progrom code is eating
up a lot of the slices. Could put it in EBR, but that's a pain as
have to create a .mem file and associated .v file for each program
then... The Guess The Number program just barely fits with 98% of
LUTs used...
Probably easier than erasing and writing
to EEPROM like the real thing though...
Using P2 microcontroller to do interactive
test where it reads a nibble in the IN port and then writes it to OUT0
port, applied to 4 pins where I have LEDs to monitor.
This test assembly code is placed at the
beginning of the Guess the Number code, see test1.asm to see it.
It counts up, then counts down. Then, endless loop of
showing 5 then A then the input.
Next, need to do a more comprehensive test...
Maybe we can do a fake LCD in the Microcontroller and have it show the
screen over serial connection.
Mastermind and Guess the Number examples
work. Waltz plays music, but display is wrong. Frogger
doesn't seem to work, display is wrong.
Had to move Program ROM into IP memory and
reduce RAM to make it fit as other programs were to big.
Changing program files isn't so hard when
you include the .ipx file instead of the .v file for the Program
ROM. Adding as a .ipx file is an option when creating the IP
memory.
Not sure why Waltz and Frogger are giving me
trouble... Think it might be crosstalk between pins, but not sure.
Maybe because these ones have a lot of
audio...
Prop2 is seeing extra nibbles (value
zero) on incoming display input, which get interpreted as end of
line chars I think.
Could break out the oscilloscope and try
to figure out what's going on, but think will just move on for
now...