Close

The basics of the code pt.1 - Bell Ring Control

A project log for Cellular conversion of vintage rotary phone

GSM conversion for rotary phone, using Arduino Pro Mini with Atmega328, a QCX601 SLIC module and a SIM800 breakout board.

johan-berglundJohan Berglund 12/12/2016 at 12:110 Comments

Ok, so the main things I had to do dealing with the SLIC module was to have it create the ring signal, and to make the pulses and states of the switch hook pin control the actions of the phone. The ringing was the easier part, as it was pretty much exactly described in the QCX601 datasheet.

Early on I had decided to base my code on timings using the millis() function, so the "ringing" took this form, based on that diagram:

// Ringing interval 
// How much time has passed, accounting for rollover with subtraction!
if ((unsigned long)(currentMillis - ringPreviousMillis) >= ringInterval) {
  digitalWrite (rcPin,1); // Ring
  // Use the snapshot to set track time until next event
  ringPreviousMillis = currentMillis;
}
if (digitalRead(rcPin) && ((unsigned long)(currentMillis - ringPreviousMillis) >= ringDuration)) {
    digitalWrite(rcPin, 0); // Silent after ring duration
}
// 25Hz oscillation      
// How much time has passed, accounting for rollover with subtraction!
if ((unsigned long)(currentMillis - oscPreviousMillis) >= oscInterval) {
  // It's time to do something!
  if (digitalRead(rcPin)) {
    digitalWrite(hzPin, !digitalRead(hzPin)); // Toggle the 25Hz pin
  }    
  // Use the snapshot to set track time until next event
  oscPreviousMillis = currentMillis;
}
The rflPin is set to be LOW all the time, and the timings are defined like this for typical Swedish ringing:
#define oscInterval 20
#define ringInterval 6000
#define ringDuration 1200
Basically, for every lap in the loop when in ringing state it does this...

If it's time to sound the bell again, put the RC pin HIGH, then reset the time for this (wait 6 seconds until next go).

If the RC pin is HIGH, and it has been 1.2 seconds since it was put HIGH, set the RC pin LOW to stop ringing.

If it has been more than 20 ms since last toggle of the 25Hz pin, reset the time for this and toggle the 25Hz pin should the RC pin be HIGH.

(And then there are checks if we should stop all the ringing and go to some other state, of course.)

Discussions