Realization method of relay state detection device
By designing a relay status detection device in the equipment, using the ADC and SCI modules of the F28335 chip to communicate with the upper computer, and real-time detection of the relay status, the problem of low fault detection efficiency in the existing technology is solved, and fault positioning and repairability are improved.
Patent Information
- Application Number
- CN202411173890.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-26
- Publication Date
- 2024-12-03
AI Technical Summary
When using relays, existing equipment lacks automatic fault detection and reporting functions, resulting in low troubleshooting efficiency and affecting product reliability and repairability.
A relay status detection device is designed, using the ADC module and SCI module of the F28335 chip, communicate with the upper computer software through the RS422 bus, detect the relay status in real time, and pass the results back to the upper computer to achieve fault location.
It realizes rapid and real-time detection of relay status, shortens troubleshooting time, and improves the health management capabilities of the equipment.
Smart Images

Figure CN119064771A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of electronic technology, and in particular relates to a method for realizing a relay state detection device. Background Art
[0002] A certain device has implemented 4 power supply lines. In order to meet the voltage isolation requirements of the control circuit and the output circuit, two relays are generally used in each line, and they are connected in a two-stage cascade mode. The first-stage relay is also called the control (stage) relay, and the second-stage relay is also called the output (stage) relay. The upper computer software is responsible for controlling the first-stage relay to be turned on and off. When the output of the first-stage relay is valid, the second-stage relay can be further controlled to be turned on and off. The connection relationship is shown in Figure 1 .
[0003] Since the electromagnetic relay is the key executive component of the equipment and is a consumable component, the possibility of failure gradually increases after working tens of thousands of times. Figure 1 The circuit uses a two-stage relay in series for control and output on a single 28V signal output line. If any one stage of the function fails, the 28V output function of the line will fail. This reduces the reliability of the system to a certain extent. Especially when the equipment uses this method to achieve multi-channel 28V output in large quantities, when a line output fails, the equipment cannot automatically detect and report the fault point, which, on the one hand, causes slow troubleshooting efficiency, and on the other hand, fails to capture and locate occasional faults in the first place and properly solve them. Subsequent faults appear and disappear from time to time, which will have an adverse effect on the functional performance and maintainability of the product.
[0004] In summary, in order to capture the cause of the fault in the first time, locate the faulty device, and improve the product health management capability, it is necessary to design such a relay status detection device, which can establish an RS422 bus command / response communication mechanism with the existing host computer software. Under its reliable control, it can quickly and in real time detect the working status of all line-related relays of the onboard equipment, and transmit the results back to the host computer software through the RS422 bus for subsequent analysis and judgment by the host computer to locate the faulty relay. Summary of the invention
[0005] 1. Technical issues to be resolved
[0006] The technical problem to be solved by the present invention is: to design a relay status detection device, which can establish an RS422 bus command / response communication mechanism with the existing host computer software. Under its reliable control, it can quickly and in real time detect the working status of all line-related relays of the airborne equipment, and transmit the results back to the host computer software through the RS422 bus for subsequent analysis and judgment by the host computer to locate the faulty relay.
[0007] (II) Technical solution
[0008] In order to solve the above technical problems, the present invention provides a method for implementing a relay state detection device, which is designed to include an ADC module, an SCI module, a processor module in an F28335 chip, and two interface circuits implemented based on the F28335 chip, one of which is an RS422 bus interface circuit for completing data communication with a host computer; and the other is a 16-channel AD conversion interface circuit for collecting a maximum of 16 relay output signals;
[0009] One end of the RS422 bus interface circuit is connected to the serial communication interface B pin module SCIB in the three SCI modules in the F28335 chip, and the other end is connected to the RS422 interface line of the host computer; the RS422 bus interface circuit is responsible for converting the serial port data between the UART level and the differential RS422 level;
[0010] The ADC conversion interface circuit includes a voltage divider circuit and an op amp follower circuit. The voltage divider circuit divides the 28V output of the relay by a ratio of 1 / 10 and converts it into 2.8V, which matches the input voltage range of 0-3V of the ADC module of the F28335 chip. The voltage is then transmitted to the ADC pin of the ADC module in the F28335 chip through the op amp follower circuit to maintain the stability of the input signal amplitude.
[0011] The ADC module converts up to 16 analog signals at the same time, which are divided into two groups, A and B, with 8 signals in each group. In addition to the 12-bit digital-to-analog converter, the ADC module also has two sequencers, SEQ1 and SEQ2. In the sequencer non-overlapping mode, they each form a sequence set with up to 8 analog signals, and perform AD acquisition and conversion operations in sequence, that is, batch automatic conversion of the signal sequence set, and save the results to the corresponding registers of the ADC module; in the sequencer overlapping mode, the two sequencers are combined into one sequencer SEQ, and one sequence conversion includes AD acquisition and conversion of up to 16 signals and at least 1 signal; in the dual-channel simultaneous sampling mode, the Nth signal of the two groups A and B is sampled and converted at the same time, 0<=N<=7; in the sequential sampling mode, only one signal is sampled at a time; the acquisition order of each analog signal, the total number of signals and the entire sequence start acquisition instruction are all implemented by the configured corresponding registers;
[0012] During the software initialization phase of the ADC module, the register configuration of the ADC module is completed to determine the clock frequency of the ADC module, the signal sampling time window, the signal sampling sequence, the total number of signal samples, the sequential sampling / simultaneous sampling mode, whether it is the superposition sequencer mode, and whether continuous sampling;
[0013] There are three SCI modules, namely, serial communication interface A pin module SCIA, serial communication interface B pin module SCIB, serial communication interface C pin module SCIC. The three SCI modules are configured so that SCIB has the function of sending and receiving serial port data with FIFO mode.
[0014] The processor module implements the relay status detection process based on the configuration of the ADC module and the SCI module.
[0015] Preferably, the specific implementation methods and basis for determining the clock frequency, signal sampling time window, signal sampling order, total number of signal sampling, sequential sampling / simultaneous sampling mode, whether it is a superposition sequencer mode, and whether continuous sampling of the ADC module in the software initialization stage of the ADC module are as follows:
[0016] 1). It is known that the input clock of the F28335 chip is 20MHz. After the internal 10 times and 2 division register settings are converted, a 100MHz system clock SYSCLK is generated; the high-speed peripheral pre-division register SysCtrlRegs.HSPCLK is set to 2 to generate a high-speed on-chip peripheral clock of 100 / 2 / 2 = 25MHz for the ADC module;
[0017] 2). The ADCLKPS field of the ADCTRL3 register of the ADC module is set to 0, and the CPS field of the ADCTRL1 register is set to 0, which is used to keep HSPCLK without frequency division and directly output as 25MHz ADCCLK with a period of 40ns;
[0018] 3). The SMODE_SEL field of the ADCTRL3 register of the ADC module is set to 0 to determine the use of sequential sampling mode instead of dual-channel simultaneous sampling mode;
[0019] 4). The ACQ_PS field of the ADCTRL1 register of the ADC module is set to 7, which is used to determine the sampling time window as 7+1 times the ADCCLK cycle, that is, the sampling time of each input analog signal is 8*40ns=320ns in total;
[0020] 5). The SEQ_CASC field of the ADCTRL1 register of the ADC module is set to 1, which is used to determine that the two 8-channel sequencers SEQ1 and SEQ2 inside the ADC module are combined into a superimposed 16-channel sequencer;
[0021] 6). The CONT_RUN field of the ADCTRL1 register of the ADC module is set to 0, which is used to determine that after SEQ completes all signal conversions each time, the next round of sequence conversion is stopped until a new round of sequence conversion is initiated;
[0022] 7). In the sequencer overlay mode, the CONV00~15 fields in the ADCCHSELSEQ1~4 registers of the ADC module are set to 0~15 respectively, and the ADCMAXCONV register is set to 15, which is used to inform the overlay sequencer SEQ that the total number of signals for each sequence conversion is 15+1=16, and the order of the signals is the 0th to 7th signals of group A and the 0th to 7th signals of group B; the register initialization of the ADC module is now completed, and in the subsequent main loop stage implemented by the processor module, the AD conversion results of 16 channels are obtained through the following operations;
[0023] 8). Before starting each sequence conversion, set the RST_SEQ1 field of the ADCTRL2 register of the ADC module to 1 to reset the sequencer state to the initial state, wait for the trigger instruction to start the sequence conversion, and prepare to start the conversion from the first signal;
[0024] 9). Set the SOC_SEQ1 field of the ADCTRL2 register to 1 to start a new round of sequence conversion;
[0025] 10). Wait for the INT_SEQ1 field of the ADCST register of the ADC module to become non-0. Although it is an interrupt flag and 1 is valid, when the interrupt is not enabled, the ADC module sets it to 1 each time the sequencer completes all signal conversions. Therefore, when it is 1, it is determined that the ADC module has completed a sequence conversion.
[0026] 11). Set the INT_SEQ1_CLR field of the ADCST register to 1 to clear the INT_SEQ1 flag;
[0027] 12). Read the conversion result from the upper 12 bits of the ADC module's 16 result registers, ADCRESULT0 to 15, and save them in a temporary array;
[0028] 13). Repeat steps 8) to 13) for a total of 3 times, take the average of the 16 results of the 3 sequence conversions to generate the final conversion result. The final conversion result occupies a total of 32 bytes, each result occupies 2 bytes, the high 8 bits are in front, the low 8 bits are in the back, the high 4 bits are invalid, and the remaining 12 bits of data are valid data in the final conversion result, ranging from 0 to 4095, corresponding to 0 to 3V in proportion.
[0029] Preferably, the registers in the SCI module SCIB are configured as follows, so that the SCIB has the function of receiving and sending serial port data in FIFO mode:
[0030] It is known that the input clock of the F28335 chip is 20MHz. After conversion by the 10 times and 2 division registers in the SCIB, a 100MHz system clock SYSCLK is generated. Then the low-speed peripheral pre-division register SysCtrlRegs.LSPCLK in the SCIB is set to 2 to generate a low-speed on-chip peripheral clock of 100 / 2 / 2=25MHz for use by the SCIB.
[0031] Initialize the five registers in SCIB and determine the GPIO pins of the F28335 chip used by the SCIB module; use GPIO18 as the transmit pin and GPIO19 as the receive pin, enable the internal pull-up resistors of these two pins, and set the receive pin to asynchronous sampling mode;
[0032] Initialize the receiving interrupt service function of SCIB. When a receiving error occurs in SCIB, an interrupt is generated and the SCIB is reset by software in the receiving interrupt service function. The SWRESET field of the SCICTL1 register in SCIB is first written to 0 and then to 1 to complete the reset so that it can continue to receive data normally.
[0033] Enable the peripheral interrupt expansion module PIE Block, enable the 9th group No. 3 interrupt of PIE Block, enable the 9th group interrupt in the interrupt enable register, and turn on the interrupt general enable switch;
[0034] Configure the FIFO register of SCIB. In hardware, the receiving and transmitting channels each have a 16-byte FIFO. First, write 0 to the TXFIFOXRESET position of the SCIFFTX register in SCIB, and then write 1 to the SCIRST, SCIFFENA, TXFIFOXRESET, and TXFFINTCLR of the SCIFFTX register. This is to turn on the FIFO function of SCIB, continue to send and receive, reset the pointer of the transmit FIFO to 0, and clear the transmit FIFO interrupt flag. First, write 0 to the RXFIFORESET position of the SCIFFRX register, and then write 1 to the RXFIFORESET, RXFFINTCLR, and 15 to the RXFFIL position of the SCIFFRX register. This is to reset the pointer of the receive FIFO to 0, re-enable the receive FIFO, clear the receive FIFO interrupt flag, and set the byte quantity threshold of the receive FIFO interrupt to 15 bytes.
[0035] Configure the SCICHAR of the SCICCR register in the SCIB to 7 and the other fields to 0, which means that the SCIB uses 1 stop bit, non-loopback, no parity check, and 8-bit transmission as a serial port; configure the SCILBAUD register in the SCIB to 0x1A; configure the RXENA, TXENA, RXERRINTENA, and SWRESET fields of the SCICTL1 register in the SCIB to 1, which enables the receiving and sending functions of the SCIB, enables the receiving error interrupt, and makes the SCIB start to work normally.
[0036] Preferably, the SCIB receive interrupt is on interrupt number 3 of group 9.
[0037] Preferably, the core of the F28335 chip only supports 16 interrupt line sources in total, which is much smaller than the dozens of on-chip peripheral interrupts that may be generated.
[0038] Preferably, the relay state detection process implemented by the processor module is as follows:
[0039] 1). Wait for the RXFFST field of the SCIFFRX register in the SCIB to become non-zero, indicating that the hardware module SCIB has new data received into the FIFO;
[0040] 2). Read the received byte content from the SCIRXBUF register in the SCIB, and compare it with the fixed 5-byte sequence (0x55, 0xAA, 0x01, 0x61, 0x02) one by one, that is, compare the i-th byte received with the i-th byte of the 5-byte sequence, 1<=i<=5; if all 5 bytes are the same as the fixed sequence, it means that the detection device has received the detection command from the host computer normally, and then starts the AD conversion operation; if any byte received in the middle is inconsistent with the fixed sequence, write 0 first and then 1 in the RXFIFORESET field of the SCIFFRX register to reset the receive FIFO, receive new bytes again and start judging from the first byte of the fixed sequence;
[0041] 3). Repeat the AD conversion operation three times to obtain three AD conversion results. The operation process for each time is:
[0042] (1) Set the RST_SEQ1 field of the ADCTRL2 register of the ADC module to 1 to reset the sequencer SEQ1 to the initial state CONV00;
[0043] (2) Set the SOC_SEQ1 field of the ADCTRL2 register to 1 to start the automatic conversion operation of the sequencer of the ADC module;
[0044] (3) Wait for the interrupt flag INT_SEQ1 field of the ADCST register to automatically change to 1, indicating that all sequencer AD conversion operations have been completed;
[0045] (4) Set the INT_SEQ1_CLR field of the ADCST register to 1 to clear the INT_SEQ1 interrupt flag;
[0046] (5) Read the high 12 bits from the 16 registers ADCRESULT0 to ADCRESULT15 of the ADC module as the AD conversion results of the 16 channels and save them in a temporary array; the lowest 0 of the 12-bit binary number represents 0V, and the highest 4095 represents 3V;
[0047] 4). Take the average of the three AD conversion results as the final result; each channel result occupies two bytes, the lower 12 bits are valid, and the upper 4 bits are invalid, a total of 32 bytes;
[0048] 5). Send the 32-byte result to the host computer through the serial port in a fixed format, the fixed format is: 0x55, 0xAA, 0x20, 32 bytes, checksum; wherein the 1st and 2nd bytes are fixed data headers, the 3rd byte 0x20 is the length of the subsequent valid data is 32, and the checksum is the final result starting from the 3rd byte 0x20, accumulated with the subsequent bytes in sequence and then divided modulo 256.
[0049] Preferably, in step 5, when sending data, when it is determined that the value of the TXFFST field in the SCIFFTX register in the SCIB is greater than or equal to 16, the sending operation is no longer performed, that is, the writing of the next byte to be sent into the SCITXBUF register is stopped; when the value of the TXFFST field is greater than or equal to 16, it means that the sending FIFO in the SCIB is full, and the new sending byte can be written only after the SCIB completes sending the next byte.
[0050] Preferably, the F28335 chip is a TMS320F28335 digital signal processor.
[0051] The invention also provides a detection device implemented based on the method.
[0052] The invention also provides an application of the device in the field of electronic technology.
[0053] (III) Beneficial effects
[0054] The present invention proposes a method for realizing a relay state detection device based on a TMS320F28335 digital signal processor, which establishes communication with the host computer software using the RS422 bus, completes the A / D acquisition, data conversion and feedback functions of the power supply state of the relay control end (input stage), the power input end and the power output end (output stage) under the control of the host computer software, and provides the host computer software with the current relay working state. When a fault occurs, the host computer software can accurately locate the specific faulty relay unit, shorten the equipment troubleshooting time, and improve the equipment health management capability. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] Figure 1 It is a schematic diagram of the connection relationship of the upper computer software in the existing equipment that is responsible for controlling the primary and secondary relays;
[0056] Figure 2 It is a structural schematic diagram of a relay state detection device of the present invention;
[0057] Figure 3 It is a software processing flow chart of the device of the present invention. DETAILED DESCRIPTION
[0058] In order to make the purpose, content and advantages of the present invention more clear, the specific implementation methods of the present invention are further described in detail below in conjunction with the drawings and examples.
[0059] The following is a detailed introduction to the specific content of the relay state detection device using the TMS320F28335 digital signal processor. It mainly includes the hardware circuit connection method (such as Figure 2 As shown), the setting method and software processing flow of the registers in the two on-chip ADC and SCI modules (as shown Figure 3 shown).
[0060] Hardware circuit connection method
[0061] The hardware of the detection device mainly includes the ADC module, SCI module, processor module in the F28335 chip, and two interface circuits based on the F28335 chip, one is the RS422 bus interface circuit, which is used to complete data communication with the host computer; the other is the 16-channel AD conversion interface circuit, which is used to collect up to 16 relay output signals. They are designed according to the requirements of the F28335 chip manual.
[0062] One end of the RS422 bus interface circuit is connected to the serial communication interface B pin (SCIB) in the three SCI modules in the F28335 chip, and the other end is connected to the RS422 interface line of the host computer; the RS422 bus interface circuit is responsible for converting serial port data between UART level and differential RS422 level.
[0063] The ADC conversion interface circuit is mainly composed of a voltage divider circuit and an op amp follower circuit. The voltage divider circuit divides the 28V output of the relay at a ratio of 1 / 10 and converts it into 2.8V, which matches the input voltage range of 0~3V of the ADC module (AD conversion module) of the F28335 chip. It is then transmitted to the ADC pin of the ADC module in the F28335 chip through the op amp follower circuit to maintain the stability of the input signal amplitude.
[0064] Configuration and usage of ADC module
[0065] The ADC module of the F28335 chip is called the analog-to-digital conversion module. It can convert up to 16 analog signals at the same time, which are divided into two groups, AB, with 8 signals in each group. The range is 0~3V, and the digital accuracy is 12 bits. In addition to the core 12-bit digital-to-analog converter, the ADC module also has two sequencers, SEQ1 and SEQ2. In the sequencer non-overlapping mode, they each form a sequence set of up to 8 analog signals, and perform AD acquisition and conversion operations in sequence, that is, batch automatic conversion of the signal sequence set, and save the results to the corresponding registers of the ADC module; in the sequencer overlapping mode, the two sequencers are merged into one sequencer SEQ, and one sequence conversion can include AD acquisition and conversion of up to 16 signals and at least 1 signal. In the dual-channel simultaneous sampling mode, the Nth signal of the two groups A and B can be sampled and converted at the same time, 0<=N<=7; in the sequential sampling mode, only one signal is sampled at a time. The acquisition order of each analog signal, the total number of signals and the start acquisition instruction of the entire sequence are all implemented by the corresponding configured registers.
[0066] The register configuration of the ADC module is completed during the software initialization phase of the ADC module, which is used to determine the ADC module's clock frequency, signal sampling time window, signal sampling order, total number of signal samples, sequential sampling / simultaneous sampling mode, whether it is an overlay sequencer mode, whether continuous sampling, and other usage details. The specific implementation methods and basis of these usage details in the software are as follows:
[0067] 1). It is known that the input clock of the F28335 chip is 20MHz. After the internal 10 times and 2 times register setting results are converted, a 100MHz system clock SYSCLK is generated. Based on this, the high-speed peripheral pre-division register SysCtrlRegs.HSPCLK is set to 2 to generate a high-speed on-chip peripheral clock of 100 / 2 / 2 = 25MHz for the ADC module.
[0068] 2). The ADCLKPS field of the ADCTRL3 register of the ADC module is set to 0, and the CPS field of the ADCTRL1 register is set to 0, which is used to keep HSPCLK without frequency division and directly output as 25MHz ADCCLK with a period of 40ns.
[0069] 3). The SMODE_SEL field of the ADCTRL3 register of the ADC module is set to 0 to determine the use of sequential sampling mode instead of dual-channel simultaneous sampling mode.
[0070] 4). The ACQ_PS field of the ADCTRL1 register of the ADC module is set to 7, which is used to determine the sampling time window to be 7+1 times the ADCCLK cycle, that is, the sampling time of each input analog signal is a total of 8*40ns=320ns.
[0071] 5). The SEQ_CASC field of the ADCTRL1 register of the ADC module is set to 1 to determine that the two 8-channel sequencers SEQ1 and SEQ2 inside the ADC module are combined into a 16-channel sequencer after superposition.
[0072] 6). The CONT_RUN field of the ADCTRL1 register of the ADC module is set to 0, which is used to determine that after SEQ completes all signal conversions each time, the next round of sequence conversion is stopped until the software initiates a new round of sequence conversion.
[0073] 7). Since 16-channel AD conversion is to be performed, in the sequencer overlay mode, the CONV00~15 fields in the ADCCHSELSEQ1~4 registers of the ADC module are set to 0~15 respectively, and the ADCMAXCONV register is set to 15, which is used to inform the overlay sequencer SEQ that the total number of signals for each sequence conversion is 15+1=16, and the order of the signals is the 0th to 7th signals of group A and the 0th to 7th signals of group B; the register initialization work of the ADC module is now completed, and subsequently in the main loop stage of the software, the AD conversion results of the 16 channels can be obtained through the following operations.
[0074] 8). Before starting each sequence conversion, set the RST_SEQ1 field of the ADCTRL2 register of the ADC module to 1 to reset the sequencer state to the initial state, wait for the trigger instruction to start the sequence conversion, and prepare to start the conversion from the first signal.
[0075] 9). Set the SOC_SEQ1 field of the ADCTRL2 register to 1 to start a new round of sequence conversion.
[0076] 10). Wait for the INT_SEQ1 field of the ADCST register of the ADC module to become non-0. Although it is an interrupt flag and 1 is valid, when the interrupt is not enabled, the ADC module will set it to 1 each time the sequencer completes all signal conversions. Therefore, the software can determine that the ADC module has completed a sequence conversion when it is 1.
[0077] 11). Set the INT_SEQ1_CLR field of the ADCST register to 1 to clear the INT_SEQ1 flag.
[0078] 12). Read the conversion result from the upper 12 bits of the 16 result registers ADCRESULT0 to 15 of the ADC module and save them in a temporary array.
[0079] 13). Repeat steps 8) to 13) for a total of 3 times, and average the 16 results of the 3 sequence conversions to generate the final conversion result. The final conversion result occupies a total of 32 bytes, with each result occupying 2 bytes, with the high 8 bits in front and the low 8 bits in the back. The high 4 bits are invalid, and the remaining 12 bits are valid data in the final conversion result, ranging from 0 to 4095, corresponding to 0 to 3V in proportion.
[0080] SCI module configuration and usage
[0081] The SCI module of the F28335 chip stands for serial communication interface module. There are three modules in total, numbered SCIA, SCIB, and SCIC. Here, the configuration registers under SCIB are used as an example to illustrate how to set the registers in the SCI module SCIB.
[0082] 1. It is known that the input clock of the F28335 chip is 20MHz. After the conversion of the 10 times and 2 division register settings in the SCIB, a 100MHz system clock SYSCLK is generated. Based on this, the low-speed peripheral pre-division register SysCtrlRegs.LSPCLK in the SCIB is set to 2 to generate a low-speed on-chip peripheral clock of 100 / 2 / 2 = 25MHz for use by the SCI module SCIB.
[0083] 2. Initialize the five registers in SCIB and determine the GPIO pins of the F28335 chip used by the SCIB module. Combined with the hardware circuit design, GPIO18 is used as the sending pin and GPIO19 as the receiving pin, and the internal pull-up resistors of these two pins are enabled, and the receiving pin is set to asynchronous sampling mode.
[0084] 3. Initialize the receiving interrupt service function of SCIB. When a receiving error occurs in SCIB, an interrupt is generated and the SCIB is reset by software in the receiving interrupt service function. First write 0 to the SWRESET field of the SCICTL1 register in SCIB, then write 1 to complete the reset so that it can continue to receive data normally.
[0085] 4. Enable PIE Block (Peripheral Interrupt Extension Module), enable interrupt No. 3 of Group 9 of PIE Block, enable interrupt No. 9 in the interrupt enable register, and turn on the interrupt general enable switch. The core of the F28335 chip only supports 16 interrupt line sources in total, which is far less than the dozens of on-chip peripheral interrupts that may be generated. Therefore, using PIE Block, the original 12 interrupts of the core can be divided into groups of 8 interrupts per group. This can meet the interrupt quantity requirements of all on-chip peripherals. Among them, the SCIB receive interrupt is on the interrupt No. 3 of Group 9.
[0086] 5. Configure the FIFO register of SCIB. In hardware, the receiving and transmitting channels each have a 16-byte FIFO. Software can use them to improve the robustness of the code. First write 0 to the TXFIFOXRESET position of the SCIFFTX register in SCIB, and then write 1 to the SCIRST, SCIFFENA, TXFIFOXRESET and TXFFINTCLR of the SCIFFTX register. This is to turn on the FIFO function of SCIB, continue to send and receive, reset the pointer of the transmit FIFO to 0, and clear the transmit FIFO interrupt flag; first write 0 to the RXFIFORESET position of the SCIFFRX register, and then write 1 to the RXFIFORESET, RXFFINTCLR and RXFFIL position of the SCIFFRX register, which is to reset the pointer of the receive FIFO to 0, re-enable the receive FIFO, clear the receive FIFO interrupt flag, and set the byte quantity threshold of the receive FIFO interrupt to 15 bytes.
[0087] 6. Configure the SCICHAR of the SCICCR register in the SCIB to 7, and the other fields to 0, which means that the SCIB uses 1 stop bit, no loopback, no parity check, and 8-bit transmission as a serial port; configure the SCILBAUD register in the SCIB to 0x1A (corresponding to decimal 26), and under the premise that the low-speed peripheral clock is 25MHz, it will generate 25000000 / (26+1) / 8=115741Bit / s baud rate data, which is closest to the baud rate of 115200. Configure the RXENA, TXENA, RXERRINTENA and SWRESET fields of the SCICTL1 register in the SCIB to 1, which is used to enable the receiving and sending functions of the SCIB, enable the receiving error interrupt, and make the SCIB start to work normally.
[0088] After the software configures the relevant registers in the SCIB according to the above process, the hardware SCIB already has the function of sending and receiving serial port data in FIFO mode.
[0089] The software main loop processing process (relay status detection process) implemented by the processor module:
[0090] 1. Wait for the RXFFST field of the SCIFFRX register in the SCIB to become non-zero, indicating that the hardware module SCIB has new data received into the FIFO;
[0091] 2. Read the received byte content from the SCIRXBUF register in the SCIB, and compare it with the fixed 5-byte sequence (0x55, 0xAA, 0x01, 0x61, 0x02) one by one, that is, compare the i-th (1<=i<=5) byte received with the i-th byte of the 5-byte sequence. If all 5 bytes are identical to the fixed sequence, it means that the detection device has received the detection command from the host computer software normally, and then starts the AD conversion operation; if any byte received in the middle is inconsistent with the fixed sequence, write 0 first and then 1 in the RXFIFORESET field of the SCIFFRX register to reset the receive FIFO, receive new bytes again and start judging from the first byte of the fixed sequence;
[0092] 3. Repeat the AD conversion operation three times to obtain three AD conversion results. The operation process for each time is:
[0093] 1) Set the RST_SEQ1 field of the ADCTRL2 register of the ADC module to 1 to reset the sequencer SEQ1 to the initial state CONV00;
[0094] 2) Set the SOC_SEQ1 field of the ADCTRL2 register to 1 to start the automatic conversion operation of the sequencer of the ADC module;
[0095] 3) Wait for the interrupt flag INT_SEQ1 field of the ADCST register to automatically change to 1, indicating that all sequencer AD conversion operations have been completed;
[0096] 4) Set the INT_SEQ1_CLR field of the ADCST register to 1 to clear the INT_SEQ1 interrupt flag. Although the INT_SEQ1 interrupt flag is used here and no interrupt-related configuration has been performed before, the ADC module will still automatically generate an interrupt flag after the sequencer is executed, so the software can judge and use it normally.
[0097] 5) Read the high 12 bits from the 16 registers ADCRESULT0 to ADCRESULT15 of the ADC module as the AD conversion results of 16 channels and save them in a temporary array; the lowest 0 of the 12-bit binary number represents 0V, and the highest 4095 represents 3V;
[0098] 4. Take the average of the three AD conversion results as the final result. Each channel result occupies two bytes, the lower 12 bits are valid, and the upper 4 bits are invalid, a total of 32 bytes;
[0099] 5. Send the 32-byte result to the host computer through the serial port in a fixed format, the fixed format is: 0x55, 0xAA, 0x20, 32 bytes, checksum; wherein the first and second bytes are fixed data headers, the third byte 0x20 is the length of the subsequent valid data is 32, and the checksum is the final result starting from the third byte 0x20, accumulated with the subsequent bytes in sequence and then divided modulo 256.
[0100] In step 5, when sending data, when it is determined that the value of the TXFFST field in the SCIFFTX register in the SCIB is greater than or equal to 16, the sending operation is no longer performed, that is, the next byte to be sent is stopped in the SCITXBUF register; when the value of the TXFFST field is greater than or equal to 16, it means that the send FIFO in the SCIB is full, and the software must wait for the SCIB to complete the next byte transmission before continuing to write the new transmission byte.
[0101] The hardware part of the detection device and the cross-linking relationship between the two hardware interfaces of the host computer refer to Figure 1 , 2 The software part of the processor module is implemented in C language programming in the development environment based on the F28335 chip. The software performs the following functions in sequence from startup to the initial stage of entering the main loop:
[0102] 1. The crystal array output frequency used by the hardware is 20MHz. When the software initializes the phase-locked loop parameters, it uses the parameter of multiplying 10 and dividing 2 to determine the internal system clock of the chip to be 20*10 / 2=100MHz.
[0103] 2. The division coefficients of the high-speed peripheral HSPCLK and the low-speed peripheral LSPCLK are both set to 2, which is used to generate a 100 / 2 / 2=25MHz clock for the ADC peripheral module (high speed) and the SCI peripheral module (low speed).
[0104] 3. Turn on the ADC module peripheral and SCIB peripheral clock source.
[0105] 4. Initialize the SCIB pins according to the hardware circuit definition.
[0106] 5. Initialize the peripheral interrupt expansion module PIE and set the interrupt service function of SCIB.
[0107] 6. Initialize the ADC module, use two 8-channel sequencers to superimpose a 16-channel sequencer, sample the 16-channel voltages in sequence, and stop immediately after the sampling is completed.
[0108] 7. Initialize the SCIB's FIFO function and serial port parameters to approximately 115200 baud rate, 8 bits, 1 stop bit, and no parity.
[0109] In the main loop of the software, the software determines whether the byte sequence received by SCIB satisfies the fixed sequence 0x55, 0xAA, 0x01, 0x61, 0x62 in sequence. If all of them are satisfied, AD conversion and result transmission operations are performed. If any byte does not match the fixed sequence, the receive FIFO data is cleared and new bytes are waited for input from SCIB again.
[0110] The AD conversion is repeated three times. Each time the SEQ sequencer is reset, the sequencer starts the conversion, waits for the conversion completion flag to be valid, clears the conversion completion flag, and obtains the 16-channel conversion results.
[0111] After AD conversion, the average of the three conversion results is calculated as the final conversion result, and sent to the host computer through the SCIB's send FIFO in a fixed format to complete all the processes of this AD conversion.
[0112] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A method for implementing a relay state detection device, characterized in that: The device is designed to include an ADC module, an SCI module, a processor module in the F28335 chip, and two interface circuits based on the F28335 chip, one is an RS422 bus interface circuit for data communication with the host computer; the other is a 16-channel AD conversion interface circuit for collecting a maximum of 16 relay output signals; One end of the RS422 bus interface circuit is connected to the serial communication interface B pin module SCIB among the three SCI modules in the F28335 chip, and the other end is connected to the RS422 interface line of the host computer; The RS422 bus interface circuit is responsible for converting serial port data between UART level and differential RS422 level; The ADC conversion interface circuit includes a voltage divider circuit and an op amp follower circuit. The voltage divider circuit divides the 28V output of the relay by a ratio of 1 / 10 and converts it into 2.8V, which matches the input voltage range of 0-3V of the ADC module of the F28335 chip. The voltage is then transmitted to the ADC pin of the ADC module in the F28335 chip through the op amp follower circuit to maintain the stability of the input signal amplitude. The ADC module converts up to 16 analog signals at the same time, which are divided into two groups, A and B, with 8 signals in each group. In addition to the 12-bit digital-to-analog converter, the ADC module also has two sequencers, SEQ1 and SEQ2. In the sequencer non-overlapping mode, they each form a sequence set with up to 8 analog signals, and perform AD acquisition and conversion operations in sequence, that is, batch automatic conversion of the signal sequence set, and save the results to the corresponding registers of the ADC module; in the sequencer overlapping mode, the two sequencers are combined into one sequencer SEQ, and one sequence conversion includes AD acquisition and conversion of up to 16 signals and at least 1 signal; in the dual-channel simultaneous sampling mode, the Nth signal of the two groups A and B is sampled and converted at the same time, 0<=N<=7; in the sequential sampling mode, only one signal is sampled at a time; the acquisition order of each analog signal, the total number of signals and the entire sequence start acquisition instruction are all implemented by the configured corresponding registers; During the software initialization phase of the ADC module, the register configuration of the ADC module is completed to determine the clock frequency of the ADC module, the signal sampling time window, the signal sampling sequence, the total number of signal samples, the sequential sampling / simultaneous sampling mode, whether it is the superposition sequencer mode, and whether continuous sampling; There are three SCI modules, namely, serial communication interface A pin module SCIA, serial communication interface B pin module SCIB, serial communication interface C pin module SCIC. The three SCI modules are configured so that SCIB has the function of sending and receiving serial port data with FIFO mode. The processor module implements the relay status detection process based on the configuration of the ADC module and the SCI module.
2. The method according to claim 1, characterized in that The specific implementation methods and basis for determining the clock frequency, signal sampling time window, signal sampling order, total number of signal samples, sequential sampling / simultaneous sampling mode, whether it is the superposition sequencer mode, and whether continuous sampling of the ADC module during the software initialization phase of the ADC module are as follows: 1). It is known that the input clock of the F28335 chip is 20MHz. After the internal 10 times and 2 division register settings are converted, a 100MHz system clock SYSCLK is generated; the high-speed peripheral pre-division register SysCtrlRegs.HSPCLK is set to 2 to generate a high-speed on-chip peripheral clock of 100 / 2 / 2 = 25MHz for the ADC module; 2). The ADCLKPS field of the ADCTRL3 register of the ADC module is set to 0, and the CPS field of the ADCTRL1 register is set to 0, which is used to keep HSPCLK without frequency division and directly output as 25MHz ADCCLK with a period of 40ns; 3). The SMODE_SEL field of the ADCTRL3 register of the ADC module is set to 0 to determine the use of sequential sampling mode instead of dual-channel simultaneous sampling mode; 4). The ACQ_PS field of the ADCTRL1 register of the ADC module is set to 7, which is used to determine the sampling time window as 7+1 times the ADCCLK cycle, that is, the sampling time of each input analog signal is 8*40ns=320ns in total; 5). The SEQ_CASC field of the ADCTRL1 register of the ADC module is set to 1, which is used to determine that the two 8-channel sequencers SEQ1 and SEQ2 inside the ADC module are combined into a superimposed 16-channel sequencer; 6). The CONT_RUN field of the ADCTRL1 register of the ADC module is set to 0, which is used to determine that after SEQ completes all signal conversions each time, the next round of sequence conversion is stopped until a new round of sequence conversion is initiated; 7). In the sequencer overlay mode, the CONV00~15 fields in the ADCCHSELSEQ1~4 registers of the ADC module are set to 0~15 respectively, and the ADCMAXCONV register is set to 15, which is used to inform the overlay sequencer SEQ that the total number of signals for each sequence conversion is 15+1=16, and the order of the signals is the 0th to 7th signals of group A and the 0th to 7th signals of group B; the register initialization of the ADC module is now completed, and in the subsequent main loop stage implemented by the processor module, the AD conversion results of 16 channels are obtained through the following operations; 8). Before starting each sequence conversion, set the RST_SEQ1 field of the ADCTRL2 register of the ADC module to 1 to reset the sequencer state to the initial state, wait for the trigger instruction to start the sequence conversion, and prepare to start the conversion from the first signal; 9). Set the SOC_SEQ1 field of the ADCTRL2 register to 1 to start a new round of sequence conversion; 10). Wait for the INT_SEQ1 field of the ADCST register of the ADC module to become non-0. Although it is an interrupt flag and 1 is valid, when the interrupt is not enabled, the ADC module sets it to 1 each time the sequencer completes all signal conversions. Therefore, when it is 1, it is determined that the ADC module has completed a sequence conversion. 11). Set the INT_SEQ1_CLR field of the ADCST register to 1 to clear the INT_SEQ1 flag; 12). Read the conversion result from the upper 12 bits of the ADC module's 16 result registers, ADCRESULT0 to 15, and save them in a temporary array; 13). Repeat steps 8) to 13) for a total of 3 times, take the average of the 16 results of the 3 sequence conversions to generate the final conversion result. The final conversion result occupies a total of 32 bytes, each result occupies 2 bytes, the high 8 bits are in front, the low 8 bits are in the back, the high 4 bits are invalid, and the remaining 12 bits of data are valid data in the final conversion result, ranging from 0 to 4095, corresponding to 0 to 3V in proportion.
3. The method according to claim 2, characterized in that Configure the registers in the SCI module SCIB as follows to enable SCIB to send and receive serial port data in FIFO mode: It is known that the input clock of the F28335 chip is 20MHz. After conversion by the 10 times and 2 division registers in the SCIB, a 100MHz system clock SYSCLK is generated. Then the low-speed peripheral pre-division register SysCtrlRegs.LSPCLK in the SCIB is set to 2 to generate a low-speed on-chip peripheral clock of 100 / 2 / 2=25MHz for use by the SCIB. Initialize the five registers in SCIB and determine the GPIO pins of the F28335 chip used by the SCIB module; use GPIO18 as the transmit pin and GPIO19 as the receive pin, enable the internal pull-up resistors of these two pins, and set the receive pin to asynchronous sampling mode; Initialize the receiving interrupt service function of SCIB. When a receiving error occurs in SCIB, an interrupt is generated and the SCIB is reset by software in the receiving interrupt service function. The SWRESET field of the SCICTL1 register in SCIB is first written to 0 and then to 1 to complete the reset so that it can continue to receive data normally. Enable the peripheral interrupt expansion module PIE Block, enable the 9th group No. 3 interrupt of PIE Block, enable the 9th group interrupt in the interrupt enable register, and turn on the interrupt general enable switch; Configure the FIFO register of SCIB. In hardware, the receiving and transmitting channels each have a 16-byte FIFO. First, write 0 to the TXFIFOXRESET position of the SCIFFTX register in SCIB, and then write 1 to the SCIRST, SCIFFENA, TXFIFOXRESET, and TXFFINTCLR of the SCIFFTX register. This is to turn on the FIFO function of SCIB, continue to send and receive, reset the pointer of the transmit FIFO to 0, and clear the transmit FIFO interrupt flag. First, write 0 to the RXFIFORESET position of the SCIFFRX register, and then write 1 to the RXFIFORESET, RXFFINTCLR, and 15 to the RXFFIL position of the SCIFFRX register. This is to reset the pointer of the receive FIFO to 0, re-enable the receive FIFO, clear the receive FIFO interrupt flag, and set the byte quantity threshold of the receive FIFO interrupt to 15 bytes. Configure the SCICHAR of the SCICCR register in the SCIB to 7 and the other fields to 0, which means that the SCIB uses 1 stop bit, non-loopback, no parity check, and 8-bit transmission as a serial port; configure the SCILBAUD register in the SCIB to 0x1A; configure the RXENA, TXENA, RXERRINTENA, and SWRESET fields of the SCICTL1 register in the SCIB to 1, which enables the receiving and sending functions of the SCIB, enables the receiving error interrupt, and makes the SCIB start to work normally.
4. The method according to claim 3, characterized in that The SCIB receive interrupt is on interrupt number 3 of group 9.
5. The method according to claim 3, characterized in that The core of the F28335 chip only supports a total of 16 interrupt line sources, which is far less than the dozens of on-chip peripheral interrupts that may be generated.
6. The method according to claim 3, characterized in that The relay status detection process implemented by the processor module is as follows: 1). Wait for the RXFFST field of the SCIFFRX register in the SCIB to become non-zero, indicating that the hardware module SCIB has new data received into the FIFO; 2). Read the received byte content from the SCIRXBUF register in the SCIB, and compare it with the fixed 5-byte sequence (0x55, 0xAA, 0x01, 0x61, 0x02) one by one, that is, compare the i-th byte received with the i-th byte of the 5-byte sequence, 1<=i<=5; if all 5 bytes are the same as the fixed sequence, it means that the detection device has received the detection command from the host computer normally, and then starts the AD conversion operation; if any byte received in the middle is inconsistent with the fixed sequence, write 0 first and then 1 in the RXFIFORESET field of the SCIFFRX register to reset the receive FIFO, receive new bytes again and start judging from the first byte of the fixed sequence; 3). Repeat the AD conversion operation three times to obtain three AD conversion results. The operation process for each time is: (1) Set the RST_SEQ1 field of the ADCTRL2 register of the ADC module to 1 to reset the sequencer SEQ1 to the initial state CONV00; (2) Set the SOC_SEQ1 field of the ADCTRL2 register to 1 to start the automatic conversion operation of the sequencer of the ADC module; (3) Wait for the interrupt flag INT_SEQ1 field of the ADCST register to automatically change to 1, indicating that all sequencer AD conversion operations have been completed; (4) Set the INT_SEQ1_CLR field of the ADCST register to 1 to clear the INT_SEQ1 interrupt flag; (5) Read the high 12 bits from the 16 registers ADCRESULT0 to ADCRESULT15 of the ADC module as the AD conversion results of 16 channels and save them in a temporary array; The lowest 0 of a 12-bit binary number represents 0V, and the highest 4095 represents 3V; 4). Take the average of the three AD conversion results as the final result; each channel result occupies two bytes, the lower 12 bits are valid, and the upper 4 bits are invalid, a total of 32 bytes; 5). Send the 32-byte result to the host computer through the serial port in a fixed format, the fixed format is: 0x55, 0xAA, 0x20, 32 bytes, checksum; wherein the 1st and 2nd bytes are fixed data headers, the 3rd byte 0x20 is the length of the subsequent valid data is 32, and the checksum is the final result starting from the 3rd byte 0x20, accumulated with the subsequent bytes in sequence and then divided modulo 256.
7. The method according to claim 6, characterized in that In step 5, when sending data, when it is determined that the value of the TXFFST field in the SCIFFTX register in the SCIB is greater than or equal to 16, the sending operation is no longer performed, that is, the next byte to be sent is stopped in the SCITXBUF register; when the value of the TXFFST field is greater than or equal to 16, it means that the send FIFO in the SCIB is full, and the new send byte can be written only after the SCIB completes the next byte transmission.
8. The method according to claim 1, characterized in that The F28335 chip is a TMS320F28335 digital signal processor.
9. A detection device implemented based on the method according to any one of claims 1 to 8.
10. Use of the device as claimed in claim 9 in the field of electronic technology.
