home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Commodore Free 36
/
Commodore_Free_Issue_36_2010_Commodore_Computer_Club.d64
/
work
< prev
next >
Wrap
Text File
|
2023-02-26
|
7KB
|
240 lines
u
*************************************
Commodore At Work
Daniele Redivo
*************************************
Introduction
In my job I take care of software
configuration for big engines. The
software has to control the engine,
ensuring safe operation and the
correct engine performance. The
software acts much like a human when
driving a car : when the driver wants
to go faster, he just pushes the
pedal deeper feeding more fuel to the
engine, or when the car encounters a
steep ramp, the driver has to push
the pedal deeper in order to keep a
constant speed . Instead of a driver,
a big engine is controlled by
electronic modules, that reading the
speed and the load produced by the
engine shaft, generate an output
signal proportional to the needed
fuel amount.
The idea of an engine simulator came
in summer 2008. At that time I wanted
to develop a tool for testing the
engine software before it would be
actually used on a real engine.
Basically I wanted to have the engine
control modules (ECMs, where the
engine software is downloaded) on my
desk and connect them to something
that would simulate the engine
behaviour, in terms of electrical
signals. I needed three main things:
a hardware interface for signal
exchange with the engine control
modules, a controller for the
hardware interface and a software for
the controller.
I thought that the controller could
be a Commodore 64, I would prepare
the software for it and also built
the hardware interface.
First attempts
In summer 2008 I began doing some
experiments with a Commodore 64 whose
SID was removed. In this way I had
free access to part of the address
bus and the whole data bus,
furthermore I had the read/write and
chip select (for $d400) signals
available. I had one read address for
reading an analogue signal and one
write address for 8 digital outputs.
The analogue input was used for
reading the fuel amount, one digital
output was used for speed simulation
(a square wave) and the other digital
outputs for other signals to the
ECMs. I packed the hardware interface
all inside the C64 and it had a real
nice looking. Unfortunately, I soon
realized that the all-inside solution
was not expandable at all. The more I
went on testing engine control
software, the more signals and
functionalities I needed to simulate.
So I thought I needed something very
flexible, something that would not
require to be re-built in case I
needed further expansion. It came
obvious that the expansion port was
the way to go and that the SID could
be put in its place, producing the
awesome music it had always produced.
After all I hated to have a silent
C64!
Towards an expandable system: the
opto interface cards
In January 2009 I started studying
the expansion port signals and
various datasheets of the available
components on the market. First of
all I built two cards for opto
isolation between the C64 and the
interface hardware: one for signal
from the C64 to the external hardware
and one for the other way around.
Each card is dedicated to reproduce
the 8-bit data bus and part of the
address bus across the opto couplers.
Then the data bus and the address bus
signals are routed through four (two
for each read/write card) ribbon
cables to the other cards of the
interface hardware. In this way the
opto isolators ensure a safe
operation of the C64, any electrical
trouble on the interface hardware
will not affect the C64, also because
the digital part of the C64 works at
0-5V, the interface hardware cards
have several voltages (-5v, 0V, 5V,
15V and 24V). Since there are several
opto isolators (and these draw a lot
of current) I use a C128 power supply
(but I am planning on building my own
heavy duty PSU).
The input/output cards
The other cards I built are dedicated
to:
- 3 channels of 4-20mA output with
8-bit resolution
- 4 x 8 channels of digital outputs
0-24V
- 2 frequency channels with square
wave output 0-15V (range 0- < 4MHz),
16-bit resolution
- 4 channels for 4-20mA reading with
8-bit resolution
The 4-20mA output channels are used
for analogue signal generation, for
example the load signal.
The digital outputs are used for
enabling certain states inside the
ECMs, for example the start and stop
signals. The frequency outputs are
used for speed generation. There is a
big difference with the first attempt
I made. There the speed was generated
using a digital output controlled
totally by the C64, using a NMI for
toggling the digital output high/low
state. Now the C64 sends a 16-bit (2
bytes) value, which is the number of
cycles the card has to count before
it toggles the output. The card has a
4MHz crystal clock onboard and acts
much like a CIA timer. I added a
feature so that the 16-bit value is
not sent to the card counters until
the low byte is written. So a write
to it would be:
lda Hbyte
sta $de17 ;counters still have the
;previous reference value
lda Lbyte
sta $de18 ;now the new 16-bit is
;sent to the counters
This avoids overlapping between old
and new bytes in frequency generation
when writing a new value. Also, I
built it so that in case the 16-bit
value is zero the frequency is
infinite (for simulating zero speed).
The frequency cards are very useful
for generating independent frequency
signals and also for not keeping the
C64 busy with the NMI when toggling
the digital output. The 4-20mA
reading card is used for reading
analogue signals from the ECMs, for
example the fuel amount signal. Each
card has a custom burned EPROM (using
the C64 EPROM burner, what a nice
tool!) used for address bus decoding.
I used the 27c512, which provides 8
chip-select signals per card. Each
chip-select goes to a channel output
and enables its latches for either
reading or writing, except for the
frequency channels, which need two
chip select signals per channel
(16-bit resolution, thus 2 bytes).
The software part
The software has also gone under big
changes and developments. I
originally wrote the software in
assembler for time critical parts and
used BASIC for monitoring what was
going on inside the assembler part,
by PEEKing and POKEing. For this
purpose, BASIC has proved to be
excellent! With BASIC I could just
write a line with a conversion
formula between the 16-bit word sent
to the frequency output and the
engine speed in rpm and get an
immediate result on the screen! But
for time critical stuff BASIC is just
too slow and cannot trigger routines
at a given instant. At the moment the
assembler part of software does a
lot. There are several interrupts
active:
- some $d012 raster interrupt for
splitting the screen for nice
visualization of the speeds
- a CIA 1 interrupt at 50Hz for
reading the keyboard and doing the
math calculations
- BASIC program running in the
background
The engine model implemented in the
software, takes care not only of the
engine itself but also of the
electrical generator usually coupled
with these big engines. Then the
engine model can simulate two engines
running in parallel and feeding the
same electrical network.
=====================================