CN102298095A - Method for ensuring accurate measurement on pulse width in multi-task singlechip system and device - Google Patents

Method for ensuring accurate measurement on pulse width in multi-task singlechip system and device Download PDF

Info

Publication number
CN102298095A
CN102298095A CN201110174985A CN201110174985A CN102298095A CN 102298095 A CN102298095 A CN 102298095A CN 201110174985 A CN201110174985 A CN 201110174985A CN 201110174985 A CN201110174985 A CN 201110174985A CN 102298095 A CN102298095 A CN 102298095A
Authority
CN
China
Prior art keywords
interrupt
chip microcomputer
int0
timer
int1
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201110174985A
Other languages
Chinese (zh)
Other versions
CN102298095B (en
Inventor
樊巧玲
孟祥聪
李建生
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Aero Geophysical Survey & Remote Sensing Center For Land And Resources
Original Assignee
China Aero Geophysical Survey & Remote Sensing Center For Land And Resources
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Aero Geophysical Survey & Remote Sensing Center For Land And Resources filed Critical China Aero Geophysical Survey & Remote Sensing Center For Land And Resources
Priority to CN201110174985.6A priority Critical patent/CN102298095B/en
Publication of CN102298095A publication Critical patent/CN102298095A/en
Application granted granted Critical
Publication of CN102298095B publication Critical patent/CN102298095B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Microcomputers (AREA)

Abstract

The embodiment of the invention provides a method for ensuring accurate measurement on pulse width in a multi-task singlechip system and a device. The method comprises the following steps: carrying out a pulse width measurement task by utilizing external interrupts INT0 and INT1; when other tasks are executed, by utilizing the interrupt service routines of the tasks, detecting whether the interrupt identification of the external interrupt INT0 is met or not; if the interrupt identification of the external interrupt INT0 is met, clearing the interrupt identification of the external interrupt INT0; and by utilizing the interrupt service routines of the tasks, detecting whether the interrupt identification of the external interrupt INT1 is met or not; if the interrupt identification of the external interrupt INT1 is met, detecting whether a timer T0 is started or not; and if the timer T0 is started, stopping the counting of the timer T0. In the method and the device for ensuring the accurate measurement on the pulse width in the multi-task singlechip system, a judgment on starting and stopping the pulse width measurement task is introduced into the interrupt service routines of other tasks, and the timer T0 is controlled according to the judgment, thereby, the accuracy of pulse width measurement data in a singlechip is ensured.

Description

Guarantee the method and apparatus of pulse width correct measurement in the multitask Single Chip Microcomputer (SCM) system
Technical field
The present invention relates to the single-chip microcomputer applied technical field, especially relate to the method and apparatus that guarantees the pulse width correct measurement in a kind of multitask Single Chip Microcomputer (SCM) system.
Background technology
Nowadays, The application of single-chip computer is more and more wider, and wherein 51 series monolithics are single-chip microcomputers of elementary course, also is most widely used a kind of single-chip microcomputer.51 series monolithics are single task work, generally adopt the cooperating type that timeslice controls or adopt the preemptive type of interrupt mode to realize based on the multi-job operation of this single-chip microcomputer, below the measurement of pulse width in this dual mode are introduced respectively:
The cooperating type of controlling with timeslice in the multitask Single Chip Microcomputer (SCM) system is measured the mode that pulse width generally adopts wait: when the timeslice of measuring pulse width arrives, judge that when impulse level was high level, program was waited for; When being low level, the zero clearing of timer T0 elder generation is restarted timer T0 and is begun counting (TR0=1), and program is waited for simultaneously.When impulse level becomes high level by low level, stop timer T0 counting (TR0=0).Count value clock ticktack cycle of multiply by timer T0 of timer T0 this moment is pulse width.
The preemptive type of multitask Single Chip Microcomputer (SCM) system interrupt mode is to adopt to interrupt carrying out each task, and it is measured pulse width and realizes with external interrupt INT0 and INT1: the negative edge of pulse is caught by INT0, and the rising edge of next pulse is caught by INT1.First zero clearing timer T0 in the INT0 interrupt service routine, restart timer T0 and begin counting, in the INT1 interrupt service routine, judge whether timer T0 opens earlier, if open then stop T0 timer counting, the clock ticktack cycle that the count value in this moment T0 timer multiply by timer T0 is pulse width.
But above-mentioned cooperating type realizes that the multi-job operation real-time is poor, and the mcu resource waste is serious, and utilization factor is not high.Though and preemptive type is realized the good and mcu resource utilization factor height of multi-job operation real-time, but can clash between interrupting, especially for the exigent pulse width measuring of real-time in the multitask data acquisition, the pulse width of measuring when clashing can be made mistakes.
Summary of the invention
The embodiment of the invention provides the method and apparatus that guarantees the pulse width correct measurement in a kind of multitask Single Chip Microcomputer (SCM) system, avoids when utilizing preemptive type to realize multi-job operation, and its pulse width measuring task data is made mistakes.
On the one hand, the embodiment of the invention provides the method that guarantees the pulse width correct measurement in a kind of multitask Single Chip Microcomputer (SCM) system, and this method comprises the steps: to utilize external interrupt INT0 and INT1 to carry out the pulse width measuring task; When carrying out other task of removing described pulse width measuring task, utilize the interrupt service routine of these tasks to detect the interrupt identification that whether runs into external interrupt INT0, if run into the interrupt identification of external interrupt INT0, then remove the interrupt identification of described external interrupt INT0; When carrying out other task of removing described pulse width measuring task, utilize the interrupt service routine of these tasks to detect the interrupt identification that whether runs into external interrupt INT1, if run into the interrupt identification of external interrupt INT1, whether then detect timer T0 starts, if timer T0 starts, then stop timer T0 counting.
Preferably, the INT0 termination of the single-chip microcomputer in the embodiment of the invention is gone into the pulse-width modulation PWM pulse signal, and the INT1 termination of described single-chip microcomputer is gone into through anti-phase pwm pulse signal.
Preferably, utilize external interrupt INT0 and INT1 to carry out the pulse width measuring task in the embodiment of the invention and comprise: external interrupt INT0 and INT1 that single-chip microcomputer is set are the negative edge triggering, and it is timing mode that timer T0 is set; Utilize INT0 to interrupt catching the negative edge of pwm pulse, when capturing the pwm pulse negative edge, utilize the zero clearing timer T0 of INT0 interrupt service routine elder generation to restart timer T0 and begin counting; Utilize INT1 to interrupt catching the rising edge of next pwm pulse, when capturing the rising edge of next pwm pulse, utilize the INT1 interrupt service routine to judge whether timer T0 opens earlier, count if open then stop timer T0.
On the other hand, the embodiment of the invention also provides the method that guarantees the pulse width correct measurement in a kind of multitask Single Chip Microcomputer (SCM) system, and this method comprises the steps: to utilize external interrupt INT0 and INT1 to carry out the pulse width measuring task; When carrying out other task of removing described pulse width measuring task, utilize the interrupt service routine of these tasks to detect the interrupt identification that whether runs into external interrupt INT0, if run into the interrupt identification of external interrupt INT0, then first zero clearing timer T0 opening timing device T0 again counts, and removes the interrupt identification of described external interrupt INT0 at last; When carrying out other task of removing described pulse width measuring task, utilize the interrupt service routine of these tasks to detect the interrupt identification that whether runs into external interrupt INT1, if run into the interrupt identification of external interrupt INT1, whether then detect timer T0 starts, if timer T0 starts, then stop timer T0 counting.
Preferably, the INT0 termination of the single-chip microcomputer in the embodiment of the invention is gone into the pulse-width modulation PWM pulse signal, and the INT1 termination of described single-chip microcomputer is gone into through anti-phase pwm pulse signal.
Preferably, utilize external interrupt INT0 and INT1 to carry out the pulse width measuring task in the embodiment of the invention and comprise: external interrupt INT0 and INT1 that single-chip microcomputer is set are the negative edge triggering, and it is timing mode that timer T0 is set; Utilize INT0 to interrupt catching the negative edge of pwm pulse, when capturing the pwm pulse negative edge, utilize the zero clearing timer T0 of INT0 interrupt service routine elder generation to restart timer T0 and begin counting; Utilize INT1 to interrupt catching the rising edge of next pwm pulse, when capturing the rising edge of next pwm pulse, utilize the INT1 interrupt service routine to judge whether timer T0 opens earlier, count if open then stop timer T0.
On the other hand, the embodiment of the invention also provides the device that guarantees the pulse width correct measurement in a kind of multitask Single Chip Microcomputer (SCM) system, described single-chip microcomputer is C8051F020, comprise: phase inverter, first level transferring chip, second level transferring chip, one road signal of pwm pulse inputs to the INT0 external interrupt of the P0.4 pin of described single-chip microcomputer as described Single Chip Microcomputer (SCM) system, another road signal of pwm pulse inputs to the input end of described phase inverter, the output terminal of described phase inverter is connected to the ITN1 external interrupt of the P0.5 pin of described single-chip microcomputer as described Single Chip Microcomputer (SCM) system, rs 232 serial interface signal UART0 imports as first serial by the P0.1 pin that described first level transferring chip is connected to described single-chip microcomputer, rs 232 serial interface signal UART1 imports as second serial by the P0.3 pin that described second level transferring chip is connected to described single-chip microcomputer, simulating signal ADC0 is connected to the AIN0.0 pin of described single-chip microcomputer, as analog input, interrupt service routine unit in the described single-chip microcomputer is used for when carrying out serial ports input signal collection and analog input signal acquisition tasks, detect the interrupt identification that whether runs into external interrupt INT0, if run into the interrupt identification of external interrupt INT0, then remove the interrupt identification of described external interrupt INT0; And detect whether run into the interrupt identification of external interrupt INT1, if run into the interrupt identification of external interrupt INT1, whether the timer T0 that then detects in the single-chip microcomputer starts, if timer T0 starts, then stops timer T0 counting.
Preferably, the embodiment of the invention also comprises first build-out resistor that is arranged on the signal reflex that is used for eliminating the serial communication cable on the first serial input end, and second build-out resistor that is arranged on the signal reflex that is used for eliminating the serial communication cable on the second serial input end.
Preferably, the embodiment of the invention also comprises the oscillator that is made of capacitor C 1, C2, quartz crystal G1 and single-chip microcomputer U3, and the two ends of described quartz crystal G1 are connected to the XTAL1 pin and the XTAL2 pin of described single-chip microcomputer respectively and think that described Single Chip Microcomputer (SCM) system provides clock.
On the other hand, the embodiment of the invention also provides the device that guarantees the pulse width correct measurement in a kind of multitask Single Chip Microcomputer (SCM) system, described single-chip microcomputer is C8051F020, comprise: phase inverter, first level transferring chip, second level transferring chip, one road signal of pwm pulse inputs to the INT0 external interrupt of the P0.4 pin of described single-chip microcomputer as described Single Chip Microcomputer (SCM) system, another road signal of pwm pulse inputs to the input end of described phase inverter, the output terminal of described phase inverter is connected to the ITN1 external interrupt of the P0.5 pin of described single-chip microcomputer as described Single Chip Microcomputer (SCM) system, rs 232 serial interface signal UART0 imports as first serial by the P0.1 pin that described first level transferring chip is connected to described single-chip microcomputer, rs 232 serial interface signal UART1 imports as second serial by the P0.3 pin that described second level transferring chip is connected to described single-chip microcomputer, simulating signal ADC0 is connected to the AIN0.0 pin of described single-chip microcomputer, as analog input, interrupt service routine unit in the described single-chip microcomputer is used for when carrying out serial ports input signal collection and analog input signal acquisition tasks, detect the interrupt identification that whether runs into external interrupt INT0, if run into the interrupt identification of external interrupt INT0, then first zero clearing timer T0 opening timing device T0 again counts, and removes the interrupt identification of described external interrupt INT0 at last; And detect whether run into the interrupt identification of external interrupt INT1, and if run into the interrupt identification of external interrupt INT1, then detect timer T0 and whether start, if timer T0 starts, then stop timer T0 counting.
The embodiment of the invention is by introducing the judgement that the pulse-width measuring task starts and stops in the interrupt service routine of other task except that the pulse width measuring task, and judge according to this and to come control timer T0, thereby guaranteed the correctness of pulse width measuring data in the single-chip microcomputer.
Description of drawings
In order to be illustrated more clearly in the embodiment of the invention or technical scheme of the prior art, the accompanying drawing of required use is done to introduce simply in will describing embodiment below, apparently, accompanying drawing in describing below only is some embodiments of the present invention, for those of ordinary skills, under the prerequisite of not paying creative work, can also obtain other accompanying drawing according to these accompanying drawings.
Guarantee the method flow synoptic diagram of pulse width correct measurement in a kind of multitask Single Chip Microcomputer (SCM) system that Fig. 1 provides for the embodiment of the invention;
Guarantee the method flow synoptic diagram of pulse width correct measurement in the another kind of multitask Single Chip Microcomputer (SCM) system that Fig. 2 provides for the embodiment of the invention;
Guarantee the apparatus structure synoptic diagram of pulse width correct measurement in a kind of multitask Single Chip Microcomputer (SCM) system that Fig. 3 provides for the embodiment of the invention.
Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the invention, the technical scheme in the embodiment of the invention is clearly and completely described, obviously, described embodiment only is the present invention's part embodiment, rather than whole embodiment.Based on the embodiment among the present invention, those of ordinary skills belong to the scope of protection of the invention not making the every other embodiment that is obtained under the creative work prerequisite.
Be illustrated in figure 1 as the method flow synoptic diagram that guarantees the pulse width correct measurement in a kind of multitask Single Chip Microcomputer (SCM) system that the embodiment of the invention provides, it is to be noted, Single Chip Microcomputer (SCM) system in the embodiment of the invention utilizes preemptive type to realize multi-job operation, and this method comprises the steps:
S101: utilize external interrupt INT0 and INT1 to carry out the pulse width measuring task.
In the present embodiment, can insert pulse signal respectively at the INT0 of single-chip microcomputer and INT1 end and realize the pulse width measuring task, such as, utilize the negative edge of the INT0 interruption seizure pulse of single-chip microcomputer, when capturing the pulse negative edge, utilize the INT0 interrupt service routine earlier with timer T0 zero clearing, restart timer T0 and begin counting; Utilize the rising edge of the INT1 interruption seizure next pulse of single-chip microcomputer simultaneously, when capturing the rising edge of next pulse, utilize the INT1 interrupt service routine to judge whether timer T0 opens earlier, count if open then stop timer T0.Certainly, when utilizing aforesaid way to carry out the pulse width measuring task, at first need the external interrupt INT0 and the INT1 of single-chip microcomputer are arranged to the negative edge triggering, timer T0 is set to timing mode.
As one embodiment of the present of invention, when the external interrupt INT0 of single-chip microcomputer and INT1 triggering mode being arranged to negative edge triggering, the INT0 termination of single-chip microcomputer can be gone into the pulse-width modulation PWM pulse signal, and the INT1 termination of single-chip microcomputer is gone into through anti-phase pwm pulse signal.
S102: when carrying out other task of removing described pulse width measuring task, utilize the interrupt service routine of these tasks to detect the interrupt identification that whether runs into external interrupt INT0, if run into the interrupt identification of external interrupt INT0, then remove the interrupt identification of described external interrupt INT0.
In the present embodiment, other task of above-mentioned single-chip microcomputer is such as comprising rs 232 serial interface signal collection, collection of simulant signal etc.When single-chip microcomputer is carried out these tasks, if the interrupt service routine of these tasks (has run into the negative edge of pulse when detecting the interrupt identification of external interrupt INT0, need starting impulse width measure task), the interrupt identification of removing external interrupt INT0.Like this, need just to be equivalent to make this pulse width measuring task to carry out in the beginning pulse width measuring task, wait for that next cycle proceeds to carry out again if in single-chip microcomputer is carried out the process of other task, run into.Otherwise, if do not carry out aforesaid operations, single-chip microcomputer can remove to carry out the interrupt service routine of INT0, promptly first zero clearing timer T0 again after above-mentioned other task executes so, restart timer T0 and begin counting, thereby cause the last resulting measurement result can be littler than actual value.
S103: when carrying out other task of removing described pulse width measuring task, utilize the interrupt service routine of these tasks to detect the interrupt identification that whether runs into external interrupt INT1, if run into the interrupt identification of external interrupt INT1, whether then detect timer T0 starts, if timer T0 starts, then stop timer T0 counting.In the present embodiment, when single-chip microcomputer when carrying out above-mentioned other task, if the interrupt service routine of these tasks (has run into the rising edge of next pulse when detecting the interrupt identification of external interrupt INT1, when needing stop pulse width measure task), whether continue to detect timer T0 more starts, if timer T0 starts, then stop timer T0 counting.This way is before other task of execution, if begun to have carried out the pulse width measuring task, and this pulse width measuring task is to stop in the process of other task of execution, then need in the interrupt service routine of other task, force to stop the T0 counting, the clock ticktack cycle that the count value of taking-up timer T0 this moment multiply by timer T0 then is pulse width, thereby can guarantee to obtain at last the correctness of data.Otherwise if do not carry out aforesaid operations, single-chip microcomputer can go to stop to carry out the pulse width measuring task after above-mentioned other task executes again so, thereby causes the last resulting test result can be bigger than actual value.
Because single-chip microcomputer can not truly be realized multitask and operate simultaneously, its same time period can only be carried out the task on a kind of software, but, because the pulse width measuring task relates to this hardware of timer T0, therefore, when other task of carrying out except that the pulse width measuring task, just need utilize the interrupt service routine of these tasks that timer T0 is controlled, promptly guarantee the correct realization of pulse width measuring task by other task.
It is pointed out that above-mentioned steps S101 is not the execution sequence of each step of expression to step S103, some step can be carried out simultaneously, and such as step S102 and step S103, promptly the embodiment of the invention is not limited the execution sequence of step.
The embodiment of the invention is by introducing the judgement that the pulse-width measuring task starts and stops in the interrupt service routine of other task except that the pulse width measuring task, and judge according to this and to come control timer T0, thereby guaranteed the correctness of pulse width measuring data in the single-chip microcomputer.
Be illustrated in figure 2 as the method flow synoptic diagram that guarantees the pulse width correct measurement in the another kind of multitask Single Chip Microcomputer (SCM) system that the embodiment of the invention provides, this method comprises the steps:
S201: utilize external interrupt INT0 and INT1 to carry out the pulse width measuring task.
S202: when carrying out other task of removing described pulse width measuring task, utilize the interrupt service routine of these tasks to detect the interrupt identification that whether runs into external interrupt INT0, if run into the interrupt identification of external interrupt INT0, then first zero clearing timer T0 opening timing device T0 again counts, and removes the interrupt identification of described external interrupt INT0 at last.
S203: when carrying out other task of removing described pulse width measuring task, utilize the interrupt service routine of these tasks to detect the interrupt identification that whether runs into external interrupt INT1, if run into the interrupt identification of external interrupt INT1, whether then detect timer T0 starts, if timer T0 starts, then stop timer T0 counting.
The embodiment of present embodiment and Fig. 1 correspondence is similar, different is that step S202 is interior when the interrupt service routine of other tasks detects the interrupt identification of external interrupt INT0 in the present embodiment, the zero clearing of timer T0 elder generation, begin counting again, remove the interrupt identification of external interrupt INT0 at last.When using this mode, it is not too short needing pulse width, promptly need after other task is finished, just can run into the rising edge of next pulse,, also can guarantee the correctness of last measurement result even in other task implementation, started timer T0 like this.
The embodiment of the invention is by introducing the judgement that the pulse-width measuring task starts and stops in the interrupt service routine of other task except that the pulse width measuring task, and judge according to this and to come control timer T0, thereby guaranteed the correctness of pulse width measuring data in the single-chip microcomputer.
Be illustrated in figure 3 as the apparatus structure synoptic diagram that guarantees the pulse width correct measurement in a kind of multitask Single Chip Microcomputer (SCM) system that the embodiment of the invention provides, single-chip microcomputer is selected C8051F020 for use in the present embodiment.
As seen from Figure 3, this device comprises: phase inverter D1B, level transferring chip U1, level transferring chip U2, one road signal of pwm pulse inputs to the INT0 external interrupt of the P0.4 pin of single-chip microcomputer as Single Chip Microcomputer (SCM) system, another road signal of pwm pulse inputs to the input end 3 of phase inverter D1B, and the output terminal 4 of phase inverter D1B is connected to the ITN1 external interrupt of the P0.5 pin of single-chip microcomputer as Single Chip Microcomputer (SCM) system.
Rs 232 serial interface signal UART0 imports as first serial by the P0.1 pin that level transferring chip U1 is connected to described single-chip microcomputer.Adopt the MAX485 chip such as, level transferring chip U1, rs 232 serial interface signal UART0 is connected to 6,7 pins of MAX485 chip, 2 of the MAX485 chip, 3,4,5 pin ground connection in addition, and 8 pins connect power supply, and 1 pin then is connected to the P0.1 pin of single-chip microcomputer.
Rs 232 serial interface signal UART1 imports as second serial by the P0.3 pin that level transferring chip U2 is connected to single-chip microcomputer.Adopt the MAX485 chip such as, level transferring chip U2, rs 232 serial interface signal UART1 is connected to 6,7 pins of MAX485 chip, 2 of the MAX485 chip, 3,4,5 pin ground connection in addition, and 8 pins connect power supply, and 1 pin then is connected to the P0.3 pin of single-chip microcomputer.
Simulating signal ADC0 is connected to the AIN0.0 pin of described single-chip microcomputer, as analog input.
As one embodiment of the present of invention, also comprise the build-out resistor R1 that is arranged on the signal reflex that is used for eliminating the serial communication cable on the rs 232 serial interface signal UART0 end, the two ends of this build-out resistor R1 are connected to two input ends of rs 232 serial interface signal UART0 respectively.Also comprise the build-out resistor R2 that is arranged on the signal reflex that is used for eliminating the serial communication cable on the rs 232 serial interface signal UART1 end in addition, the two ends of this build-out resistor R2 are connected to two input ends of rs 232 serial interface signal UART1 respectively.
As one embodiment of the present of invention, also comprise the oscillator that constitutes by capacitor C 1, C2, quartz crystal G1 and single-chip microcomputer U3, capacitor C 1 one end ground connection, the other end is connected to first end of quartz crystal G1, capacitor C 2 one end ground connection, the other end is connected to second end of quartz crystal G1, and first end of quartz crystal G1 and second end then are connected to the XTAL1 pin and the XTAL2 pin of described single-chip microcomputer respectively and think that Single Chip Microcomputer (SCM) system provides clock.
In the present embodiment, interrupt service routine unit in the single-chip microcomputer can be when carrying out collection of serial ports input signal and analog input signal acquisition tasks, detect the interrupt identification that whether runs into external interrupt INT0, if run into the interrupt identification of external interrupt INT0, then remove the interrupt identification of described external interrupt INT0; And detect whether run into the interrupt identification of external interrupt INT1, if run into the interrupt identification of external interrupt INT1, whether the timer T0 that then detects in the single-chip microcomputer starts, if timer T0 starts, then stops timer T0 counting.
As an alternative embodiment of the invention, interrupt service routine unit in the single-chip microcomputer is when carrying out collection of serial ports input signal and analog input signal acquisition tasks, if detect the interrupt identification of external interrupt INT0, also can restart timer T0 by first zero clearing timer T0, remove the interrupt identification of external interrupt INT0 at last, when using this mode, it is not too short needing pulse width, promptly need after being finished, other task just can run into the rising edge of next pulse, even in other task implementation, started timer T0 like this, also can guarantee the correctness of last measurement result.
Based on said apparatus how the present invention is guaranteed that pulse width task correct measurement is explained in further detail below:
At first, external interrupt INT0 is set in program initialization and INT1 is the negative edge triggering, and timer T0 is a timing mode; Wherein the negative edge of pwm pulse (t0) is caught by INT0, and the rising edge of next pulse (t1) is caught by INT1.Be 0 at the counting of the mid-timer T0 of the interrupt service routine of INT0 (TH0=0, and TL0=0, wherein TH0 is the most-significant byte of timer T0, and TL0 is the least-significant byte of timer T0), start timer simultaneously and begin counting (TR0=1); Earlier judge whether timer T0 opens in the interrupt service routine of INT1, count (TR0=0) if open then stop timer T0, the clock ticktack cycle that the count value of taking-up timer T0 this moment multiply by timer T0 then is pulse width.
In order to guarantee the correct measurement of pwm pulse width, the embodiment of the invention is at UART0, and UART1 has increased following two kinds and detected judgement in the ADC0 interrupt service routine:
If a runs into the interrupt identification (IE0=1) of external interrupt INT0, promptly run into the negative edge of pulse, then remove the interrupt identification (IE0=0) of external interrupt INT0, perhaps first zero clearing timer T0 restarts timer T0, removes the interrupt identification (IE0=0) of external interrupt INT0 at last again.
If b runs into the interrupt identification (IE1=1) of external interrupt INT1, promptly run into the rising edge of next pulse, and timer T0 begun counting when (TR=1), then stop timer T0 counting (TR0=0).
The embodiment of the invention is by introducing the judgement that the pulse-width measuring task starts and stops in the interrupt service routine of other task except that the pulse width measuring task, and judge according to this and to come control timer T0, thereby guaranteed the correctness of pulse width measuring data in the single-chip microcomputer.
One of ordinary skill in the art will appreciate that all or part of flow process that realizes in the foregoing description method, can finish by the hardware circuit and the software programming of single-chip microcomputer, described program can be stored in the Single Chip Microcomputer (SCM) program storer, this program can comprise the flow process as the embodiment of above-mentioned each side method when carrying out.
Above-described specific embodiment; purpose of the present invention, technical scheme and beneficial effect are further described; institute is understood that; the above only is specific embodiments of the invention; and be not intended to limit the scope of the invention; within the spirit and principles in the present invention all, any modification of being made, be equal to replacement, improvement etc., all should be included within protection scope of the present invention.

Claims (10)

1. guarantee the method for pulse width correct measurement in the multitask Single Chip Microcomputer (SCM) system, it is characterized in that described method comprises the steps:
Utilize external interrupt INT0 and INT1 to carry out the pulse width measuring task;
When carrying out other task of removing described pulse width measuring task, utilize the interrupt service routine of these tasks to detect the interrupt identification that whether runs into external interrupt INT0, if run into the interrupt identification of external interrupt INT0, then remove the interrupt identification of described external interrupt INT0;
When carrying out other task of removing described pulse width measuring task, utilize the interrupt service routine of these tasks to detect the interrupt identification that whether runs into external interrupt INT1, if run into the interrupt identification of external interrupt INT1, whether then detect timer T0 starts, if timer T0 starts, then stop timer T0 counting.
2. the method for claim 1 is characterized in that, the INT0 termination of described single-chip microcomputer is gone into the pulse-width modulation PWM pulse signal, and the INT1 termination of described single-chip microcomputer is gone into through anti-phase pwm pulse signal.
3. method as claimed in claim 2 is characterized in that, describedly utilizes external interrupt INT0 and INT1 to carry out the pulse width measuring task to comprise:
External interrupt INT0 and INT1 that single-chip microcomputer is set are the negative edge triggering, and it is timing mode that timer T0 is set;
Utilize INT0 to interrupt catching the negative edge of pwm pulse, when capturing the pwm pulse negative edge, utilize the zero clearing timer T0 of INT0 interrupt service routine elder generation to restart timer T0 and begin counting;
Utilize INT1 to interrupt catching the rising edge of next pwm pulse, when capturing the rising edge of next pwm pulse, utilize the INT1 interrupt service routine to judge whether timer T0 opens earlier, count if open then stop timer T0.
4. guarantee the method for pulse width correct measurement in the multitask Single Chip Microcomputer (SCM) system, it is characterized in that described method comprises the steps:
Utilize external interrupt INT0 and INT1 to carry out the pulse width measuring task;
When carrying out other task of removing described pulse width measuring task, utilize the interrupt service routine of these tasks to detect the interrupt identification that whether runs into external interrupt INT0, if run into the interrupt identification of external interrupt INT0, then first zero clearing timer T0 opening timing device T0 again counts, and removes the interrupt identification of described external interrupt INT0 at last;
When carrying out other task of removing described pulse width measuring task, utilize the interrupt service routine of these tasks to detect the interrupt identification that whether runs into external interrupt INT1, if run into the interrupt identification of external interrupt INT1, whether then detect timer T0 starts, if timer T0 starts, then stop timer T0 counting.
5. method as claimed in claim 4 is characterized in that, the INT0 termination of described single-chip microcomputer is gone into the pulse-width modulation PWM pulse signal, and the INT1 termination of described single-chip microcomputer is gone into through anti-phase pwm pulse signal.
6. method as claimed in claim 5 is characterized in that, describedly utilizes external interrupt INT0 and INT1 to carry out the pulse width measuring task to comprise:
External interrupt INT0 and INT1 that single-chip microcomputer is set are the negative edge triggering, and it is timing mode that timer T0 is set;
Utilize INT0 to interrupt catching the negative edge of pwm pulse, when capturing the pwm pulse negative edge, utilize the zero clearing timer T0 of INT0 interrupt service routine elder generation to restart timer T0 and begin counting;
Utilize INT1 to interrupt catching the rising edge of next pwm pulse, when capturing the rising edge of next pwm pulse, utilize the INT1 interrupt service routine to judge whether timer T0 opens earlier, count if open then stop timer T0.
7. guarantee the device of pulse width correct measurement in the multitask Single Chip Microcomputer (SCM) system, described single-chip microcomputer is C8051F020, it is characterized in that, comprise: phase inverter, first level transferring chip, second level transferring chip, one road signal of pwm pulse inputs to the INT0 external interrupt of the P0.4 pin of described single-chip microcomputer as described Single Chip Microcomputer (SCM) system, another road signal of pwm pulse inputs to the input end of described phase inverter, the output terminal of described phase inverter is connected to the ITN1 external interrupt of the P0.5 pin of described single-chip microcomputer as described Single Chip Microcomputer (SCM) system, rs 232 serial interface signal UART0 imports as first serial by the P0.1 pin that described first level transferring chip is connected to described single-chip microcomputer, rs 232 serial interface signal UART1 imports as second serial by the P0.3 pin that described second level transferring chip is connected to described single-chip microcomputer, simulating signal ADC0 is connected to the AIN0.0 pin of described single-chip microcomputer, as analog input, interrupt service routine unit in the described single-chip microcomputer is used for when carrying out serial ports input signal collection and analog input signal acquisition tasks, detect the interrupt identification that whether runs into external interrupt INT0, if run into the interrupt identification of external interrupt INT0, then remove the interrupt identification of described external interrupt INT0; And detect whether run into the interrupt identification of external interrupt INT1, if run into the interrupt identification of external interrupt INT1, whether the timer T0 that then detects in the single-chip microcomputer starts, if timer T0 starts, then stops timer T0 counting.
8. guarantee the device of pulse width correct measurement in the multitask Single Chip Microcomputer (SCM) system as claimed in claim 7, it is characterized in that, also comprise first build-out resistor that is arranged on the signal reflex that is used for eliminating the serial communication cable on the first serial input end, and second build-out resistor that is arranged on the signal reflex that is used for eliminating the serial communication cable on the second serial input end.
9. guarantee the device of pulse width correct measurement in the multitask Single Chip Microcomputer (SCM) system as claimed in claim 7, it is characterized in that, also comprise the oscillator that is made of capacitor C 1, C2, quartz crystal G1 and single-chip microcomputer U3, the two ends of described quartz crystal G1 are connected to the XTAL1 pin and the XTAL2 pin of described single-chip microcomputer respectively and think that described Single Chip Microcomputer (SCM) system provides clock.
10. guarantee the device of pulse width correct measurement in the multitask Single Chip Microcomputer (SCM) system, described single-chip microcomputer is C8051F020, it is characterized in that, comprise: phase inverter, first level transferring chip, second level transferring chip, one road signal of pwm pulse inputs to the INT0 external interrupt of the P0.4 pin of described single-chip microcomputer as described Single Chip Microcomputer (SCM) system, another road signal of pwm pulse inputs to the input end of described phase inverter, the output terminal of described phase inverter is connected to the ITN1 external interrupt of the P0.5 pin of described single-chip microcomputer as described Single Chip Microcomputer (SCM) system, rs 232 serial interface signal UART0 imports as first serial by the P0.1 pin that described first level transferring chip is connected to described single-chip microcomputer, rs 232 serial interface signal UART1 imports as second serial by the P0.3 pin that described second level transferring chip is connected to described single-chip microcomputer, simulating signal ADC0 is connected to the AIN0.0 pin of described single-chip microcomputer, as analog input, interrupt service routine unit in the described single-chip microcomputer is used for when carrying out serial ports input signal collection and analog input signal acquisition tasks, detect the interrupt identification that whether runs into external interrupt INT0, if run into the interrupt identification of external interrupt INT0, then first zero clearing timer T0 opening timing device T0 again counts, and removes the interrupt identification of described external interrupt INT0 at last; And detect whether run into the interrupt identification of external interrupt INT1, and if run into the interrupt identification of external interrupt INT1, then detect timer T0 and whether start, if timer T0 starts, then stop timer T0 counting.
CN201110174985.6A 2011-06-27 2011-06-27 Method for ensuring accurate measurement on pulse width in multi-task singlechip system and device Expired - Fee Related CN102298095B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201110174985.6A CN102298095B (en) 2011-06-27 2011-06-27 Method for ensuring accurate measurement on pulse width in multi-task singlechip system and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201110174985.6A CN102298095B (en) 2011-06-27 2011-06-27 Method for ensuring accurate measurement on pulse width in multi-task singlechip system and device

Publications (2)

Publication Number Publication Date
CN102298095A true CN102298095A (en) 2011-12-28
CN102298095B CN102298095B (en) 2014-04-16

Family

ID=45358650

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201110174985.6A Expired - Fee Related CN102298095B (en) 2011-06-27 2011-06-27 Method for ensuring accurate measurement on pulse width in multi-task singlechip system and device

Country Status (1)

Country Link
CN (1) CN102298095B (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104698286A (en) * 2014-07-24 2015-06-10 北京航空航天大学 Timer-based PWM (Pulse Width Modulation) wave acquisition method
CN109361500A (en) * 2018-10-25 2019-02-19 南通先进通信技术研究院有限公司 A method of the plesiochronous external pulse of self-correcting based on chip
CN111220843A (en) * 2020-01-18 2020-06-02 惠州华阳通用电子有限公司 Signal level duration time measuring method and device
CN112242828A (en) * 2020-09-11 2021-01-19 深圳市杉川机器人有限公司 Method, device and equipment for capturing pulse width modulation signal
CN113300902A (en) * 2021-03-29 2021-08-24 明峰医疗系统股份有限公司 Multichannel pulse width measurement and data transmission processing method
CN115292398A (en) * 2022-08-02 2022-11-04 中国自然资源航空物探遥感中心 Data format conversion method and device, electronic equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
DE3236207A1 (en) * 1982-09-30 1984-04-05 Robert Bosch Gmbh, 7000 Stuttgart Method and device for measuring and processing signals
CN1605713A (en) * 2004-10-21 2005-04-13 山东科技大学 Ultrasonic well logging instrument
CN201611380U (en) * 2010-02-24 2010-10-20 浙江大学宁波理工学院 Digital frequency characteristic tester
CN202102054U (en) * 2011-06-27 2012-01-04 中国国土资源航空物探遥感中心 Apparatus in multitask one-chip microcomputer system for ensuring accurate measuring of pulse width

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
DE3236207A1 (en) * 1982-09-30 1984-04-05 Robert Bosch Gmbh, 7000 Stuttgart Method and device for measuring and processing signals
CN1605713A (en) * 2004-10-21 2005-04-13 山东科技大学 Ultrasonic well logging instrument
CN201611380U (en) * 2010-02-24 2010-10-20 浙江大学宁波理工学院 Digital frequency characteristic tester
CN202102054U (en) * 2011-06-27 2012-01-04 中国国土资源航空物探遥感中心 Apparatus in multitask one-chip microcomputer system for ensuring accurate measuring of pulse width

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
朱玉红: "MCS-51单片机对连续脉冲宽度测量的实现", 《自动化与仪器仪表》, no. 1, 31 January 2003 (2003-01-31) *

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104698286A (en) * 2014-07-24 2015-06-10 北京航空航天大学 Timer-based PWM (Pulse Width Modulation) wave acquisition method
CN104698286B (en) * 2014-07-24 2017-10-03 北京航空航天大学 A kind of PWM ripple acquisition methods based on timer
CN109361500A (en) * 2018-10-25 2019-02-19 南通先进通信技术研究院有限公司 A method of the plesiochronous external pulse of self-correcting based on chip
CN111220843A (en) * 2020-01-18 2020-06-02 惠州华阳通用电子有限公司 Signal level duration time measuring method and device
CN112242828A (en) * 2020-09-11 2021-01-19 深圳市杉川机器人有限公司 Method, device and equipment for capturing pulse width modulation signal
CN113300902A (en) * 2021-03-29 2021-08-24 明峰医疗系统股份有限公司 Multichannel pulse width measurement and data transmission processing method
CN113300902B (en) * 2021-03-29 2022-05-20 明峰医疗系统股份有限公司 Multichannel pulse width measurement and data transmission processing method
CN115292398A (en) * 2022-08-02 2022-11-04 中国自然资源航空物探遥感中心 Data format conversion method and device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN102298095B (en) 2014-04-16

Similar Documents

Publication Publication Date Title
CN102298095B (en) Method for ensuring accurate measurement on pulse width in multi-task singlechip system and device
CN103440216A (en) Chip and method for debugging MCU through I2C slave unit
CN103179241A (en) Method and system for automatically testing power consumption of mobile terminal
CN105718257B (en) Timer arrangement and timing method based on embedded system
CN104049702A (en) Single chip microcomputer-based CPU (Central Processing Unit) reset control system, method and device
CN102314403B (en) Device and method for identifying I2C (Inter-Integrated Circuit) bus signal by taking MCU (Micro Control Unit) as slave device
CN104698941A (en) FPGA-based (field programmable gate array-based) embedded dual-core relay protecting system
TW201411333A (en) Method of getting out from error entering to test mode in USB apparatus
CN202102054U (en) Apparatus in multitask one-chip microcomputer system for ensuring accurate measuring of pulse width
CN113380015A (en) Wireless passive sensor and working method of wireless passive controller thereof
CN104572331A (en) Monitoring module with power monitoring and electrifying delay enable
CN101819460B (en) Linked switch device of host computer and display and control method thereof
CN1581079B (en) Network server down auto-reset method and system
CN101814054B (en) Instruction tracing controller for debugging microcontroller
CN103677991A (en) Task execution method based on single chip microcomputer system framework and single chip microcomputer system framework
CN207133811U (en) Digital independent apparatus and system
CN102681872A (en) Automatic cold boot method of notebook computer
CN202676894U (en) Action logic sequence checking device of backup power supply auto-switching device
CN109859697B (en) A kind of TFT display backlight control system and method
CN205375041U (en) Can bus controller
CN205725785U (en) A kind of parallel data synchronous acquisition device
CN101329646A (en) Emulator for implementing FLASH page erase emulation
CN101995927A (en) Resetting-operating method of 51 single chip microcomputer (SCM)
CN103817404B (en) A kind of hand arc welding machine three-phase electric power open phase detection method and device
CN103186753B (en) A kind of detection method of initial rate of PSAM card and device

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20140416

Termination date: 20150627

EXPY Termination of patent right or utility model