2013-09-21

Rotary Dial for digital age

As I remember good-old rotary dial phones have been around since forever. And it is used to be a part of the everyday life, like dragons during medieval period. But like dragons, all of a sudden all these marvelous ancient devices just disappeared one day. I was lucky to find one of these dinosaurs at the local flea market:


I was eager to try it out, but unfortunately I don't have a home phone line anymore. I hook it up to my Voice Over IP (VoIP) adapter that I haven't used in years. And it almost worked! Well, it rings like it is supposed to - waking up dogs and babies in a 2 block radius and I could have a pleasant conversation over it, but I can't dial out. I hear a dial tone, but it ignores the number I was trying to dial.

The problem actually is not a phone - there is nothing could go wrong with it, ever. It's probably bullet-proof and could easily survive a minor nuclear apocalypses (haven't tried it, it is in my todo list). The problem is in my Voice Over IP adapter, it's not compatible with "ancient" rotary-dial phones. It designed to work only with (well, also vintage) push-button phones.

Ironically, rotary dial (or pulse-dial) is actually digital protocol, and is supposed to be closer relative to VoIP than "modern" push-buttons phones. The later ones were using analog encoding to transmit digits. This process has a fancy name: Dual-Tone Multi-Frequency Signaling (DTMF).
And the rotary dial is pure digital - transmitting numbers as a sequence of on/off pulses. One pulse correspond to digit "1", two pulse - digit "2", etc; Ten pulses represent digit "0".

Of course I could get another VoIP adapter that supports pulse dialing, but this would be too easy.
Instead I decided to make my own pulse-to-DTMF converter.

I had a few Atmel AVR microcontrollers lying around and using them to generate DTMF signal should be trivial. Obviously, it's been done before and I found Atmel application note to do exactly that. There is nothing special there, just using a PWM (the same method I used to play audio on the TI Launchpad) to generate analog signal. The only difference is that I am not using any external memory here. DTMF consists of just two sinusoidal waves, so we have to store one period of the sin wave and it is small enough to easily fit to the microcontroller's internal memory.

As I mentioned before, reading pulses from the phone is very simple, it's already digital, just count them up - and bam you get your digit.

Here is a a test setup with my adapter still on the breadboard



From left to right:
  1. WiFi to Ethernet converter. Just because my VoIP adapter doesn't have a WiFi and I don't like having Etherent cables everywhere
  2. VoIP adapter. I had the old Cisco/Linksys PAP2
  3. Phone (kinda obvious)
  4. Breadboard. Schematic below:

Phone line voltage in the "on-hook" state (confusing term? it seems to be originated when you are supposed to keep the earpiece on the hook and "off-hook" it in order to answer the call).

Back to the voltage,  so the "on-hook" voltage is quite high, around 48V DC and even higher (around 90V AC) during the ring. I decided to connect my board after the phone switch, so I am getting the power only when the phone is in the "off-hook" state (means handset is not on the phone).

In the "off-hook" state, line voltage is supposed to drop down to around 5V DC, which is perfect for my AVR, but I still added a 5.1V zener diode D1 just in case.

Rotary dial module is disconnected from the phone circuit and connected to my adapter only. The purpose of the connection between pins F and RR is to make phone think that the dial is still connected.

I am generating DTMF/PWM signal on the AVR pin 5 and feeding it to the emitter follower Q1 via the low-pass filter (C1, R3).

If you are curios, you can grab an AVR source code here.

Here is the video testing the adapter

During the test I ran into into the interesting issue. I noticed that AVR power consumption at the power-down mode is much higher than I anticipated (~500uA instead of ~10uA). After poking around I traced the issue to the debugWIRE interface. I were using debugWIRE to download and debug code on the AVR. But apparently debugWIRE draws a lot of current (~500uA). Disabling debugWIRE via fuses and using ISP instead solved the problem.

Last steps were to wire adapter on the perforated board.




And mount it inside the phone (thank you again, hot glue)



Done! Just put the cover on. Obviously it looks exactly the same as before modifications.


Next steps. I guess there is none. Well, maybe to record how this phone rings and use it as a ringtone.

63 comments:

  1. That's funny, I also thought about recording mine, and using it as the ring tone for iPhone. There is already a bell ringer tone of course, but it's not my own! I did my own pulse to DTMF converter with pic chip: http://www.youtube.com/watch?v=mxxvJtatNx8 but would liek to know more about how your phone interface part of your circuit works. It is not clear to me from your schematic, how your Atmel is chip protected from the high voltage AC when the phone rings, and also what transistor Q1 is doing. Would you mind explaining that further? Thanks, Art.

    ReplyDelete
  2. Ok, so both my Qs were answered by reading your text! Doh!
    I hope we can chat if/when I run into difficulty though :)

    ReplyDelete
    Replies
    1. Wow, cool, your adapter is way fancier than my. Are you getting enough power from the phone line for LCD?

      Delete
    2. Hi again, sorry I didn't check back for a while. Mine is currently powered, that's what I'd like to talk with you about... that and how to get the audio into the phone.
      I don't understand everything about your schematics, I'm only good with digital circuits.

      Delete
    3. There should be an incoming friend request on Google social thing if I got it right. I'd like to have a one on one chat if possible. The phone in my video is not the destination for the project, I've got a nicer one that I didn't want to beat up while getting things to work :) My YouTube name is on my YouTube channel (Unfortunate, but I couldn't think of anything else when I was in a rush to upload my first video).
      Cheers, Art.

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Hi! This circuit is great. I built it and I use in my rotary phone, but there are some problem. Sometimes the circuit can't process the pulses from the rotary dialler and the circuit doesn't send DTMF code to the line or generate wrong tone. There is no crystal in the circuit and it can work. Do you have any idea what may be causing the problems?

    ReplyDelete
    Replies
    1. Thank you. Quartz is used to guarantee the stable frequency. I haven't tried it without the quartz, but I would guess that the frequency instability could be causing issues that you described.

      Delete
  5. I like your project. Can you send me the component part details such as voltages of the capacitors, max frequency of the chip, etc.

    ReplyDelete
  6. Hi, nice work, can you please post the sketch you used? Thanks from holland!

    ReplyDelete
  7. I am having one heck of a time trying to program my 8 pin IC. I tried using a Dragon and an Arduino. Can any one help me please?

    ReplyDelete
  8. I would like to have your sketch too. I am trying to program the IC by Arduino. Could you post the sketch please? tks

    ReplyDelete
  9. Awesome! I'm in the early stages of doing my to bluetooth with Li ion battery. We are looking forward to bringing it to our favorite beach bar this summer for kicks.

    ReplyDelete
  10. Hi, Do I just rearrange the order of 'const unsigned char auc_frequency' data in order to use in New Zealand ? We have inverted numbering phone system here. ie. number of pulses out = 10 minus number dialed. Thanks for all your work. Jim

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. I've figured it out I think. All i have to do is the following:

    Replace this:
    // Got a valid digit - process it
    if (sDS.iDialedDigit == 10)
    {
    // 10 pulses => 0
    sDS.iDialedDigit = 0;
    }
    With this:

    sDS.iDialedDigit = 10 - sDS.iDialedDigit; // For New Zealand

    Or this:

    sDS.iDialedDigit = sDS.iDialedDigit -1; // For Sweden

    ReplyDelete
  13. Can you supply the already programmed ATMEL ? Otherwise I have to run into the ATMEL story and I am actually a PIC user....
    Thanks

    ReplyDelete
    Replies
    1. I have not checked, but I might have a spare MCU. Could probably ship it to you (assuming you are in USA). Just message/email me your address.

      Delete
  14. Hello, I'm planning on making an Arduino pulse to tone converter to hook up into a similar phone as yours, but with an external Arduino power supply. Your article provides excellent information on how to pull this off. My biggest problem is maintaining the line balance (which by some resources is extremely important and regulated by the telephone companies) and telephone device impedance. Did you pay any attention to that while you were working on this project? You seemed quite sure that there would be no problems with the telephone company. Could you provide some info about how I'd be able to do some measurements to be sure? Thank you for any info.

    ReplyDelete
    Replies
    1. Are you planning to connect your device to your landline/PSTN?
      Technically, you should not connect any non FCC-approved equipment to the PSTN.
      I would recommend using a VoIP adapter instead, it is more flexible than PSTN and you won't break any rules.

      Delete
    2. Hey Boris, thanks for the quick reply. I thought as much, but I might be in luck. My parents got a new DSL router (Innbox V51 R2) which actually contains two phone inputs on itself for analog phones and/or fax machines. In the quick-start guide it says it supports the VOIP, but I'm still not convinced if it's actually the VOIP adapter or some sort of pass-through port (in which case I'm still screwed and have to buy an adapter). If you have any deeper knowledge about these devices or some additional info, it will be greatly appreciated. Thank you again.

      Delete
    3. According to the manual, you're absolutely right. But it also seems I can easily insert a PSTN phone there, because currently we have one plain PSTN DTMF phone working on one of those ports (and manual also says that is a possible option). I know for sure that is not an IP phone, because we were buying a cheap phone with just a couple of functionalities. So it kinda looks like a hybrid between a VoIP port and VoIP adapter. I intend to give it a go, hopefully the router can withstand an older phone and won't burn anything. Thanks for all the info, very much appreciated.

      Delete
  15. I do not understand how to program this, or does it work without programming?

    ReplyDelete
    Replies
    1. No, it won't work without programming, sorry. There is a link to the source code in the blog, but you have to compile and download the program to the microcontroller.

      Delete
  16. Hi. I'm trying to build this according to your specs, but I'm a little confused about the two white wires coming from the rotary dial. How can you tell which goes to ground and which goes to the SCK pin on the microcontroller? Also, are you keeping power L2 and L1 from the phone line? Is there a minimum voltage required to make it work? I'm pulling about 4.2 V on the microcontroller when everything is connected. I'm trying to do this just as a mock-up, I'm not going to connect it to a phone line, just directly to a 5V power supply. I'm just trying to get a tone in the earpiece when dialing.

    Thanks, Alexa

    ReplyDelete
    Replies
    1. White wires are connected to the switch inside the rotary dial, so they are both equal, does not matter which one goes to the GND/SCK pin. If you are powering the microcontroller externally, then just use 5V power supply, connect it to C2/C3 and eliminate R1.

      Delete
    2. This is Alexa,

      I have tried to use a live phone line and a stand alone voltage source. It makes about 3 sounds, on any number dialed, two of them are higher pitched than a normal tone and the other usually #0 makes a very quick almost like a little tune of about five very quick notes. We have the same phone and test board, Mine looks just like yours in the picture. Any ideas I have redone this many times, same results. PS I'm using the code on this page

      Thanks, Alexa

      Delete
    3. Not sure, but it sounds like your clock frequency is off. Are you using 4MHz crystal? Did you configure AVR fuses to use external crystal?

      Delete
    4. That's exactly what I was thinking. I am using a 4 MHz crystal with the caps just like in your schematic. I am a little worried about changing the fuses because I've seen how you can brick a microcontroller if you don't know what you're doing. Since I don't know what I'm doing... Is there an avrdude command that will change the fuses? I really appreciate your help. It is very kind of you to reply to my questions. --Alexa

      Delete
    5. There is an online tool to configure AVR fuses: http://www.engbedded.com/fusecalc/
      According to the tool, AVRdude arguments to configure external crystal should be: -U lfuse:w:0xfd:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m
      I didn't consider destroying this $2 MCU a big deal, but you are right, it is quite possible to lock it down (unless you have a HV programming tool, then you should be able to unbrick it in any case).

      Delete
    6. I got it to work. Since the microcontroller uses a default internal clock of 8 MHz, I changed the prescaler to divide by 2. I realize that the default is not as accurate as an external crystal, but it works for me. Again, thanks for posting this cool project and thanks for your help on it!

      Delete
    7. Hello again. I'm just curious. What is the role of your two capacitors, C2 and C3?

      Delete
  17. This comment has been removed by the author.

    ReplyDelete
  18. First of all, thank you so much for posting this project. Finally I can dial out from my old phone rather than just using it as a ringer.

    When I first built the circuit I had lots of trouble with either missed pulses or extra pulses being counted - e.g. I'd dial 7 and it would send the DTMF tone for 6 or 8. I traced the issue to the switch signal bouncing. I added some filtering to the dial and pulse switch lines to get rid of the bounce. I also swapped the dial and pulse switch lines on the microcontroller and changed the code to trigger on the falling edge of the pulse signal using the INT0 interrupt rather than polling on a timed basis. With this new setup it works every time.

    I've posted the code and Eagle files here: https://bitbucket.org/310weber/rotary_dial

    Thanks,
    Arnie

    ReplyDelete
    Replies
    1. Fantastic, thank you for sharing your findings.

      Delete
    2. From Graham.
      Thanks for the code Arnie, I have a change request ;-)

      Wouldn't it be cool if you could dial * and # as well?

      What I have in mind is, if you dialled "1" but held the dial on the finger stop so the mute contacts were closed for (say) >500ms a DTMF "*" would be produced instead of a "2".
      If you did the same thing with "2" a DTMF "#" would be produced.

      Some people might like 9 and 0 instead.

      What do you think?
      Thanks,
      Graham.

      Delete
  19. Hi

    This looks really great. Does anyone have an idea on how to adapt this to a german phone? I have a FeTAp 611-2 which seems to only have 4 wires (Yellow, Green, Brown and White). The brown and white wires seem promising, since there is 6v between them when the phone is off-hook, but I can not figure out what to use as ground.

    Thanks,
    Ali

    ReplyDelete
  20. http://postimg.org/image/c6z8yaw3l/
    http://postimg.org/image/4ok3fgznl/
    http://www.binarymagi.com/en/projects/pulse2dtmf
    Check this url's for more information.

    ReplyDelete
  21. I'm getting a tone but it seems like the same tone on all the numbers. Sometimes its there and sometimes its not, it seems to be very inconsistent. The phone line I hooked it up to didn't seem to recognize the tone either. I put the code onto a ATtiny 85 if that makes any difference.

    ReplyDelete
  22. Does the low pass filtered pwm signal need to be amplified at all? Reason I ask is because I'm trying something similar with a pic12f1840 and I can generate the tones just fine, but the signal after the low pass filter isn't "strong" enough to drive a piezo speaker I have on the breadboard. I haven't tried hooking up the pwm line directly to the phone yet because I assumed I needed an op amp to amplify the signal first

    ReplyDelete
    Replies
    1. I am using emitter follower to amplify the signal. But if you want to save a few components, it _might_ work just by feeding signal from PWM pin straight into the phone line.

      Delete
  23. Can you make the source code available; the link no longer works.

    ReplyDelete
    Replies
    1. Darin - if you follow the bitbucket link in my comment above, the first commit is Boris' original code without any of my modifications.

      Delete
    2. Darin - if you follow the bitbucket link in my comment above, the first commit is Boris' original code without any of my modifications.

      Delete
  24. Hey Boris, great project! Can I email you? I can't find your address on the blog profile.
    thanks...

    ReplyDelete
  25. I want to turn my rotary phone into a listening device. How?

    ReplyDelete
  26. I want to turn my rotary phone into a listening device. How?

    ReplyDelete
    Replies
    1. Sorry, but I have no idea what are you talking about.

      Delete
  27. Hello Mr. Cherkasskiy.
    This thing is amazing. I'd like to do this as well, but I have never tried myself in digital stuff, apart from some 40' and 50' teletype systems, but I think that's not the same. I have many questions, may I send them to the above described mailbox?

    Many thanks; Steven.

    ReplyDelete
  28. What a cool post! I have a similar project. I have a rotary dial phone. I would like to make it a walkie talkie, basically, to communicate with a PA style loudspeaker that's in my garage. My thought is, I pick up the phone, it creates a connection with the PA, I can tell the kids "it's time for dinner" they can yell back "ok" - I hang up, and we're done. I have wifi - but do you think bluetooth would be better? I am not trying to call on VOIP or do anything else with the phone. Just call the loud speaker wirelessly.

    ReplyDelete
    Replies
    1. Could you just run wires from the phone to the garage?
      This would be the easiest solution.

      Delete
  29. Is it possible to have a programmed chip?
    thank you

    ReplyDelete
    Replies
    1. Unfortunately, I do not offer it as a complete device/kit.
      So, you'll need a basic selectronic knowledge to put it all together.

      Delete
  30. for the knowledge in electronics I have no problems. but only in the programming of atting45 I have no practicality. I only need the chip

    ReplyDelete
    Replies
    1. Programming AVR MCU is very simple. There are numerous of extremely cheap adapters to program ATTiny.
      For example this one is $1.17 including free shipping: https://www.aliexpress.com/item/USB-ISP-Programmer-for-ATMEL-AVR-ATMega-ATTiny-51-AVR-Board-ISP-Downloader-Free-Shipping/2035761181.html

      Delete
  31. Hello!
    Which ATTiny45 is used for this project?
    Thanks!

    ReplyDelete
    Replies
    1. I don't remember exactly, but it probably was an old/obsolete model.
      I guess ATTINY45V-10PU should work fine for this application.

      Delete
  32. Hello! I read your blog, I have this phone http://habartorg.ru/catalog/852/. Yaby wanted to modernize it. A variant like you. It's a router, a sip adapter (like on video). Would your circuit fit my phone? When will they call me whether the phone call will work? In advance thanks for the answer ...

    ReplyDelete
  33. Hello the author of the project,say your e-mail address ,I need to talk to you ))

    ReplyDelete
  34. can the scheme adapter to use the scheme at this link http://rt20.mybb2.ru/viewtopic.php?f=40&t=99948&st=0&sk=t&sd=a&view=print to connect with http://www.radioscanner.ru/uploader/2016/glotalka_monet_000a1.jpg . This decoder 425 Hz. It is assembled on the chip NE567. It's all very simply done. If after dialing the third digit went the dial tone 425 Hz., the decoder tilts the trigger and starts the timer. While it's ringing, I don't care, I mean "busy" or CPV, the timer is constantly reset. Once the ringing has disappeared completely, it means that the connection took place and we need the coin to swallow. Indeed, the 2 second delay prisutstvuet. When a coin is swallowed, You know what happens. When we hang up, trigger additional contacts dialer and the trigger returns to its original state.

    Nothing confusing in this scheme no. On the knee cut 3A two hours of what was. In the MCU I don't think.

    The handkerchief with the external power supply. http://www.radioscanner.ru/forum/topic27813-2.html. through gsm gateway

    ReplyDelete