CN107290991B - Encoder knob control method and equipment based on Vehicle Controller - Google Patents

Encoder knob control method and equipment based on Vehicle Controller Download PDF

Info

Publication number
CN107290991B
CN107290991B CN201710387573.8A CN201710387573A CN107290991B CN 107290991 B CN107290991 B CN 107290991B CN 201710387573 A CN201710387573 A CN 201710387573A CN 107290991 B CN107290991 B CN 107290991B
Authority
CN
China
Prior art keywords
port
encoder
interruption
external interrupt
state variable
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.)
Active
Application number
CN201710387573.8A
Other languages
Chinese (zh)
Other versions
CN107290991A (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.)
Zhejiang Changjiang Automobile Electronics Co ltd
Original Assignee
Wenzhou Changjiang Automobile Electronic System Co Ltd
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 Wenzhou Changjiang Automobile Electronic System Co Ltd filed Critical Wenzhou Changjiang Automobile Electronic System Co Ltd
Priority to CN201710387573.8A priority Critical patent/CN107290991B/en
Publication of CN107290991A publication Critical patent/CN107290991A/en
Application granted granted Critical
Publication of CN107290991B publication Critical patent/CN107290991B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G05CONTROLLING; REGULATING
    • G05BCONTROL OR REGULATING SYSTEMS IN GENERAL; FUNCTIONAL ELEMENTS OF SUCH SYSTEMS; MONITORING OR TESTING ARRANGEMENTS FOR SUCH SYSTEMS OR ELEMENTS
    • G05B19/00Programme-control systems
    • G05B19/02Programme-control systems electric
    • G05B19/04Programme control other than numerical control, i.e. in sequence controllers or logic controllers

Landscapes

  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Engineering & Computer Science (AREA)
  • Automation & Control Theory (AREA)
  • Rotary Switch, Piano Key Switch, And Lever Switch (AREA)
  • Mechanical Control Devices (AREA)

Abstract

The present invention discloses a kind of encoder knob control method based on Vehicle Controller, comprising: initialization encoder port A, B, C are arranged the first Interruption and the second Interruption, configure an external interrupt for port A;It acquires the port level of port A and confirms that encoder knob rotates and closes external interrupt when port level state variable meets the external interrupt condition and open the first Interruption;It acquires each encoder port level and obtains port level state variable, the direction of rotation of encoder knob is confirmed when the port level state variable meets the second Interruption condition;The first Interruption and the second Interruption are closed, external interrupt is opened, by port level state variable clear 0.The present invention is combined by external interrupt and Interruption, and entire encoder rotation identification identification all in interrupt function guarantees the correctness of rotation identification, also evaded erroneous judgement problem when cyclic polling in task without being interrupted by other systems task.

Description

Encoder knob control method and equipment based on Vehicle Controller
Technical field
The present invention relates to automotive electronics field of embedded technology more particularly to a kind of encoder rotations based on Vehicle Controller Button control method and equipment.
Background technique
Automobile center console generally has multiple encoder knobs, facilitates driver and adjusts electronic equipment by rotating, such as The volume adjustment of vehicle entertainment system, the frequency point of radio are adjusted, adjusted there are also the temperature of air-conditioner controller, air quantity etc..At present Encoder knob control method is all by inquiring multiple port low and high level states, according to the sequencing of port low and high level Rule judge that encoder is clockwise or counterclockwise.In order to prevent erroneous judgement or without response the problems such as, this requires place Reason device fast cycle inquires the state of multiple port levels, and common way is that multiple ports are inquired in the timing of about 1 millisecond period The state change of level.But this is for a busy system, as long as the other task maximums of system, which execute the period, is greater than 1 millisecond, The system of will lead to cannot according to the state of the cyclic polling encoder port of regulation, cause erroneous judgement or without response the problems such as.And And the inquiry of every millisecond of encoder port also increases the resource utilization of processor, influences the stability of the other functions of system.
Summary of the invention
It is an object of the present invention to propose a kind of erroneous judgement when can prevent encoder from rotating or the problems such as without response, energy Enough reduce processor load resource utilization, the encoder knob controlling party based on Vehicle Controller that the present invention provides a kind of Method combines the logical process to judge encoder knob by external interrupt and Interruption, greatly promotes system load money Source utilization rate, reduce encoder rotation when erroneous judgement the problems such as.
To achieve the goals above, the technical scheme adopted by the invention is as follows:
A kind of encoder knob control method based on Vehicle Controller, includes the following steps:
The port level state variable for initializing encoder port A, encoder port B and encoder port C is 0, setting First Interruption and the second Interruption configure an external interrupt for encoder port A;
It acquires the port level of encoder port A and judges whether collected port level variation meets in the outside Disconnected condition confirms that encoder knob rotates and closes external interrupt and opens described the if meeting the external interrupt condition One Interruption;The step is recycled if being unsatisfactory for external interrupt condition;
The port level of encoder port A, encoder port B and encoder port C are acquired, port level state is obtained and becomes Amount, when the port level state variable meets the second Interruption condition, confirms the direction of rotation of encoder knob, Complete rotation detection;
The first Interruption and the second Interruption are closed, external interrupt is opened, by port level state variable clear 0.
Wherein, the second Interruption condition includes variable clockwise and variable counterclockwise;When the port level shape When state variable is equal to the variable clockwise, confirmation encoder knob is to rotate clockwise, when the port level state variable When equal to the variable counterclockwise, confirmation encoder knob is rotation counterclockwise.
Wherein, if at least two port level is low or does not collect the second Interruption in setting duty cycle Condition then closes the first Interruption and the second Interruption, external interrupt is opened, by port level state variable clear 0.
Wherein, the external interrupt of the encoder port A is the interruption of level failing edge.
Wherein, the timing cycle of first Interruption is 200us, and the timing cycle of the second Interruption is 2ms.
Invention additionally discloses a kind of, and the encoder knob based on Vehicle Controller controls equipment, comprising:
Processor is adapted for carrying out each instruction;And
Equipment is stored, is suitable for storing a plurality of instruction, described instruction is for being loaded and being executed by processor:
The port level state variable for initializing encoder port A, encoder port B and encoder port C is 0, setting First Interruption and the second Interruption configure an external interrupt for encoder port A;
It acquires the port level of encoder port A and judges whether collected port level variation meets in the outside Disconnected condition confirms that encoder knob rotates and closes external interrupt and opens described the if meeting the external interrupt condition One Interruption;The step is recycled if being unsatisfactory for external interrupt condition;
The port level of encoder port A, encoder port B and encoder port C are acquired, port level state is obtained and becomes Amount, when the port level state variable meets the second Interruption condition, confirms the direction of rotation of encoder knob, Complete rotation detection;
The first Interruption and the second Interruption are closed, external interrupt is opened, by port level state variable clear 0.
Wherein, the second Interruption condition includes variable clockwise and variable counterclockwise;When the port level shape When state variable is equal to the variable clockwise, confirmation encoder knob is to rotate clockwise, when the port level state variable When equal to the variable counterclockwise, confirmation encoder knob is rotation counterclockwise.
Wherein, if at least two port level is low or does not collect the second Interruption in setting duty cycle Condition then closes the first Interruption and the second Interruption, external interrupt is opened, by port level state variable clear 0.
Wherein, the external interrupt of the encoder port A is the interruption of level failing edge.
Wherein, the timing cycle of first Interruption is 200us, and the timing cycle of the second Interruption is 2ms.
The invention has the benefit that
One, the present invention by external break events trigger encoder key rotate judgement handle, when encoder knob without There is no need to there is any operation when rotation process, periodic scanning port state is not needed, inquiry mode is efficiently solved and leads The problem of causing processor low efficiency also reduces timing interference of the encoder identification operation to other tasks of system.
Two, it is combined by external interrupt and Interruption, so that entire encoder rotation identification is all in interrupt function Identification, so that encoder identification is not interrupted by other systems task, ensure that rotation identification by configuring the priority of interruption Correctness has also evaded erroneous judgement problem when cyclic polling in task.
Three, according to encoder port A, encoder port B and the changing rule of encoder port C level, by obtaining end It is to operate clockwise or counterclockwise that mouth level state variable, which carries out judgement, simplifies encoder and knows method for distinguishing.
Four, the present invention in external interrupt due to having had identified that key rotation process, it is contemplated that the consistency of code And robustness, rotation judgement is placed in Interruption and is handled.
Detailed description of the invention
Fig. 1 is a kind of flow chart of the encoder knob control method based on Vehicle Controller of the present invention;
Fig. 2 is the port waveform diagram that inventive encoder knob rotates clockwise;
Fig. 3 is the port waveform diagram that inventive encoder knob rotates counterclockwise.
Specific embodiment
Below with reference to specific embodiment shown in the drawings, the present invention will be described in detail.But these embodiments are simultaneously The present invention is not limited, structure that those skilled in the art are made according to these embodiments, method or functionally Transformation is included within the scope of protection of the present invention.
A kind of encoder rotation based on Vehicle Controller is disclosed refering to fig. 1 shown in Fig. 3, in one embodiment of the present invention Button control method, includes the following steps:
S100: the port level state variable of initialization encoder port A, encoder port B and encoder port C are 0, First Interruption and the second Interruption are set, configure an external interrupt for encoder port A;
Coder module is initialized, the initialization includes by encoder port A, encoder port B and encoder-side Mouth C is configured to input port, and the first Interruption and the second Interruption is arranged, and preferably setting timing cycle is 200us, but it is not turned on Interruption at this time.And an external interrupt is configured for encoder port, preferably it is set as level decline Externally interrupt.Initializing rear port level interim state variable is 0, and port level state variable is 0.
S200: the port level of acquisition encoder port A and to judge whether the variation of collected port level meets described The condition of external interrupt confirms that encoder knob rotates and closes external interrupt unlatching if meeting the external interrupt condition First Interruption;The step is recycled if being unsatisfactory for external interrupt condition;
Encoder port A, encoder port B and encoder port C are defaulted as high level, if when rotary encoder, compiled Code device port A level from high to low when, failing edge external interrupt can be generated.I.e. collected port level meets external interrupt item Part can confirm that there are rotation process.Then first Interruption is opened, after the first Interruption to timing cycle It performs the next step rapid.
S300: the port level of acquisition encoder port A, encoder port B and encoder port C obtain port level State variable confirms the rotation of encoder knob when the port level state variable meets the second Interruption condition Turn direction, completes rotation detection;
In this step, after waiting the first timing cycle to arrive, the port level of each port is acquired, in port transitory state In variable, position 0 saves the level state of encoder port A, and position 1 saves the level state of encoder port B, and position 2 saves coding The level state of device port C.If it is low level that encoder port A, encoder port B or encoder port C, which have a pin, When encoder port B is low level, the second Interruption condition, port interim state variable=0X05 are triggered;Work as encoder Port C also triggers the second Interruption condition, port interim state variable=0X03 when being low level.Port level state variable =port interim state variable.System determines the direction of rotation of encoder knob according to the value of port level state variable, described Second Interruption condition includes variable clockwise and variable counterclockwise, and variable clockwise is set in one embodiment of the present invention For 0X03, variable counterclockwise is set as 0X05.When the port level state variable is equal to the variable clockwise, confirmation is compiled Code device knob is to rotate clockwise, when the port level state variable is equal to the variable counterclockwise, confirmation encoder rotation Button is rotation counterclockwise.I.e. when encoder port B is low level, the port level state variable is equal to the change clockwise 0X03 is measured, confirmation encoder knob is to rotate clockwise.When encoder port C is low level, the port level state becomes Amount is equal to the variable 0X05 counterclockwise, and confirmation encoder knob is rotation counterclockwise.
S400: closing the first Interruption and the second Interruption, opens external interrupt, and port level state variable is clear 0.After completing primary rotation detection, each port level state variable clear 0, variable left four are restarted to revolve next time Turn detection,
If at least two port level is low or does not collect second in setting duty cycle in step S300 Interruption condition then closes the first Interruption and the second Interruption, external interrupt is opened, by port level state variable Clear 0.In a duty cycle, if the second Interruption is not triggered always, the i.e. second timing of the first Interruption will be closed It interrupts, opens external interrupt, restart rotation detection.In the duty cycle, if there are two simultaneously with upper port electricity It puts down to be low, then port level state variable clear 0, closes the first Interruption and the second Interruption, open external interrupt.Institute Stating duty cycle can be set according to demand, such as be set to 10 milliseconds, 50 milliseconds or 80 milliseconds time cycles, in task week Turn off the first Interruption, the second Interruption by force if not completing rotation detection in phase, opens external interrupt.
In above embodiment, the timing cycle of first Interruption may be set to 200us, the second Interruption Timing cycle may be set to the value between 1-2 milliseconds.First Interruption, the second Interruption can carry out spirit according to demand Configuration living.
A kind of encoder knob control equipment based on Vehicle Controller, packet are also disclosed in one embodiment of the present invention It includes:
Processor is adapted for carrying out each instruction;And
Equipment is stored, is suitable for storing a plurality of instruction, described instruction is for being loaded and being executed by processor:
The port level state variable for initializing encoder port A, encoder port B and encoder port C is 0, setting First Interruption and the second Interruption configure an external interrupt for encoder port A;
It acquires the port level of encoder port A and judges whether collected port level variation meets in the outside Disconnected condition confirms that encoder knob rotates and closes external interrupt and opens described the if meeting the external interrupt condition One Interruption and the second Interruption;The step is recycled if being unsatisfactory for external interrupt condition;
The port level of encoder port A, encoder port B and encoder port C are acquired, port level state is obtained and becomes Amount, when the port level state variable meets the second Interruption condition, confirms the direction of rotation of encoder knob, Complete rotation detection;
The first Interruption and the second Interruption are closed, external interrupt is opened, by port level state variable clear 0.
In one embodiment, the second Interruption condition includes variable clockwise and variable counterclockwise;When described When port level state variable is equal to the variable clockwise, confirmation encoder knob is to rotate clockwise, when the port electricity When flat-shaped state variable is equal to the variable counterclockwise, confirmation encoder knob is rotation counterclockwise.
In the another improvement embodiment of above embodiment, the timing cycle of first Interruption is 200us, The timing cycle of second Interruption is 2ms.
In the another improvement embodiment of above embodiment, the external interrupt of the encoder port A is level decline Along interruption.
In the another improvement embodiment of above embodiment, the timing cycle of first Interruption be may be set to 200us, the timing cycle of the second Interruption may be set to the value between 1-2 milliseconds.
In above embodiment, judgement processing is rotated by the key that external break events trigger encoder, works as encoder There is no need to there is any operation when knob operates without spin, periodic scanning port state is not needed, inquiry is efficiently solved Mode leads to the problem of processor low efficiency, also reduces timing interference of the encoder identification operation to other tasks of system.It is logical It crosses external interrupt and Interruption combines, so that entire encoder rotation identification all identifies in interrupt function, pass through and configure The priority of interruption ensure that the correctness of rotation identification, also evade so that encoder identification is not interrupted by other systems task Erroneous judgement problem in task when cyclic polling.According to the change of encoder port A, encoder port B and encoder port C level Law is to operate clockwise or counterclockwise by obtaining port level state variable to carry out judgement, simplifies encoder knowledge Method for distinguishing.The present invention in external interrupt due to having had identified that key rotation process, it is contemplated that the consistency of code and Rotation judgement is placed in Interruption and handles by robustness.
It should be appreciated that although this specification is described in terms of embodiments, but not each embodiment only includes one A independent technical solution, this description of the specification is merely for the sake of clarity, and those skilled in the art should will say As a whole, the technical solution in each embodiment may also be suitably combined to form those skilled in the art can for bright book With the other embodiments of understanding.
The series of detailed descriptions listed above only for feasible embodiment of the invention specifically Protection scope bright, that they are not intended to limit the invention, it is all without departing from equivalent implementations made by technical spirit of the present invention Or change should all be included in the protection scope of the present invention.

Claims (4)

1. a kind of encoder knob control method based on Vehicle Controller, it is characterised in that include the following steps:
The port level state variable for initializing encoder port A, encoder port B and encoder port C is 0, setting first Interruption and the second Interruption configure an external interrupt for encoder port A;
It acquires the port level of encoder port A and judges whether collected port level variation meets the external interrupt Condition confirms that encoder knob rotates and closes external interrupt unlatching described first and determines if meeting the external interrupt condition When interrupt;The step is recycled if being unsatisfactory for external interrupt condition;
The port level of encoder port A, encoder port B and encoder port C are acquired, port level state variable is obtained, When the port level state variable meets the second Interruption condition, the direction of rotation of encoder knob is confirmed, it is complete It is detected at rotation;
The first Interruption and the second Interruption are closed, external interrupt is opened, by port level state variable clear 0;
The second Interruption condition includes variable clockwise and variable counterclockwise;When the port level state variable is equal to When the variable clockwise, confirmation encoder knob is to rotate clockwise, when the port level state variable is equal to described inverse When hour hands variable, confirmation encoder knob is rotation counterclockwise;
If at least two port level is low or does not collect the second Interruption condition in setting duty cycle, close The first Interruption and the second Interruption are closed, external interrupt is opened, by port level state variable clear 0;
The external interrupt of the encoder port A is the interruption of level failing edge.
2. a kind of encoder knob control method based on Vehicle Controller according to claim 1, it is characterised in that: institute The timing cycle for stating the first Interruption is 200us, and the timing cycle of the second Interruption is 2ms.
3. a kind of encoder knob based on Vehicle Controller controls equipment, characterized by comprising:
Processor is adapted for carrying out each instruction;And
Equipment is stored, is suitable for storing a plurality of instruction, described instruction is for being loaded and being executed by processor:
The port level state variable for initializing encoder port A, encoder port B and encoder port C is 0, setting first Interruption and the second Interruption configure an external interrupt for encoder port A;
It acquires the port level of encoder port A and judges whether collected port level variation meets the external interrupt Condition confirms that encoder knob rotates and closes external interrupt unlatching described first and determines if meeting the external interrupt condition When interrupt;The step is recycled if being unsatisfactory for external interrupt condition;
The port level of encoder port A, encoder port B and encoder port C are acquired, port level state variable is obtained, When the port level state variable meets the second Interruption condition, the direction of rotation of encoder knob is confirmed, it is complete It is detected at rotation;
The first Interruption and the second Interruption are closed, external interrupt is opened, by port level state variable clear 0;
The second Interruption condition includes variable clockwise and variable counterclockwise;When the port level state variable is equal to When the variable clockwise, confirmation encoder knob is to rotate clockwise, when the port level state variable is equal to described inverse When hour hands variable, confirmation encoder knob is rotation counterclockwise;
If at least two port level is low or does not collect the second Interruption condition in setting duty cycle, close The first Interruption and the second Interruption are closed, external interrupt is opened, by port level state variable clear 0;
The external interrupt of the encoder port A is the interruption of level failing edge.
4. encoder knob according to claim 3 based on Vehicle Controller controls equipment, it is characterised in that: described the The timing cycle of one Interruption is 200us, and the timing cycle of the second Interruption is 2ms.
CN201710387573.8A 2017-05-27 2017-05-27 Encoder knob control method and equipment based on Vehicle Controller Active CN107290991B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710387573.8A CN107290991B (en) 2017-05-27 2017-05-27 Encoder knob control method and equipment based on Vehicle Controller

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710387573.8A CN107290991B (en) 2017-05-27 2017-05-27 Encoder knob control method and equipment based on Vehicle Controller

Publications (2)

Publication Number Publication Date
CN107290991A CN107290991A (en) 2017-10-24
CN107290991B true CN107290991B (en) 2019-07-02

Family

ID=60094799

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710387573.8A Active CN107290991B (en) 2017-05-27 2017-05-27 Encoder knob control method and equipment based on Vehicle Controller

Country Status (1)

Country Link
CN (1) CN107290991B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112146686B (en) * 2019-06-27 2022-07-15 西安诺瓦星云科技股份有限公司 Rotation information acquisition method, device and system and computer readable storage medium

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8866643B2 (en) * 2010-09-07 2014-10-21 Alps Electric Co., Ltd. Rotation input device
CN102866724B (en) * 2011-07-08 2015-04-22 阿尔派株式会社 Electronic equipment and adjustment method thereof
CN103207754B (en) * 2012-01-13 2016-12-14 阿尔派株式会社 E-machine and the method for controlling operation thereof of e-machine
CN104898763A (en) * 2015-04-15 2015-09-09 广东好帮手电子科技股份有限公司 Turn button control-adjustment method and system of vehicle-mounted encoder
CN106200548B (en) * 2016-08-23 2019-06-04 惠州华阳通用电子有限公司 A kind of control method and circuit of optoelectronic induction knob

Also Published As

Publication number Publication date
CN107290991A (en) 2017-10-24

Similar Documents

Publication Publication Date Title
EP3396051B1 (en) Laundry treating apparatus, control method of laundry treatment apparatus and online system including the same
Wadhwani et al. Smart home automation and security system using Arduino and IOT
JP2017513099A (en) Support for constrained devices and operating systems
EP3086563A1 (en) Gateway, management center, and remote access system
CN107290991B (en) Encoder knob control method and equipment based on Vehicle Controller
KR20120031092A (en) Remote control scheduler and method for autonomous robotic device
CN105103398B (en) Control the operation of power consuming device in power grid
CN113490578B (en) Method for operating a robot in a multi-agent system, robot and multi-agent system
US6311241B1 (en) Method and configuration for transferring programs
JP2014182606A (en) Arithmetic device and program
CN113777938A (en) Household appliance control method, device, equipment and storage medium
CN109976326A (en) Wheeled robot control method and device, terminal device and medium
CN110036620B (en) Household appliance with network interface
WO2018048676A1 (en) Wizard for configuring a motor
CN110690835A (en) Method for accelerating and decelerating motor by using S-shaped curve
CN114389910A (en) Terminal control method and terminal control device based on UWB implementation
CN107112942A (en) Input stage for motor controller and the motor controller particularly for motor
CN110277939A (en) Control system and control method, the refrigerant valve with stepper motor
CN110360705A (en) For controlling method and apparatus, server, air-conditioning and the storage medium of air-conditioning
CN106227526A (en) A kind of leveling based on MULTI-LAYER FINITE CYLINDRICAL state machine plays perpendicular control Process Design Method
US20050049724A1 (en) Re-configurable motion controller drive
CN111754749B (en) Remote controller with self-learning capability and control circuit thereof
CN109866218A (en) Standing control method and device are fallen down by robot
CN109842346A (en) Motor speed method for self-calibrating, device and the central kitchen ventilator of motor-driven valve
US20170325324A1 (en) Lighting apparatus and method of controlling the same

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CP03 Change of name, title or address
CP03 Change of name, title or address

Address after: No. 289, 291, Binhai Second Road, Wenzhou Economic and Technological Development Zone, Wenzhou City, Zhejiang Province, 325025

Patentee after: Zhejiang Changjiang Automobile Electronics Co.,Ltd.

Address before: 325025 No. 289 Binhai Second Road, Wenzhou Economic and Technological Development Zone, Zhejiang Province

Patentee before: WENZHOU CHANGJIANG AUTOMOBILE ELECTRONIC SYSTEM Co.,Ltd.