To: 999 (all members)
From: K6N (Brian Raw)
Subject: Digital Analiser
In an attempt to come up with some
sort of oscilloscope/frequency counter
which is really a hardware job I've had
a go to see just what is possible with
software alone.
There is an oscilloscope program in
the library somewhere but this uses the
analogue port, this being limited by
being sampled every 1/100th of a
second. This is only 100 HZ. So it
seems the user port is more appropriate
being limited by the code length/clock
rate. So frequencies of 10 KHZ or more
may be possible. In order to sample
these kind of frequencies it is
necessary to disable interrupts while
collecting the data re-enabling them,
to display the data.
Although this is not an oscilloscope
program but more a digital display, it
does go some way in tackling the type
of problems in such a program.
Before I send you all to sleep!
I have split the program in two for
those who just want a quick look see!
The first half generates its own data,
a 4 bit binary counter on bits 0-3 and
a clock on bit 7. The user port is then
read and bits 0-3 are compared with
those of the counter outputting :-
bit 4 count > # user port
bit 5 count = # user port
bit 6 count < # user port
The values on the port are normally
high (all 1's) so zero's may be picked
out by linking the pins on the port as
shown
0v 5v
bit 7 6 5 4 3 2 1 0 c c
value 1 1 1 1 1 1 0 0 b b
2 1
Assuming though that first time round
there is nothing on the port the value
will be 1111 so the counter can never
be greater than this so bit 4 will
always be low (0).
You may also notice there is a cursor
which reads the binary value at that
point and is displayed at the top of
the screen. Use the cursor keys to
move this across, noting how the value
changes as you go. When you reach the
blip in bit 5 this should be the value
on the user port.
Now try different values on the port
to see the effect on the output.
Notice also that from left to right
the count is down! If you like, draw
the pattern that counts up. What is the
difference?
There is also a facility to print the
screen if you have a suitable printer.
I think mine is Epson compatible but
I'm not positive, so try pressing P or
p and see what happens on yours.
The second part of the program simply
collects data from the user port
before displaying it. Bit 7 again must
have the clock for synchronisation.
The circuit to produce the outputs of
the simulation data has only 3 chips,
here it is for the enthusiasts:
Circuit Diagram
##### ##### 5v
Rb Ra
##### #####
7
6 8
555
2 Timer
C ####
#### 4
1
3
C
L
O
C
0v K
4,5
14 16
74LS193
8 0v
3 2 6 7
BIT 0
BIT 1
BIT 2
BIT 3
10 12 13 15
BIT 4 5 8
74LS85
BIT 5 6
BIT 6 7 16
9 11 14 1
BIT 7
CLOCK
b0 b1 b2 b3
Hard Wired
Value
Function
The 555 timer provides a TTL
pulse of F=1.44/((Ra + 2Rb) * C) Hz.
A reasonable square wave is produced
if Ra is approximately half Rb.
The values I used were 1500 & 3300
Ohms with a .22 microFarad capacitor
producing about 800 Hz.
This signal is fed to the 4 bit binary
counter which can count up from pin 5
or count down from pin 4.
Each output effectively divides by two,
so the whole chip divides by 16 and
produces a carry signal (high) on pin
12, in my case at 50 Hz.
Pin 14 is the reset and is active high
so needs to be held at 0v for the chip
to work. Outputs are sent to the first
four bits of the user port and on to
the comparator chip.
A value is hard wired onto the four
input pins which are normally high, so
only the 0's need be wired. However,
good practice is to use a 1K0 resistor
to tie the 1's to 5v.
There are three outputs :-
pin 5 count > value port bit 4
pin 6 count = value port bit 5
pin 7 count < value port bit 6
Finally the clock needs to be input
into port bit 7 to give the software
something to sync onto.
The frequency counter facility is
derived from the clock on bit 7. Indeed
any TTL signal within its range should
produce a result.
However, since the code operates on
the signals transition points from 1-0
and 0-1, there is no real accounting
for its mark/space ratio. This then is
the reason for the two counts high
time and low time. The frequency being
the reciprocal of the sum of these two
counts or 1/period.
While the output of bit 7 always
appears a perfect squarewave it could
equally be
or
or even
So the two counts are displayed to
give some idea of the mark/space
ratio.
If you can find some way of connecting
to bit 7 of the user port then you
could try looking at some of the
signals produced by the beeb itself.
Pin40 of the 6845 video chip is the
vertical sync running at 50 HZ, check
it and note the mark/space ratio.
From your results I hope you see that
in order to see this signal properly
you need to feed a clock rate of
higher frequency than that which you
are testing. This put into bit 7 then
sample on a different input comparing
the two should indicate the frequency
present and the mark/space can be
seen better.
Pin 39 of the same chip is the
horizontal sync and brings a different
problem of being too fast. On bit 7 I
read 27.5 KHZ with counts of 1 and 3,
these being too low to be credible.
First feeding the signal through a
divider may help here, but you will
lose the mark/space ratio. I have not
tried this yet myself so it's just a
thought. The program as is, did
however indicate the presence of a
high frequency.