PICAXE Telephone Exchange Simulator



Automatically connecting a Games Machine or Internet STB, which only has a modem connection, to a Dial-Up Network Server was no easy or cheap task without using a private telephone switchboard, but the low-cost PICAXE Telephone Exchange Simulator changes all that.



This PICAXE Telephone Exchange Simulator is presented "as is" with no warranty or guarantee of operational correctness. The electronic design has not been exhaustively tested but appears to work with the configuration used by the author, but that is no guarantee that the design is sound or that damage will not occur when used with your own equipment. Anyone using the designs or information related to it herein does so entirely at their own risk. No liability whatsoever is accepted by the author.

This project is a work in progress and should be considered as an educational resource rather than as a completed project.

Index

The PICAXE Telephone Exchange Simulator
Important Note - Limitations on Use - Prohibitions
The Exchange Simulator Prototype
Complete Build Plans
Theory of Operation
Electronics
Veroboard Layout and Track Cutting Diagram
Software
Programming the PICAXE
Using Windows 98 SE as a Dial-Up Networking Server
Making It All Work
The Dreaded Dial-Up Networking Crash
Appendix 1 - Project Journal
Appendix 1 - Project History
Appendix 3 - MS-DOS Modem Emulator Software
Appendix 4 - Establishing Line Level Settings


The PICAXE Telephone Exchange Simulator

The Telephone Exchange Simulator is designed to allow connection of any modem device which normally connects to an ISP or other service provider to connect with a local PC through an external modem.

It is a low cost, DIY design which should take just a few hours to construct and get working.

There are many devices which connect to an Internet Service Provider (ISP) through an in-built modem to obtain access to particular services. Games machines such as the Dreamcast connect to online games servers and Internet TV Set-Top Boxes allow web surfing on the household television.

In many cases, such units could equally connect to an in-house PC acting as an ISP, to either bridge the dial-up connection to a high-speed broadband internet link, or to deliver the required services locally.

Pretending to be ( or "emulating" in professional terms ) an ISP is not hard; in most cases all that is needed is a modem and some software which can handle the incoming calls to the modem. Windows, Linux and many other operating systems can act as dial-up network servers, although the facilities offered will depend upon the operating system itself and what other software is installed.

It is the ability to connect one modem to another which presents the problem. You can't connect them back-to-back, one wired directly to the other, because they need to telephone network coneection to make them work.

If you have two independent telephone lines you can dial out on one line to call back in on the other, and it works fine, except that it costs money and isn't a particularly elegant solution, tying up two household telephone lines.

If you have access to an office telephone exchange ( a PBX or PABX ), two separate extension lines can be used to keep the entire inter-connection local, but few households have their own telephone exchanges, they are not cheap to purchase, and they are often overkill for what is needed.

This project is to create a simple telephone exchange which is specifically designed to act as a two line mini telephone exchange, and most importantly of all, to be cheap and easily constructed.

The project is called a Telephone Exchange Simulator because it is not actually a telephone exchange, in fact it is limited to one particular purpose, but to a device that dials-out and expects to be connected to a genuine telephone exchange, it will appear to be one.

Such Exchange Simulators may sometimes be referred to as Telephone Line Simulators but a Line Simulator usually provides dial and other tones, ringing signals and is often designed to be indistinguishable from a public telephone exchange, and as this does none of that, it is presented under the description of an Exchange Simulator.


Important Note - Limitations on Use - Prohibitions

  Under no circumstances must the Telephone Exchange Simulator described here be connected to a public telecommunications system in any way. Doing so will render you liable to prosecution and other penalties. Connection to a public telecommunications system or any private telephone exchange will probably destroy the electronics of this device and may damage the telephone exchange.

The Exchange Simulator is a standalone unit used to connect two standalone modem devices within your own property and must not be used for any other purpose.

The electronics are incompatible with the voltages used and generated by other public and private telephone systems and the Exchange Simulator must not be used in any manner or for any purpose other than described within this document.


The Exchange Simulator Prototype

  At the heart of the Exchange Simulator is the well specified PICAXE-08M, shown in this prototype which differs slightly from the layout presented later. Connecting it all up would probably benefit from having a greater choice of coloured wire to hand.


Complete Build Plans

Complete build plans; circuit diagrams and veroboard layout and track cutting diagrams are available on a single page for convenient printing. Please see the following page for details ...

  PICAXE Telephone Exchange Simulator Build Plans


Theory of Operation

The project is really an attempt to build a telephone exchange in miniature. Although full-blown public and private telephone exchanges are extremely complex, they are based upon incredible simple principles which go all the way back to the very earliest 'plug-in a cord' manual routing exchanges. Although telephone technology has moved on, phones and modems are still compliant with those principles.

A very simple telephone voice link can be established with just a power supply, and a resistor ...

                                      -.- +12V
                                       |
          .--------------.            .|.            .--------------.
        .-|  .--------.  |       330R | |            |  .--------.  |-.
        | `--' `----' `--'            |_|            `--' `----' `--' |
        \   | [] [] [] |               |               | [] [] [] |   /
        /   | [] [] [] |    .---O )----^----( O---.    | [] [] [] |   \
        \___| [] [] [] |===={                     }====| [] [] [] |___/
            | [] [] [] |    `---O )----.----( O---'    | [] [] [] |
            `----------'               |               `----------'
                                      -^- 0V

This is about the simplest 'telephone exchange' one could build; when both handsets are lifted ( 'off-hook' ) users of both telephones can talk to each other. As the resistance on one side of the circuit increases and decreases during speech, the voltage change in the potential divider is reflected in the level of sound produced on the other. It's a bit more involved than that, but that's the general principle, and will suffice here.

Because modems are pretty much telephones hidden inside a box, we can quite easily use the same circuit to connect two modems back-to-back ...

                                      -.- +12V          .-----.
                                       |                |  PC |-----.
        .---------------.             .|.               |     |     |
        |    Dial-Out   |        330R | |             .-^=====^-.   |
        |     Device    |             |_|             `---------'   |
        |               |              |                            |
        |  .---------.  |   .---O )----^----( O---.   .---------.   |
        |  |  Modem  |======{                     }===|  Modem  |---'
        |  `---------'  |   `---O )----.----( O---'   `---------'
        `---------------'              |
                                      -^- 0V

The voltage supply is reasonably non-critical and +12V seems to work okay, with the current drawn being below 30mA. Although it would be nice to use a +5V supply ( convenient for other electronics we will be adding later ), such attempts have not proved successful.

This system works and can be used, but it requires manual intervention on the PC to establish the communications link. The big problem with the simple system described so far is that there is no way for one party to tell the other to automatically pick-up and answer an incoming call. Real telephone exchange systems put a reasonably high voltage AC signal down the line which the telephone detects and uses to ring its bell or activate its warbler. A modem uses the very same signal to detect an incoming call and to send the "RING" message to a PC when an incoming call occurs, and the PC then tells the modem to pick-up and answer the call. Once the call is established, the communications are all under the control of the devices at each end of the line.

Although we do not want to have to add a high voltage AC signal generator to our circuit it is important to see how it would be activated if it were present.

When the Dial-Out Device is idle, it will keep its modem 'on-hook' and draw minimal current from the interface. When it dials out it will go 'off-hook', present a resistance and draw current from the supply. The current drawn can be used by a telephone exchange to detect when a caller has gone off-hook and wishes to place a call and can subsequently be used to route the ringing signal to the required destination.

We can add our own off-hook detection by using a PICAXE microcontroller manufactured by Revolution Education Limited to monitor the analogue voltage of the line linking the two modems together ...

                                      -.- +12V              -.- +5V
                                      .|.                    |
                                 330R | |                .---^---.
                                      |_|    18K         |   5V  |        .-----.
                                       |     ___         |       |        |  PC |-----.
                                       }----|___|---.--->| A2D   |        |     |     |
                                       |           .|.   |       |      .-^=====^-.   |
                                       |           | |   |   0V  |      `---------'   |
        .---------------.              |       10K |_|   `---.---'                    |
        |    Dial-Out   |              |            |        |                        |
        |     Device    |              |            }--------'                        |
        |               |              |            |                                 |
        |  .---------.  |   .---O )----^------------|---------( O---.   .---------.   |
        |  |  Modem  |======{                       |               }===|  Modem  |---'
        |  `---------'  |   `---O )----.------------^---------( O---'   `---------'
        `---------------'              |
                                      -^- 0V

The 18K and 10K resistors form a potential divider dropping the +12V line voltage down to 4.2V, below the +5V the PICAXE is powered from. If a higher line voltage is used, the resistor divider will need to be altered to not exceed the maximum A2D voltage allowed which would destroy the PICAXE.

We are now able to detect when the Dial-Out Device has gone off-hook, and must consequently issue a ringing signal to the PC modem. In reality, we don't; all the modem does when waiting for an incoming call, is to work as an AC ringing voltage detector issuing the "RING" message to the PC when it occurs. If the PICAXE can send the PC that "RING" message it will be unaware that it didn't come from the modem, will assume it has and will consequently tell the modem to pick-up the incoming call and neither are none the wiser.

Fortunately the PICAXE can easily interface to a PC serial line, and can simply be wire-or'd by diode-mixing to the very line that the modem communicates to the PC with. This makes presents an ideal solution, but does require an external modem to be used ...

                                      -.- +12V              -.- +5V
                                      .|.                    |
                                 330R | |                .---^---.        .-----.
                                      |_|    18K         |   5V  |        |  PC |=====.---.
                                       |     ___         |       |        |     |     |   |
                                       }----|___|---.--->|    TX |--.   .-^=====^-.   |   |
                                       |           .|.   |       |  |   `---------'   |   |
                                       |           | |   |   0V  |  |                 |   |
        .---------------.              |       10K |_|   `---.---'  |      |\ |       |   |
        |    Dial-Out   |              |            |        |      `------| >|-------{   |
        |     Device    |              |            }--------'             |/ |      _|_  |
        |               |              |            |                                /_\  |
        |  .---------.  |   .---O )----^------------|---------( O---.   .---------.   |   |
        |  |  Modem  |======{                       |               }===|  Modem  |==='---'
        |  `---------'  |   `---O )----.------------^---------( O---'   `---------'
        `---------------'              |
                                      -^- 0V

Note that the Exchange Simulator is one way only; it will only handle calls made from the Dial-Out Device to the PC, and not the other way round. Attempting to initiate a call out from the PC will trigger the off-hook detection and cause a "RING" message to be sent back to the PC which is likely to confuse the dialling software, and quite possibly corrupt the actual modem responses.

In normal use the potential for the "RING" message to collide with modem responses is minimal as the modem sends nothing when waiting for an incoming call. The worse case would be when the Dial-Out Device hangs up and attempts to place another call while the PC is re-initialising the modem; the Dial-Up Networking Server software should however be able to untangle the mess. It would also be possible for the PICAXE to ignore any off-hook transitions for a time after both go on-hook which will effectively ignore the problem; the Dial-Out Device should report its inability to connect during that time.


Electronics

The circuit uses a PICAXE-08M and its Serial Out connection ( leg 7 ) is used to communicate with the PC. The PICAXE-08M has a huge advantage over the PICAXE-08; it can execute at 8MHz, and permits serial communications of up to 9600 baud.

        BT431A       -.- +12V                                               BT431A
         Line        .|.                                                     Line
        Socket       | | 330R                                               Socket
       .------.      |_|                                                   .------.
   1   | =====|       |                                                    |===== |   1
   2   | =====|-------^-----------.----------------------------------------|===== |   2
   3   | =====|                   |    ___             ___                 |===== |   3
   4   | =====|                   `---|___|---.-------|___|--------.       |===== |   4
   5   | =====|-------. +5V -.-        18K    |        10K         |   .---|===== |   5
   6   | =====|       |      |                |                    |   |   |===== |   6
       `------'       |      |   .---..---.   |                    |   |   `------'
       Dial-Out       |      `---| +V  0V |---|--------------------{   |     Modem
        Device        |      .---| SI  O0 |---|---.                |   |
                      |     .|.  | D4  A1 |---'   |  |\ |     22K  |   |
           .-.        | 22K |_|  | I3  D2 |---.   `--| >|--.---.   |   |
 Download  |O|--------|------{   `--------'   |      |/ |  |  .|.  |   |
         .-|O|-----.  |     .|.  PICAXE-08M   |     1N4001 |  | |  |   |
   Run   `-|O|--.  |  | 10K |_|               |            |  |_|  |   |
           `-'  |  |  |      |                |            |   |   |   |
         Molex  |  |  }------^----------------|------------|---^---^---'
          link  |  |  |      | /|     ___     |      |\ |  |
                |  |  }------|< |----|___|----'   .--| >|--{
       .---.    |  |  |      | \|     1K8         |  |/ |  |     .---.
       |    \   |  |  |       LED                 | 1N4001 |     |    \
1      | O---\--|--|--|---------------------------|--------|-----|-O   \   1      DCD to PC
   6   |   O-|--|--|--|---------------------------|--------|-----|---O |      6   DSR to PC
2      | O---|--|--|--|---------------------------'        `-----|-O   |   2      TX  to PC
   7   |   O-|--|--|--|------------------------------------------|---O |      7   RTS from PC
3      | O---|--'  `--|------------------------------------------|-O   |   3      RX  from PC
   8   |   O-|--------|------------------------------------------|---O |      8   CTS to PC
4      | O---|--------|------------------------------------------|-O   |   4      DTR from PC
   9   |   O-|--------|------------------------------------------|---O |      9   RI  to PC
5      | O---/--------^---.--------------------------------------|-O   /   5      GND
       |    /             |                                      |    /
       `---'             -^- 0V                                  `---'
    9-Way Male D                                             9-Way Female D
     From Modem                                                  From PC

Although not an absolute necessity, an additional 'Diagnostics Port' can be added which allows a PC or other device to monitor the Exchange Simulator's operation through a serial line. The Diagnostics Port can be used to help configure the Exchange Simulator should the default software not operate reliably or correctly with its default line voltage monitoring settings.

                                         .---.
                                         |    \
                                 .-------|-O   \   1      DCD to PC
                    PICAXE       }-------|---O |      6   DSR to PC
                     'D4'  >-----|-------|-O   |   2      TX  to PC
                                 |   .---|---O |      7   RTS from PC
                                 |   |   | O   |   3      RX  from PC
                                 |   `---|---O |      8   CTS to PC
                                 `-------|-O   |   4      DTR from PC
                                         |   O |      9   RI  to PC
                           .-------------|-O   /   5      GND
                           |             |    /
                       0V -^-            `---'
                                     9 Way Female D
                                          To PC

Using a PICAXE-18X

Unfortunately, the PICAXE-08M had not been released when this project was jump-started into life, but the 08M can be replaced by an 18X which has the same capabilities as the 08M.

The PICAXE-18X can be wired to act as the PICAXE-08M as shown in the following diagram ...

              .--------------------.    .---------------------.
              |                    `----'                     |
              |                                               |
            __|                                               |__
        +V |__|-------.-----------------------.   .-----------|__| 0V
              |       |    .------------------|---|-------.   |
              |      .|.   |    PICAXE-18X    |   |       |   |
              |  4K7 | |   |   .----..----.   |   |       |   |
            __|      |_|   |   | A2    A1 |---|---|---.   |   |__
        SI |__|---.   |    `---| SO    A0 |   |   |   |   `---|__| O0
              |   `---|--------| SI    I7 |   |   |   |       |
              |       `--------| RST   I6 |   |   |   |       |
              |       .--------| 0V    +V |---'   |   |       |
            __|       |        | O0    O7 |       |   |       |__
        D4 |__|---.   |        | O1    O6 |       |   `-------|__| A1
              |   |   |    .---| O2    O5 |       |           |
              |   |   |    |   | O3    O4 |---.   |           |
              |   |   |    |   `----------'   |   |           |
            __|   |   |    |                  |   |           |__
        I3 |__|   |   |    `------------------|---|-----------|__| D2
              |   |   `-----------------------|---'           |
              |   `---------------------------'               |
              |                                               |
              `-----------------------------------------------'

The PICAXE-08M software will run without change on a PICAXE-18X wired as shown in the above diagram.

Using a PICmicro

Any PICmicro which is pin compatible with the PICAXE-08 or 08M would be usable, but software development would be more complex, and beyond the scope of most people who aren't programmers, and programming a PICmicro requires more than just a serial cable - The ease of use of the PICAXE development system means the PICAXE can be used by anyone without any programming experience, and is cost free beyond the PICAXE-08M purchase.

The advantage of using a PICmicro is of course much better control over what the software is doing, in particular the ability to code serial communication routines which run at higher baud rates, but the penalty is in having to have the necessary skills to achieve that. It is a valid choice to use a PICmicro for those who can, but it is currently outside the scope of this present design.

UK Line Socket Pinout

The following diagram shows the UK Line Socket pinout when viewed looking into the socket, with the pins at the top. The UK Line Socket and wiring standard is used by all domestic and commercial telephone service providers within the UK.

Most Line Sockets will have six pins, but some may only have four. If there are only four pins, they will be the middle ones, pins 5, 4, 3 and 2.

           6  5  4  3  2  1
        .--------------------.
        |  \/ \/ \/ \/ \/ \/ `.
        |                    .'
        `--------------------'
        UK Line Socket - BT431A

The wiring connections in the circuit diagram are those used within the UK and may need to be changed for use in other countries.

Power Supply

The +12V used for providing power to the telephone line sockets needs to be fairly well regulated and the following power supply circuit is recommended ...

                                              .--------------------------> +12V
                              7812            |        7805
            |\ |           .---------.        |     .---------.
    VUR >---| >|---.-------| I     O |----.---^-----| I     O |----.-----> +5V
            |/ |   |       |   GND   |    |         |   GND   |    |
                 __|__     `----.----'  __|__       `----.----'  __|__
                 ===== 4700uF   |       --.-- 100nF      |       --.-- 100nF
                   |    25V     |         |              |         |
     0V >----------^------------^---------^--------------^---------^-----> 0V

The unregulated input voltage (VUR) can be AC or DC, and should create +15V or slightly more at the inputs of the 7812 and 7805 regulators. The 7V drop across the 7805 regulator is not a problem, as the PICAXE part of the circuit draws very little current. Both regulators can be of the 100mA type and don't require heatsinks.

A Power-On LED ( not shown in the above diagram ) can be added, powered through a 4K7 resistor connected after the rectifying diode.

Parts List

    1 x PICAXE-08M
    1 x 8-Pin DIL Socket
    1 x 7812 or 78L12 +12V Regulator
    1 x 7805 or 78L05 +5V Regulator
    4 x 1N4148 Signal Diodes
    1 x Red LED ( Power On )
    1 x Green LED ( Status )
    1 x 4700uF/25V Electrolytic Capacitor
    2 x 100nF Polyester Capacitor
    1 x 330R Resistor
    1 x 1K8 Resistor
    1 x 4K7 Resistor
    2 x 10K Resistor
    1 x 18K Resistor
    2 x 22K Resistor
    1 x 3-Pin 0.1" Molex Terminal
    1 x 2-Pin 0.1" Molex Link
    1 x 9-Way Female D Socket
    1 x 9-Way Female D Socket ( Optional : Diagnostic Port )
    1 x 9-Way Male D Socket
    2 x UK Single Telephone Line Sockets


Veroboard Layout and Track Cutting Diagram

The Veroboard ( Stripboard ) layout I used is shown below. It may not be the best layout possible, but comes quite close. The board is reasonably densely packed and was entirely laid out by hand. There are no 'dubious connections' and it is quite straight forward to assemble, requiring only a few track cuts.

The veroboard has its tracks running horizontally, has 12 tracks, and 20 columns; 1.2" x 2.0".

The following diagrams shows the component placements and track cuts required as seen from the component side of the board. When tracing the tracks from the component placement diagram, all tracks are continuous except under horizontally mounted components where there is an implied track break ( explicitly shown in the track cutting diagram ), and where a track cut is explicitly marked with a yellow "X".

The solid red and solid grey wires connecting to the left of the board are the two power supply inputs; VUR and 0V respectively. The shaded yellow wire is the diagnostic serial line output which if used should connect to Pin 2 of a Female D connector, with the shaded grey wire, its corresponding 0V, connected to Pin 5 of the same connector.


Software

The PICAXE controlling software is quite simple; at turn-on the Exchange Simulator waits until the modem that will be initiating the call is on-hook, waits for an off-hook detection, sends a "RING" message, and repeats the cycle.

The LED is used to indicate the status; the status indications are described later.

Note that five lines of the source code have been split over consecutive lines to make the program more readable; these lines will have to be concatenated to single lines in order to successfully compile the program if you cut and paste the code presented here into the Programming Editor.

    '   ***************************************************************
    '   *                                                             *
    '   *   PICAXE-08M Telephone Exchange Simulator    PICAXELS.BAS   *
    '   *                                                             *
    '   ***************************************************************

        SYMBOL A2D                     = 1
        SYMBOL LED                     = 2
        SYMBOL TX                      = 4

        SYMBOL LED_PIN                 = pin2

        SYMBOL ledStatus               = w0 ' b0/b1

        SYMBOL lineLevel               = b2
        SYMBOL minLineLevel            = b3
        SYMBOL maxLineLevel            = b4

        SYMBOL onHookCount             = b5
        SYMBOL offHookCount            = b6

        SYMBOL powerOnDelay            = b7
        SYMBOL ringDelay               = b8

        SYMBOL MIN_ON_HOOK_LINE_LEVEL  = 224
        SYMBOL MAX_OFF_HOOK_LINE_LEVEL = 152

        SYMBOL LINE_LEVEL_GAP          = MIN_ON_HOOK_LINE_LEVEL -
                                         MAX_OFF_HOOK_LINE_LEVEL

        SYMBOL LINE_LEVEL_OFFSET       = LINE_LEVEL_GAP / 3

        SYMBOL ON_HOOK_LINE_LEVEL      = MIN_ON_HOOK_LINE_LEVEL -
                                         LINE_LEVEL_OFFSET
        SYMBOL OFF_HOOK_LINE_LEVEL     = MAX_OFF_HOOK_LINE_LEVEL +
                                         LINE_LEVEL_OFFSET

        SYMBOL ON_HOOK_THRESHOLD       = 5
        SYMBOL OFF_HOOK_THRESHOLD      = 5

        SYMBOL LED_STATUS_POWERUP      = %0100000000000000
        SYMBOL LED_STATUS_UNKNOWN      = %0000000011111111
        SYMBOL LED_STATUS_ERROR        = %0011001100110011
        SYMBOL LED_STATUS_RING_DELAY   = %0011111111111111
        SYMBOL LED_STATUS_ON_HOOK      = %0000000000000000
        SYMBOL LED_STATUS_OFF_HOOK     = %1111111111111111

        SYMBOL TX_BAUD                 = N2400 ' 4800 @ 8MHz

    PowerOnReset:

        SETFREQ M8

        LOW LED
        ledStatus = LED_STATUS_POWERUP

        FOR powerOnDelay = 0 TO 100 ' 5s
          GOSUB UpdateLedAndCheckLineLevel
        NEXT

        SEROUT TX,TX_BAUD,("= ",#OFF_HOOK_LINE_LEVEL,
                           "/",#ON_HOOK_LINE_LEVEL,CR,LF)

        onHookCount  = 0
        offHookCount = 0

        minLineLevel = 255
        maxLineLevel = 0

        ledStatus = LED_STATUS_UNKNOWN

    UnknownState:

        GOSUB UpdateLedAndCheckLineLevel
        IF onHookCount  >= ON_HOOK_THRESHOLD  THEN GoneOnHook
        IF offHookCount <  OFF_HOOK_THRESHOLD THEN UnknownState

        ledStatus = LED_STATUS_ERROR

        SEROUT TX,TX_BAUD,("Stuck ")

        GOTO IsOffHook

    GoneOnHook:

        ledStatus = LED_STATUS_ON_HOOK

    IsOnHook:

        SEROUT TX,TX_BAUD,("On",CR,LF)

    OnHook:

        GOSUB UpdateLedAndCheckLineLevel
        IF offHookCount < OFF_HOOK_THRESHOLD THEN OnHook

    GoneOffHook:

        ledStatus = LED_STATUS_RING_DELAY

    IsOffHook:

        SEROUT TX,TX_BAUD,("Off",CR,LF)

        IF ledStatus <> LED_STATUS_RING_DELAY THEN OffHook

        FOR ringDelay = 0 TO 100 ' 5s
          GOSUB UpdateLedAndCheckLineLevel
          IF onHookCount >= ON_HOOK_THRESHOLD THEN GoneOnHook
        NEXT

        ledStatus = LED_STATUS_OFF_HOOK

        SEROUT TX,TX_BAUD,("Ring",CR,LF)

        SERTXD("RING",CR,LF)

    OffHook:

        GOSUB UpdateLedAndCheckLineLevel
        IF onHookCount < ON_HOOK_THRESHOLD THEN OffHook

        GOTO GoneOnHook

    UpdateLedAndCheckLineLevel:

        PAUSE 100 ' 50mS @ 8MHz

        LED_PIN = bit15
        ledStatus = ledStatus * 2 | bit15

        IF powerOnDelay <= 100 THEN InPowerUpDelay

        READADC A2D,lineLevel

        GOSUB UpdateOnAndOffHookCounts
        GOSUB CheckMinAndMaxLineLevelChanges

    InPowerUpDelay:

        RETURN

    UpdateOnAndOffHookCounts:

        IF lineLevel >= ON_HOOK_LINE_LEVEL  THEN GotOnHookLineLevel
        IF lineLevel <= OFF_HOOK_LINE_LEVEL THEN GotOffHookLineLevel
        RETURN

    GotOnHookLineLevel:

        onHookCount  = onHookCount+1
        offHookCount = 0
        RETURN

    GotOffHookLineLevel:

        offHookCount = offHookCount+1
        onHookCount  = 0
        RETURN

    CheckMinAndMaxLineLevelChanges:

        IF lineLevel >= minLineLevel AND
           lineLevel <= maxLineLevel THEN NoMinOrMaxLineLevelChange

    CheckMinLineLevel:

        IF lineLevel >= minLineLevel THEN CheckMaxLineLevel
        minLineLevel = lineLevel

    CheckMaxLineLevel:

        IF lineLevel <= maxLineLevel THEN ReportMinAndMaxLineLevels
        maxLineLevel = lineLevel

    ReportMinAndMaxLineLevels:

        SEROUT TX,TX_BAUD,(#minLineLevel,"..",#maxLineLevel,CR,LF)

    NoMinOrMaxLineLevelChange:

        RETURN

In addition to providing the Telephone Exchange Simulator functionality, the program also provides a diagnostics output on its 'D4' pin ( leg 3 ) which can be used to monitor the operation of the program through an additional serial line.

The diagnostic information is delivered at 4800 baud, and consists of messages to indicate when the modems go on and off-hook and the minimum and maximum Line Levels read which can be used to set the MIN_ON_HOOK_LINE_LEVEL and MAX_OFF_HOOK_LINE_LEVEL constants - see Appendix 4 for further details.

LED Status Indication

The red LED is on when power is applied to the Exchange Simulator. The green LED is used to display the Exchange Simulator's status ...

LED blips-on

    The Exchange Simulator has been powered-up and is waiting for line level voltages to stabilise. This will normally last around 5 seconds.

LED flashing quickly

    The Exchange Simulator has powered-up, and it appears that the dialling-out modem is off-hook. This is an 'error condition' because the PC will not receive any "RING" message. The error condition is cleared when the dialling-out device puts its modem on-hook.

LED off

    The dialling-out device has its modem on-hook. This is the normal state when the dial-out device is turned off or has not dialled out.

LED on, blips-off

    The Exchange Simulator has detected that the dial-out device has taken its modem off-hook, and there is an approximately 5 second delay before it issues the "RING" message to the PC.

LED on

    The dialling-out device has its modem off-hook, the "RING" message has been sent to the PC. This is the normal state when the dial-out device has called the PC.

Diagnostics Information

The information presented as 4800 baud serial data through the Diagnostics Port is as follows ...

= off/on

    This message is presented whenever the Exchange Simulator is powered-up. Both 'off' and 'on' are decimal numbers indicating what values the OFF_HOOK_LINE_LEVEL and ON_HOOK_LINE_LEVEL constants have in the program being executed.

Stuck Off

    This message indicates that when the Exchange Simulator was powered-up it detected that the dialling-out device's modem was already off-hook.

On

    This message indicates that an off-hook to on-hook transition was detected; the modem is on-hook.

Off

    This message indicates that an on-hook to on-hook transition was detected; the modem is off-hook.

Ring

    This message indicates that a "RING" message has been sent to the PC.

min..max

    Both 'min' and 'max' are decimal values indicating the minimum and maximum line level values seen since the Exchange Simulator was poweed-up.


Programming the PICAXE

The PICAXE is programmed through the same serial port connection used to link to the PC when operating as an Exchange Simulator. To enable programming, the Molex Link must be moved to the position furthest from the PICAXE which also disconnects the serial connection to the modem to prevent interference during downloading. If there are any problems during downloading; disconnect the modem's serial cable from the Exchange Simulator.

The PICAXE can be programmed using the same PC serial port as is used during operation or through any other serial port. If the port is the same as that used during normal operation, the Dial-Up Networking Server must be disabled to allow access to the serial port.

To perform the programming, the PICAXE Programming Editor must be launched, the View then Options menu option should be clicked and the processor type set to program a PICAXE-08M at 4MHz, and the correct serial port must be selected.

The program to be executed by the PICAXE should be typed, copied, or loaded ( if already saved to disk ), into the Programming Editor, and downloaded using the PICAXE then Run menu option.

If the program does not download; check you have selected the correct PICAXE processor and operating speed, the correct serial port, and have powered the Exchange Simulator on, and try again.

If the program still does not download; power-down the Exchange Simulator, disconnect the modem's serial cable from the Exchange Simulator, attempt the download again, turning the Exchange Simulator on when the "Looking for hardware" pop-up appears. In PICAXE circles, this is known as a "Hard Reset".

When programming is complete, the Exchange Simulator should be powered-down and the Molex link moved to the position nearest the PICAXE to enable normal operation.


Using Windows 98 SE as a Dial-Up Networking Server

I, and most of those of my friends who use the Windows operating system at home, still use Windows 98 Second Edition - primarily because of its far superior MS-DOS support to that offered in Windows XP. For that reason I am only able to explain configuring the Dial-Up Networking Server ( DUN Server ) as used on a Windows 98 SE based PC, but the principles should be the same for other Windows operating systems.

The PICAXE Telephone Exchange Simulator was originally envisaged to allow a Bush Internet IBX Set-Top Box to connect to a PC so pages served from a local web server could be delivered to the STB. The actual implementation is a bit more complex than that, and uses an own-designed web server to provide a great deal more additional functionality than a traditional web server does. The description here will be limited to getting a Bush STB displaying pages from a standard PC web server, then displaying pages from the internet using the PC as a bridge to an ISP.

The instructions here are given as guidance to people who are unfamiliar with Dial-Up Networking Services but cannot hope to cover all eventualities and possibilities. The instructions should however be sufficient to get most people up and running. If you are running firewall software, then this may need to be re-configured or disabled to get Dial-Up Networking to function as required.

Installing a PC Web Server

If you do not have a web server already installed on your PC you will need to install one. If entering http://127.0.0.1 into your web browser address field returns a "Page not found" or "No such server" error message, you either don't have a web server installed, it is not running, or it hasn't been configured correctly.

If you have a web server installed, configured and running correctly, then it should display a home page ( most likely to be index.htm ). If you know you have a web server installed but the page or server is not found then you need to configure it correctly.

If you don't have a web server installed, then you need to get one. There are numerous web servers available for Windows, many of which are superb pieces of software and entirely free; the web server to be installed here is the SimpleServer:WWW from AnalogX, not because it is necessarily the best or most functional, but because it is free, a small download, and is very easy and quick to configure. It is a very competent offering and is well suited to what we are attempting to do. The web server can be replaced by another at a later time if it is so desired.

Installing the AnalogX SimpleServer:WWW

You will need to download the SimpleServer:WWW installation from the following page ...

Create a C:\DUNWWW directory and download the SSWWWI.EXE executable to it; it is about 200KB and should be a fairly quick download.

When the download completes, run the C:\DUNWWW\SSWWWI.EXE executable. Follow the on-screen instructions and the web server will be installed.

Configuring the AnalogX SimpleServer:WWW

Use Windows Notepad or some other text editor ( not a word processor ) to create a file with the following contents ...

    <HTML>
      <BODY>
        <SCRIPT LANGUAGE="JavaScript">
        document.writeln( "Yippee - " + location.host )
        </SCRIPT>
        <P>
        <A HREF="http://news.bbc.co.uk">BBC News</A><BR>
        <A HREF="http://www.google.com">Google</A><BR>
      </BODY>
    </HTML>

Save the file as INDEX.HTM in the C:\DUNWWW directory - Remember to select "Save as type : All Files (*.*)" or the file will be given a .TXT filename extension not the .HTM it needs to have.

Use the Start Menu and through Programs, AnalogX, SimpleServer and WWW launch the SimpleServer.WWW application - Take care to launch the right application !

Take a look at the top 'button' and make a note of what it says; mine says "http://10.0.0.10/" but yours will probably be very different. The information is needed to test the web server and when we come to configure the Bush Internet Set-Top Box later.

Click the Click here to set web directory button and locate the C:\DUNWWW\INDEX.HTM file. Click OK, then click the Start button of the SimpleServer:WWW application. The web server will now be running.

Enter http://127.0.0.1 into your web browser's address field ( or click the link ), and, after a short delay, you should see the "Yippee" message you placed in the C:\DUNWWW\INDEX.HTM file displayed, followed by "127.0.0.1".

Repeat the process again using the information you wrote down earlier in the address field ( in my case "http://10.0.0.10" ); this should also display the "Yippee" message followed by the numbers specified in the address bar.

Installing a PC Proxy Server

A proxy server acts as a bridge between a device trying to get to the internet and the internet itself; the device which wants to obtain a web page asks the proxy to go and fetch it for it and then hand it over. This avoids all the complexities of what is known as "routing", although it does not offer the same level of capabilities as a proper software router would. A proxy server is however good enough to demonstrate the capabilities that can be enabled.

The proxy server we shall be using is another free offering from AnalogX, again, not because it is necessarily the best or most comprehensive but for the very same reasons we used their web server; because it is free, a small download, is very easy and quick to configure and does the job it needs to.

Installing the AnalogX Proxy Server

You will need to download the proxy server installation from the following page ...

Download the PROXYI.EXE file into the C:\DUNWWW directory we created for the SimpleServer:WWW; it is about 300KB and should be another fairly quick download.

When the download completes, run the C:\DUNWWW\PROXYI.EXE executable. Follow the on-screen instructions and the proxy server will be installed.

Configuring the AnalogX Proxy Server

Use the Start Menu and through Programs, AnalogX and Proxy launch the Proxy application - Take care to launch the right application !

Ignore the warning message for now, click OK. If the proxy server minimises itself to the System Tray, right-click upon it and select Configure to bring up the configuration options ...

Set the configuration as shown above, click the OK button, and the application will be minimised; it will return to the System Tray and run in the background. That's all there is to it.

Configuring the Bush Internet Set-Top Box

The instructions provided here are for the Bush IBX-100 but should be applicable to all versions manufactured, including those produced for OEM's such as Freeserve, Virgin and Nationwide Building Society. It is assumed that you are familiar with using the remote control or remote keyboard, entering and selecting options; if not, a read of the user manual or a bit of guesswork goes a long way.

Connect your Bush IBX STB to your TV, turn it on, and press the yellow "Internet" button on the remote control. The opening navigation screen should appear showing "World Wide Web" and "Options" images. Use the remote control cursor keys to move to select the "Options" graphic ...

Press the "Select" button, and the option menus will appear. Use the cursor keys to move to the "Telephone" image. Press the "Select" button and the telephone dialling options will appear ...

Use the remote control cursor keys to select the options required ...

    Tone or Pulse Dialing : Tone
    Use Dialing Prefix : No
    Wait for Dial Tone : No

When the options have been selected, use the cursor keys to move to the "Complete" image, and press the "Select" button again. This will return you to the options menu again.

Use the cursor keys to move to the "Timeouts" image. Press the "Select" button and the timeout options will appear ...

Use the cursor keys to select the timeout required. "Off" will leave the STB on-line until instructed to turn off and is the preferred option. The others will set an idle time after which the STB will automatically hang-up its modem. While important when paying for outgoing calls, a timeout need not be specified unless you want to.

When the desired timeout has been selected, move to the "Complete" image, and press the "Select" button again. This will return you to the options menu again. Move to the "Complete" image if not automatically selected, and press the "Select" button again. You will be returned to the main navigation screen.

Now things get a little awkward; we have to access the secret ISP configuration menus.

Access to the secret menu is through the use of a code sequence which is entered when the main navigation screen is displayed. Although the access code changed at times, some of the control codes which have been identified, are in common use, and have been reported to work by a large number of people are as follows ...

IBX-100 / IBX-101     IBX-200       IBX-250       IBX-260      ITV8401

    39d8sk43k2       fk39x39662    4927dkan93    12603belt    86ilm37924
    25fh5n66as
    81fhm29421
    86ilm37924
    muf1312129
If none of the codes appear to work, you will have to try the more complex mechanism of gaining access to the Service Provider configuration menus described on the Bush IBX page.

Once the correct code has been entered, the Service Provider Screen will be displayed ...

Select the "Change Details" image and press the "Select" button. This brings up the first of three ISP configuration screens ...

Set the entries as shown below but for the "Home URL" enter the numbers which were shown by the SimpleServer:WWW earlier. Include the "http://" prefix, but do not include a trailing forward-slash. The "0800" telephone number is set to give a delay when the STB makes its out going call and to make it safe should it be connected to an external telephone line by mistake.

    ISP Name : bushstb
    ISP Telephone Number : 0800
    User name : bushstb
    Password : bushstb
    Home URL : http://10.0.0.10 - See above text !

The "Password" will be masked on entry, so take care when entering it, and count that the correct number of characters have been typed.

When the required details have been entered, move to "Next" and press the "Select" button. This will bring up the second ISP configuration screen ...

The first three settings are not particularly important for basic web browsing but may cause problems with the STB software if not provided, and the two DNS settings may be important if you are using a 'proxy server' to bridge to the internet through the PC; you will have to determine what these should be for yourself. The "Dial script" must not be changed unless you know what you are doing, and even then it should not be necessary to change it. My STB was previously used on an NTL service and has the following settings, which should be usable by anyone ...

    ISP domain name : ntlworld.com
    Primary DNS : 194.168.4.100
    Secondary DNS : 194.168.8.100
    Dial Script : "\nATZ\n" "OK\nAT&C1&D ... NECT\n\n" "\n\n"

When any changes required have been made, move to "Next" and press the "Select" button. This will bring up the final ISP configuration screen ...

For basic web browsing all entries on this screen should be deleted except the entry for the HTTP proxy server, which, as with "Home URL" above, needs the numbers which were shown by the SimpleServer:WWW entering. This time, just include the numbers, no "http://" prefix, and again, do not include a trailing forward-slash, but add ":6588" at the end ...

    E-mail URL : 
    Search URL : 
    Time server : 
    HTTP proxy server : 10.0.0.10:6588 - See text above !
    FTP proxy server : 

With the entire configuration completed, move to the "Confirm" image and press the "Select" button. The Service Provider configuration ( using your PC as an ISP ) will be stored in the STB's non-volatile memory so it will be restored after being powered-off and you will be returned to the main navigation screen.

The Bush STB is ready for connection to the PC server.

Configuring the PC's Modem

Launch Control Panel, click Modems, then click the Add button to start the installation of a modem which will communicate at the same baud rate as the PICAXE will be using.

Tick the Don't detect my modem; I will select it from a list checkbox and click the Next button. Select Standard 9600 bps Modem regardless of what modem you actually have, and click Next. Select the serial port to which the modem is connected and click Next again. When Windows has installed the modem, click Finish.

When back at the Modem Properties page, select the Diagnostics tab, select the Standard 9600 bps Modem, and click the More Info button. After a short while, information relating to the modem should be displayed; this indicates the modem is working correctly and Windows has it properly installed. Click the OK button, then Close the Modem Properties window and Control Panel.

Installing the Dial-Up Networking Server

Use the Start Menu and through Programs, Accessories and Communications launch the Dial-Up Networking application.

Click the Connections menu, and if the entry at the bottom of the drop-down menu list is "Dial-Up Server" then the Dial-Up Networking Server is already installed.

If Dial-Up Networking Server isn't installed, then launch Control Panel, click Add/Remove Programs, and then select the Windows Setup tab. Double left-click the Communications option, tick the Dial-Up Server checkbox and click the OK button. Click the OK button of the Add/Remove Programs Properties window and the Dial-Up Networking Server will be installed.

Configuring the Dial-Up Networking Server

Use the Start Menu and through Programs, Accessories and Communications launch the Dial-Up Networking application.

Through the Connections menu option select Dial-Up Server.

When the dial-up server screen appears, the first thing to do is to select the tab for the Standard 9600 bps Modem, then select the Allow Caller Access option ...

Next the password must be set. Click the Change Password button, leave the Old Password field blank, and enter bushstb in the New Password and Confirm Password fields, then click OK.

Click on Server Type to configure the link protocol ...

The PPP: Internet, Windows NT Server, Windows 98 option should be selected, the Software Compression checkbox should be ticked and the Require Encrypted Password checkbox unchecked.

When configured, click OK, and OK again to place the DUN Server into the System Tray where it will run in the background.


Making It All Work

Connect the Bush STB to one of the telephone line sockets, and the modem to the other; it doesn't matter which goes to which. Plug the modem into the Exchange Simulator, and also connect that to the PC. Power-up the STB ( and of course your television ), the modem and the Exchange Simulator.

Start the SimpleServer:WWW web server running on your PC - make sure you press the Start button and check that you can access it through your PC web browser, and minimise it to the System Tray.

Launch the Dial-Up Networking Server, select the Standard 9600 bps Modem and enable incoming calls.

Use your STB's remote control to connect to the World Wide Web, sit back and watch as it dials out, connects, verifies and delivers a page from your PC ...

The first page to be displayed will be the "Yippee" one delivered by the local web server, and following the two links should bring up the BBC News home page ( which cleverly works out we have a "Low Graphics Mode" browser ), and the Google search site delivered through the Proxy Server ...


The Dreaded Dial-Up Networking Crash

When using Windows 98 SE, there is an annoying tendancy for Dial-Up networking to crash if it can't establish its link to the modem, with the result that when continuing to use Dial-Up networking, everything appears to be dead, even though Windows' reports indicate that things are working as they should be.

The problem often occurs in particular when allowing caller access to the DUN Server when the modem is not connected or powered off, and when the programming Molex link on the PICAXE Exchange Simulator is in the Download rather than Run position.

The problem usually identifies itself with a pop-up indicating that Dial-Up Networking was unable to connect to the modem or the modem failed to respond properly ...

It would be expected that acknowledging the message and closing the DUN Server down when using that would be enough to put Dial-Up Networking into a state where further attempts to use it would be successful once the underlying problem is rectified, but not necessarily. Further attempts to use Dial-Up Networking may report successful operation when the modem is unconnected or even powered off. Needless to say, it can be very frustrating to tell what's going on if you are imagining that Dial-Up Networking is working properly and doing its job.

If, after getting a Dial-Up Networking error, closing the DUN Server Down if using that, you press Ctrl-Alt-Del once ( twice and it will re-boot your machine, losing all data you've been working with ! ), you should see the Task Manager window appear ...

If "Rnaapp" is lurking in the task list, then Dial-Up Networking has most likely crashed. The "Rnaapp" task can be forced to end, but it will not necessarily resolve the problem. There is often no alternative but to re-boot the PC, while singing the praises of Microsoft's software.


Project Journal

As indicated at the start of this document, this is a work in progress, and the following is a brief 'journal' on the development of the Exchange Simulator development. If you're under the age of 30, you'll perhaps prefer to think of it as a "Blog".

8th July 2004

An idea which has been floating around in my head for a long while ( over two years ) suddenly finds the impetus to flower into reality.

Day one is spent tracking down all my notes on telephone systems and getting up to date with information relating to telephone interfacing on the internet. The Bi-Directional Telephone Line Simulator remains as probably the best telephone exchange / simulator projects I have seen on the internet and is a highly recommended resource for anyone embarking upon such a project. A more recent project from Silicon Chip Magazine is a PICAXE Controlled Telephone which works along similar grounds.

Despite an intensive search, not one web page or datasheet I could find suggests or supports my idea that it is possible to build a voice path using two ( or more ) telephones in parallel with a single resistor pull-up; all use either capacitor or transformer coupled interfaces, or have the two telephones in series.

9th July 2004

The day is spent producing the first pass of this web page describing the project, creating circuit diagrams and working out pin connections for the various sockets.

10th July 2004

A day off, doing things other than electronics. That does not mean that project thoughts are not floating around in the back of my mind; the concerns I have as to whether my proposed design will work, or be a catastrophic failure, are not easy to allay, as, although a software engineer by profession and familiar with digital electronics, I'm virtually an amateur when it comes to analogue electronic design.

11th July 2004

It is disconcerting and nagging at me that no one else has used such a simplistic system to link two telephones together; either it's been tried and it didn't work, and was therefore not worth documenting, or no one has ever thought of trying it, and have relied upon existing designs using the telephones in series.

Armed with a variable voltage power supply, a dual telephone line socket connector, a 330R resistor and two analogue telephones, it's time to find out if my idea works or not.

A single analogue phone works okay; noise picked up by the mouthpiece can be heard in the earpiece, and dialling DTMF tones can be heard clearly. The setup draws about 10mA at 9V when off-hook, nothing measurable when on-hook. A meter across the phone shows 9V when on-hook, dropping to about 6V when off-hook. Two phones together work just as well; speech from one being heard in the other and dial tones passing over clearly. The current rises to around 13mA when both are off-hook.

Time to step into dangerous territory and put 'expensive hardware' into the circuit. A Bush Internet Set-Top Box is connected to the Exchange Simulator in parallel with a phone. When the STB dials-out, the modem signals can be clearly heard. When again connected to a real telephone line, the STB continues to work as expected, so no apparent damage done.

The phone is replaced by a PC modem; the real 'fingers crossed' test, as anything amiss could potentially destroy the modem. A dial-out from the STB is initiated while Windows Terminal is used to talk directly to the modem. Issuing an "ATA" command causes the PC's modem to pick-up the incoming call, and the familiar inter-modem whistling and wailing is heard. The elastic band sounding 'boing' encouragingly confirms that high-speed communications are being established and soon the PPP link establishment packets sent from the STB appear on the Terminal display - Success !

Various trials were attempted in an effort to use 5V for the telephone line supply, but with no joy at all below 7V or so, even with a reduced resistor value; the two modems seemed to get themselves into a tangle with much annoying wailing from them, and gnashing of teeth elsewhere.

It's disappointing that a single 5V supply can't be used, but it's really a minor inconvenience with little cost impact. The big news is that the one resistor pull-up idea works, or at least does for me.

12th July 2004 - Early Morning

Can a Windows Dial-Up Networking Server ( DUN Server ) be fooled into responding to a "RING" message that's faked to appear as if it's coming from a modem ? It is fundamental to the project design but it's an untested idea. Time to find out.

The easiest way to try it is to wire the PC's two serial ports back-to-back, start up the DUN Server and use Windows Terminal to send back "OK" replies to any commands sent to the modem, and when that's all done, send the magical "RING" message and see if an "ATA" ( Answer ) command gets sent out. Running two copies of Windows Terminal should be enough to check the loop-back works in both directions before firing up the DUN Server.

The idea was fine but the reality wasn't; whatever Windows Terminal does, it didn't work on my system when the DUN Server ran, but resorting to writing an MS-DOS Modem Emulator ( see Appendix 3 ) showed the project's principle to be solid and revealed that DUN Server does work as expected, although it doesn't seem to care about Carriage Returns after the "RING" message.

One thing the testing did show was that when the DUN Server was instructed to use a Standard 2400 bps Modem, it still insisted on communicating with it at 9600 baud. This appears to mean that the PICAXE-08 is unusable with the configuration as its maximum serial transmission speed is limited to 2400 baud.

12th July 2004 - After Some Sleep, The Afternoon Arrives

The joys of writing configuration instructions are upon me. It is only when you start to write instructions on how to do something which is second nature because of previous experience that you realise what a steep learning curve there is to becoming truly computer literate.

Although those of you reading this page probably have a good idea of what you want to do with the configuration described here, it is guaranteed that many of you have never tried to do anything like this before, and aren't sure where to start. Trying to guess at reader's technical capabilities and prior experience is incredibly difficult, and the best I can do is offer some comprehensive instructions on how it should all happen and hope it goes as well for you as it did for me. There are far too many possible problems along the way to list and account for - typing the wrong IP address into my browser kept be mystified for an hour until I twigged what the stupid mistake was - but hopefully the instructions will be good enough for the great majority of people who want to give the project a spin.

Even with enthusiasm, there's only so much writing anyone can do at a time, and especially so when there are electronic designs to play with; testing with a real modem beckons.

With a PICAXE development board loaded with an 18X and a serial Y-lead built with the diode mixing required for the transmit to PC line it's time to see if the project works with everything connected and the PICAXE generating the "RING" message with a push of a button.

And yes it does - and brilliantly so too. The Bush STB is instructed to fetch a page from the PC's local IP address, it takes its modem off-hook, the PICAXE button is pushed, the "RING" message is sent, the DUN Server springs into action, answers the incoming call and establishes a connection, and to great relief the expected page is displayed on my television.

13th July 2004

After a long but fruitless task of trying to make the DUN Server actually communicate with a 2400 bps modem at 2400 baud ( to enable the use of a PICAXE-08 ), it's back to the grind of documentation and other distractions, such as tidying up the house; it's amazing just how much mess 'Rapid Development' can create, with bits of cut wire and potential components accumulating in many nooks and crannies.

With tidying up out of the way, it's on to the tortuous task of creating a veroboard ( stripboard ) layout and track cutting diagram, which can then be turned into a graphical image to be published as part of the documentation.

The task is invariably harder than imagined, with blind alleys, mistakes and a great deal of tweaking involved. Like a great work of art, it's sometimes hard to tell when you've got a satisfactory result, and say "it's done". With the circuit compressed into just over 1" x 2" without any 'dodgy dealings' it has been quite a success, and the effort put in has been well rewarded.

With a veroboard design complete though, it means realistic and representative hardware can be constructed, and any circuit and veroboard layout and tracking errors identified.

15th July 2004

It's been ages since I've reconfigured a Bush STB ( mine has been running through a genuine private telephone exchange for over two years ), so time to get the notes out and wire it all up for video capture to get some screen shots to explain it properly.

It also seemed sensible to get some 'web proxy' software running and the STB configured to use it at the same time.

That was fun, more involved than expected, and revealed a tendency for the STB to hang up its modem while waiting for pages to be delivered through the proxy. I suspected a problem with the proxy of firewall configuration, but bumping the line voltage up to 12V seems to have cured the problem; the connection stayed up for a number of hours and hadn't failed when I disconnected it by choice.

16th July 2004 - Early Morning

A nightmare of a morning, the sort which makes you wish you'd gone to bed before doing "just one more thing".

What's the worse thing that can happen when you've been running your modem through potentially dodgy electronics ? You find you can't dial out to the internet and use it to upload web pages.

The "Not Responding" messages pile-up as soon as the modem goes off-hook. Sometimes it dies immediately, sometimes it connects to the ISP only to have the username or password rejected, and all accompanied by an unuseful error message; "The other computer disconnected you. Double-click to try again", and everything's compounded by the dreaded Dial-Up Networking crash, with the Dial-Up Networking 'Rnaapp' application lurking rogue-like in the background having failed to terminate itself appearing to interfere with further attempts to dial-out.

The first thought, that I'd burnt the modem out, turned out to be unfounded after a bit of experimentation - it all works fine with the Y-lead interface being used for the Exchange Simulator unplugged. So there are one of two possibilities; there's a short or break in the lead, or it doesn't like the high speed ( 57600 baud ) being used to talk to the modem when the Y-lead is in place.

My money's on the latter, as it still works fine as a DUN Server at 9600 baud using the Standard 9600 bps Modem, when a lead fault would also be expected to generate an error.

Forcing the modem to only use 9600 baud and it's absolutely perfect; panic over, no damage done beyond paying connection charges for abortive calls to various ISP's. But it does pose interesting questions as to; why ( I guess it's the diodes leaving the serial line floating, ringing, or slugging the signal, but I don't own a 'scope to look at what is actually happening ), what, if anything to do about it, and what the baud rate limitations are now and with any potential fixes in place.

Time for further investigations later in the day - hopefully something as simple as a pull-down resistor from the diode-mixing point will do the job - the weird thing is, I am convinced I tested this early on in the project's development.

16th July 2004 - Daylight

Baud rate it is. The modem works fine at up to 38400 baud, but the jump up to 57600 is just too much. As hoped for, a 22K pull-down to 0V solves the problem, at least for 57600 baud, and hopefully beyond.

Thinking back, I did test the serial link with the Y-lead in place, but with the modem connected as the "Standard 9600 bps Modem" - ce'st la vie !

Time for an update to the circuit diagram, layout and a trip to the component supplier to buy the bits of hardware I don't have.

17th July 2004

I now have all bit one component ready to build a prototype. Unfortunately the missing component is the 4V7 zener diode to protect the PICAXE from any excessive line voltages.

Although the design should work safely without the zener, it's better to be safe than sorry, especially as the current test bed is a rat's nest of wires. This will introduce a short delay to the proceedings while I obtain a suitable zener, but it will give me a chance to look at some of the other projects I'm working on.

18th July 2004

One prototype built, and almost working too.

Having a zener in my hand proved to be a bad move. Whatever the problem, the 4V7 zener seemed to be clamping the voltage into the PICAXE at less than 3V. Checking resistance values meant having to unsolder some components, and by the time I'd re-assembled the board, I'd lost the zener, somewhere on the floor - I knew I should have bought two. The voltages present are within specification anyway, so it's now removed from the circuit and layout.

One thing that clouded my vision by developing with a PICAXE-18X instead of the target 08M is the maximum serial baud rates allowed. The 18X allows user serial rates of up to 9600 baud, but the 08M using SEROUT is limited to 2400 baud at 4MHz, 4800 baud at 8MHz; the only 9600 baud communications being serial output using SERTXD. The original choice to use the Serial Out ( leg 7 ) and SERTXD probably reflected this. Unfortunately, this means the diagnostics port can only be run at 4800 baud, not the 9600 originally envisaged, but it is not a major problem for this project.

19th July 2004

With the prototype complete and tested, it's time to put everything together and make sure it works in anger.

And it does. A delay between detecting the dial-out modem going off-hook and the "RING" message being sent was added to stop the two modems getting themselves into a tangle and stuck in a symphony of cacophony as they negotiated the connection, and the on-hook and off-hook transition state code was improved upon to create a much more robust solution and to provide better Diagnostic Port messages.

Although only tested through a 15V regulated supply and not a mains transformer or wall-PSU, it all works fine. Any problems with an unregulated supply will probably be due to ripple, which should be easily fixable.

20th July 2004

Revolution Education Limited announce the launch of the PICAXE-08M ahead of schedule. It'll soon be time to put one in the prototype and check it works okay.

Future Plans

The Exchange Simulator has to be tested with a PICAXE-08M when I get one in my grubby mits, but is not envisaged that there will be any changes required, so the only things left now, is to test the Exchange Simulator on other systems, complete the documentation and get someone to work through it to check its accuracy, and give further examples of using the Exchange Simulator - configuring a Dreamcast web browser, and getting it to download games and mini-applications into a Dreamcast's Visual Memory Unit is one particular area I'd like to cover.

I wouldn't like to put a timescale on when any of this is likely to get done though !


Appendix 2 - Project History

This is a brief list of all the changes and modifications which have had to be made during the project development. It should hopefully help anyone else who wishes to develop their own version of the Exchange Simulator; it's always handy to know what pitfalls may await and have potential solutions to hand.

The Line Voltage was increased from an initial +9V to +12V

    With only 9V, the modem had a tendancy to drop out after only a short period of connection.

A 22K pull-down was added to the diode-mixed serial to the PC

    Without the 22K pull-down, the modem and PC failed to communicate reliably above 38400 baud.


Appendix 3 - MS-DOS Modem Emulator Software

The following program connects its serial port to the serial port a modem would normally be connected to and is used to emulate that modem and display data that is received. It is used to see what commands are sent when Dial-Up Networking Server is activated.

The program reads commands sent to the modem using "AT" commands and replies with "OK" to each. Pressing the "R" key sends a "RING" message out, and pressing "Q" terminates the program. The program is written in FirstBasic / PowerBasic.

        PORT$ = "COM2:9600,N,8,1"

        OPEN PORT$+",RS,DS" AS #1

        ON ERROR GOTO TRAP

        DO
          WHILE LOC(1) <> 0
            C$ = INPUT$(1,1)
            IF C$ = CHR$(&hD) THEN
              PRINT
              PRINT#1, "OK"+CHR$(&hD);
            ELSE
              PRINT C$;
            END IF
          WEND
          K$ = UCASE$(INKEY$)
          IF K$ = "R" THEN
            PRINT#1, "RING"+CHR$(&h0D);
          END IF
        LOOP UNTIL K$ = "Q"

        CLOSE#1
        SYSTEM

    TRAP:
        RESUME NEXT

The following interaction is observed by the modem emulator ( "OK" responses and "RING" message not shown ) ...

    Caller access allowed ...

        AT
        ATE0V1
        AT
        ATS0=0

    DUN Server waits for "RING" message ...

    The "RING" message is sent ...

    DUN Server instructs modem to answer the incoming call ...

        ATA

    PPP link establishment packet data sent from DUN Server

    PPP link establishment fails ...

        AT
        ATE0V1
        ATH
        ATZ
        AT
        ATE0V1
        AT
        ATS0=0

    DUN Server waits for "RING" message ...

    Incoming calls disallowed ...

        ATZ

The "AT" commands are presumed to be there to force the modem to the correct baud rate ( modems use auto-baud rate sensing ) and to illicit "OK" messages from the modem to confirm its correct operation. The "ATS0=0" command instructs the modem to issue a "RING" message when the first ringing signal is received. The "ATA" command instructs the modem to answer the incoming call. The "ATH" instructs the modem to hang-up the call. "ATZ" and "ATE0V1" are used to set the modem into the mode required by the DUN Server; Factory Default, No Echoing of Commands Sent, and Low Speaker Volume.


Appendix 4 - Establishing Line Level Settings

Line Level Settings ( the values required for the MIN_ON_HOOK_LINE_LEVEL and MAX_OFF_HOOK_LINE_LEVEL constants in the PICAXELS.BAS program presented earlier ) can be determined by monitoring the diagnostic output from the program. This is a serial transmission at 4800 baud through the Diagnostics Port if fitted, or from Leg 3 of the PICAXE.

The Telephone Exchange Simulator program ( PICAXELS.BAS ) should be downloaded and then powered-up with two analogue telephones connected with either both on-hook or with just one off-hook.

Ignoring any "On-Hook" and "Off-Hook" messages, the line voltage data is returned as two decimal numbers; the minimum and maximum values read from the telephone line socket line since started, so the program needs to be run twice for both on-hook and off-hook situations. To restart the program, turn the power off and then back on.

Run the program for a short while in both situations, and record the range of readings obtained. Talk and shout down the phone when off-hook, and press the dialling keypad to ensure the voltage changes caused are noted, although they may well be too small to register on some phones. Note that the levels are only transmitted when a change in reading is detected.

Take the lowest reading obtained when on-hook, this is the MIN_ON_HOOK_LINE_LEVEL and take the highest reading obtained when off-hook, this is the MAX_OFF_HOOK_LINE_LEVEL.

These two values should be entered into PICAXELS.BAS program using the Programming Editor and the new program downloaded into the PICAXE.

The program itself will determine the gap between these two readings and will create two offset points from the on-hook and off-hoook values to create two points which are then used to determine if the modem is on-hook or off-hook ...

                              MIN_ON_HOOK_LINE_LEVEL - MAX_OFF_HOOK_LINE_LEVEL
        LINE_LEVEL_OFFSET  =  ------------------------------------------------
                                                     3

        ON_HOOK_LEVEL   =  MIN_ON_HOOK_LINE_LEVEL - LINE_LEVEL_OFFSET

        OFF_HOOK_LEVEL  =  MAX_OFF_HOOK_LEVEL + LINE_LEVEL_OFFSET

The Dial-Out Device modem will be deemed to be on-hook when the voltage read is greater than the ON_HOOK_LINE_LEVEL and off-hook when lower than the OFF_HOOK_LINE_LEVEL - Note that the voltage drops when going from on-hook to off-hook.

The software continually tracks the line voltage so any small 'glitches' which make the modem appear on-hook when it is off-hook, and vice-versa, are ignored.


Line Voltage Readings
  The image shows the voltages read at the Line Socket when the phone is on-hook ( left-hand side ) and when off-hook ( right-hand side ). The two grey bands show the range of voltages read in both cases, and the upper blue line marks the determined ON_HOOK_LINE_LEVEL, and the lower green line marks the determined OFF_HOOK_LINE_LEVEL. When the voltage is continuously above the blue line the phone is deemed to be on-hook, and off-hook when below the green line.


PICAXE is a trademark of Revolution Education Ltd. Windows is a registered trademark of Microsoft Corporation.





Associated Articles

  The PICAXE Processors
  PICAXE News
  PICAXE Questions & Answers
  PICAXE Comparisons
  PICAXE Pinouts
  PICAXE Serial Interfacing
  PICAXE Infra-Red Interfacing
  PICAXE Wireless Interfacing
  PICAXE LCD Interfacing
  PICAXE LCD Interfacing
  A Real-Time Clock for the PICAXE-18X
  PICAXE Optimisations
  The PICAXE Birthday Box Project
  The Brainf**ked PICAXE
  The PICAXE Extended Programming Interpreter
  Build Your Own Basic Stamp
  Tech Toys



Sites to Visit

  PICAXE Home Page
  Revolution Education Ltd

  Tech-Supplies Ltd



Site Navigation

  Home Page
  What's New
  Search
  Add Bookmark
  Have Your Say
  Guestbook



PICAXE Telephone Exchange Simulator © 2004, The Happy Hippy


First published on Friday the 9th of July, 2004 at 18:49:01
Last upload was on Monday the 20th of December, 2004 at 14:07:23