CN102298095B - 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
CN102298095B
CN102298095B CN201110174985.6A CN201110174985A CN102298095B CN 102298095 B CN102298095 B CN 102298095B CN 201110174985 A CN201110174985 A CN 201110174985A CN 102298095 B CN102298095 B CN 102298095B
Authority
CN
China
Prior art keywords
interrupt
int0
chip microcomputer
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.)
Expired - Fee Related
Application number
CN201110174985.6A
Other languages
Chinese (zh)
Other versions
CN102298095A (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

The method and apparatus of ensuring accurate measurement on pulse width in multi-task singlechip system
Technical field
The present invention relates to single-chip microcomputer applied technical field, especially relate to a kind of method and apparatus of ensuring accurate measurement on pulse width in multi-task singlechip system.
Background technology
Nowadays, the application of single-chip microcomputer is more and more wider, and wherein 51 series monolithics are single-chip microcomputers for elementary course, is also most widely used a kind of single-chip microcomputer.51 series monolithics are single task work, and the multi-job operation based on this single-chip microcomputer generally adopts the cooperating type that timeslice controls or adopts the preemptive type of interrupt mode to realize, and below the measurement of pulse width in these two kinds of modes is introduced respectively:
The cooperating type ranging pulse width of controlling by timeslice in multitask Single Chip Microcomputer (SCM) system generally adopts the mode of wait: when the timeslice of ranging pulse width arrives, judge when impulse level is high level, program is waited for; While being low level, the first zero clearing of timer T0, restarts timer T0 and starts counting (TR0=1), and program is waited for simultaneously.When impulse level is when low level becomes high level, stop timer T0 counting (TR0=0).The clock ticktack cycle that now count value of timer T0 is multiplied by timer T0 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 its ranging pulse width is realized 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 INT0 interrupt service routine, restart timer T0 and start counting, in INT1 interrupt service routine, first judge whether timer T0 opens, if opened, stop T0 timer counting, the clock ticktack cycle that now count value in T0 timer is multiplied by timer T0 is pulse width.
But it is poor that above-mentioned cooperating type is realized multi-job operation real-time, mcu resource waste is serious, and utilization factor is not high.And preemptive type is realized, although multi-job operation real-time is good and mcu resource utilization factor is high, but can clash between interrupting, especially for the very high pulse width measuring of requirement of real-time in Multitask Data gathers, the pulse width of measuring while clashing can be made mistakes.
Summary of the invention
The embodiment of the present invention provides a kind of method and apparatus of ensuring accurate measurement on pulse width in multi-task singlechip 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 present invention provides a kind of method of ensuring accurate measurement on pulse width in multi-task singlechip system, and the method comprises the steps: to utilize external interrupt INT0 and INT1 to carry out 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, 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 detect timer T0 starts, if timer T0 starts, stop timer T0 counting.
Preferably, the INT0 termination of the single-chip microcomputer in the embodiment of the present invention enters pulse-width modulation PWM pulse signal, and the INT1 termination of described single-chip microcomputer enters through anti-phase pwm pulse signal.
Preferably, in the embodiment of the present invention, utilize external interrupt INT0 and INT1 to carry out pulse width measuring task and comprise: external interrupt INT0 and INT1 that single-chip microcomputer is set are 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 pwm pulse negative edge, utilize the first zero clearing timer of INT0 interrupt service routine T0 to restart timer T0 and start counting; Utilize INT1 to interrupt catching the rising edge of next pwm pulse, when capturing the rising edge of next pwm pulse, utilize INT1 interrupt service routine first to judge whether timer T0 opens, if opened, stop timer T0 counting.
On the other hand, the embodiment of the present invention also provides a kind of method of ensuring accurate measurement on pulse width in multi-task singlechip system, and the method comprises the steps: to utilize external interrupt INT0 and INT1 to carry out 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, first zero clearing timer T0 again opening timing device T0 count, finally 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 detect timer T0 starts, if timer T0 starts, stop timer T0 counting.
Preferably, the INT0 termination of the single-chip microcomputer in the embodiment of the present invention enters pulse-width modulation PWM pulse signal, and the INT1 termination of described single-chip microcomputer enters through anti-phase pwm pulse signal.
Preferably, in the embodiment of the present invention, utilize external interrupt INT0 and INT1 to carry out pulse width measuring task and comprise: external interrupt INT0 and INT1 that single-chip microcomputer is set are 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 pwm pulse negative edge, utilize the first zero clearing timer of INT0 interrupt service routine T0 to restart timer T0 and start counting; Utilize INT1 to interrupt catching the rising edge of next pwm pulse, when capturing the rising edge of next pwm pulse, utilize INT1 interrupt service routine first to judge whether timer T0 opens, if opened, stop timer T0 counting.
On the other hand, the embodiment of the present invention also provides a kind of device of ensuring accurate measurement on pulse width in multi-task singlechip system, described single-chip microcomputer is C8051F020, comprise: phase inverter, the first level transferring chip, second electrical level conversion chip, pwm pulse Yi road signal inputs to the P0.4 pin of described single-chip microcomputer as the INT0 external interrupt of 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 P0.5 pin of described single-chip microcomputer as the ITN1 external interrupt of described Single Chip Microcomputer (SCM) system, the P0.1 pin that rs 232 serial interface signal UART0 is connected to described single-chip microcomputer by described the first level transferring chip is inputted as first serial, the P0.3 pin that rs 232 serial interface signal UART1 is connected to described single-chip microcomputer by described second electrical level conversion chip is inputted as second serial, simulating signal ADC0 is connected to the AIN0.0 pin of described single-chip microcomputer, as analog input, interrupt service routine unit in described single-chip microcomputer is for when carrying out the 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, 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 detecting in single-chip microcomputer starts, if timer T0 starts, stops timer T0 counting.
Preferably, the embodiment of the present invention also comprises the first build-out resistor that is arranged on first serial input end the signal reflex for eliminating serial communication cable, and is arranged on second serial input end the second build-out resistor of the signal reflex for eliminating serial communication cable.
Preferably, the embodiment of the present invention also comprises the oscillator consisting 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 respectively XTAL1 pin and the XTAL2 pin of described single-chip microcomputer and think that described Single Chip Microcomputer (SCM) system provides clock.
On the other hand, the embodiment of the present invention also provides a kind of device of ensuring accurate measurement on pulse width in multi-task singlechip system, described single-chip microcomputer is C8051F020, comprise: phase inverter, the first level transferring chip, second electrical level conversion chip, pwm pulse Yi road signal inputs to the P0.4 pin of described single-chip microcomputer as the INT0 external interrupt of 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 P0.5 pin of described single-chip microcomputer as the ITN1 external interrupt of described Single Chip Microcomputer (SCM) system, the P0.1 pin that rs 232 serial interface signal UART0 is connected to described single-chip microcomputer by described the first level transferring chip is inputted as first serial, the P0.3 pin that rs 232 serial interface signal UART1 is connected to described single-chip microcomputer by described second electrical level conversion chip is inputted as second serial, simulating signal ADC0 is connected to the AIN0.0 pin of described single-chip microcomputer, as analog input, interrupt service routine unit in described single-chip microcomputer is for when carrying out the 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, first zero clearing timer T0 again opening timing device T0 count, finally remove the interrupt identification of described external interrupt INT0, and detect whether run into the interrupt identification of external interrupt INT1, and if run into the interrupt identification of external interrupt INT1, detect timer T0 and whether start, if timer T0 starts, stop timer T0 counting.
The judgement that the embodiment of the present invention is measured task start and stopped by introducing pulse-width in the interrupt service routine of other task except pulse width measuring task, and carry out control timer T0 according to this judgement, thereby guaranteed the correctness of pulse width measuring data in single-chip microcomputer.
Accompanying drawing explanation
In order to be illustrated more clearly in the embodiment of the present invention or technical scheme of the prior art, below the accompanying drawing of required use during embodiment is described is briefly described, apparently, accompanying drawing in the following describes is only some embodiments of the present invention, for those of ordinary skills, do not paying under the prerequisite of creative work, can also obtain according to these accompanying drawings other accompanying drawing.
The method flow schematic diagram of a kind of ensuring accurate measurement on pulse width in multi-task singlechip system that Fig. 1 provides for the embodiment of the present invention;
The method flow schematic diagram of the another kind of ensuring accurate measurement on pulse width in multi-task singlechip system that Fig. 2 provides for the embodiment of the present invention;
The apparatus structure schematic diagram of a kind of ensuring accurate measurement on pulse width in multi-task singlechip system that Fig. 3 provides for the embodiment of the present invention.
Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the present invention, the technical scheme in the embodiment of the present invention is clearly and completely described, obviously, described embodiment is only the present invention's part embodiment, rather than whole embodiment.Based on the embodiment in the present invention, those of ordinary skills, not making the every other embodiment obtaining under creative work prerequisite, belong to the scope of protection of the invention.
Be illustrated in figure 1 the method flow schematic diagram of a kind of ensuring accurate measurement on pulse width in multi-task singlechip system that the embodiment of the present invention provides, it is to be noted, Single Chip Microcomputer (SCM) system in the embodiment of the present invention utilizes preemptive type to realize multi-job operation, and the method comprises the steps:
S101: utilize external interrupt INT0 and INT1 to carry out pulse width measuring task.
In the present embodiment, can access respectively pulse signal at the INT0 of single-chip microcomputer and INT1 end and realize pulse width measuring task, such as, utilize the INT0 of single-chip microcomputer to interrupt catching the negative edge of pulse, when capturing pulse negative edge, utilize INT0 interrupt service routine first by timer T0 zero clearing, restart timer T0 and start counting; Utilize the INT1 of single-chip microcomputer to interrupt catching the rising edge of next pulse simultaneously, when capturing the rising edge of next pulse, utilize INT1 interrupt service routine first to judge whether timer T0 opens, if opened, stop timer T0 counting.Certainly, when utilizing aforesaid way to carry out pulse width measuring task, first need the external interrupt INT0 of single-chip microcomputer and INT1 to be arranged to 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 and triggering, the INT0 termination of single-chip microcomputer can be entered to pulse-width modulation PWM pulse signal, and the INT1 termination of single-chip microcomputer enters 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, 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 while the interrupt identification of external interrupt INT0 being detected, need starting impulse width measure task), the interrupt identification of removing external interrupt INT0.Like this, if when running into and need to start pulse width measuring task, be just equivalent to make this pulse width measuring task to carry out, wait for that next cycle proceeds to carry out again in single-chip microcomputer is carried out the process of other task.Otherwise, if do not carry out aforesaid operations, single-chip microcomputer can remove to carry out the interrupt service routine of INT0, i.e. first zero clearing timer T0 after above-mentioned other tasks carrying is complete again so, restart timer T0 and start counting, thereby cause the measurement result finally obtaining can be less 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 detect timer T0 starts, if timer T0 starts, stop timer T0 counting.In the present embodiment, when single-chip microcomputer is when carrying out above-mentioned other task, if the interrupt service routine of these tasks (has run into the rising edge of next pulse while the interrupt identification of external interrupt INT1 being detected, while needing stop pulse width measure task), whether continue to detect timer T0 starts again, if timer T0 starts, stop timer T0 counting.This way is before carrying out other task, if started to have carried out pulse width measuring task, and this pulse width measuring task is to stop in process that carrying out other task, need in the interrupt service routine of other task, force to stop T0 counting, taking out the clock ticktack cycle that then count value of timer T0 be now multiplied by timer T0 is pulse width, thereby can guarantee finally to obtain the correctness of data.Otherwise if do not carry out aforesaid operations, single-chip microcomputer can go to stop carrying out pulse width measuring task after above-mentioned other tasks carrying is complete again so, thereby cause the test result finally obtaining can be larger than actual value.
Because single-chip microcomputer can not truly be realized multitask and operates simultaneously, its same time period can only be carried out the task on a kind of software, but, because pulse width measuring task relates to this hardware of timer T0, therefore, when other task of carrying out except pulse width measuring task, just need to utilize the interrupt service routine of these tasks to control timer T0, by other task, guarantee the correct realization of pulse width measuring task.
It is pointed out that above-mentioned steps S101 is not the execution sequence that represents each step to step S103, some step can be carried out simultaneously, and such as step S102 and step S103, the embodiment of the present invention is not limited the execution sequence of step.
The judgement that the embodiment of the present invention is measured task start and stopped by introducing pulse-width in the interrupt service routine of other task except pulse width measuring task, and carry out control timer T0 according to this judgement, thereby guaranteed the correctness of pulse width measuring data in single-chip microcomputer.
The method flow schematic diagram that is illustrated in figure 2 the another kind of ensuring accurate measurement on pulse width in multi-task singlechip system that the embodiment of the present invention provides, the method comprises the steps:
S201: utilize external interrupt INT0 and INT1 to carry out 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, first zero clearing timer T0 again opening timing device T0 count, finally remove the interrupt identification of described external interrupt INT0.
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 detect timer T0 starts, if timer T0 starts, stop timer T0 counting.
The embodiment that the present embodiment and Fig. 1 are corresponding is similar, difference is that in the present embodiment, step S202 is interior when the interrupt service routine of other tasks detects the interrupt identification of external interrupt INT0, the first zero clearing of timer T0, start again counting, finally remove the interrupt identification of external interrupt INT0.In the time of in this way, it is not too short needing pulse width, the rising edge that need to just can run into next pulse after other tasks carrying, even if started timer T0 like this in other tasks carrying process, also can guarantee the correctness of last measurement result.
The judgement that the embodiment of the present invention is measured task start and stopped by introducing pulse-width in the interrupt service routine of other task except pulse width measuring task, and carry out control timer T0 according to this judgement, thereby guaranteed the correctness of pulse width measuring data in single-chip microcomputer.
The apparatus structure schematic diagram that is illustrated in figure 3 a kind of ensuring accurate measurement on pulse width in multi-task singlechip system that the embodiment of the present invention provides, single-chip microcomputer is selected C8051F020 in the present embodiment.
As seen from Figure 3, this device comprises: phase inverter D1B, level transferring chip U1, level transferring chip U2, pwm pulse Yi road signal inputs to the P0.4 pin of single-chip microcomputer as the INT0 external interrupt of 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 P0.5 pin of single-chip microcomputer as the ITN1 external interrupt of Single Chip Microcomputer (SCM) system.
The P0.1 pin that rs 232 serial interface signal UART0 is connected to described single-chip microcomputer by level transferring chip U1 is inputted as first serial.Such as, level transferring chip U1 adopts MAX485 chip, and rs 232 serial interface signal UART0 is connected to 6,7 pins of MAX485 chip, 2 of MAX485 chip, 3,4,5 pin ground connection in addition, 8 pins connect power supply, and 1 pin is connected to the P0.1 pin of single-chip microcomputer.
The P0.3 pin that rs 232 serial interface signal UART1 is connected to single-chip microcomputer by level transferring chip U2 is inputted as second serial.Such as, level transferring chip U2 adopts MAX485 chip, and rs 232 serial interface signal UART1 is connected to 6,7 pins of MAX485 chip, 2 of MAX485 chip, 3,4,5 pin ground connection in addition, 8 pins connect power supply, and 1 pin 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 rs 232 serial interface signal UART0 end the signal reflex for eliminating serial communication cable, the two ends of this build-out resistor R1 are connected to respectively two input ends of rs 232 serial interface signal UART0.Also comprise in addition the build-out resistor R2 that is arranged on rs 232 serial interface signal UART1 end the signal reflex for eliminating serial communication cable, the two ends of this build-out resistor R2 are connected to respectively two input ends of rs 232 serial interface signal UART1.
As one embodiment of the present of invention, also comprise the oscillator being formed 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 the first end of quartz crystal G1, capacitor C 2 one end ground connection, the other end is connected to the second end of quartz crystal G1, and the first end of quartz crystal G1 and the second end are connected to respectively XTAL1 pin and the XTAL2 pin of described single-chip microcomputer and think that Single Chip Microcomputer (SCM) system provides clock.
In the present embodiment, interrupt service routine unit in single-chip microcomputer can be when carrying out the 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, 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 detecting in single-chip microcomputer starts, if timer T0 starts, stops timer T0 counting.
As an alternative embodiment of the invention, interrupt service routine unit in single-chip microcomputer is when carrying out the collection of serial ports input signal and analog input signal acquisition tasks, if the interrupt identification of external interrupt INT0 detected, also can restart timer T0 by first zero clearing timer T0, finally remove the interrupt identification of external interrupt INT0, in the time of in this way, it is not too short needing pulse width, need to after other tasks carrying, just can run into the rising edge of next pulse, even if started timer T0 like this in other tasks carrying process, also can guarantee the correctness of last measurement result.
Based on said apparatus, how the present invention is guaranteed to pulse width task correct measurement is explained in further detail below:
First, external interrupt INT0 is set in program initialization and INT1 is negative edge triggering, and timer T0 is timing mode; Wherein the negative edge of pwm pulse (t0) is caught by INT0, and the rising edge (t1) of next pulse is caught by INT1.The mid-timer T0 of interrupt service routine of INT0 be counted as 0 (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 start counting (TR0=1); In the interrupt service routine of INT1, first judge whether timer T0 opens, if opened, stop timer T0 counting (TR0=0), take out the clock ticktack cycle that then count value of timer T0 be now multiplied by timer T0 to be pulse width.
In order to guarantee the correct measurement of pwm pulse width, the embodiment of the present invention is at UART0, and UART1, has increased following two kinds and detected judgement in ADC0 interrupt service routine:
If a runs into the interrupt identification (IE0=1) of external interrupt INT0, run into the negative edge of pulse, remove the interrupt identification (IE0=0) of external interrupt INT0, or first zero clearing timer T0 restarts timer T0, finally remove again the interrupt identification (IE0=0) of external interrupt INT0.
If b runs into the interrupt identification (IE1=1) of external interrupt INT1, run into the rising edge of next pulse, and timer T0 started counting when (TR=1), stop timer T0 counting (TR0=0).
The judgement that the embodiment of the present invention is measured task start and stopped by introducing pulse-width in the interrupt service routine of other task except pulse width measuring task, and carry out control timer T0 according to this judgement, thereby guaranteed the correctness of pulse width measuring data in single-chip microcomputer.
One of ordinary skill in the art will appreciate that all or part of flow process realizing in above-described embodiment method, can complete by the hardware circuit of single-chip microcomputer and software programming, described program can be stored in a Single Chip Microcomputer (SCM) program storer, this program, when carrying out, can comprise as the flow process of the embodiment of above-mentioned each side method.
Above-described specific embodiment; object of the present invention, technical scheme and beneficial effect are further described; institute is understood that; the foregoing is only specific embodiments of the invention; the protection domain being not intended to limit the present invention; within the spirit and principles in the present invention all, any modification of making, be equal to replacement, improvement etc., within all should being included in protection scope of the present invention.

Claims (4)

1. a method for ensuring accurate measurement on pulse width in multi-task singlechip system, is characterized in that, described method comprises the steps:
Utilize external interrupt INT0 and INT1 to carry out 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, 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 detect timer T0 starts, if timer T0 starts, stop timer T0 counting;
Wherein, the INT0 termination of described single-chip microcomputer enters pulse-width modulation PWM pulse signal, and the INT1 termination of described single-chip microcomputer enters through anti-phase pwm pulse signal;
Describedly utilize external interrupt INT0 and INT1 to carry out pulse width measuring task to comprise:
External interrupt INT0 and INT1 that single-chip microcomputer is set are 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 pwm pulse negative edge, utilize the first zero clearing timer of INT0 interrupt service routine T0 to restart timer T0 and start counting;
Utilize INT1 to interrupt catching the rising edge of next pwm pulse, when capturing the rising edge of next pwm pulse, utilize INT1 interrupt service routine first to judge whether timer T0 opens, if opened, stop timer T0 counting.
2. a method for ensuring accurate measurement on pulse width in multi-task singlechip system, is characterized in that, described method comprises the steps:
Utilize external interrupt INT0 and INT1 to carry out 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, first zero clearing timer T0 again opening timing device T0 count, finally 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 detect timer T0 starts, if timer T0 starts, stop timer T0 counting;
Wherein, the INT0 termination of described single-chip microcomputer enters pulse-width modulation PWM pulse signal, and the INT1 termination of described single-chip microcomputer enters through anti-phase pwm pulse signal;
Describedly utilize external interrupt INT0 and INT1 to carry out pulse width measuring task to comprise:
External interrupt INT0 and INT1 that single-chip microcomputer is set are 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 pwm pulse negative edge, utilize the first zero clearing timer of INT0 interrupt service routine T0 to restart timer T0 and start counting;
Utilize INT1 to interrupt catching the rising edge of next pwm pulse, when capturing the rising edge of next pwm pulse, utilize INT1 interrupt service routine first to judge whether timer T0 opens, if opened, stop timer T0 counting.
3. the device of an ensuring accurate measurement on pulse width in multi-task singlechip system, described single-chip microcomputer is C8051F020, it is characterized in that, comprise: phase inverter, the first level transferring chip, second electrical level conversion chip, pwm pulse Yi road signal inputs to the P0.4 pin of described single-chip microcomputer as the INT0 external interrupt of 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 P0.5 pin of described single-chip microcomputer as the ITN1 external interrupt of described Single Chip Microcomputer (SCM) system, the P0.1 pin that rs 232 serial interface signal UART0 is connected to described single-chip microcomputer by described the first level transferring chip is inputted as first serial, the P0.3 pin that rs 232 serial interface signal UART1 is connected to described single-chip microcomputer by described second electrical level conversion chip is inputted as second serial, simulating signal ADC0 is connected to the AIN0.0 pin of described single-chip microcomputer, as analog input, interrupt service routine unit in described single-chip microcomputer is for when carrying out the 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, 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 detecting in single-chip microcomputer starts, if timer T0 starts, stops timer T0 counting,
Wherein, described device also comprises the first build-out resistor that is arranged on first serial input end the signal reflex for eliminating serial communication cable, and is arranged on second serial input end the second build-out resistor of the signal reflex for eliminating serial communication cable; The oscillator consisting of capacitor C 1, C2, quartz crystal G1 and described single-chip microcomputer, the two ends of described quartz crystal G1 are connected to respectively XTAL1 pin and the XTAL2 pin of described single-chip microcomputer and think that described Single Chip Microcomputer (SCM) system provides clock.
4. the device of an ensuring accurate measurement on pulse width in multi-task singlechip system, described single-chip microcomputer is C8051F020, it is characterized in that, comprise: phase inverter, the first level transferring chip, second electrical level conversion chip, pwm pulse Yi road signal inputs to the P0.4 pin of described single-chip microcomputer as the INT0 external interrupt of 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 P0.5 pin of described single-chip microcomputer as the ITN1 external interrupt of described Single Chip Microcomputer (SCM) system, the P0.1 pin that rs 232 serial interface signal UART0 is connected to described single-chip microcomputer by described the first level transferring chip is inputted as first serial, the P0.3 pin that rs 232 serial interface signal UART1 is connected to described single-chip microcomputer by described second electrical level conversion chip is inputted as second serial, simulating signal ADC0 is connected to the AIN0.0 pin of described single-chip microcomputer, as analog input, interrupt service routine unit in described single-chip microcomputer is for when carrying out the 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, first zero clearing timer T0 again opening timing device T0 count, finally remove the interrupt identification of described external interrupt INT0, and detect whether run into the interrupt identification of external interrupt INT1, and if run into the interrupt identification of external interrupt INT1, detect timer T0 and whether start, if timer T0 starts, 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 CN102298095A (en) 2011-12-28
CN102298095B true 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)

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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
CN113300902B (en) * 2021-03-29 2022-05-20 明峰医疗系统股份有限公司 Multichannel pulse width measurement and data transmission processing method
CN115292398B (en) * 2022-08-02 2023-07-25 中国自然资源航空物探遥感中心 Data format conversion method and device, electronic equipment and storage medium

Family Cites Families (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
CN100348834C (en) * 2004-10-21 2007-11-14 山东科技大学 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

Also Published As

Publication number Publication date
CN102298095A (en) 2011-12-28

Similar Documents

Publication Publication Date Title
CN102298095B (en) Method for ensuring accurate measurement on pulse width in multi-task singlechip system and device
CN102035455A (en) M/T speed measuring method for frequency converter
CN111323626A (en) Uncovering detection circuit integrated in MCU and uncovering detection method based on MCU
CN212159910U (en) MCU integrated uncapping detection circuit and electric energy meter control chip
CN205228803U (en) Isolator state test device
CN103227558B (en) Wave-by-wave current limiting method and device
CN102621378B (en) Ultralow-power-consumption method for measuring voltage of power supply by RC (Resistor-Capacitor) integral
CN102087335B (en) Circuit signal detection device
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
CN101819460B (en) Linked switch device of host computer and display and control method thereof
CN108594626B (en) Power-down timing method, circuit and electronic equipment thereof
CN202676894U (en) Action logic sequence checking device of power supply spare power automatic switching device
CN203617782U (en) Double-power-supply automatic switching controller based on ATmega16 single chip microcomputer
CN207133811U (en) Digital independent apparatus and system
CN110457158A (en) House dog implementation method, device, equipment and storage medium based on finite state machine
CN109859697B (en) A kind of TFT display backlight control system and method
CN103817404B (en) A kind of hand arc welding machine three-phase electric power open phase detection method and device
CN205375041U (en) Can bus controller
CN204807625U (en) A SOC chip for vehicle automated inspection
CN204302356U (en) A kind of circuit structure of negtive voltage detection device and negtive voltage detection device
CN205209603U (en) Parameter automatic test system based on ultrasonic flowmeter circuit board
CN102353408B (en) Output signal detection circuit and detection method of dish-washing machine flowmeter
CN101995927A (en) Resetting-operating method of 51 single chip microcomputer (SCM)
CN206363186U (en) A kind of electrochemical capacitor active circuit

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