Translate

Sunday, May 31, 2020

Old PSTN entry phone - door opening - #4


In this article I'm  describing the final version of hardware and firmware for the door opening.
Previous articles :


Let start with a more close schematic.




This schematic has a power supply section.
I opted to use a DC/DC regulator from DROK. Is small and allows to obtain a stable 5V from 6V to 24V up to 3A. Of course we'll not even be close to 1, so we are more than safe here.
For extra safety the external power supply is applied to a rectifier bridge.
This allow to connect the power supply regardless the polarity or an AC source.
A couple of capacitors to filter the incoming power supply and we are ok.

Connectors are used for the power supply, the relay output and the rotary disc input.
I did left on the PCB a connection for the neopixel for two reasons :
  1. connect quickly  a neopixel to debug the decoding
  2. use the PCB for other projects, like a UV timer since it share the main components, i.e. DC/DC/ Trinket, Neopixel, pushbutton, releay
Here a rendering of a possible PCB :



The schematic and PCB is available on the EasyEDA site.

BOM


Let see some components used and possible source.
  • PCB (LCSC)
  • Trinket (Adafruit)
  • Dork miniature DC/DC (Amazon)
  • Songle relay 5V coil (Amazon)
  • Connectors
  • Resistors
  • Capacitors
  • Pushbutton
  • Transistor NPN
  • Diode 1n400x
  • Bridge rectifier

The breadboard prototype


Just to start to have something working I started to put together a breadboard prototype.
I had around some 5cm x 5cm breadboard so I tried to put everything on it, little bit crammed.
On the schematic is used a 5V Songle relay, however on the breadboard prototype I did use a reed relay, because the lack of space.





The code


The code is based on two state machines :
  • a "Main" state machine
  • a "Rotary Dial" state machine
The two state machines interact closely.


Main state machine


The main state machine dictate some high level operations and controls (run) the Rotary Dial state machine.
The main state machine has these states :
  • START
  • IDLE
  • OPEN
  • PROG
  • SAVE
The START state is the of course the starting one and it initialize variables, including the starting state (START) of the Rotary Dial state machine.
After the initialization the Main state machine goes in the IDLE state.
The main job of the IDLE state is to call the Rotary Dial state machine and check if the Programming push-button is pressed.
If the Programming push-button is pressed a flag is set in order to use differently the number built from the Rotary Dial State machine.
When the number is built in the Rotary State machine, a new state is set.
OPEN if the programming flag is off (default) or SAVE if the programming flag is on.
In OPEN the Rotary State machine is not called anymore (stops to run), the phone number dialed is compared with the stored one and if identical open the door (activate the relay for 1 second.
In SAVE the Rotary State machine is not called anymore (stops to run), the phone number dialed is saved to be compared in the OPEN state.
After OPEN and SAVE the main state machine is set to START to restart the cycle.

Rotary Dial state machine

As the name suggests, this state machine is used to read the rotary dial device.
These are the states :
  • START
  • IDLE
  • COUNT
  • CHECK
  • END
The rotary dial state machine is called from the IDLE state of the main state machine.
The START initialize counters/timers and reset the read digit then goes in the IDLE where is waiting for the signalling process to start.
When it starts, a expiring number timer is started (about 3 seconds) and the state changes in COUNT state, where the pulses from the rotary dial are read.
When the signalling state ends the counted pulses (the digit) is saved on the composing number and if the end of number timer expires the state machine goes in END where basically is doing nothing.
If before the timer expires another signaling sequence starts, the state machine goes back to COUNT.

No comments:

Post a Comment