This is only a preview of the March 2008 issue of Silicon Chip. You can view 32 of the 104 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Articles in this series:
Items relevant to "12V-24V High-Current DC Motor Speed Controller, Pt.1":
Articles in this series:
Items relevant to "A Digital VFO with LCD Graphics Display":
Items relevant to "A Low-Cost PC-to-I²C Interface For Debugging":
Items relevant to "One-Pulse-Per Second Driver For Quartz Clocks":
Purchase a printed copy of this issue for $10.00. |
PICAXE VSM:
It’s Time to PLAY!
In the third part of our PICAXE VSM tutorials Clive Seager
talks us through using some of the ‘virtual instrumentation’
included with the software – from a simple voltmeter to an
advanced I2C protocol debugger!
A
fter you have designed a circuit using PICAXE VSM,
you will naturally want to test it! Fortunately VSM
has a wide range of ‘virtual instruments’ available
for testing purposes. This article assumes you have worked
through the tutorials in parts 1 and 2 of this series, so are
familiar with drawing circuits in the VSM software.
Voltmeter and Ammeter
Voltage and current can be measured in two separate
ways. As an example, open the ‘high command.dsn’ sample file from the /samples/picaxe/commands folder. You
will then need to use the ‘File>Save As’ menu to save
with a different filename so you can experiment and save
modifications to it.
Fig.1 shows the circuit with a traditional voltmeter connected across the LED. When run, the voltmeter will show
the voltage when the LED switches on and off.
An ammeter can be added by deleting the wire between the resistor and PICAXE pin. Right click and select
Place>Virtual Instrument>DC Ammeter. Once dropped,
right click on the ammeter symbol and edit the properties
‘Display Range’ from amps to milliamps. Then draw the
Fig.2: virtual ammeter
added to the circuit.
Remember to change to
mA range!
two wires back in as shown in Fig.2.
When run you will now have a display of both current
and voltage. If you change any of the other component
properties – eg, (changing the ‘Forward Voltage’ of the LED
from 2V to 2.5V or the resistor from 330W to 270W) you
will see corresponding changes in the current.
The second, slightly simpler way of measuring voltage
and current is to just add probes onto any component pin
or wire. To do this, right click, select place and then either
the voltage or current probes (see Fig.3). Once the simulation is run, the probes will show the current or voltage at
the probe position.
Oscilloscope
Fig.1: simple LED circuit
with voltmeter attached.
46 Silicon Chip
On occasions you may wish to trace the voltage or a
signal over a period of time. This is when the virtual oscilloscope is of use
Open the ‘infrain.command dsn’ sample file and re-save
with a different filename. This uses a ‘simulated’ IR LED
and IR receiver (eg, equivalent to the TSOP4840). Two
siliconchip.com.au
Fig.3: right-click the mouse to add voltage and current
probes.
Fig:6: serial terminal demonstration.
channels of the oscilloscope are connected across the LED
output and the receiver output.
When run, the oscilloscope display panel will appear
on screen, showing the trace from the two channels. As
can be seen from Fig.5 the top LED trace clearly shows
the modulating signal, while the receiver trace shows the
demodulated inverted output! The virtual oscilloscope
includes all controls that you would expect to find on a
real device, and so the position, timebase etc can all be
adjusted as you require.
Serial Terminal
This time take a look at the ‘sertxd command.dsn’ sample
file. This demonstrates the ‘Virtual Terminal’ which acts as
an RS232 serial terminal for testing programs with serial
data. When run, the serial data output from the PICAXE
chip is displayed on screen within the terminal window.
As with all serial systems, you do need to set the baud
rate and polarity of the terminal to match the PICAXE settings (4800,n,8,1 [inverted polarity] in this case). This is
carried out by right-clicking on the terminal symbol and
selecting ‘Edit Properties’.
COMPIM
While we are talking about serial communication it
is also worth mentioning the COMPIM (COM Physical
Interface Model). This ‘symbol’ acts as a link between the
Fig.4: two PICAXE chips communicating via a simulated
infrared link.
Fig.5: virtual oscilloscope trace.
siliconchip.com.au
Fig.7: remember to set the serial baud rate and other
parameters, or you will see corrupt characters on screen!
March 2008 47
simulator and the real serial port of the computer. This,
amazingly, allows connection of real serial devices to a
simulated PICAXE chip!
As an example you could connect a serial GPS module
to the serial port of the computer and then have the simulated PICAXE chip parse the NMEA serial data stream!
The ‘COMPIM demo.dsn’ file demonstrates the COMPIM
feature.
Signal Generator
The Signal Generator is demonstrated via the ‘count
command.dsn’ file. When this simulation is run the Signal
Generator control panel is displayed on screen. First make
sure the generator is outputting a square wave (sawtooth,
triangular and sine are also available) of around 5V and
then try adjusting the frequency. The change in frequency
should result in a different ‘count command’ value displayed on the serial terminal.
An alternate, simpler, way of applying test signals to
a wire is to just drop a generator probe onto the wire (as
Fig.10: I2C debugger analysing data written to a 24LC16B
EEPROM
but fortunately the technicalities of the protocols are taken
care of automatically in the PICAXE system, via use, as an
example, of the writei2c and readi2c commands.
Those interested in studying these protocols further may
be interested in the function of the I2C and spi debugger
instruments. For instance, the writei2c command.dsn’ file
demonstrates how the ‘I2C debugger’ instrument is connected to the I2C bus.
When the simulation is run the details of each I2C
transaction – start signal (S), address (AO), data pulses,
ack pulses (A), nack pulses (N), stop signals (P) etc – are
clearly listed in sequence on screen. This makes it an in-
Fig.8: demonstration of the COMPIM feature.
with the voltage and current probes). This is carried out
by right-clicking and selecting Place>Generator.
SPI and I2C debuggers
SPI and I2C are two different communication protocols
used to link ICs together. The protocols are quite complex
Fig.11: I2C debugger trace. This shows the time, and type,
of all activity on the I2C bus
valuable learning tool for those interested in understanding
these protocols.
Summary
Fig.9: virtual signal generator.
48 Silicon Chip
The software also contains a few other instruments such
as a logic analyser – have a play with them! Using ‘virtual
simulated’ instruments will never be quite the same experience as twiddling dials on real-life bench-top models but
using these simulations is still a worthwhile process.
PICAXE VSM incorporates an impressive array of virtual
instruments – and you certainly wouldn’t be able to buy
a new oscilloscope, signal generator or I2C debugger for
anything like the price of a VSM licence!
SC
siliconchip.com.au
|