Menu English Ukrainian russian Home

Free technical library for hobbyists and professionals Free technical library


ENCYCLOPEDIA OF RADIO ELECTRONICS AND ELECTRICAL ENGINEERING
Free library / Schemes of radio-electronic and electrical devices

Development of set-top boxes on PIC-controllers. Encyclopedia of radio electronics and electrical engineering

Free technical library

Encyclopedia of radio electronics and electrical engineering / Microcontrollers

Comments on the article Comments on the article

Devices made on microcontrollers make it possible to provide the developed structures with such functions that are difficult or even impossible to implement on rigid logic. This article describes the design of various set-top boxes based on PIC controllers.

Recently, quite a lot of descriptions of small set-top boxes for a telephone line have appeared in the radio engineering literature. They do not require power from the 220 V mains. They are easy to manufacture and do not need to be tuned, which makes them attractive to radio amateurs of various training. When such a device is made on separate elements, the radio amateur can understand its operation in detail and, if desired, modify it to suit his requirements. However, when using a microcontroller, the main algorithms for the operation of products become inaccessible to a radio amateur. In addition, it is far from always possible to find firmware for published circuits, not to mention the source code of programs.

For those who want to independently design a device using a PIC controller, sooner or later the question arises of developing their own program. Methods for writing programs for set-top boxes to a telephone line are discussed in this article. By "prefixes" are meant relatively simple devices such as blockers, combination locks. micro-PBX, etc., powered only by a telephone line and working with pulse dialers.

The author assumes that the reader is at least in general familiar with the P/C controller architecture and instruction set. It should only be reminded once again: for all devices connected to the public telephone networks, a certificate must be obtained.

In the most general form, any set-top box is a device that monitors the state of the telephone line and. depending on the change in its parameters, takes certain actions. It usually monitors the voltage in the line and, by its change, judges whether the receiver is off-hook, dialing, or receiving an incoming call signal.

Let's take a closer look at how this happens. With a free line, i.e. when the handset of the telephone set is laid, the voltage on the line should be within 48 ... 60 V. When the handset is removed, a current of about 30 mA will flow through the device and the voltage will drop to 5 ... 10 V If apply this voltage through the divider shown in Fig. 1, to the input of the PIC controller, you can register the moment of picking up the handset or read the digits of the dialed number. The operating threshold of the P1C controller when powered at 4 V is in the range of 1,3 ... 1,4 V (meaning the input without a Schmitt trigger). Therefore, when the tube is laid, the controller will be given a high level, and when removed, it will be low.

Development of set-top boxes on PIC-controllers

If several telephone sets are connected to the telephone line at the same time, then it is impossible to judge by the voltage in it which particular device is active. In the case when it is necessary to monitor the status of a particular phone, you can use the diagram shown in Fig. 2a. When the tube is lowered, the transistor VT1 is closed and there is a high level on its collector. When the tube is removed, a current begins to flow through the resistor R1. transistor VT1 opens and a low level occurs on its collector. Diode VD1 is needed to discharge the phone capacitor during a call.

Development of set-top boxes on PIC-controllers

On fig. 2b shows another unit for controlling the current flow in the telephone. It works similarly, but instead of a transistor, an optocoupler is used. This node is different. that it can be connected to the line without observing the polarity.

When designing current monitoring nodes, several points must be taken into account. First, the current in the phone can also flow when the handset is down. Sometimes it is quite large - over 0.5 mA. determined according to GOST 7153-85 (see [11]). Devices should not operate on this current. Secondly, with a call signal, the outputs of these devices will have pulses with a frequency of 25 Hz and an indefinite duty cycle. Therefore, the processing program must take this into account in order not to mistake the call signal for picking up the phone.

And the third unpleasant moment is that on some telephone lines of old PBXs, sometimes there is a short-term decrease in current in the entire line, which can be perceived by the processor as putting the handset on the phone or as dialing the number "1". This usually happens when a connection is established or disconnected. To avoid errors in this case, it is advisable to check the voltage on the line as a whole after detecting a decrease in current in the phone. If the current in the phone disappeared, and the voltage in the line did not increase, then we can assume that no action was taken on the phone.

In addition to monitoring the seizing or dialing process, it is often necessary to log an incoming call signal. Usually it is a sinusoid with a frequency of 25 Hz and an amplitude from peak to peak of 100 ... 150 V. while maintaining a constant component, or a meander of the order of 60 V. In the simplest case, the appearance of this signal can be determined in the same way as line voltage is monitored, i.e. i.e. using a conventional resistive divider (see Fig. 1). resistor R2 should have a resistance of 27 kOhm.

Voltage over 100 V may appear in the line not only during a call signal, but also at the time of dialing or hanging up. This happens during the operation of some types of old PBXs and is due to the inductance of the station relay. Therefore, the program must "be able" to distinguish false impulses from the call signal. On fig. 3 shows a diagram of a ringing signal sensor that extracts a variable component. This sensor is preferably used when the line voltage and the ringing signal are not known in advance.

Development of set-top boxes on PIC-controllers

In most cases, the described control methods are sufficient to create a completely modern set-top box for a telephone line. Typically, in such devices, the controller controls the current switches KR10T4KT1V or the like, through which telephone sets or some other elements are switched.

Particular attention should be paid to the power supply unit of the controller (Fig. 4). When it is connected to the line, the controller supply voltage will increase relatively slowly (about 1 ... 2 s), which does not allow resetting the processor by its standard means. This means that program execution can start (at least theoretically) from any ROM address. If the program build fails, "freezes" will be noted during device power-up, even if the watchdog timer is enabled. Therefore, the program algorithm must be developed in such a way that, under certain initial influences on the processor inputs (for example, when the handsets are dropped and there is no call signal), the program could return to a certain starting point and perform self-initialization, regardless of the values ​​that are in the RAM registers.

Development of set-top boxes on PIC-controllers

For small programs, this condition is satisfied quite easily. However, as the size of the program grows, its visibility deteriorates, and sometimes you have to take special measures to check the program for the possibility of hanging. This is a very important point, because a telephone set-top box is such a device that is constantly in operation, and at least once every few months the processor will fail due to some external interference. Therefore, a device with an unfinished program will either simply stop working, or even harm, for example, capture the line.

The low power supply puts a limit on the clock speed of the controller. The KZh101V current stabilizer can deliver up to 160 μA. This means that the clock frequency of the controller must be such that this current is enough for its normal operation. Usually, either a "clock" quartz resonator at a frequency of 32768 Hz is used. or an RC oscillator with a frequency of about 50 kHz. In the event that a large clock frequency is required, for example, 4 MHz. the processor can be used in sleep mode, leaving it only for certain actions.

Now let's move on to programming. Let's write a small program for the device, the scheme of which is shown in Fig. 5. This device is not of great practical importance, however, using its example, you can trace the basic methods of programming telephone set-top boxes. The device uses the most popular PIC16F84 controller. which is best suited for debugging simple programs thanks to the EEPROM. Most of its features, such as interrupts, timer, watchdog timer, sleep mode, will not be used.

Development of set-top boxes on PIC-controllers

The device controls the voltage in the line (let's denote this signal as Uline) and the current through the phone (Itel). The RB2 output of the DD1 controller controls the current switch K1, which can close the line to the resistor R3. The device can read the numbers dialed on the telephone set, provide coded access to long-distance communication and block dialing from any device connected directly to the line ("anti-piracy" mode). The long distance access code, for simplicity, will consist of one digit, which must be dialed after the long distance access digit.

We accept some notation used in the text of the program. The names of RAM registers and the names of subroutines will be denoted by lowercase letters with a capital letter at the beginning of the word, constants by uppercase letters, labels by lowercase letters, prefixed with an underscore If the designation consists of several words, we will also separate them with an underscore. As a header, we will use a standard file with a description of the controller registers p16f84.inc. This file is supplied with the development environment for MPLAB PIC controllers.

Let's define constants for initializing ports (TRVS registers) and OPTION and INTCON registers using the equ directive and set the password number for long distance access, let it be the number "3" (Table 1).

Development of set-top boxes on PIC-controllers

Next, we define the RAM registers that will be used in the program. This can be done by giving each symbolic register name its own address (for example, REG1 equ OxOC), but it is more convenient to use the cblock and endc directives. With their help, you can set a single starting address for the block of registers used, and the assembler will arrange all registers in ascending order during assembly. The only thing to watch out for. - so that the total number of given names does not exceed the number of physically existing controller registers. The fragment of the program, where the names of the registers are set, is shown in Table. 2.

Development of set-top boxes on PIC-controllers

Let's use the #define directive to set the symbolic names for the input/output lines used and the names of the flags (Table 3).

Development of set-top boxes on PIC-controllers

In table. 4 shows the initialization routine.

Development of set-top boxes on PIC-controllers

Now let's create a so-called waiting loop, i.e. that code. which is executed by the program when the tubes are laid and in the absence of a call signal. Usually the task of this loop is to perform initializations and monitor any inputs. In relation to our task, the program needs to monitor the voltage in the line, waiting for it to drop when the tube is removed. It is also necessary to reset all flags, reset the Figure and Number_of_Figure registers and apply a low level to the input C of the K1 key. so as not to close the line through the resistor R3 (Table 5).

Development of set-top boxes on PIC-controllers

It is in this cycle that the program should fall when it starts, even if its execution started from a random address.

If a low level is detected on the Uline, it is necessary to determine whether the handset is indeed off-hook or a ringing signal is transmitted on the line. During a call signal, the Uline input will receive pulses with a frequency of 25 Hz. To distinguish between them, you need to make sure that for some time, more than a few ringing periods, the Uline is low. According to [1], "lifting the handset" on the phone is considered to be a line closure for more than 250 ms. Let's write a program fragment that monitors the low voltage on the line for 300 ms (Table 6).

Development of set-top boxes on PIC-controllers

This snippet should immediately follow the previous snippet.

If there is low voltage on the line for 300 ms, it means that the receiver is off-hook from some phone. Then you need to check for a low level at the Itel input, that is, to recognize whether the handset is off the phone connected through the device, or from the device connected directly to the line. When "own" phone is involved, the program must switch to the mode of reading the number dialed on it, otherwise dialing should be blocked. So let's add two lines to the program:

btfsc Itel

call block

The Block subroutine performs the function of blocking dialing. In its simplest form, its operation algorithm may look like this: a high level is set to the Key output and the line is closed to the resistor R3. After some time, for example, after 1 s. a low level is set on Key and after a short delay (about 20 ms) it is checked. the tube is not in place. If the tube is not laid, then again a high level is applied to the Key, and this cycle repeats. Otherwise, the goto_begin statement is executed and the program starts over. We will not consider the assembler text of this subroutine, since it is quite simple and does not require special comments.

Next, the number dialed on the telephone is read. As noted above, dialing is a series of pulses that need to be recalculated. We will read the dialing number using the Itel input, although it can also be done using Uline. The assembler code of this part of the program is shown in Table. 7.

Development of set-top boxes on PIC-controllers

In the loop labeled _dial_01, the program waits for the dialing of a digit to begin. At the same time, it constantly calls the lnit initialization routine and sets the gate of the K1 key to a low level. This is necessary to avoid freezes when starting the device or in case of failures due to external interference. If you do not reset the Key output, then it may turn out like this. that there will be a high level on it, the line will close on R3 and the voltage in it will drop. As a result, the program will never exit this loop. If the TRISB register is not initialized (which is done in the lnit subroutine), then as a result of a failure, the Key line can be programmed as an input, and the K1 key will be opened by the accumulated charge on the gate, which will again lead to a program hang. To avoid this, a resistor with a resistance of about 200 kΩ is connected between the K1 gate and the common wire.

After a high level appears on Itel, the counter of received pulses is reset. Further, with the Supress flag cleared, the purpose of which will be explained below, the Delay10 subroutine is called, which performs a delay of 10 ms. The text of this subroutine is not given here, since it is quite simple. The same applies to a similar 80ms delay subroutine.

Then we check if the voltage in the line has increased. If not, then it is considered that the current drop in the phone is caused by a current drop in the line, and not by the operation of the dialer, and the program returns to the _dial_0l label. Otherwise, a counter is initialized, consisting of the Counterl o and CounterHi registers, for a time of 400 ms. If during this time the high level on Itel does not disappear, then we can assume that the phone has been put down, and control will be transferred to the beginning, i.e., to the _begin label.

When a low level occurs, a delay of 10 ms is made to protect against bounce of the dialer contacts, and then the counter of received pulses is incremented and the time counter is initialized to 100 ms. When a new pulse appears, the program performs similar actions, and if a new pulse is not detected within 100 ms, then it is considered that the dialing of the digit is completed and the counter of received digits is incremented.

Next, you need to process the received digit. In our example, it is required to disable access to long-distance communications with a password. It is assumed that long-distance communication can be reached by dialing the number "8" immediately after picking up the handset. A fragment of the program for this case is shown in Table. 8.

Development of set-top boxes on PIC-controllers

If the Supress and Parol flags are reset, and after lifting the handset and dialing the first digit, this is indeed the case. then the program checks the dialed digit for equality to the eight. If this equality is true, the Supress and Parol flags are set. Setting the Supress flag leads to the fact that at the moment the line is opened by the dialer, a resistor R80 is connected to it for 3 ms, as a result of which the dialing of a digit in the line is not skipped. However, the program still has the ability to recalculate the dialing pulses after disconnecting the resistor R3 from the line.

If the entered password digit matches the given one, both of these flags are reset and the controller stops blocking the set of digits. If the password is entered incorrectly, then only the Parol flag is reset, and the set continues to be blocked until then. until the phone is hung up.

The voltage diagram in the telephone line when dialing the number "2" is blocked is shown in fig. 6.

Development of set-top boxes on PIC-controllers

At time t, the line is opened by the dialer. Then, at the time interval t0 -t1, the voltage rises until the controller detects it. Further, at the moment t1. resistor R3 is connected. At time t2, the dial pulse ends, and at time U, resistor R3 is turned off.

Thus, only short pulses will be passed into the line from the moment the line is opened until the resistor R3 is turned on. Most PBXs will not be affected by these pulses, however, at some electronic telephone exchanges, they may be perceived as dialing. In order to get rid of these pulses, you can block the set not with a resistor, but with a zener diode. In this case, the program operation algorithm must be changed so that the zener diode is not connected for 80 ms. like resistor R3. but constantly. In this case, if the line breaks during dialing, the current will flow through the zener diode, and when the line is closed, through the telephone. This method of blocking dialing is used in the switch described in [2].

Consider now the operation of the device, the scheme of which is shown in Fig. 7. It is a parallel telephone blocker with a certain set of additional service functions. The blocker is designed to connect two telephone sets (SLT) to one line with the possibility of priority when picking up the handset on the first telephone.

Development of set-top boxes on PIC-controllers

Priority for SLT 1 allows a free line to be transferred to this phone, even if it is in use by another phone. In this case, before disconnection, the TA2 subscriber will be given a warning signal and given a time of about 6 ... 7 s to end the conversation. This feature allows you to make the presence of a second phone as inconspicuous as possible for the owner of the first one. It can be enabled or disabled with the SA1 toggle switch. With the SA2 toggle switch, you can set this TA2 operation mode for an incoming call, when it starts ringing after the third call.

The blocker is made on a cheap and minimally sized PIC12C508-04/P controller.

Both telephones are connected via current keys VT1 and VT2. Each of the phones is controlled by current using optocouplers U1.1 and U1.2. The incoming call signal is monitored through the divider R4R5.

Toggle switches SA1 and SA2 are turned on in such a way that their position can be determined by applying a low level to the gates of transistors VT1 and VT2. In this case, the output of the telephone current control system will be low when the toggle switch is closed, and high when it is open. This inclusion does not require separate processor outputs and allows you to get by with only five available controller lines for the entire blocker.

However, there is one feature that caused the use of resistors R9 and R10. In their absence (i.e., when signals are applied directly from the optocoupler transistor collectors to the controller inputs), at the moment the device is connected, a situation may arise when, for example, the GP2 and GP3 outputs will be programmed as outputs with zero and one signals on each, respectively. If at the same time the SA1 toggle switch is closed, then a current will flow through the VD3 diode, which, due to the low power of the power source, will not allow the supply voltage to reach the required level. The clock generator will not be able to start and the device will not work. This current must be limited, which is what these resistors are for.

The blocker program is built similarly to the one discussed above. In the initial cycle, initialization and setting of a high level to the gates of transistors VT1 and VT2 take place. This cycle also monitors the state of the phones and checks for an incoming call signal. After picking up the handset, both phones are turned off for a short time and the position of the toggle switches SA1 and SA2 is determined. Their state is stored in the corresponding program flags.

Then the program enters dialing standby mode. In this case, if the handset is removed from TA2 and with the SA1 toggle switch closed. after a short time interval, the first phone is connected to the line. This allows the priority function to be provided. If you start dialing on TA2, the first phone will be switched off again to avoid ringing when dialing. After the end of dialing the last digit, it will be connected again.

If the SA1 toggle switch is open, then TA1 will not connect to the line and the device will work as a normal parallel phone blocker.

In case of picking up the handset on TA1 while talking on the second phone, the device generates a short warning signal by applying an audio frequency voltage to the gate VT2. TA1 disconnects and a delay of 6...7 s is formed to give the TA2 subscriber the opportunity to end the conversation. After that, a signal is given again, TA2 is turned off and after 1 s the line is transferred to the first telephone. Thus, the priority function for the first phone is implemented.

An incoming call is processed by the program as follows. When a high level appears on the resistor R5, the program reads the state of the SA1 toggle switches. SA2 and when SA2 is closed, disconnects TA2 from the line. Next, the controller recalculates the number of periods in the call. If this number is less than the one specified in one of the program constants, then it is considered that interference has passed along the line, and not a call. Then the program execution starts again. Otherwise, the contents of the message counter increase, and the program waits for the handset to be picked up from one of the phones or for a new call to appear. This happens in about 8 seconds. If during this time the handset was not picked up and the next message was not received, then we can assume that the call signal is over and the program execution starts again.

When the next message is detected and when the number of periods in it is greater than or equal to the one specified in the program constant, the message counter is incremented. When this counter reaches state 3 (this number is set in the program constants section and can be changed), TA2 is connected to the line. as a result, he, too, with each next parcel will issue a call signal.

The R13C2 circuit sets the frequency of the controller's internal oscillator. With the ratings indicated on the diagram, it is 50 kHz ± 10%. LEDs HL1 and HL2 indicate a busy phone, and using HL3 you can determine the polarity of the line when connected.

The blocker is assembled on a printed circuit board made of one-sided foil fiberglass (Fig. 8).

Development of set-top boxes on PIC-controllers

When soldering the controller, the watchdog timer must be disabled.

The text of the program for the device in fig. 7

Literature

  1. Kialuk A. I. Handbook on the device and repair of telephone sets of foreign and domestic production. - M.; Antelcom. 1999.
  2. Kulakov V. Telephone microprocessor switch 1x5 - Radio. 1999. No. 10. p. 30-32.

Author: V.Kulakov, Rostov-on-Don

See other articles Section Microcontrollers.

Read and write useful comments on this article.

<< Back

Latest news of science and technology, new electronics:

Machine for thinning flowers in gardens 02.05.2024

In modern agriculture, technological progress is developing aimed at increasing the efficiency of plant care processes. The innovative Florix flower thinning machine was presented in Italy, designed to optimize the harvesting stage. This tool is equipped with mobile arms, allowing it to be easily adapted to the needs of the garden. The operator can adjust the speed of the thin wires by controlling them from the tractor cab using a joystick. This approach significantly increases the efficiency of the flower thinning process, providing the possibility of individual adjustment to the specific conditions of the garden, as well as the variety and type of fruit grown in it. After testing the Florix machine for two years on various types of fruit, the results were very encouraging. Farmers such as Filiberto Montanari, who has used a Florix machine for several years, have reported a significant reduction in the time and labor required to thin flowers. ... >>

Advanced Infrared Microscope 02.05.2024

Microscopes play an important role in scientific research, allowing scientists to delve into structures and processes invisible to the eye. However, various microscopy methods have their limitations, and among them was the limitation of resolution when using the infrared range. But the latest achievements of Japanese researchers from the University of Tokyo open up new prospects for studying the microworld. Scientists from the University of Tokyo have unveiled a new microscope that will revolutionize the capabilities of infrared microscopy. This advanced instrument allows you to see the internal structures of living bacteria with amazing clarity on the nanometer scale. Typically, mid-infrared microscopes are limited by low resolution, but the latest development from Japanese researchers overcomes these limitations. According to scientists, the developed microscope allows creating images with a resolution of up to 120 nanometers, which is 30 times higher than the resolution of traditional microscopes. ... >>

Air trap for insects 01.05.2024

Agriculture is one of the key sectors of the economy, and pest control is an integral part of this process. A team of scientists from the Indian Council of Agricultural Research-Central Potato Research Institute (ICAR-CPRI), Shimla, has come up with an innovative solution to this problem - a wind-powered insect air trap. This device addresses the shortcomings of traditional pest control methods by providing real-time insect population data. The trap is powered entirely by wind energy, making it an environmentally friendly solution that requires no power. Its unique design allows monitoring of both harmful and beneficial insects, providing a complete overview of the population in any agricultural area. “By assessing target pests at the right time, we can take necessary measures to control both pests and diseases,” says Kapil ... >>

Random news from the Archive

CD 500 TB 08.11.2021

A team of scientists from the University of Southampton in the UK has created a CD that can hold up to 500TB of data.

We are talking about a "five-dimensional" disk of quartz glass with a diameter of 127 mm and a thickness of 4 mm. Scientists claim that it can record up to 500 TB of data. Information on it can be stored for 14 billion years.

A new method of 5D recording is to conduct laser micropulses on quartz glass. When recording a disc, pulses create volumetric microcrystals of various shapes in it.

The volume of each microcrystal, as well as the strength and polarization of the light pulse that returns from it when read, provide these "five dimensions" in which data can be encoded.

The new method allows to increase the write speed by 150 times up to 225 kilobytes per second, and when using a laser with a frequency of 40 MHz - up to several megabytes per second. This makes such discs practical.

Other interesting news:

▪ ASUS Hyper M.2 X16 Card V2 Expansion Card

▪ Vibration feeds the sensor

▪ Prosthetic eye with night vision

▪ A drug to stimulate the growth of new teeth

▪ Pregnancy changes the mother's bones

News feed of science and technology, new electronics

 

Interesting materials of the Free Technical Library:

▪ section of the site Palindromes. Article selection

▪ article Application of footages. video art

▪ article Why is the water in the geyser hot? Detailed answer

▪ article Operation of steam and hot water boilers at oil product supply enterprises. Standard instruction on labor protection

▪ article Bicycle speedometer. Encyclopedia of radio electronics and electrical engineering

▪ article Automation and telemechanics. Automatic equipment overload prevention. Encyclopedia of radio electronics and electrical engineering

Leave your comment on this article:

Name:


Email (optional):


A comment:





All languages ​​of this page

Home page | Library | Articles | Website map | Site Reviews

www.diagram.com.ua

www.diagram.com.ua
2000-2024