Three-way segment switch based on single chip microcomputer design

Publisher:闪耀星空Latest update time:2014-02-20 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  The segment switch is an energy-saving electronic product. When there are only two power lines, it can be used to control lamps with multiple bulbs, fluorescent lamps, and energy-saving lamps in groups, avoiding the pain of rewiring the lighting circuit. Common segment switches are controlled by a one-position switch, and different lighting states are generated by different switching times. This control method has two defects: first, the bulb is constantly switched on and off during the control process. Since the service life of the bulb, fluorescent lamp, and energy-saving lamp is closely related to the number of switches, this method can easily cause damage; second, it is more troublesome to use. If there are three groups of lamps in the lamp, it must be switched on and off four times to turn on all the lights. The following introduces a three-way segment switch designed with a single-chip microcomputer. A switch and three buttons are used on the control panel. After turning on the switch, different groups of lamps can be controlled by pressing different buttons. The three groups of lamps are independently controlled, which is intuitive and convenient to use.

  1. Circuit Working Principle

  The sectionalizer consists of a control panel and a receiving controller. The control panel is mounted on the switch box, and the receiving controller is mounted on the lamp. The control panel and the receiving controller are connected by two power lines. The control signal is transmitted through the power line in the form of power carrier. In order to prevent interference from the 50Hz AC power supply and facilitate separation, a 100kHz high-frequency pulse signal is used as the control signal. In order to simplify the circuit, the pulse counting method is used to distinguish different control signals.

  1. Control panel circuit

  The control panel mainly generates different control signals to control different lamp groups.

  The circuit is shown in the figure below. The delay circuit is composed of the NAND gates A1 and A2 in IC1, resistors R1~R4, capacitors C1~C3, etc. The working principle is explained below by taking pressing S1 as an example: when S1 is not pressed, the input terminal of A1 is low level, so after two inversions, A2 also outputs low level; when S1 is pressed, since the voltage on C1 cannot change suddenly, the input terminal of A1 is high level, and A2 also outputs high level. After that, the voltage at both ends of C1 gradually rises after being charged by R4, and the potential at the input terminal of A1 gradually decreases. When the potential drops to VDD/2, that is, below 4.5V, the output of A2 changes from high level to low level. In this way, when the buttons S1NS3 are pressed respectively, the output terminal of A2 generates three different single positive pulse signals with pulse widths of 15mS, 23mS, and 34mS, which are used as control signals of the multivibrator respectively. NAND gates A1, A2, resistors R5, R6, capacitor C5, etc. form a multivibrator with an oscillation frequency of about 100kHz. When A2 outputs a high level, the multivibrator works and A4 outputs a 100kHz pulse signal. Since the number of its output pulse signals is controlled by the time of the high level output by A2, A4 can output different numbers of pulses by pressing different buttons in S1 to S3, and the corresponding numbers of pulses are about 1500, 2300, and 3400 respectively. Transistor VTl, high-frequency transformer T1, etc. form an output circuit, and the pulse signal output by A4 is amplified by VT1 and transmitted to the power line through C8. L1 is a high-frequency choke inductor, which can prevent the 100kHz pulse signal from being short-circuited by other electrical equipment and prevent it from generating interference signals to the outside.

  C7, VD2, VD3, C6 and other components form a capacitor step-down power supply circuit, in which the 9V power supply stabilized by the voltage stabilizing diode VD1 is used by IC1.

  2. Receiving controller circuit

  The receiving controller circuit is shown in Figure 2. The circuit consists of a receiving circuit, a single-chip microcomputer circuit, and a power supply circuit.

  R1 and C1 form the reset circuit of the microcontroller. After the power is turned on, the reset terminal 1 pin of the microcontroller AT89C2051 obtains a high-level reset pulse, which makes the microcontroller enter the initial state set by the program. Its pin P1.0 outputs a high level, P1~1 and P1.2 output a low level, the transistor VTl is turned on, VT2 and VT3 are turned off, so that the relay K1 is attracted, and K2 and K3 are in a released state. In this way, when the switch S4 on the control panel is turned on, the first group of lights is lit, and the other two groups of lights are off. When in use, the commonly used group of lights is generally connected to the control contact of K1.

  C4, T1, \\/T1, etc. form the input signal processing circuit. C4 plays the role of isolating 50Hz AC signals. In order to improve the anti-interference ability, VT1 does not add DC bias voltage. The pulse signal with an amplitude of 5V output by its collector is input to the single-chip microcomputer through the P3.4 pin for processing. The single-chip microcomputer decides to change the working state of pins P1.0~P1.2 according to the number of input pulse signals. Specifically, about 1500 pulse signals correspond to P1.0, about 2300 pulse signals correspond to P1.1, and about 3400 pulse signals correspond to P1.2.

  The following takes the second circuit as an example to illustrate the working process of the circuit. After the power is turned on, press the button S2, then the P1.1 terminal of the single-chip microcomputer is converted from low level to high level, the relay K2 is energized, and the corresponding normally open contact k2 is closed to turn on the corresponding light group. Press S2 again, and the P1.1 terminal of the single-chip microcomputer is converted from high level to low level, turning off the corresponding light group. The working process of the other two circuits is similar. When the working state of one circuit is controlled, the working states of the other two circuits are not affected, that is, each circuit can be controlled independently.

  C5, VD4~VD8, IC2, etc. form a capacitor step-down power supply circuit to provide +12V and +5V power supplies. The function of L1 in the circuit is the same as that of L1 in the control panel circuit.

 2. Program Introduction

  The program is written in C language, and the timer TO is set as a counter, and the P3.4 pin is used as the input end of the counting pulse. Timer T0 counts the input pulse signal, and by judging the number of pulses, it can be known which switch is pressed on the control panel, thereby changing the working state of the corresponding relay. [page]

  The program list is as follows:

  #include

  unsignedchari,DelayTime;unsignedintn:

  sbitP1_O=p1^0;

  sbitP1_1=P1^1;

  sbitP1_2=P1^2;

  sbitP3_4=P3^4;

  voiddelay(DdayTime) //delay subroutine

  {

  for(;DelayTime>0;DelayTime——)

  {

  for(i=0;i<250;i++);

  }

  }

  voiDMAin(void) //main program

  {

  P1_0=1;

  P1_1=O;

  P1_2=0;

  TMOD=0x05;

  //Timer TO works in mode 1 counting

  TH0=0;

  TL0=0:

  TRO=1: //Turn on timer TO

  for(;;)

  {

  while(P3_4=1);//Judge whether there is

  Input pulse

  TR0=1: //Start timer TO

  delay(50);

  //Delay 50mS, let timer TO count

  TRO=O: //Turn off timer TO

  n=TL0ㄧ(TH0<<8); //get the count value

  TH0=0;

  TLO=O:

  if(n>1300&&n<1700)//If the pulse

  The average number is about 1500

  P10=!P10: //P1.0 input

  Output level inversion

  elseif(n>2000&&n<2600)//If

  The number of pulses is about 2300

  P1_1=!P1_1; //P1.1 input

  Output level inversion

  elseif(n>3000&&n<3800)//If

  The number of pulses is about 3400

  P1_2=!P1_2; //P1.2 input

  Output level inversion

  }

  }

  In the program, "while(P3_4==1):" detects whether the P3.4 pin is at a high level. When the control panel does not send out a pulse signal, the P3.4 pin is always at a high level, and the program is in a waiting state; once a pulse signal is sent out, the P3.4 pin will be at a low level. After the program detects it, it will execute downward, and the timer T0 counts the pulse signal input from the P3.4 pin. Since the longest duration of the control signal sent by the control panel is 34mS, 50mS is selected here for the timer TO to count to ensure that the pulse signal is not lost. After the counting is completed, the program screens the count value. Since the control panel uses an RC oscillator, its frequency stability is poor. In order to improve the reliability of the circuit operation, a certain error is allowed in the number of pulse signals during screening.

  3. Installation and debugging

  IC1 in the control panel uses CMOS NAND gate integrated circuit CD4011, and capacitors C1, C2, C3, and C5 use polyester capacitors with good stability to ensure the stability of the circuit. S1~S4 use touch button switches. The core of inductor L1 uses E16 ferrite core, which is wound with 100T enameled wire with a diameter of 0.41. The high-frequency transformer T1 uses E1

  3's ferrite core, use φ0.19 enameled wire to wind 200T on the primary and 50T on the secondary.

  In the receiving controller, IC1 uses ATMEL's AT89C2051 single-chip integrated circuit, IC2 uses a low-power three-terminal voltage regulator integrated circuit 78L05. X1 uses a 12MHz quartz crystal. VD1~VD7 use rectifier diodes 1N4004, VT1 uses transistors 2SC945, and VT2~VT4 use transistors 2SCl815. Relays K1~K3 use HRS1-S, 12VDC relays, and their contact loads are 3A120/220VAC.

  The parameters of inductor L1 are the same as those of L1 in the control panel. High-frequency transformer T1 uses E13 ferrite core and uses φ0.19 enameled wire for primary and secondary windings with 1OOT.

  Before installation, use a programmer to write the compiled target file switch.hex into the AT89C2051 chip.

  The debugging work after installation is mainly to adjust the delay time of the control panel and the oscillation frequency of the multivibrator. During debugging, turn on the power switch S4 of the control panel, and then press the button switches S1, S2, and S3 in turn to see if the corresponding relays in the receiving controller have any action. If there is no response, if there is no problem with the circuit, it may be that the output frequency error of the control panel is large. The problem can be solved by properly adjusting the parameters of R6 or C5 in the circuit. If conditions permit, the output frequency of A4 can be measured with a frequency meter, and the input end of A1 and +9V can be connected with a wire for measurement. After that, if there is no response when a certain button switch is pressed, it means that the delay error of this channel is large, and the capacity of the corresponding delay capacitor can be changed. Finally, press the three buttons S1~S3 of the transmitter in turn. If the working status of the corresponding three-way relay can change, the debugging work is completed.

Reference address:Three-way segment switch based on single chip microcomputer design

Previous article:Display board circuit diagram with 6-digit LED and 4 buttons
Next article:Design and implementation of three-dimensional rotating LED based on STC11F02E

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号