Method and system for calculating average current of proportional electromagnetic valve
Through the collaborative work of peripheral hardware circuits and DMA modules, accurate sampling and calculation of high-frequency currents are achieved, solving the problems of high CPU load and large calculation errors in traditional methods, and improving the accuracy and efficiency of solenoid valve average current calculations.
Patent Information
- Application Number
- CN202410664552.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-27
- Publication Date
- 2024-08-27
AI Technical Summary
Traditional solenoid valve average current calculation relies on high-frequency ADC sampling, resulting in high CPU load and vulnerability to PWM switching noise interference. Reducing the ADC sampling frequency will lead to increased calculation errors.
The current signal is collected through the peripheral hardware circuit and transmitted to the ADC module for conversion processing. After the current data is obtained, it is selectively transmitted to the RAM module through the DMA module. Based on the RAM module, the preset calculation strategy is used for calculation to realize the sampling and calculation of high-frequency current. , reduce CPU load.
While ensuring the accuracy of average current calculation, it reduces the CPU load, improves the utilization of hardware resources, reduces the CPU load pressure, and improves the system response speed and calculation accuracy.
Smart Images

Figure CN118549690A
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of electrical control, and in particular to a method and system for calculating average current of a proportional solenoid valve. Background Art
[0002] When the proportional solenoid valve is used, the average current control mode is basically adopted, that is, a current reference value is set, and the PWM (Pulse Width Modulation) generator will adjust the duty cycle so that the average current generated by the solenoid valve is consistent with the reference current. Therefore, the measurement of the solenoid valve current and the calculation of the average current are crucial, which is related to the current control accuracy of the solenoid valve. The traditional solenoid valve average current acquisition relies on high-frequency ADC (Analog-To-Digital Converter) sampling, and periodically triggers interrupts to complete the accumulation and average value calculation in the interrupt service program. When the ADC sampling frequency is very high, the CPU (Central Processing Unit) will spend a lot of time performing the accumulation operation, which not only affects the system response, but also the calculation result is easily interfered by the PWM switching noise. If the ADC sampling frequency is reduced, the average current calculation will produce a large error due to insufficient sampling points.
[0003] Therefore, how to reduce the CPU load while ensuring the accuracy of average current calculation is a problem that needs to be solved urgently. Summary of the invention
[0004] The main purpose of the present application is to provide a method and system for calculating the average current of a proportional solenoid valve, aiming to solve the technical problem of reducing the CPU load while ensuring the accuracy of the average current calculation.
[0005] To achieve the above purpose, the present application proposes a method for calculating the average current of a proportional solenoid valve, the method comprising:
[0006] Collecting a current signal through the peripheral hardware circuit and transmitting the current signal to the ADC module;
[0007] The ADC module converts the current signal to obtain current data, and transmits the current data to the DMA module;
[0008] Selectively transmitting the current data to the RAM module through the DMA module;
[0009] The current data is calculated based on the RAM module using a preset calculation strategy to obtain an average current.
[0010] In one embodiment, the ADC module includes a logic AND gate, a conversion channel, an accumulator and a storage unit connected in sequence, the peripheral hardware circuit includes a signal conditioning circuit, the signal conditioning circuit is connected to the conversion channel, and the steps of converting the current signal through the ADC module to obtain current data and transmitting the current data to the DMA module include:
[0011] Receiving an ADC gating signal and an ADC trigger signal through the logic AND gate, and processing the ADC gating signal and the ADC trigger signal to obtain a conversion signal;
[0012] receiving the conversion signal and the current signal through the conversion channel;
[0013] The conversion signal and the current signal are processed through the conversion channel, the accumulator and the storage unit to obtain current data, and the current data is transmitted to the DMA module.
[0014] In one embodiment, the microcontroller further includes a timer module, the timer module is connected to the ADC module, the timer module includes an edge capturer, a first timing comparator and a second timing comparator, the edge capturer is connected to the first timing comparator, the current signal is converted and processed by the ADC module to obtain current data, and before the current data is transmitted to the DMA module, the method further includes:
[0015] Generate an ADC gating signal through the edge capture device and the first timing comparator;
[0016] An ADC trigger signal is generated by the second timing comparator, and the ADC gating signal and the ADC trigger signal are transmitted to the ADC module.
[0017] In one embodiment, the timer further includes a third timing comparator, the third timing comparator is connected to the edge capturer, and the step of generating the ADC gating signal through the edge capturer and the first timing comparator includes:
[0018] Acquire the PWM signal generated by the third timing comparator through the edge capture device, and process the PWM signal to obtain a PWM rising edge event and a PWM falling edge event;
[0019] The PWM rising edge event and the PWM falling edge event are processed by the first timing comparator to generate an ADC gating signal.
[0020] In one embodiment, the storage unit is connected to the DMA module, and the steps of processing the conversion signal and the current signal through the conversion channel, the accumulator and the storage unit to obtain current data, and transmitting the current data to the DMA module include:
[0021] Convert the current signal according to the conversion channel and the conversion signal to obtain initial current data, and transmit the initial current data to the accumulator;
[0022] Performing an accumulation operation on the initial current data according to the accumulator to obtain accumulated data, and transmitting the accumulated data to the storage unit;
[0023] The accumulated data is processed according to the storage unit to obtain current data, and the current data is transmitted to a DMA module.
[0024] In one embodiment, the storage unit includes a first storage unit and a second storage unit, the DMA module includes a first channel and a second channel, the first storage unit is connected to the first channel, the second storage unit is connected to the second channel, the current data includes first accumulated data stored in the first storage unit and second accumulated data stored in the second storage unit, and the step of processing the accumulated data according to the storage unit to obtain current data and transmitting the current data to the DMA module includes:
[0025] comparing the first accumulated data with a preset value in the storage unit;
[0026] When the first accumulated data is less than the preset value, transmitting the first accumulated data to the first channel;
[0027] When the first accumulated data is equal to the preset value, the first accumulated data is transferred to the second storage unit to obtain second accumulated data, and the second accumulated data is transferred to the second channel.
[0028] In one embodiment, the ADC module includes an accumulator and a storage unit connected in sequence, the storage unit includes a first storage unit and a second storage unit, the DMA module includes a first channel and a second channel, the RAM module includes a first buffer and a second buffer, the accumulator is connected to the second channel, the microcontroller also includes: a timer module, the timer module includes a third timing comparator, the third timing comparator is connected to the first channel, the current data includes first accumulated data stored in the first storage unit and second accumulated data stored in the second storage unit, and the step of selectively transmitting the current data to the RAM module through the DMA module includes:
[0029] Acquire the first trigger signal generated by the third timing comparator and the second trigger signal generated by the accumulator through the DMA module;
[0030] connecting a first channel between the ADC module and the first buffer area according to the first trigger signal, and transmitting the first accumulated data to the first buffer area;
[0031] The second channel between the ADC module and the second buffer area is connected according to the second trigger signal, and the second accumulated data is transmitted to the second buffer area.
[0032] In one embodiment, the peripheral hardware circuit includes: a proportional solenoid valve, a current sampling circuit and a signal conditioning circuit connected in sequence, the signal conditioning circuit is connected to the ADC module, and the step of collecting the current signal through the peripheral hardware circuit and transmitting the current signal to the ADC module includes:
[0033] Acquiring the desired current generated by the proportional solenoid valve through the current sampling circuit;
[0034] Converting the desired current according to the current sampling circuit to obtain an initial current signal, and transmitting the initial current signal to the signal conditioning circuit;
[0035] The initial current signal is filtered and amplified according to the signal conditioning circuit to obtain a current signal, and the current signal is transmitted to the ADC module.
[0036] In one embodiment, the peripheral hardware circuit further includes a drive circuit, the microcontroller further includes a timer module, the drive circuit is connected to the timer module, and before obtaining the expected current generated by the proportional solenoid valve through the current sampling circuit, the method further includes:
[0037] Generate an initial PWM signal through the timer module, and transmit the initial PWM signal to the driving circuit;
[0038] The initial PWM signal is amplified by the driving circuit to obtain a target PWM signal, and the proportional solenoid valve is controlled to generate a desired current through the target PWM signal.
[0039] In addition, to achieve the above-mentioned purpose, the present application also proposes a proportional solenoid valve average current calculation system, which includes an interrupt controller and the proportional solenoid valve average current calculation device described above.
[0040] The present application provides a method for calculating the average current of a proportional solenoid valve, wherein the present application collects current signals through the peripheral hardware circuit and transmits the current signals to the ADC module; the current signals are converted and processed by the ADC module to obtain current data, and the current data is transmitted to the DMA module; the current data is selectively transmitted to the RAM module through the DMA module; the current data is calculated based on the RAM module using a preset calculation strategy to obtain the average current. In summary, the present application realizes the sampling and calculation of high-frequency current by making full use of the hardware resources inside the microcontroller, solves the problem of how to reduce the CPU load while ensuring the accuracy of the average current calculation, improves the utilization of hardware resources, and reduces the CPU load pressure. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0042] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0043] Figure 1 A flow chart of a first embodiment of a method for calculating average current of a proportional solenoid valve provided in the present application;
[0044] Figure 2 This is a schematic diagram of the overall structure of the average current calculation device for the proportional solenoid valve of the present application;
[0045] Figure 3 A flow chart of a second embodiment of a method for calculating average current of a proportional solenoid valve provided in the present application;
[0046] Figure 4 A schematic diagram of the internal structure of a microcontroller according to a second embodiment of the method for calculating average current of a proportional solenoid valve of the present application;
[0047] Figure 5 A signal generation schematic diagram of an embodiment of a method for calculating average current of a proportional solenoid valve of the present application;
[0048] Figure 6 A flow chart of a third embodiment of a method for calculating an average current of a proportional solenoid valve according to the present application;
[0049] Figure 7 This is another schematic diagram of the structure inside the microcontroller of the third embodiment of the method for calculating the average current of a proportional solenoid valve of the present application;
[0050] Figure 8 A flow chart of a fourth embodiment of a method for calculating average current of a proportional solenoid valve according to the present application;
[0051] Fig. 9 This is another schematic diagram of the structure inside the microcontroller of the fourth embodiment of the method for calculating the average current of a proportional solenoid valve of the present application;
[0052] Fig.10 A schematic diagram of the RAM memory data structure of an embodiment of a method for calculating average current of a proportional solenoid valve of the present application;
[0053] Fig.11 This is a software program execution flow chart of an embodiment of a method for calculating average current of a proportional solenoid valve of the present application.
[0054] Description of Figure Numbers:
[0055] Label name Label name 10 Peripheral hardware circuit M03 accumulator 101 Drive circuit M04 Storage Unit 102 Proportional solenoid valve 202 DMA module 103 Current sampling circuit 203 RAM Modules 104 Signal conditioning circuit 204 Timer module 20 Microcontroller N01 First timing comparator 201 ADC module N02 Second timing comparator M01 Logic AND Gate N03 Third timing comparator M02 Convert Channel 205 Interrupt Controller
[0056] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0057] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0058] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0059] The main solution of the embodiment of the present application is: collecting current signals through the peripheral hardware circuit and transmitting the current signals to the ADC module; converting and processing the current signals through the ADC module to obtain current data, and transmitting the current data to the DMA module; selectively transmitting the current data to the RAM module through the DMA module; and calculating the current data based on the RAM module using a preset calculation strategy to obtain an average current.
[0060] When the proportional solenoid valve is used, the average current control mode is basically adopted, that is, a current reference value is set, and the PWM generator will adjust the duty cycle so that the average current generated by the solenoid valve is consistent with the reference current. Therefore, the measurement of the solenoid valve current and the calculation of the average current are crucial, which is related to the current control accuracy of the solenoid valve. The traditional solenoid valve average current acquisition relies on high-frequency ADC sampling and periodically triggers interrupts to complete the accumulation and average value calculation in the interrupt service program. When the ADC sampling frequency is very high, the CPU will spend a lot of time performing the accumulation operation, which not only affects the system response, but also the calculation result is easily disturbed by the PWM switching noise. If the ADC sampling frequency is reduced, the average current calculation will produce a large error due to insufficient sampling points. Therefore, how to reduce the CPU load while ensuring the accuracy of the average current calculation is a problem that needs to be solved urgently.
[0061] This application realizes the sampling and calculation of high-frequency current by making full use of the hardware resources inside the microcontroller, solves the problem of how to reduce the CPU load while ensuring the accuracy of average current calculation, improves the utilization rate of hardware resources, and reduces the load pressure on the CPU.
[0062] It should be noted that the execution subject of this embodiment is a proportional solenoid valve average current calculation system, and it can also be an electronic device that can realize the above-mentioned proportional solenoid valve average current calculation function, and this embodiment does not specifically limit this. The following takes the proportional solenoid valve average current calculation system as an example to illustrate this embodiment and the following embodiments.
[0063] Based on this, the embodiment of the present application provides a method for calculating the average current of a proportional solenoid valve, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the method for calculating the average current of a proportional solenoid valve of the present application.
[0064] In this embodiment, the proportional solenoid valve average current calculation method is applied to the proportional solenoid valve average current calculation device, referring to Figure 2 , Figure 2 The overall structural diagram of the proportional solenoid valve average current calculation device of the present application. The proportional solenoid valve average current calculation device comprises: a peripheral hardware circuit 10 and a microcontroller 20 connected to each other, and the peripheral hardware circuit 10 comprises: a drive circuit 101, a proportional solenoid valve 102, a current sampling circuit 103 and a signal conditioning circuit 104. The microcontroller 20 comprises: a timer module 204 and an ADC module 201, a DMA module 202, and a RAM module 203 connected in sequence.
[0065] The method for calculating the average current of the proportional solenoid valve comprises steps S10 to S40:
[0066] Step S10: collecting current signals through the peripheral hardware circuit, and transmitting the current signals to the ADC module.
[0067] It should be noted that the peripheral hardware circuit 10 in this embodiment includes: a drive circuit 101, a proportional solenoid valve 102, a current sampling circuit 103 and a signal conditioning circuit 104, and the peripheral hardware circuit 10 is connected to the microcontroller 20. The microcontroller 20 includes an ADC module 201, a DMA module 202, a RAM module 203 and a timer module 204, and the peripheral hardware circuit 10 is specifically connected to the ADC module 201 in the microcontroller 20. Specifically, the current flowing through the proportional solenoid valve 102 is controlled by the current sampling circuit 103 of the peripheral hardware circuit 10, and then processed by the signal conditioning circuit 104, and then the current signal is transmitted to the ADC module 201.
[0068] In a feasible implementation manner, the step S10 specifically includes:
[0069] Step S101: obtaining the expected current generated by the proportional solenoid valve through the current sampling circuit.
[0070] It should be noted that in the specific process, the current sampling circuit 103 is responsible for converting the current flowing through the proportional solenoid valve 102 into the expected current. The expected current refers to the current generated by the current sampling circuit 103 controlling the proportional solenoid valve 102. The expected current is the current value that the proportional solenoid valve 102 is expected to generate, and is a reference value pre-set according to demand.
[0071] Step S102: converting the expected current according to the current sampling circuit to obtain an initial current signal, and transmitting the initial current signal to the signal conditioning circuit.
[0072] It should be noted that the initial current signal is an unprocessed current signal output by the current sampling circuit 103. It directly reflects the current condition of the proportional solenoid valve 102, but generally contains noise and interference components, and needs to be filtered and amplified by the subsequent signal conditioning circuit 104.
[0073] Step S103: filtering and amplifying the initial current signal according to the signal conditioning circuit to obtain a current signal, and transmitting the current signal to the ADC module.
[0074] It should be noted that the current signal is a higher quality analog current signal obtained after being processed by the signal conditioning circuit 104 , which removes the noise and interference components in the initial current signal, and the amplitude range is more suitable for the processing requirements of the ADC module 201 .
[0075] In this embodiment, the current flowing through the proportional solenoid valve 102 is converted into a current signal by the current sampling circuit 103 and the signal conditioning circuit 104, and the generated current signal is filtered and amplified by the signal conditioning circuit 104 to ensure the stability and accuracy of the signal. The actual current is converted into a current signal that can be processed by the microcontroller 20, providing a basis for the subsequent calculation and control of the average current.
[0076] In a feasible implementation manner, before step S10, the method further includes:
[0077] Step S01: Generate an initial PWM signal through the timer module, and transmit the initial PWM signal to the driving circuit.
[0078] It should be noted that the initial PWM signal refers to an unprocessed PWM signal. In this step, the timer module 204 generates a corresponding initial PWM signal according to preset PWM frequency and duty cycle parameters.
[0079] Step S02: amplifying the initial PWM signal according to the driving circuit to obtain a target PWM signal, and controlling the proportional solenoid valve to generate a desired current through the target PWM signal.
[0080] It should be noted that after receiving the initial PWM signal, the driving circuit 101 will amplify the current to obtain a target PWM signal. The target PWM signal can directly control the proportional solenoid valve 102 to generate a desired current.
[0081] In this embodiment, the driving circuit 101 amplifies and converts the initial PWM signal to ensure that the proportional solenoid valve 102 can accurately respond to the control of the PWM signal.
[0082] Step S20: converting the current signal through the ADC module to obtain current data, and transmitting the current data to the DMA module.
[0083] It should be noted that the ADC module 201 is a component in the microcontroller 20 for converting analog signals into digital signals. It can convert continuous analog signals into discrete digital signals, which is convenient for the microcontroller 20 to perform subsequent processing and calculations. In addition, it should be noted that in this step, the current data is a digital data of the current obtained by converting the current signal, and the ADC module 201 converts the received current signal into digital current data. The conversion process usually includes steps such as sampling, quantization and encoding to ensure that the analog current signal can be accurately and quickly converted into current data. The converted current data is then transmitted to the DMA module 202.
[0084] Step S30: selectively transmitting the current data to the RAM module through the DMA module.
[0085] It should be noted that, specifically, the DMA module 202 selectively transmits the current data converted by the ADC module 201 to the RAM module 203. This process is controlled by the DMA module 202 and is automatically completed according to the preset transmission rules without the intervention of the CPU. The role of this step is to further reduce the load of the CPU and improve the efficiency of data transmission. For example, after the current data is transmitted from the buffer of the ADC module 201 to the DMA module 202, the DMA module 202 will transfer the data to a specified location in the RAM module 203 according to the preset rules. This location is a pre-allocated memory area for storing the current data to be processed.
[0086] Step S40: Calculate the current data using a preset calculation strategy based on the RAM module to obtain an average current.
[0087] It should be noted that the preset calculation strategy is a data processing and analysis rule formulated according to actual application requirements and system characteristics. In this embodiment, the current average value is calculated according to the data stored in the RAM module 203 and the preset calculation strategy. The preset calculation strategy mainly includes steps such as data accumulation and average value calculation to ensure that the final average current value has high accuracy and reliability.
[0088] This embodiment provides a method for calculating the average current of a proportional solenoid valve. This embodiment collects current signals through the peripheral hardware circuit 10, and transmits the current signals to the ADC module 201; the ADC module 201 converts and processes the current signals to obtain current data, and transmits the current data to the DMA module 202; the DMA module 202 selects and transmits the current data to the RAM module 203; the RAM module 203 uses a preset calculation strategy to calculate the current data to obtain the average current. In summary, this embodiment realizes the sampling and calculation of high-frequency current by making full use of the hardware resources inside the microcontroller 20, solves the problem of how to reduce the CPU load while ensuring the accuracy of the average current calculation, improves the utilization of hardware resources, and reduces the CPU load pressure.
[0089] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can refer to the above introduction, and will not be repeated later. Figure 3 and Figure 4 , Figure 3 This is a flow chart of the second embodiment of the method for calculating the average current of a proportional solenoid valve of the present application. Figure 4 This is a schematic diagram of the internal structure of a microcontroller according to the second embodiment of the method for calculating the average current of a proportional solenoid valve of the present application.
[0090] In this embodiment, the timer module 204 is connected to the ADC module 201, and the timer module 204 includes an edge capturer 0, a first timing comparator N01, a second timing comparator N02 and a third timing comparator N03, and the edge capturer 0 is connected to the first timing comparator N01 and the third timing comparator N03 respectively.
[0091] Before step S20, the method further includes:
[0092] Step A10: Generate an ADC gating signal through the edge capture device and the first timing comparator.
[0093] It should be noted that the timer module 204 in this embodiment includes: an edge capturer 0, a first timing comparator N01, a second timing comparator N02 and a third timing comparator N03.
[0094] In addition, it should be noted that the edge capturer 0 is a hardware device that can accurately capture signal edges (such as rising edges and falling edges). The first timing comparator N01 here is a hardware device that can process signals according to preset time parameters and generate corresponding control signals.
[0095] In a feasible implementation manner, the step A10 specifically includes:
[0096] Step A101: Acquire the PWM signal generated by the third timing comparator N03 through the edge capture device, and process the PWM signal to obtain a PWM rising edge event and a PWM falling edge event.
[0097] It should be noted that PWM signal is a technology that digitally represents analog signal levels. In PWM signal, the "high" or "on" state (usually the maximum voltage of the power supply) and the "low" or "off" state (usually 0V or close to 0V) of the signal are used to encode information. The key parameters of PWM signal include: Period (T): The time from one PWM rising edge to the next PWM rising edge (or the corresponding falling edge to the falling edge). Duty cycle (D): The ratio of the time the signal is in the "high" state to the total cycle time within a PWM cycle.
[0098] Step A102: Process the PWM rising edge event and the PWM falling edge event through the first timing comparator to generate an ADC gating signal.
[0099] refer to Figure 5 , Figure 5This is a signal generation schematic diagram of an embodiment of a method for calculating average current of a proportional solenoid valve of the present application.
[0100] It should be noted that the PWM rising edge event refers to when the PWM signal changes from a "low" state to a "high" state. This moment is called the rising edge of the PWM signal. In digital systems, the rising edge is usually used to trigger an event or operation, such as starting a count, starting an action, or capturing a value. The PWM falling edge event refers to when the PWM signal changes from a "high" state to a "low" state. This moment is called the falling edge of the PWM signal. In the specific implementation process, refer to Figure 5 As shown, the first timing comparator resets its internal counter according to the PWM rising edge event and falling edge event. In addition, it should be noted that the ADC gating signal is usually a periodic signal used to control the sampling or conversion window of the ADC module. It is used to control when the ADC module should sample the input current analog signal and convert it into a digital value. By adjusting the frequency and duty cycle of the gating signal, the sampling rate and conversion frequency of the ADC module can be controlled.
[0101] It can be understood that, in this embodiment, the ADC gating signal also has a filtering delay function. The filtering delay in the ADC gating signal can remove the PWM on and off instantaneous noise and reduce the error of the average current calculation.
[0102] In this implementation, by capturing edge events of the PWM signal and generating an ADC gating signal, the system can ensure that current sampling is performed within a critical period of the solenoid valve current, thereby improving sampling accuracy and efficiency.
[0103] Step A20: Generate an ADC trigger signal through the second timing comparator, and transmit the ADC gating signal and the ADC trigger signal to the ADC module.
[0104] It should be noted that the ADC trigger signal refers to a signal used to start the ADC. When the trigger signal is activated (eg, changes from a low level to a high level), the ADC module 201 starts sampling its input current signal and outputs corresponding data after a period of time.
[0105] In this embodiment, the timer module 204 performs edge and filtering processing on the PWM signal to generate an ADC gating signal and an ADC trigger signal, thereby achieving precise control of the sampling of the current signal by the ADC module 201 and ensuring the accuracy and efficiency of the sampling.
[0106] Based on the first and second embodiments of the present application, in the third embodiment of the present application, the same or similar contents as those of the above-mentioned first and second embodiments can be referred to the above introduction and will not be repeated later.
[0107] On this basis, please refer to Figure 6 and Figure 7 , Figure 6 This is a flow chart of the third embodiment of the method for calculating the average current of a proportional solenoid valve of the present application. Figure 7 This is another schematic diagram of the internal structure of a microcontroller according to the third embodiment of the method for calculating the average current of a proportional solenoid valve of the present application.
[0108] In this embodiment, the ADC module 201 includes a logic AND gate M01, a conversion channel M02, an accumulator M03 and a storage unit M04 connected in sequence, and the peripheral hardware circuit 10 includes a signal conditioning circuit 104, and the signal conditioning circuit 104 is connected to the conversion channel M02. The step S20 includes:
[0109] Step S201: receiving an ADC gating signal and an ADC trigger signal through the logic AND gate, and processing the ADC gating signal and the ADC trigger signal to obtain a conversion signal.
[0110] It should be noted that the ADC module 201 in this embodiment includes: a logic AND gate M01, a conversion channel M02, an accumulator M03 and a storage unit M04 connected in sequence. In this step, the logic AND gate M01 receives the ADC gating signal and the ADC trigger signal from the timer module 204. The two signals are ANDed through the logic AND gate M01. When both signals are high, the logic AND gate M01 outputs a conversion signal (Trig_Conv). For details, please refer to Figure 5 .
[0111] Step S202: receiving the conversion signal and the current signal through the conversion channel.
[0112] It should be noted that, specifically, under the control of the conversion signal (Trig_Conv), the conversion channel M02 starts to work, receives the current analog signal from the current sampling circuit 103, and prepares to perform analog-to-digital conversion.
[0113] Step S203: Processing the conversion signal and the current signal through the conversion channel, the accumulator and the storage unit to obtain current data, and transmitting the current data to the DMA module.
[0114] It should be noted that the DMA module 202 is connected to the storage unit M04 of the ADC module 201. The current data refers to the digital quantity converted by the conversion channel M02 from the received current analog signal under the control of the conversion signal Trig_Conv, and these digital quantities are sent to the accumulator M03 for accumulation operation. When the accumulated quantity reaches the expected quantity, the accumulator M03 sends the result to the storage unit M04.
[0115] In a feasible implementation manner, the step S203 specifically includes:
[0116] Step B10: converting the current signal according to the conversion channel and the conversion signal to obtain initial current data, and transmitting the initial current data to the accumulator;
[0117] It should be noted that in this step, when the conversion channel M02 receives the conversion signal Trig_Conv generated by the AND gate logic M01, the conversion channel M02 starts to work. The conversion channel M02 converts the current analog signal (i.e., current signal) output by the current sampling circuit 103 into a digital signal, i.e., initial current data. These initial current data represent the real-time current value passing through the proportional solenoid valve 102. Subsequently, these initial current data are directly transmitted to the accumulator M03 for further processing.
[0118] Step B20: performing an accumulation operation on the initial current data according to the accumulator to obtain accumulated data, and transmitting the accumulated data to the storage unit;
[0119] It should be noted that the accumulator M03 is a component in the ADC module 201 for performing accumulation operations, and the storage unit M04 is a storage unit for storing the accumulation results. In this step, after the accumulator M03 receives the initial current data, it performs an accumulation operation. For example, the accumulator M03 accumulates the initial current data obtained from each conversion to form an accumulated value. When the accumulated number reaches a preset expected number (such as a preset number of sampling times), the accumulator M03 transfers the accumulated data.
[0120] Step B30: Processing the accumulated data according to the storage unit to obtain current data, and transmitting the current data to a DMA module.
[0121] It should be noted that the DMA module 202 is a hardware mechanism that can perform data transmission without direct control by the CPU, which can significantly improve the efficiency and speed of data transmission. In this step, when the accumulated number reaches the expected number, the accumulator M03 generates a trigger signal Trig_Res to start the DMA module 202, and then the DMA module 202 reads the accumulated data from the storage unit.
[0122] In this embodiment, by converting the analog current signal into current data (ie, digital signal), it is convenient for the microcontroller 20 to perform more processing and analysis on the current, while reducing the load of the CPU.
[0123] In a feasible implementation manner, the step B30 specifically includes:
[0124] Step B301: comparing the first accumulated data with a preset value in the storage unit;
[0125] It should be noted that the storage unit M04 includes a first storage unit (i.e., unit 0) and a second storage unit (i.e., unit 1), the DMA module 202 includes a first channel (i.e., channel 1) and a second channel (i.e., channel 0), the first storage unit is connected to the first channel, the second storage unit is connected to the second channel, and the current data includes first accumulated data stored in the first storage unit and second accumulated data stored in the second storage unit.
[0126] In addition, it should be noted that the preset value is a value preset in the system. Specifically, in this step, the system first reads the first accumulated data in unit 0 of the storage unit M04 and compares it with a preset value. Through this comparison, the system can determine whether the first accumulated data has reached or exceeded the preset threshold, thereby determining the subsequent data processing flow.
[0127] Step B302: When the first accumulated data is less than the preset value, transmitting the first accumulated data to the first channel;
[0128] It should be noted that the first accumulated data refers to the current data accumulated continuously in the unit 0 of the storage unit M04. These data points are usually collected continuously within a certain time interval.
[0129] Step B303: when the first accumulated data is equal to the preset value, the first accumulated data is transferred to the second storage unit to obtain second accumulated data, and the second accumulated data is transferred to the second channel.
[0130] It should be noted that the second accumulated data refers to the current data stored in unit 1 of M04. For example, in the specific execution steps, when the first accumulated data is equal to the preset value, the system will migrate these data from the first storage unit to the second storage unit to form the second accumulated data. At the same time, these second accumulated data will be transmitted to channel 0 of DMA module 202 for subsequent operations such as data storage and average value calculation.
[0131] In this implementation, the current sum within a period of time is obtained by accumulating the initial current data obtained by multiple samplings, and the accumulated current data is classified and stored to prepare for calculating the average current.
[0132] In this embodiment, the ADC gating signal and the ADC trigger signal are received by the logic AND gate M01 to generate the Trig_Conv signal, thereby realizing efficient conversion of the current signal, reducing the CPU load and noise interference, and improving the response speed and calculation accuracy of the system.
[0133] Based on the first, second and third embodiments of the present application, in the fourth embodiment of the present application, the same or similar contents as those in the above embodiments can be referred to the above description, and will not be described in detail later. Figure 8 and Fig. 9 , Figure 8 This is a flow chart of a fourth embodiment of a method for calculating average current of a proportional solenoid valve of the present application. Fig. 9 This is another schematic diagram of the internal structure of the microcontroller according to the fourth embodiment of the method for calculating the average current of a proportional solenoid valve of the present application.
[0134] The step S30 further includes:
[0135] Step S301: Acquire the first trigger signal generated by the third timing comparator and the second trigger signal generated by the accumulator through the DMA module.
[0136] It should be noted that, in the present embodiment, the microcontroller 20 further includes an interrupt controller 205, and the interrupt controller 205 is connected to the DMA module 202. The RAM module 203 includes a first buffer (buffer 1) and a second buffer (buffer 0). The first buffer (buffer 1) is connected to the first channel (channel 1), and the second buffer (buffer 0) is connected to the second channel (channel 0). The timer module 204 includes a third timing comparator, and the third timing comparator is connected to the first channel (channel 1), and the accumulator M03 is connected to the first channel (channel 0).
[0137] In addition, it should be noted that the first trigger signal refers to the Trig_PRD signal, which is the trigger signal Trig_PRD generated by the third timing comparator N03 at the PWM cycle moment, and periodically triggers the operation of channel 1 in the DMA module 202. The second trigger signal refers to the Trig_Res signal, which is the trigger signal Trig_Res generated by the accumulator M03, and the trigger signal triggers the operation of channel 0 of the DMA module 202.
[0138] Step S302: connecting the first channel between the ADC module and the first buffer area according to the first trigger signal, and transmitting the first accumulated data to the first buffer area.
[0139] It should be noted that in this step, when the DMA module 202 receives the Trig_PRD trigger signal, the DMA module 202 closes channel 1, so that unit 0 in the storage unit M04 transmits data with the buffer 1, and transmits the data to unit 0 of the buffer 1. In addition, it should be noted that after the transmission is completed, the interrupt controller 205 triggers an interrupt to disconnect channel 1 of the DMA module 202.
[0140] Step S303: connecting the second channel between the ADC module and the second buffer area according to the second trigger signal, and transmitting the second accumulated data to the second buffer area.
[0141] It should be noted that in this step, when the DMA module 202 receives the Trig_Res trigger signal, the DMA module 202 will close channel 0, so that unit 1 in the storage unit M04 and the buffer 0 in the RAM module 203 will transmit data, and the data will be transferred to unit 0 of buffer 0. When the Trig_Res trigger signal is received for the second time, the data will be transferred to unit 1 of buffer 0, and so on.
[0142] In this embodiment, through the Trig_PRD trigger signal, the DMA module 202 channel 1 is periodically triggered to transfer the value in unit 0 of the storage unit M04, so that the result of each accumulation operation can be stored in the RAM module in a timely and accurate manner (that is, when a PWM periodic event occurs, the accumulator M03 may not be able to accumulate the expected number of converted digital quantities. At this time, the value in unit 0 of the storage unit M04 is an intermediate result and has not yet been moved to unit 1, but the value in unit 0 still needs to be read), which provides reliable data support for the subsequent average current calculation and improves the calculation accuracy of the average current.
[0143] refer to Fig.10 and Fig.11 , Fig.10 This is a RAM memory data structure diagram of an embodiment of a method for calculating average current of a proportional solenoid valve of the present application. Fig.11 This is a software program execution flow chart of an embodiment of a method for calculating average current of a proportional solenoid valve of the present application.
[0144] RAM module 203 stores the result value accumulated by accumulator M03, and its data structure is as follows: Fig.10As shown, it includes: buffer 0, buffer 1, buffer 0 base address pointer Buffer0Ptr, buffer 1 base address pointer Buffer1Ptr, pending buffer start address startPtr, pending buffer end address endPtr. Buffer 0 saves the accumulated result from unit 1 of storage unit M04. Buffer 1 saves the accumulated result from unit 0 of storage unit M04. Buffer 0 base address pointer Buffer0Ptr saves the first address of buffer 0, that is, the address of unit 0 of buffer 0. Buffer 1 base address pointer Buffer1Ptr saves the first address of buffer 1, that is, the address of unit 0 of buffer 1. After the DMA module 202 channel 1 transmission is completed, an interrupt will be triggered through the interrupt controller 205, and the interrupt service program will be entered. In this program, the data between the pending buffer start address startPtr and the pending buffer end address endPtr will be accumulated, and then added with the data of unit 0 of buffer 1, and the period average value of the solenoid valve current will be calculated according to the following formula. After the accumulation is completed, startPtr is updated to endPtr. After entering the interrupt service routine of DMA module 202 channel 1 again, repeat the above accumulation process and press
[0145] Formula 1 calculates the average current value.
[0146]
[0147] In the above formula 1, N is the number of sampling points of the electromagnetic valve current in the calculation cycle, and the higher the output signal frequency of the timing comparator 2 in the timer module 204, the more sampling points there are. The essence of the above formula 1 is to calculate the average value by the rectangular method, and the trapezoidal method can also be used for calculation, and this application does not limit this.
[0148] Specifically, the software implementation includes the initialization process, the DMA channel 1 interrupt service current calculation process, such as Fig.11As shown. The initialization process includes register initialization of ADC module 201, DMA module 202, RAM memory module 203, and interrupt controller 205. Configure the third timing comparator N03 in the timer module 204 to PWM generation mode, fill in the filter delay parameter of the first timing comparator N01, and configure the ADC trigger signal frequency of the second timing comparator N02. During initialization, the startPtr pointer in the RAM module 203 is also initialized to the address of buffer 0 unit 0, that is, Buffer0Ptr. The interrupt service current calculation process of channel 1 of DMA module 202 is used to calculate the average value of the solenoid valve current. The third timing comparator N03 in the timer module 204 triggers the data transmission of channel 1 in DMA module 202 at the PWM cycle, and transfers the data of unit 0 of storage unit M04 to unit 0 of buffer 1 in RAM memory module 203. After completion, the execution of the channel 1 interrupt service current calculation process of DMA module 202 is triggered. After entering the process, first obtain the endPtr pointer from the DMA module 202, and save the data in the storage unit M04 unit 0 to a temporary variable tempVar; then, clear the content in the storage unit M04 unit 0 to 0; then perform the accumulation operation, including: the data in the unit between startPtr and endPtr; the data in the temporary variable tempVar; the data in the global variable v_Sum, which stores the accumulated value calculated when entering the interrupt service last time. Finally, according to the flag bit of whether the current cycle ends or not, the average current is calculated according to formula 1, and the global variable v_Sum is cleared to zero.
[0149] In addition, the present application also provides a proportional solenoid valve average current calculation system, which includes an interrupt controller and the proportional solenoid valve average current calculation device of all the above-mentioned examples. The proportional solenoid valve average current calculation system provided by the present application adopts the proportional solenoid valve average current calculation method in the above-mentioned embodiment, which can solve the technical problem of how to reduce the CPU load while ensuring the accuracy of average current calculation. Compared with the prior art, the beneficial effects of the proportional solenoid valve average current calculation system provided by the present application are the same as the beneficial effects of the proportional solenoid valve average current calculation method provided by the above-mentioned embodiment, and the other technical features in the proportional solenoid valve average current calculation device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0150] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0151] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0152] The flow chart and block diagram in the accompanying drawings illustrate the possible implementation architecture, function and operation of the device and method according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the module, the program segment, or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the box can also occur in a sequence different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0153] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0154] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A method for calculating the average current of a proportional solenoid valve. It is characterized in that The proportional solenoid valve average current calculation method is applied to a proportional solenoid valve average current calculation device, the proportional solenoid valve average current calculation device comprises: a microcontroller and a peripheral hardware circuit connected to each other, the microcontroller comprises: an ADC module, a DMA module, and a RAM module connected in sequence; Collecting a current signal through the peripheral hardware circuit and transmitting the current signal to the ADC module; The ADC module converts the current signal to obtain current data, and transmits the current data to the DMA module; Selectively transmitting the current data to the RAM module through the DMA module; The current data is calculated based on the RAM module using a preset calculation strategy to obtain an average current.
2. The method according to claim 1, It is characterized in that The ADC module includes a logic AND gate, a conversion channel, an accumulator and a storage unit connected in sequence, the peripheral hardware circuit includes a signal conditioning circuit, and the signal conditioning circuit is connected to the conversion channel. The steps of converting the current signal through the ADC module to obtain current data and transmitting the current data to the DMA module include: Receiving an ADC gating signal and an ADC trigger signal through the logic AND gate, and processing the ADC gating signal and the ADC trigger signal to obtain a conversion signal; receiving the conversion signal and the current signal through the conversion channel; The conversion signal and the current signal are processed through the conversion channel, the accumulator and the storage unit to obtain current data, and the current data is transmitted to the DMA module.
3. The method according to claim 1, It is characterized in that The microcontroller further includes a timer module, the timer module is connected to the ADC module, the timer module includes an edge capturer, a first timing comparator and a second timing comparator, the edge capturer is connected to the first timing comparator, the current signal is converted and processed by the ADC module to obtain current data, and before the current data is transmitted to the DMA module, the method further includes: Generate an ADC gating signal through the edge capture device and the first timing comparator; An ADC trigger signal is generated by the second timing comparator, and the ADC gating signal and the ADC trigger signal are transmitted to the ADC module.
4. The method according to claim 3, It is characterized in that The timer further includes a third timing comparator, and the third timing comparator is connected to the edge capturer. The step of generating an ADC gating signal through the edge capturer and the first timing comparator includes: Acquire the PWM signal generated by the third timing comparator through the edge capture device, and process the PWM signal to obtain a PWM rising edge event and a PWM falling edge event; The PWM rising edge event and the PWM falling edge event are processed by the first timing comparator to generate an ADC gating signal.
5. The method according to claim 2, It is characterized in that The storage unit is connected to the DMA module, and the steps of processing the conversion signal and the current signal through the conversion channel, the accumulator and the storage unit to obtain current data, and transmitting the current data to the DMA module include: Convert the current signal according to the conversion channel and the conversion signal to obtain initial current data, and transmit the initial current data to the accumulator; Performing an accumulation operation on the initial current data according to the accumulator to obtain accumulated data, and transmitting the accumulated data to the storage unit; The accumulated data is processed according to the storage unit to obtain current data, and the current data is transmitted to a DMA module.
6. The method according to claim 5, It is characterized in that The storage unit includes a first storage unit and a second storage unit, the DMA module includes a first channel and a second channel, the first storage unit is connected to the first channel, the second storage unit is connected to the second channel, the current data includes first accumulated data stored in the first storage unit and second accumulated data stored in the second storage unit, and the step of processing the accumulated data according to the storage unit to obtain current data and transmitting the current data to the DMA module includes: comparing the first accumulated data with a preset value in the storage unit; When the first accumulated data is less than the preset value, transmitting the first accumulated data to the first channel; When the first accumulated data is equal to the preset value, the first accumulated data is transferred to the second storage unit to obtain second accumulated data, and the second accumulated data is transferred to the second channel.
7. The method according to claim 1, It is characterized in that The ADC module includes an accumulator and a storage unit connected in sequence, the storage unit includes a first storage unit and a second storage unit, the DMA module includes a first channel and a second channel, the RAM module includes a first buffer and a second buffer, the accumulator is connected to the second channel, the microcontroller also includes: a timer module, the timer module includes a third timing comparator, the third timing comparator is connected to the first channel, the current data includes first accumulated data stored in the first storage unit and second accumulated data stored in the second storage unit, and the step of selectively transmitting the current data to the RAM module through the DMA module includes: Acquire the first trigger signal generated by the third timing comparator and the second trigger signal generated by the accumulator through the DMA module; connecting a first channel between the ADC module and the first buffer area according to the first trigger signal, and transmitting the first accumulated data to the first buffer area; The second channel between the ADC module and the second buffer area is connected according to the second trigger signal, and the second accumulated data is transmitted to the second buffer area.
8. The method according to claim 1, It is characterized in that The peripheral hardware circuit includes: a proportional solenoid valve, a current sampling circuit and a signal conditioning circuit connected in sequence, the signal conditioning circuit is connected to the ADC module, and the steps of collecting the current signal through the peripheral hardware circuit and transmitting the current signal to the ADC module include: Acquiring the desired current generated by the proportional solenoid valve through the current sampling circuit; Converting the desired current according to the current sampling circuit to obtain an initial current signal, and transmitting the initial current signal to the signal conditioning circuit; The initial current signal is filtered and amplified according to the signal conditioning circuit to obtain a current signal, and the current signal is transmitted to the ADC module.
9. The method according to claim 8, It is characterized in that The peripheral hardware circuit further includes a driving circuit, the microcontroller further includes a timer module, the driving circuit is connected to the timer module, and before obtaining the expected current generated by the proportional solenoid valve through the current sampling circuit, the method further includes: Generate an initial PWM signal through the timer module, and transmit the initial PWM signal to the driving circuit; The initial PWM signal is amplified by the driving circuit to obtain a target PWM signal, and the proportional solenoid valve is controlled to generate a desired current through the target PWM signal.
10. A proportional solenoid valve average current calculation system, It is characterized in that The proportional solenoid valve average current calculation system comprises an interrupt controller and a proportional solenoid valve average current calculation device as claimed in any one of claims 1 to 9.
