Motor control method and electronic equipment

By controlling the vibration stop of the motor with delay, the problem of the motor hitting the wall during vibration conflict is solved, extending the service life of the motor and improving the user experience.

CN120342278APending Publication Date: 2025-07-18HONOR DEVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410034762.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-01-09
Publication Date
2025-07-18

AI Technical Summary

Technical Problem

In the prior art, motors are prone to wall collisions when vibrating, which affects service life and user experience.

Method used

By controlling the motor to stop vibration by delay, the amplitude of the driving voltage signal is stopped at or near zero, reducing the amplitude of the motor and thus reducing the probability of the wall hitting.

Benefits of technology

It extends the service life of the motor and improves the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120342278A_ABST
    Figure CN120342278A_ABST
Patent Text Reader

Abstract

The invention provides a motor control method and electronic equipment, and relates to the technical field of motor driving. According to the method, when the motor needs to stop vibrating, the motor can be controlled to stop vibrating by delaying the first duration, so that the amplitude (magnitude) of the voltage driving signal is zero or close to zero when the motor stops vibrating, the amplitude when the motor stops vibrating can be reduced, the probability that the motor collides with the wall can be reduced, and the effect of prolonging the service life of the motor is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the technical field of motor drive, and in particular, to a control method for a motor and an electronic device. Background Art

[0002] In order to improve the user experience when using a terminal, when a user performs certain operations on the terminal, the terminal can prompt the user by vibrating. For example, when the user is playing a game on the terminal, the terminal can vibrate when the user performs a preset operation to give the user a tactile feedback and enable the user to have an immersive experience. Among them, the vibration of the terminal is realized by the vibration of a motor installed in the terminal.

[0003] In the related art, in the case of vibration conflicts in the motor, for example, when the motor vibrates in response to the user's typing operation and the terminal needs to vibrate again because a new message is received, the phenomenon of the motor hitting the wall easily occurs, which affects the service life of the motor and the user experience. Therefore, how to provide a control method that can reduce the probability of the motor hitting the wall has become an urgent problem to be solved at present. Summary of the Invention

[0004] The embodiments of the present application provide a control method for a motor and an electronic device, which can reduce the probability of the motor hitting the wall and extend the service life of the motor.

[0005] To achieve the above object, the embodiments of the present application adopt the following technical solutions:

[0006] In a first aspect, an embodiment of the present application provides a method for controlling a motor. The electronic device includes a vibration chip and a motor. The method includes: at a first moment, receiving a first event for triggering the motor to vibrate, and the first moment can be any moment. In response to the first event, controlling the vibration chip to output a first drive voltage signal to the motor based on a first vibration description parameter, so that the motor vibrates, and the first vibration description parameter is the vibration description parameter corresponding to the first event. At a second moment, receiving a second event for triggering the motor to vibrate, and the second moment is any moment later than the first moment. In response to the second event, controlling the motor to stop vibrating after a first time period starting from the second moment, and controlling the motor to vibrate again. Wherein, the vibration description parameter includes amplitude parameters arranged in sequence, and the amplitude parameter is used to indicate the amplitude of the drive voltage signal. The first time period is the time difference between the target moment and the second moment. The amplitude of the first drive voltage signal at the target moment corresponds to the target amplitude parameter, and the target amplitude parameter is any one of the first amplitude parameters. The first amplitude parameter is the amplitude parameter that is located after the second amplitude parameter in the first vibration description parameter and indicates that the amplitude of the first drive voltage signal is 0. The second amplitude parameter is the amplitude parameter corresponding to the amplitude of the first drive voltage signal at the second moment. It should be noted that indicating that the amplitude of the drive voltage signal is 0 does not mean that the amplitude parameter is strictly 0, but can be a value close to 0.

[0007] That is to say, when the electronic device needs to control the motor to stop vibrating, it does not immediately control the motor to stop vibrating, but adds a certain delay (i.e., the first time period), so that the amplitude (magnitude) of the voltage drive signal is zero or close to zero when controlling the motor to stop vibrating. This can reduce the amplitude when the motor stops vibrating and reduce the probability of the motor hitting the wall, thereby achieving the effect of extending the life of the motor.

[0008] In an implementation manner provided in the first aspect, the target amplitude parameter is the amplitude parameter closest to the second amplitude parameter among the first amplitude parameters. In this way, the electronic device can control the motor to stop vibrating at a zero point closest to the current drive voltage, enabling the motor to stop vibrating as soon as possible and quickly respond to user needs.

[0009] In an implementation provided in the first aspect, the target amplitude parameter is the amplitude parameter in the third amplitude parameters that is closest to the second amplitude parameter. The third amplitude parameters include the amplitude parameters in the first amplitude parameters whose corresponding playback delay is greater than the interaction delay. The playback delay of an amplitude parameter is the time required from the second moment to the moment when the drive voltage signal corresponding to the amplitude parameter is output. Thus, since the electronic device cannot ensure that the motor stops vibrating when the voltage drive signal is zero when the first delay is less than the interaction delay, using the amplitude parameter in the third amplitude parameters as the target amplitude parameter can ensure that the first delay is greater than the interaction delay, and further ensure that the motor stops vibrating when the voltage drive signal is zero. Further, using the amplitude parameter in the third amplitude parameters that is closest to the second amplitude parameter can control the motor to stop vibrating at the zero point that is closest to the current drive voltage and can make the first delay greater than the interaction delay, enabling the motor to stop vibrating as soon as possible.

[0010] In an implementation provided in the first aspect, the method further includes: obtaining a first parameter and a second parameter, where the first parameter is the number of amplitude parameters in the first vibration description parameters that have been written into the vibration chip, and the second parameter is the number of amplitude parameters in the vibration chip; determining the second amplitude parameter according to the first parameter and the second parameter; using a preset number of zero points after the second amplitude parameter in the first vibration description parameters as the first amplitude parameters; where a zero point is an amplitude parameter indicating that the amplitude of the drive voltage signal is 0; calculating the playback delay corresponding to the first amplitude parameter; obtaining an interaction delay, where the interaction delay is used to indicate the time required to obtain the second parameter; and determining the minimum value in the playback delays greater than the interaction delay as the first duration.

[0011] In an implementation provided in the first aspect, controlling the vibration chip to output a first drive voltage signal to the motor based on the first vibration description parameters includes: when the amplitude parameters in the first vibration description parameters have not been completely written into the vibration chip and the third event for triggering the motor to stop vibrating has not been received, circularly writing a parameter subsequence into the vibration chip; where the parameter subsequence includes a plurality of amplitude parameters, and the last amplitude parameter in the parameter subsequence indicates that the amplitude of the drive voltage signal is 0; and controlling the vibration chip to output the first drive voltage signal to the motor according to the parameter subsequence to control the motor to vibrate.

[0012] In this way, by writing the first vibration description parameter into the vibration chip in multiple times, the motor can start vibrating after the parameter subsequence is written into the vibration chip for the first time. In this way, the motor can start vibrating as soon as possible, reducing the delay caused by writing the amplitude parameter. In addition, since the last amplitude parameter in the parameter subsequence is zero, in the case where the electronic device fails to successfully control the motor to stop vibrating at the target amplitude parameter, the last amplitude parameter of the parameter subsequence can be used as zero to stop the motor vibrating, further reducing the probability of the motor hitting the wall and achieving the effect of extending the service life of the motor.

[0013] In an implementation manner provided in the first aspect, writing the parameter subsequence into the vibration chip in a loop includes: when the first quantity is less than a preset interruption threshold, writing the parameter subsequence into the vibration chip, where the first quantity is the number of remaining amplitude parameters of the vibration chip.

[0014] In an implementation manner provided in the first aspect, when the second quantity is less than or equal to the third quantity, the parameter subsequence includes all amplitude parameters in the first vibration description parameter that have not been written into the vibration chip; where the second quantity is the number of amplitude parameters in the first vibration description parameter that have not been written into the vibration chip, and the third quantity is the number of amplitude parameters that can be accommodated in the remaining space of the vibration chip; when the second quantity is greater than the third quantity, the parameter subsequence includes the (N + 1)-th to the M-th amplitude parameters in the first vibration description parameter, and the M-th amplitude parameter is the last amplitude parameter indicating that the amplitude of the drive voltage signal is 0 between the (N + 1)-th amplitude parameter and the (N + Q)-th amplitude parameter in the first vibration description parameter, N is the number of amplitude parameters in the first vibration description parameter that have been written into the vibration chip, and Q is the third quantity.

[0015] In an implementation manner provided in the first aspect, before writing the parameter subsequence into the vibration chip, the method further includes: determining a target quantity according to the second quantity and the third quantity, where the target quantity is the number of amplitude parameters written into the vibration chip; where, when the second quantity is less than or equal to the third quantity, the target quantity is the second quantity, and when the second quantity is greater than the third quantity, the target quantity is the number of amplitude parameters separated by the second amplitude parameter and the M-th amplitude parameter; writing the parameter subsequence into the vibration chip based on the target quantity.

[0016] In an implementation manner provided in the first aspect, the first duration satisfies the formula: T = Δ×δt; where T is the first duration, Δ is the number of amplitude parameters separated by the target amplitude parameter and the second amplitude parameter, and δt is a preset time interval.

[0017] In a second aspect, an embodiment of the present application further provides an electronic device, which includes: a memory, one or more processors, a vibration chip, and a motor; the memory and the vibration chip are coupled to the processor, and the vibration chip is connected to the motor; wherein, the memory is used to store computer program code, and the computer program code includes computer instructions; when the computer instructions are executed by the processor, the electronic device is caused to execute the method described in the first aspect and any one of its implementation manners.

[0018] In a third aspect, a computer-readable storage medium includes computer instructions; when the computer instructions are run on an electronic device, the electronic device is caused to execute the method described in the first aspect and any one of its implementation manners.

[0019] In a fourth aspect, the present application provides a computer program product, which, when run on a terminal device, causes the terminal device to execute the method described in the first aspect and any possible design manner thereof.

[0020] In a fifth aspect, the present application provides a chip system, which includes one or more interface circuits and one or more processors. The interface circuits and the processors are interconnected by lines. The above chip system can be applied to an electronic device including a communication module and a memory. The interface circuit is used to receive a signal from the memory of the electronic device and send the received signal to the processor, and the signal includes computer instructions stored in the memory. When the processor executes the computer instructions, the electronic device can execute the method described in the first aspect and any possible design manner thereof.

[0021] Among them, for the technical effects brought by any one of the design manners in the second aspect to the fifth aspect, reference can be made to the technical effects brought by different design manners in the first aspect, which will not be elaborated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Figure 1A is a schematic diagram of a scenario provided by an embodiment of the present application;

[0023] Figure 1B is a schematic diagram of a voltage waveform provided by an embodiment of the present application;

[0024] Figure 2 is a schematic diagram of the structure of an electronic device provided by an embodiment of the present application;

[0025] Figure 3 is a software architecture diagram of an electronic device provided by an embodiment of the present application;

[0026] Figure 4 is an interaction diagram between modules provided by an embodiment of the present application;

[0027] Figure 5Schematic diagram 1 of a control method for a motor provided by an embodiment of the present application;

[0028] Figure 6 Schematic diagram of a control method for a motor provided by an embodiment of the present application Figure Two ;

[0029] Figure 7 Schematic diagram of a control method for a motor provided by an embodiment of the present application Figure Three ;

[0030] Figure 8 Schematic diagram of playing vibration description parameters provided by an embodiment of the present application;

[0031] Figure 9 Interaction timing diagram between vibration drive and vibration chip provided by an embodiment of the present application;

[0032] Figure 10 Schematic diagram of a control method for a motor provided by an embodiment of the present application Figure Four ;

[0033] Figure 11 Schematic diagram of a control method for a motor provided by an embodiment of the present application Figure Five ;

[0034] Figure 12 Schematic diagram of a control method for a motor provided by an embodiment of the present application Figure Six 。 Detailed implementation manners

[0035] Next, the technical solutions in the embodiments of the present application will be described with reference to the accompanying drawings in the embodiments of the present application. Among them, in the description of the embodiments of the present application, the terms used in the following embodiments are only for the purpose of describing specific embodiments and are not intended to limit the present application. As used in the specification and appended claims of the present application, the singular forms "a", "the", "above-mentioned", "this" and "such" are also intended to include, for example, the expression form of "one or more", unless there is a clear indication to the contrary in the context. It should also be understood that in the following embodiments of the present application, "at least one" and "one or more" mean one or more than two (including two). The term "and / or" is used to describe the association relationship of associated objects and indicates that three relationships can exist; for example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone, where A and B can be singular or plural. The character " / " generally represents an "or" relationship between the associated objects before and after.

[0036] References to "one embodiment" or "some embodiments" etc. described in this specification mean that a particular feature, structure, or characteristic described in connection with the embodiment is included in one or more embodiments of the present application. Thus, statements such as "in one embodiment", "in some embodiments", "in other some embodiments", "in still other embodiments", etc. that appear in different places in this specification do not necessarily all refer to the same embodiment, but rather mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "comprise", "include", "have" and their variants all mean "include but not limited to", unless otherwise specifically emphasized in other ways. The term "connection" includes direct connection and indirect connection, unless otherwise stated. "First", "second" are only used for descriptive purposes and cannot be construed as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features.

[0037] In the embodiments of the present application, words such as "exemplarily" or "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or design solution described as "exemplarily" or "for example" in the embodiments of the present application should not be construed as being more preferred or having more advantages than other embodiments or design solutions. Rather, the use of words such as "exemplarily" or "for example" is intended to present the relevant concepts in a specific manner.

[0038] The control method of the motor provided by the embodiments of the present application can be applied to scenarios where motor vibration is required, such as game scenarios, chat scenarios, incoming call reminder scenarios, etc. For example, in a game scenario, the electronic device can vibrate in response to an operation by the user to release a skill. Again, for example, in a chat scenario, the electronic device can vibrate in response to the user's typing operation or receiving a new message. Still again, for example, in an incoming call reminder scenario, the electronic device can vibrate in response to receiving an incoming call.

[0039] As Figure 1A shown, it is a schematic diagram of an application scenario. As Figure 1A shown in (a) therein, the motor of the electronic device is vibrating because the electronic device has received event 1, and this event 1 is an event for triggering motor vibration, for example, an event that the user types using a virtual keyboard. Then, as Figure 1A shown in (b) therein, the electronic device receives event 2 for triggering motor vibration again, for example, an alarm reminder. In this case, the electronic device will immediately control the motor to stop vibrating when it receives event 2, and then control the motor to vibrate again.

[0040] As Figure 1B shown, it is Figure 1ASchematic diagram of the waveform of the driving voltage signal in the shown scenario. Among them, during the period from 0 to T1, the electronic device outputs the driving voltage signal S1 to the motor. At the moment T1, event 2 is received, and the amplitude of the driving voltage signal S1 directly changes from a high level (for example, the maximum value) to 0; then the electronic device outputs the driving voltage signal S2 to the motor at the moment T2 to make the motor vibrate again.

[0041] It can be seen that when there is a vibration conflict in the motor, the motor will stop vibrating due to the sudden change of the driving voltage signal from a high level to 0, which easily leads to the phenomenon of the motor hitting the wall and results in a sluggish vibration feeling after the motor vibrates again, affecting the service life of the motor and the user experience.

[0042] To at least solve the above problems, the embodiment of the present application provides a control method for a motor. This method can extend the time of outputting the driving voltage signal when there is a vibration conflict in the motor, so that the driving voltage signal ends with zero, reduce the risk of the motor hitting the wall, and extend the service life of the motor.

[0043] The embodiment of the present application provides a control method for a motor, which can be applied to an electronic device including a motor. Among them, the electronic device can be a mobile phone (including a straight mobile phone, a folding screen mobile phone, etc.), a tablet computer, a personal communication service (PCS) phone, a virtual reality (VR) electronic device, an augmented reality (AR) device, a wireless terminal in industrial control, a wireless terminal in self-driving, a wireless terminal in remote medical surgery, a wireless terminal in a smart grid, a wireless terminal in transportation safety, a wireless terminal in a smart city, a wireless terminal in a smart home, etc., and no specific limitation is made here.

[0044] Figure 2 Schematic diagram of the structure of an electronic device provided by the embodiment of the present application. As Figure 2As shown in the figure, the electronic device may include: a processor 210, an external memory interface 220, an internal memory 221, a universal serial bus (USB) interface 230, a charging management module 240, a power management module 241, a battery 242, an antenna 1, an antenna 2, a mobile communication module 250, a wireless communication module 260, an audio module 270, a speaker 270A, a receiver 270B, a microphone 270C, a headphone interface 270D, a sensor module 280, a button 290, a motor 291, an indicator 292, a camera 293, a display screen 294, and a subscriber identification module (SIM) card interface 295, etc.

[0045] Among them, the processor 210 may include one or more processing units. For example, the processor 210 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Among them, different processing units may be independent devices or integrated in one or more processors. The processor 210 may be the nerve center and command center of the electronic device. The processor 210 may generate operation control signals according to the instruction operation code and timing signal to complete the control of fetching and executing instructions.

[0046] A memory may also be provided in the processor 210 for storing instructions and data. In some embodiments, the memory in the processor 210 is a cache memory. This memory may save the instructions or data that the processor 210 has just used or recycled. If the processor 210 needs to use the instruction or data again, it can directly call it from the memory. This avoids repeated accesses, reduces the waiting time of the processor 210, and thus improves the efficiency of the system.

[0047] In some embodiments, the processor 210 may include one or more interfaces. The interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0048] The external memory interface 220 may be used to connect to an external memory card, such as a Micro SD card, to implement the storage capacity expansion of the electronic device. The external memory card communicates with the processor 210 through the external memory interface 220 to implement the data storage function. For example, files such as music and videos are saved in the external memory card.

[0049] The internal memory 221 may be used to store computer-executable program codes, and the executable program codes include instructions. The processor 210 executes various functional applications and data processing of the electronic device by running the instructions stored in the internal memory 221. For example, in the embodiments of the present application, the processor 210 may execute the instructions stored in the internal memory 221. The internal memory 221 may include a storage program area and a storage data area.

[0050] Among them, the storage program area may store an operating system, applications required for at least one function (such as a motor vibration function, an image playback function, etc.). The storage data area may store data created during the use of the electronic device (such as audio data, vibration parameters corresponding to different types of vibrations, etc.). In addition, the internal memory 221 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.

[0051] The motor 291 may generate a vibration prompt. The motor 291 may be used for an incoming call vibration prompt or for a touch vibration feedback, etc.

[0052] It can be understood that the interface connection relationships among the modules illustrated in this embodiment are only illustrative descriptions and do not constitute a structural limitation on the electronic device. In other embodiments, the electronic device may also include more or fewer modules than those provided in the above embodiments, and different interface connection methods as described in the above embodiments, or a combination of multiple interface connection methods, may be adopted among the modules.

[0053] The software system of the above electronic device may adopt a layered architecture, an event-driven architecture, a microkernel architecture, a microservices architecture, or a cloud architecture. The embodiments of the present invention take the layered architecture of the system as an example to exemplarily illustrate the software structure of the electronic device.

[0054] The layered architecture divides the software into several layers, and each layer has a clear role and division of labor. Communication between layers is carried out through interfaces. In some embodiments, the system may include an application layer, an application framework layer, an Android runtime, a system library, a hardware abstraction layer (HAL), and a kernel layer. It should be noted that the embodiments of this application take the system as an example. In other operating systems (for example, the system, etc.), as long as the functions implemented by each functional module are similar to those of the embodiments of this application, the solution of this application can also be implemented.

[0055] Among them, the application layer may include a series of application packages. As Figure 3 shown, the application packages may include applications such as a camera, a gallery, a calendar, a call, a map, a navigation, a WLAN, a settings, a music, a lock screen, and a short message. Of course, the application layer may also include other application packages, such as third-party applications such as a payment application, a shopping application, a bank application, a chat application, or a financial management application, which are not limited in this application.

[0056] The application framework layer provides application programming interfaces (APIs) and programming frameworks for the applications in the application layer. The application framework layer includes some predefined functions. For example, it may include an activity manager, a window manager, a content provider, a view system, a resource manager, a notification manager, a vibrator service, etc., and the embodiments of this application do not impose any restrictions on this. The vibrator service is used to provide services related to vibration support.

[0057] The system library can include multiple functional modules. For example, a surface manager, media libraries, a 3D graphics processing library (e.g., OpenGL ES), a 2D graphics processing library (e.g., SGL), etc.

[0058] The Android runtime includes a core library and a virtual machine. The Android runtime is responsible for the scheduling and management of the Android system. The core library consists of two parts: one part is the functional functions that the Java language needs to call, and the other part is the core library of Android. The application layer and the application framework layer run in the virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object lifecycle management, stack management, thread management, security and exception management, and garbage collection.

[0059] The HAL layer is an encapsulation of the Linux kernel driver, providing an interface upward and shielding the implementation details of the underlying hardware. The HAL layer can include a vibrator HAL, a camera HAL, and a vibration algorithm library, etc.

[0060] Among them, the vibrator HAL can include a vibration interface for interacting with the vibration driver in the kernel layer.

[0061] The vibration algorithm library can interact with the vibrator HAL, construct vibration description parameters for describing the voltage drive waveform according to the vibration parameters transmitted by the vibrator HAL, and transmit the constructed vibration description parameters to the vibrator HAL.

[0062] The kernel layer is the layer between hardware and software. Among them, the kernel layer includes a vibration driver, a display driver, an audio driver, etc. The vibration driver is a program that allows high-level computer software to interact with hardware, that is, a set of programs that drive the motor to work. Through this vibration driver, the control of the motor can be achieved.

[0063] In the embodiment of the present application, the kernel layer adopts an input framework. The input framework is used to implement read and write access to hardware devices (such as vibration chips), interrupt settings, and convert events generated by the hardware into specifications defined by the core layer and submit them to the application framework layer. Specifically, the input framework includes an input event layer (input handler), an input kernel layer (input core), and an input driver layer (input device). Among them, the input processor can process the input events reported by the input kernel and provide an access interface to the HAL layer. The input kernel plays a connecting role, which can notify the input processor to process the events and can also provide an operation interface for the input device. The input driver layer can receive input events from the bottom layer and forward them to the upper-layer input processor. Among them, drivers such as vibration drivers, display drivers, and audio drivers are located in the input driver layer. Under the input framework, the driver (such as the vibration driver) cannot have a sleep operation, otherwise it will cause the kernel to crash, resulting in the phone crashing (crush).

[0064] As Figure 3 shown, the electronic device also includes hardware such as a memory, a vibration chip, and a motor. Among them, the vibration chip is used to output a drive voltage signal to the motor to drive the motor to vibrate. The motor is used to vibrate to bring a vibration sensation to the user.

[0065] Next, the software modules involved in the motor control method provided by the embodiment of the present application and the interaction between the modules will be described. As Figure 4 shown, the first application in the application layer can interact with the vibration service in the application framework layer by calling a preset application programming interface (API), and send a vibration instruction a to the vibration service. The vibration instruction a carries vibration parameters, such as vibration duration, vibration type, etc. After receiving the vibration instruction a, the vibration service can determine whether the motor vibrates. If the motor does not vibrate, the vibration service can interact with the vibration HAL in the HAL layer and send the vibration instruction a to the vibration HAL. The vibration HAL can send the vibration parameters carried in the vibration instruction a to the vibration algorithm library in the same HAL layer. The vibration algorithm library can generate vibration description parameters according to the vibration parameters and send the vibration description parameters to the vibration HAL. The vibration HAL can interact with the vibration driver in the kernel layer and send the vibration description parameters to the vibration driver. The vibration driver can write the vibration description parameters into the vibration chip. The vibration chip outputs a drive voltage signal to the motor based on the vibration description parameters to control the motor to vibrate.

[0066] Still as Figure 4As shown, during the vibration of the motor, the second application can send a vibration instruction b to the vibration service. After receiving the vibration instruction b, the vibration service can determine whether the motor is vibrating. Since the motor is vibrating, the vibration service first sends a stop vibration instruction to the vibration HAL, the vibration HAL sends a stop vibration instruction to the vibration driver, the vibration driver sends a stop vibration instruction to the vibration chip, and the vibration chip stops outputting a drive voltage signal to the motor to control the motor to stop vibrating. Then, the vibration chip can send a vibration stop feedback to the vibration service through the vibration driver and the vibration HAL. The vibration stop feedback is used to indicate that the motor has stopped vibrating. After receiving the vibration stop feedback, the vibration service can send the vibration instruction b to the vibration HAL. The process after the vibration HAL receives the vibration instruction b is similar to the process after it receives the vibration instruction a, which will not be elaborated here.

[0067] Next, the control method for the motor provided in the embodiments of the present application will be specifically described with reference to the accompanying drawings.

[0068] Refer to Figure 5 , which is a schematic flowchart I of a control method for a motor provided in an embodiment of the present application. This method can be applied to an electronic device including a motor. As Figure 5 shown, a control method for a motor provided in an embodiment of the present application may include steps S510 to S540.

[0069] S510, at time t1, receive a first event for triggering the vibration of the motor.

[0070] Among them, the first event can trigger the vibration of the motor. For example, the first event can be an event that the user unlocks the electronic device, an event that the user makes an online payment, an event that the user enters a face, an operation that the user releases a skill in a game application, an operation that the user types, an event that the user pulls down the chat interface (such as the chat interface of the TM WeChat application), etc. For another example, the first event can be an event that the electronic device receives an incoming call / sms, an event that the current time matches the reminder time preset by the user (i.e., alarm reminder), etc.

[0071] It should be noted that the first event can also be other, and the embodiments of the present application do not make specific limitations on this. In addition, the above time t1 is the time when the electronic device receives the first event, and does not refer to any specific time. This time t1 can also be referred to as the first time.

[0072] S520, in response to the first event, control the vibration chip to output a first drive voltage signal to the motor based on the first vibration description parameter, so that the motor vibrates.

[0073] In the embodiments of the present application, a vibration description parameter is used to describe a drive voltage signal. A vibration description parameter includes a plurality of amplitude parameters arranged in sequence, and each amplitude parameter is used to indicate the vibration amplitude of the drive voltage signal (which can be simply referred to as amplitude or magnitude). In this way, the vibration chip of the electronic device can output drive voltages corresponding to the magnitudes of each amplitude parameter in the vibration description parameter to the motor in sequence, and the multiple drive voltages form a drive voltage signal.

[0074] It should be noted that for the convenience of understanding the following content, the drive voltage corresponding to the amplitude parameter output by the vibration chip (magnitude) can be referred to as the vibration chip playing the amplitude parameter.

[0075] Exemplarily, the vibration description parameter can be as shown in Table 1:

[0076] Table 1

[0077] 0.010173 0.011596 0.013218 0.015066 0.017173 …… 0.03876 -0.00644 -0.05059 -0.09386 -0.13592 …… -0.13595 -0.09321 -0.05159 -0.00642 0.03879 ……

[0078] Among them, "0.010173", "0.011596", "0.013218", "0.015066", etc. are all amplitude parameters. Based on the vibration description parameter shown in Table 1, the vibration chip can play amplitude parameters such as "0.010173", "0.011596", "0.013218", "0.015066" in sequence. In other words, the vibration chip can output drive voltages corresponding to the magnitudes of "0.010173", "0.011596", "0.013218", "0.015066" in sequence.

[0079] In the embodiments of the present application, the vibration description parameter also includes the duration corresponding to each amplitude parameter. The vibration chip of the electronic device can output drive voltages corresponding to the magnitudes of each amplitude parameter to the motor in sequence according to the order of the multiple amplitude parameters in the vibration description parameter, and the time for outputting each drive voltage is the duration corresponding to the amplitude parameter.

[0080] For example, the vibration description parameter includes amplitude parameter 1, amplitude parameter 2, amplitude parameter 3, etc. Among them, the durations of amplitude parameter 1, amplitude parameter 2, and amplitude parameter 3 are time 1, time 2, and time 3 respectively, and amplitude parameter 1 corresponds to drive voltage 1, amplitude parameter 2 corresponds to drive voltage 2, and amplitude parameter 3 corresponds to drive voltage 3. Then the electronic device can output drive voltage 1 at 0 ms and last for time 1, and then output drive voltage 2 at the end of time 1 and last for time 2.

[0081] It should be noted that the duration corresponding to each amplitude parameter can be the same or different. In the following, the case where the duration corresponding to each amplitude parameter is the same will be taken as an example for illustration. When the duration corresponding to each amplitude parameter is the same, the vibration chip can play the amplitude parameters according to a preset frequency, and the duration corresponding to each amplitude parameter is the reciprocal of the preset frequency.

[0082] In a possible design, different driving voltages corresponding to amplitude parameters are pre-stored in the electronic device. Then, the vibration chip can directly read the driving voltage corresponding to each amplitude parameter and then output a driving voltage of the corresponding magnitude.

[0083] In another possible design, the maximum value of the driving voltage signal (which can also be referred to as the maximum amplitude) is pre-stored in the electronic device. Then, the vibration chip can calculate the corresponding amplitude according to the amplitude parameter and the maximum value, and then output a driving voltage of the corresponding amplitude (magnitude).

[0084] In the embodiment of the present application, the first vibration description parameter is the vibration description parameter corresponding to the first event and is used to describe the first driving voltage signal. Combining Figure 3 and Figure 4 it can be known that after the electronic device receives the first event, the application (such as the first application) affected by the first event can send a vibration instruction to the vibration service. The vibration instruction carries corresponding vibration parameters, which can be used to describe the duration, type, etc. of the vibration triggered by the first event. Then, the vibration service can send the vibration instruction to the vibration HAL. The vibration HAL can parse the corresponding vibration parameters from the vibration instruction and send the corresponding vibration parameters to the vibration algorithm library. The vibration algorithm library can generate the first vibration description parameter based on the corresponding vibration parameters.

[0085] Continuing to refer to Figure 5 , the control method of the motor provided in the embodiment of the present application further includes the following step S530.

[0086] S530, at time t2, a second event for triggering the motor to vibrate is received.

[0087] The second event is different from the first event. Among them, the description of the second event can refer to the relevant description of the first event in S510, which will not be elaborated here.

[0088] It should be noted that time t2 is later than time t1. The above time t2 is the time when the electronic device receives the second event and does not specifically refer to any specific time. This time t2 can also be referred to as the second time.

[0089] S540, in response to a second event, controls the motor to stop vibrating after a first duration starting from time t2, and controls the vibration chip to output a second drive voltage signal to the motor based on the second vibration description parameter, so that the motor vibrates again.

[0090] In the embodiment of the present application, the second vibration description parameter is the vibration description parameter corresponding to the second event, and is used to describe the second drive voltage signal. Wherein, for the process of obtaining the second vibration description parameter, reference may be made to the process of obtaining the first vibration description parameter in S520, which will not be elaborated here.

[0091] In the embodiment of the present application, the first duration is the time difference between the target time and the second time. The amplitude of the first drive voltage signal at the target time corresponds to the first target amplitude parameter (which may also be referred to as the target amplitude parameter). The first target amplitude parameter is any one of the first amplitude parameters. The first amplitude parameters include the amplitude parameters that are located after the second amplitude parameter in the first vibration description parameter and indicate that the amplitude of the first drive voltage signal is 0. The second amplitude parameter is the amplitude parameter corresponding to the amplitude of the first drive voltage signal at the second time.

[0092] It should be noted that the amplitude parameter indicating that the amplitude of the drive voltage signal is 0 can be called a zero point. A zero point is an amplitude parameter with a value of 0 or close to 0. For example, in the vibration description parameters shown in Table 1, when the amplitude parameter changes from "0.03876" to "-0.00644", the amplitude of the drive voltage signal will change from positive to negative, that is, it will pass through zero. Therefore, since the amplitude parameter "0.03876" is close to 0, "0.03876" is a zero point. Another example is that when the amplitude parameter changes from "-0.00642" to "0.03879", the amplitude of the drive voltage signal will change from negative to positive, that is, it will pass through zero, then the amplitude parameter "-0.00642" is also a zero point.

[0093] It can be understood that the amplitude of the drive voltage signal can affect the amplitude of the motor. Among them, the smaller the amplitude of the drive voltage signal, the slower the rotation speed of the motor, and the slower the rotation speed of the motor, the smaller the amplitude of the motor. Therefore, in the embodiment of the present application, by controlling the motor to stop vibrating after the first duration starting from time t2 (i.e., at the target time), the electronic device can stop outputting the drive voltage signal when the drive voltage signal is at or close to the zero point, that is, make the drive voltage signal stop at the position of the zero point or close to the zero point. This can make the motor stop vibrating when the amplitude is small, thereby reducing the risk of the motor hitting the wall and prolonging the service life of the motor.

[0094] For the process in which the foregoing electronic device controls the vibration chip to output the first drive voltage signal to the motor based on the first vibration description parameter to make the motor vibrate, the embodiment of the present application provides a possible implementation manner, as Figure 6 shownFigure 6 Flow schematic of the motor control method provided by the embodiment of the present application Figure Two . As Figure 6 shown, the aforementioned S520 includes S610 to S620.

[0095] S610, when the amplitude parameter in the first vibration description parameter is not completely written into the vibration chip and the third event for triggering the motor to stop vibrating is not received, cyclically write the parameter subsequence to the vibration chip.

[0096] Among them, in addition to the events exemplified for the first event in S510, the third event also includes that the actual vibration duration of the motor reaches the vibration duration corresponding to the first event.

[0097] In a possible design, the electronic device can determine whether the amplitude parameter in the first vibration description parameter is completely written into the vibration chip through the value of the first flag bit. Exemplarily, the value of the first flag bit (for example, written_done) can be 0 or 1, where the value of the first flag bit being 1 indicates that the amplitude parameter in the first vibration description parameter has been completely written into the vibration chip, and the value of the first flag bit being 0 indicates that the amplitude parameter in the first vibration description parameter has not been completely written into the vibration chip.

[0098] The electronic device can also determine whether the third event for triggering the motor to stop vibrating is received through the value of the second flag bit. Exemplarily, the value of the second flag bit (for example, cancelled) can be 0 or 1, where the value of the second flag bit being 1 indicates that the third event for triggering the motor to stop vibrating is received, and the value of the second flag bit being 0 indicates that the third event for triggering the motor to stop vibrating is not received.

[0099] It should be noted that the values of the above first flag bit and second flag bit are only examples, and can also be others, for example, can be full, null or empty, etc., as long as different values represent different meanings.

[0100] In the embodiment of the present application, the parameter subsequence can be cyclically written to the vibration chip through the vibration drive of the electronic device. The parameter subsequence includes some consecutive amplitude parameters in the first vibration description parameter. That is to say, the order of the multiple amplitude parameters included in the parameter subsequence is the same as their order in the first vibration description parameter. Thus, the vibration drive of the electronic device can write the first vibration description parameter into the vibration chip in multiple times.

[0101] Among them, writing the parameter subsequence to the vibration chip is actually writing the amplitude parameters to the first in first out (FIFO) queue of the vibration chip in sequence. In other words, the vibration chip can store the written amplitude parameters through its FIFO queue.

[0102] In the embodiment of the present application, the parameter subsequences written into the vibration chip by the vibration drive are different each time, but the last amplitude parameter of the parameter subsequence written each time is zero. That is to say, the last amplitude parameter in the FIFO queue is always zero. The method for making the last amplitude parameter of the parameter subsequence zero will be described later through steps S701 to S714 and will not be described here for the time being.

[0103] It should be noted that each time the electronic device writes a parameter subsequence to the vibration chip, the third flag bit can be updated. The value of the third flag bit is used to identify the number of amplitude parameters in the first vibration description parameter that have been written into the vibration chip (which can also be called the first parameter), and can be represented by samples_written for example. For example, if the value of samples_written is 31, it means that 31 amplitude parameters in the first vibration description parameter have been written into the vibration chip.

[0104] In a possible design, when the value of samples_written (i.e., the third flag bit) is the number of all amplitude parameters in the first vibration description parameter (for example, num_all), the electronic device can set written_done (i.e., the first flag bit) to 1 to indicate that the amplitude parameters in the first vibration description parameter have all been written into the vibration chip.

[0105] In the embodiment of the present application, the electronic device can obtain a first quantity, which is the number of remaining amplitude parameters in the FIFO queue, that is, the number of remaining amplitude parameters of the vibration chip, and can be represented by FIFO_left for example. If the first quantity is less than a preset interruption threshold, a parameter subsequence is written to the vibration chip once, thereby implementing the process of circularly writing parameter subsequences to the vibration chip.

[0106] It can be understood that when the first quantity (FIFO_left) is less than the interruption threshold, it indicates that there are fewer amplitude parameters in the FIFO queue. Therefore, writing a parameter subsequence to the vibration chip again to supplement the amplitude parameters in the FIFO queue can reduce the risk of the motor stopping vibrating due to insufficient amplitude parameters.

[0107] In the embodiment of the present application, the amplitude parameters included in the parameter subsequence are associated with the second quantity and the third quantity. Wherein, the second quantity is the number of amplitude parameters in the first vibration description parameter that have not been written into the vibration chip (for example, represented by samples_unwritten), and the third quantity is the number of amplitude parameters that can be accommodated in the remaining space of the FIFO queue (vibration chip) (for example, represented by FIFO_res). Taking the second quantity samples_unwritten = P, the third quantity FIFO_res = Q, and samples_written = N as an example, then:

[0108] When the second quantity P is less than or equal to the third quantity Q, the parameter subsequence includes all the amplitude parameters in the first vibration description parameter that have not been written into the vibration chip. In this case, the last amplitude parameter of the parameter subsequence is the last amplitude parameter of the first vibration description parameter, which is zero.

[0109] When the second quantity P is greater than the third quantity Q, the parameter subsequence includes the (N + 1)-th to the M-th amplitude parameters in the first vibration description parameter, and the M-th amplitude parameter is the last zero point between the (N + 1)-th and the (N + Q)-th amplitude parameters in the first vibration description parameter. In this case, the last amplitude parameter of the parameter subsequence is the M-th amplitude parameter of the first vibration description parameter, which is zero.

[0110] S620, control the vibration chip to output a drive voltage signal to the motor according to the parameter subsequence to control the vibration of the motor.

[0111] In the embodiment of the present application, the vibration chip can play each amplitude parameter in the FIFO queue in the principle of first in first out, that is, output drive voltages corresponding to the sizes of each amplitude parameter in turn. It should be noted that each time an amplitude parameter is played, one amplitude parameter is reduced in the FIFO queue.

[0112] Thus, the electronic device can write the first vibration description parameter into the vibration chip in multiple times, so that the process of writing the amplitude parameter into the vibration chip and the process of motor vibration can be carried out simultaneously, reducing the problem that the motor response is slow due to the too long time spent on writing the amplitude parameter.

[0113] To make the last amplitude parameter of the parameter subsequence written into the vibration chip each time be zero, a possible implementation manner is provided in the embodiment of the present application, as Figure 7 shown Figure 7 is the flow schematic of the control method of the motor provided by the embodiment of the present application Figure Three , and this method can be executed by the vibration driver in the electronic device kernel. As Figure 7As shown, the control method of the motor provided by the embodiment of the present application further includes S701 to S714.

[0114] S701, determine whether written_done is 1.

[0115] If written_done is not 1, execute S702; if written_done is 1, execute S713.

[0116] S702, determine whether cancelled is 1.

[0117] If cancelled is not 1, execute S703; if cancelled is 1, the process of writing parameter subsequence can be ended.

[0118] S703, obtain the second quantity and the third quantity.

[0119] Among them, the second quantity is the number of amplitude parameters in the first vibration description parameters that have not been written into the vibration chip. Where samples_unwritten = num_all - samples_written.

[0120] The third quantity is the number of amplitude parameters that the remaining space of the FIFO queue can accommodate, which can also be understood as the number of amplitude parameters that the remaining space of the vibration chip can accommodate. In the embodiment of the present application, the electronic device can obtain the maximum number of amplitude parameters that the FIFO queue can accommodate, for example, represented by FIFO_max; and obtain the number of amplitude parameters in the FIFO queue, that is, the number of amplitude parameters in the vibration chip (which can also be called the second parameter), for example, represented by FIFO_num. Then the third quantity FIFO_res = FIFO_max - FIFO_num.

[0121] S704, determine whether the second quantity is less than or equal to the third quantity.

[0122] If the second quantity is less than or equal to the third quantity, execute S705; if the second quantity is greater than the third quantity, execute S706.

[0123] It can be understood that when the second quantity is less than or equal to the third quantity, it indicates that the remaining space of the FIFO queue can accommodate all the amplitude parameters in the first vibration description parameters that have not been written into the vibration chip, so execute S705; when the second quantity is greater than the third quantity, it indicates that the remaining space of the FIFO queue is not enough to accommodate all the amplitude parameters in the first vibration description parameters that have not been written into the vibration chip, so execute S706.

[0124] S705, determine that the target quantity is the second quantity.

[0125] In the embodiment of the present application, the target quantity is the number of amplitude parameters written to the vibration chip this time. Since the last amplitude parameter of the first vibration description parameter must be zero, this can ensure that the last amplitude parameter written to the vibration chip according to the second quantity is the last amplitude parameter of the first vibration description parameter, making the last amplitude parameter in the parameter subsequence zero.

[0126] S706. Determine the second target amplitude parameter.

[0127] It can be understood that the second target amplitude parameter is the Mth amplitude parameter in the first vibration description parameter described in S610. Among them, taking the number of amplitude parameters in the first vibration description parameter that have been written to the vibration chip as N (that is, the value of the third flag bit samples_written is N) and the third quantity as Q as an example, the second target amplitude parameter is the last zero among the amplitude parameters from the (N + 1)th amplitude parameter to the (N + Q)th amplitude parameter in the first vibration description parameter.

[0128] S707. Calculate the target quantity according to the sorting of the second target amplitude parameter in the first vibration description parameter and samples_written.

[0129] Among them, subtracting the number described in S707 from the sorting in S707 can obtain the target quantity.

[0130] Exemplarily, taking N = 110, P = 20, and the electronic device determining that the last zero between the 111th to the 130th bits in the first vibration description parameter is the 129th amplitude parameter of the first vibration description parameter as an example, the electronic device can determine that the second target amplitude parameter is the 129th amplitude parameter of the first vibration description parameter, and the target quantity is 19.

[0131] This can not only ensure that the last amplitude parameter written to the vibration chip according to the second quantity is the second target amplitude parameter, that is, zero, but also maximize the use of the accommodation space of the FIFO, write as many amplitude parameters as possible to the FIFO queue of the vibration chip at one time, reduce the number of times of writing amplitude parameters, and save I / O resources.

[0132] S708. Write the target quantity of amplitude parameters to the vibration chip.

[0133] S709. Update samples_written.

[0134] S710. Determine whether samples_written is equal to num_all.

[0135] If samples_written is equal to the number of all amplitude parameters in the first vibration description parameter, execute S711; if samples_written is not equal to the number of all amplitude parameters in the first vibration description parameter, interruption reporting can be waited for, and S701 can be re-executed after receiving the interruption reporting.

[0136] S711, set written_done to 1.

[0137] S712, turn off interruption reporting.

[0138] S713, determine whether the third quantity is equal to FIFO_max.

[0139] Understandably, by determining whether the third quantity is equal to FIFO_max (i.e., the maximum number of amplitude parameters that the FIFO queue can accommodate), it can be determined whether the amplitude parameters in the FIFO queue have been played out.

[0140] If the third quantity is equal to FIFO_max, it means that the amplitude parameters in the FIFO queue have been played out, then S714 can be executed; if the third quantity is not equal to FIFO_max, interruption reporting can be waited for, and S701 can be re-executed after receiving the interruption reporting.

[0141] S714, control the vibration chip to stop outputting the drive voltage signal.

[0142] It should be noted that after the vibration drive writes a parameter subsequence to the vibration chip once, the vibration chip can output the drive voltage signal to the motor according to the parameter subsequence, and the process of the vibration chip outputting the drive voltage signal to the motor according to the parameter subsequence can be carried out synchronously with the process of the vibration drive writing the parameter subsequence to the vibration chip. That is to say, during the execution of the above S701 to S714, the vibration chip can output the drive voltage signal to the motor synchronously according to the amplitude parameters in the FIFO queue.

[0143] In a possible design, in order to enable the motor of the electronic device to stop vibrating as soon as possible after receiving the second event, the target amplitude parameter can be the amplitude parameter in the first amplitude parameters that is closest to the second amplitude parameter in sorting.

[0144] Among them, the electronic device can determine the first duration according to the first position of the second amplitude parameter in the first vibration description parameter, the second position of the first target amplitude parameter in the first vibration description parameter, and the preset frequency. The position of the amplitude parameter can be understood as the serial number, sorting, etc. of the amplitude parameter in the first vibration description parameter, such as the 1st bit, the 2nd bit, the Xth bit, etc.

[0145] Further, the electronic device can determine the number of amplitude parameters between the second amplitude parameter and the first target amplitude parameter based on the first position and the second position, and then calculate the first duration according to the number and the preset frequency.

[0146] Specifically, T = Δ × δt. Where T is the first duration, Δ is the number of amplitude parameters between the second amplitude parameter and the first target amplitude parameter, and δt is the preset time interval. It can be understood that the preset time interval is the reciprocal of the above preset frequency.

[0147] Exemplarily, as shown in (a) and (b) of Figure 8 taking the first vibration description parameter including amplitude parameters a, b, c, d, etc., where the amplitude parameters a, b, c, d are the 1st, 9th, 31st, and 63rd amplitude parameters in the first vibration description parameter respectively, and both the amplitude parameter c and the amplitude parameter d are zero points, the amplitude parameter b played by the vibration chip at time t2, and the first target amplitude parameter is the amplitude parameter d, and the preset frequency is 50Hz as an example. The electronic device can determine that the second amplitude parameter is the amplitude parameter b, and then determine that the first position is 9. The electronic device can also determine that the first amplitude parameter includes the amplitude parameters c and d.

[0148] When the first target amplitude parameter can be any one of the amplitude parameters in the first amplitude parameter, if the first target amplitude parameter is the amplitude parameter d, the electronic device can determine that the second position is 63. Therefore, the time interval is 20ms, and there are a total of 54 amplitude parameters between the second amplitude parameter (i.e., the amplitude parameter b) and the first target amplitude parameter (i.e., the amplitude parameter d). Thus, the electronic device can determine that the first duration is 54 × 20 = 1080ms. That is to say, the target time is t2 + 1080ms. The electronic device can control the motor to stop vibrating at the moment of t2 + 1080ms, and the amplitude of the drive voltage signal at this moment corresponds to the amplitude parameter d, which is zero.

[0149] When the first target amplitude parameter is the amplitude parameter in the first amplitude parameter that is closest in order to the second amplitude parameter, since the amplitude parameter c is closer to the amplitude parameter b (i.e., the second amplitude parameter) than the amplitude parameter d, the electronic device can determine that the first target amplitude parameter can be the amplitude parameter c, and the second position is 31. Therefore, the time interval is 20ms, and there are a total of 22 amplitude parameters between the second amplitude parameter (i.e., the amplitude parameter b) and the first target amplitude parameter (i.e., the amplitude parameter c). Thus, the electronic device can determine that the first duration is 22 × 20 = 440ms. That is to say, the target time is t2 + 440ms. The electronic device can control the motor to stop vibrating at the moment of t2 + 440ms, and the amplitude of the drive voltage signal at this moment corresponds to the amplitude parameter c, which is zero.

[0150] Comparison Figure 8 From (a) and (b) in Figure 8 , it can be seen that taking the amplitude parameter in the first amplitude parameters that is closest to the second amplitude parameter as the first target amplitude parameter can reduce the first duration, enabling the motor to stop vibrating as soon as possible, and thus enabling the motor to start the second vibration faster.

[0151] In the embodiments of the present application, the electronic device can determine the first position of the second amplitude parameter in the first vibration description parameter according to the number of amplitude parameters in the FIFO queue (i.e., FIFO_num) and the number of amplitude parameters in the first vibration description parameter that have been written into the vibration chip (i.e., samples_written). Specifically, the second amplitude parameter is located at the (samples_written - FIFO_num) -th position in the first vibration description parameter.

[0152] For example, if the vibration driver has written 320 amplitude parameters into the vibration chip and the FIFO queue includes 50 amplitude parameters, it can be determined that the vibration chip is currently playing the 270 -th amplitude parameter in the first vibration description parameter.

[0153] That is to say, the electronic device cannot directly obtain the first position of the second amplitude parameter in the first vibration description parameter. It is necessary to first determine the number of amplitude parameters in the FIFO queue through the interaction between the vibration driver (i.e., software) and the vibration chip (i.e., hardware), and then further determine this first position. This process has a certain interaction delay, which may cause the drive voltage signal not to stop at zero.

[0154] Exemplarily, as Figure 9 shown, at time T3, the vibration driver of the electronic device sends a query instruction to the vibration chip. The vibration chip receives the query instruction at time T4 and feeds back the number of amplitude parameters in the FIFO queue (i.e., FIFO_num) to the vibration driver. The vibration driver receives this number FIFO_num at time T5, so the interaction delay is T5 - T3.

[0155] Assume that after the vibration driver obtains FIFO_num, it determines that the first duration is T6 - T3, that is, the target time is T6. In the case where T6 - T3 is less than T5 - T3, it means that when the vibration driver determines the first duration at time T5, the vibration chip has already played the target amplitude parameter corresponding to the target time, and the purpose of controlling the drive voltage signal to stop at the target amplitude parameter cannot be achieved.

[0156] To at least solve the above problems, the first target amplitude parameter can be the amplitude parameter in the third amplitude parameters that is closest to the second amplitude parameter, and the third amplitude parameters include the amplitude parameters in the first amplitude parameters whose corresponding play delays are greater than the interaction delay.

[0157] Understandably, the playback delay corresponding to the amplitude parameter is the time required from the second moment to the moment when the drive voltage signal corresponding to the amplitude parameter is output.

[0158] Still taking Figure 8 the first vibration description parameter shown as an example, when the interaction delay is 500 ms, since the playback delay corresponding to the amplitude parameter c is 440 ms (less than 500 ms) and the playback delay corresponding to the amplitude parameter d is 1080 ms (greater than 500 ms), the electronic device takes the amplitude parameter d as the target amplitude parameter and determines 1080 ms as the first duration.

[0159] The following gives a specific implementation manner for an electronic device to determine the first duration in conjunction with the accompanying drawings. As Figure 10 shown, Figure 10 is a schematic flow chart of the control method for the motor provided by the embodiment of the present application Figure Four , and this method can be executed by the vibration drive in the electronic device kernel. As Figure 10 shown, the control method for the motor provided by the embodiment of the present application further includes S1001 to S1006.

[0160] S1001, receiving a first event.

[0161] S1002, determining a second amplitude parameter according to samples_written and FIFO_num.

[0162] S1003, taking a preset number of zeros after the second amplitude parameter as the first amplitude parameter.

[0163] Among them, the preset number is, for example, 2, 3, etc. Taking the preset number as 2 as an example, the vibration drive of the electronic device can take the 1st zero and the 2nd zero after the first position as the first amplitude parameter.

[0164] S1004, respectively calculating the playback delay corresponding to each amplitude parameter in the first amplitude parameter.

[0165] Among them, the process of calculating the playback delay corresponding to each amplitude parameter can refer to the above process of determining the first duration, which will not be elaborated here.

[0166] S1005, determining the interaction delay.

[0167] Among them, the process of determining the interaction delay refers to the above Figure 9 , which will not be elaborated here.

[0168] S1006, determining the minimum value of the playback delays greater than the interaction delay as the first duration.

[0169] Taking the preset quantity as 2 and the interaction time delay as 500 ms as an example, in Figure 8 Among the first vibration description parameters shown, the electronic device can determine that the first position is the position where the amplitude parameter b is located. The first amplitude parameter includes amplitude parameter c and amplitude parameter d. Among them, the playback time delay corresponding to amplitude parameter c is 440 ms (less than 500 ms), and the playback time delay corresponding to amplitude parameter d is 1080 ms (greater than 500 ms). Therefore, the electronic device determines 1080 ms as the first duration.

[0170] It can be seen that the method for determining the first duration provided by the embodiments of the present application can not only ensure that the drive voltage signal stops at the target amplitude parameter, reducing the risk of the motor hitting the wall, but also enable the motor to stop vibrating as soon as possible when there is a demand for the motor to stop vibrating, achieving the effects of extending the motor life and improving the user experience.

[0171] Next, the control method for the motor provided by the embodiments of the present application will be specifically described in combination with Figure 3 the software architecture shown. Refer to Figure 11 , which is a flowchart of the control method for the motor provided by the embodiments of the present application Figure Five , which specifically illustrates the process of controlling the motor vibration and writing the amplitude parameter to the vibration chip. As Figure 11 shown, the control method for the motor provided by the embodiments of the present application includes S1101 to S1130.

[0172] S1101, in response to receiving the first event, the first application sends vibration instruction 1 to the vibration service.

[0173] S1102, the vibration service determines whether the motor is vibrating.

[0174] If the motor is not vibrating, execute S1103; if the motor is vibrating, execute S1203.

[0175] In a possible design, the vibration service can read the value of the vibration flag bit to determine whether the motor is vibrating. For example, the value of the vibration flag bit can be on or off, where the value of the vibration flag bit being on indicates that the motor is vibrating, and the value of the vibration flag bit being off indicates that the motor is not vibrating.

[0176] S1103, the vibration service sends vibration instruction 1 to the vibration HAL.

[0177] Among them, the vibration parameter is carried in the vibration instruction 1.

[0178] S1104, the vibration HAL sends the vibration parameter to the vibration algorithm library.

[0179] S1105, the vibration algorithm library sends the first vibration description parameter to the vibration HAL.

[0180] S1106, the vibration HAL sends vibration description parameter 1 to the vibration driver.

[0181] S1107, the vibration driver records all zero points in vibration description parameter 1.

[0182] Understandably, after receiving vibration description parameter 1, the vibration driver records all zero points in it in advance, without the need to query and record again when the zero points are needed subsequently, which is beneficial to improving the speed of subsequent calculation processes.

[0183] In addition, recording zero points can include recording the specific positions of zero points in vibration description parameter 1, such as being at the Xth position of vibration description parameter 1, etc.

[0184] S1108, the vibration driver sets samples_written to 0.

[0185] Understandably, by setting samples_written to 0, interference from historical vibrations to this vibration can be avoided.

[0186] S1109, the vibration driver writes parameter subsequence 1 to the vibration chip, and parameter subsequence 1 includes 1 amplitude parameter.

[0187] Among them, the number 1 is a preset parameter, and this number 1 can be any value less than or equal to FIFO_max and making the last amplitude parameter of parameter subsequence 1 a zero point, where FIFO_max is the maximum number of amplitude parameters that the FIFO queue can accommodate.

[0188] S1110, the vibration driver updates samples_written.

[0189] It should be noted that after the vibration driver writes an amplitude parameter to the vibration chip each time, samples_written needs to be updated.

[0190] S1111, the vibration driver sets the interrupt threshold to number 2.

[0191] Understandably, this number 2 can be set according to actual needs and is not specifically limited here.

[0192] S1112, the vibration driver starts interrupt reporting.

[0193] After the vibration driver starts interrupt reporting, the vibration driver can receive the interrupt notification uploaded by the vibration chip. This interrupt notification indicates that there are fewer amplitude parameters remaining in the FIFO queue of the vibration chip. After receiving this interrupt notification, the vibration driver can write amplitude parameters to the vibration chip again.

[0194] S1113, the vibration driver sends an execution feedback to the vibration HAL.

[0195] S1114, the vibration HAL sends a wake-up notification to the vibration driver.

[0196] S1115, the vibration driver sends an instruction to start vibrating to the vibration chip.

[0197] S1116, the vibration chip outputs a voltage drive signal based on parameter subsequence 1.

[0198] S1117, the vibration chip determines whether FIFO_left is less than the quantity 2.

[0199] Wherein, FIFO_left is the number of remaining amplitude parameters in the FIFO queue, that is, the number of amplitude parameters not played by the vibration chip.

[0200] If FIFO_left is less than the quantity 2, execute S1118; if FIFO_left is greater than or equal to the quantity 2, continue to execute S1116.

[0201] S1118, the vibration chip sends an interrupt notification to the vibration driver.

[0202] S1119, the vibration driver determines whether written_done is 1.

[0203] If written_done is not 1, execute S1120; if written_done is 1, it is possible to further determine whether the amplitude parameters in the FIFO queue have been played out.

[0204] S1120, the vibration driver determines whether cancelled is 1.

[0205] If cancelled is not 1, execute S1121; if cancelled is 1, the process of writing amplitude parameters can be ended.

[0206] S1121, the vibration driver obtains samples_unwritten and FIFO_res.

[0207] S1122, the vibration driver determines whether samples_unwritten is less than or equal to FIFO_res.

[0208] If samples_unwritten is less than or equal to FIFO_res, execute S1123; if samples_unwritten is greater than FIFO_res, execute S1124.

[0209] S1123, the vibration driver determines that the target quantity is samples_unwritten.

[0210] S1124, the vibration driver determines the second target amplitude parameter.

[0211] S1125, the vibration driver calculates the target quantity based on the sorting first position of the second target amplitude parameter in the first vibration description parameter and samples_written.

[0212] S1126, the vibration driver writes the parameter subsequence 2 to the vibration chip, and the parameter subsequence 2 includes the target quantity of amplitude parameters.

[0213] S1127, the vibration driver updates samples_written.

[0214] S1128, the vibration driver determines whether samples_written is equal to num_all.

[0215] Wherein, num_all is the number of all amplitude parameters in the first vibration description parameter.

[0216] If samples_written is equal to num_all, execute S1129; if samples_written is not equal to num_all, it can continue to wait for the interrupt report.

[0217] S1129, the vibration driver sets written_done to 1.

[0218] S1130, the vibration driver closes the interrupt report.

[0219] Next, in combination with Figure 3 the software architecture shown, the control method of the motor provided by the embodiment of the present application will be specifically described. Refer to Figure 12 , which is the flow schematic Figure Six of the control method of the motor provided by the embodiment of the present application, and it specifically illustrates the process of controlling the motor to stop vibrating. As Figure 12 shown, the control method of the motor provided by the embodiment of the present application includes S1201 to S1214.

[0220] S1201, in response to receiving the second event, the second application sends the vibration instruction 2 to the vibration service.

[0221] S1202, the vibration service determines whether the motor is vibrating.

[0222] If the motor is vibrating, execute S1203; if the motor is not vibrating, it can send the vibration instruction 2 to the vibration HAL, and this process is the same as Figure 11The processes after S1103 are similar and will not be elaborated here.

[0223] S1203, the vibration service sends an instruction to stop vibration to the vibration HAL.

[0224] S1204, the vibration HAL sends an instruction to stop vibration to the vibration driver.

[0225] S1205, the vibration driver sends a query instruction to the vibration chip.

[0226] S1206, the vibration chip sends FIFO_num to the vibration driver.

[0227] S1207, the vibration driver calculates the interaction delay based on time T3 and time T5.

[0228] Among them, the moment of T3 is the moment when the vibration driver sends a query instruction to the vibration chip, and T5 is the moment when the vibration driver receives FIFO_num.

[0229] S1208, the vibration driver determines the first position according to samples_written and FIFO_num.

[0230] S1209, the vibration driver takes a preset number of zeros after the first position as the first amplitude parameter.

[0231] S1210, the vibration driver calculates the playback delay corresponding to each amplitude parameter in the first amplitude parameter respectively.

[0232] S1211, the vibration driver determines the minimum value of the playback delays greater than the interaction delay as the first duration.

[0233] S1212, the vibration driver sends an instruction to stop vibration to the vibration chip after the first duration starting from time T3.

[0234] S1213, the vibration chip stops outputting the voltage drive signal.

[0235] S1214, the vibration driver closes the interrupt reporting.

[0236] In this way, it can make the vibration chip stop outputting the drive voltage signal at or near the zero point of the drive voltage signal, which can make the motor stop vibrating when the amplitude is small, thereby reducing the risk of the motor hitting the wall and prolonging the service life of the motor.

[0237] Some embodiments of the present application provide an electronic device, which may include: a memory and one or more processors. The memory and the processor are coupled. The memory is used to store computer program code, and the computer program code includes computer instructions. When the processor executes the computer instructions, the electronic device can perform each function or step executed by the electronic device in the above method embodiments. The structure of the electronic device may refer to Figure 2 the structure of the electronic device shown.

[0238] Embodiments of the present application also provide a motor, which can be used to implement vibration waveforms and the like under various configuration parameters in the above embodiments. An electronic device installed with the motor can perform each function or step executed by the electronic device in the above method embodiments.

[0239] Embodiments of the present application also provide a computer-readable storage medium, which includes computer instructions. When the computer instructions run on the above electronic device, the electronic device is caused to perform each function or step executed by the electronic device in the above method embodiments.

[0240] Embodiments of the present application also provide a computer program product. When the computer program product runs on an electronic device, the electronic device is caused to perform each function or step executed by the electronic device in the above method embodiments.

[0241] Through the description of the above embodiments, those skilled in the art can clearly understand that, for the convenience and brevity of description, only the above division of each functional module is used as an example. In actual applications, the above functions can be allocated to different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above.

[0242] In several embodiments provided by the present application, it should be understood that the disclosed device and method can be implemented in other ways. For example, the device embodiments described above are only illustrative. For example, the division of the module or unit is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point, the displayed or discussed coupling or direct coupling or communication connection between each other can be through some interfaces. The indirect coupling or communication connection of the device or unit can be in an electrical, mechanical or other form.

[0243] The unit described as a separation component may or may not be physically separated. The component shown as a unit may be a single physical unit or multiple physical units, that is, it may be located in one place or distributed to multiple different places. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0244] In addition, in each embodiment of the present application, each functional unit may be integrated in a processing unit, may exist physically separately for each unit, or two or more units may be integrated in one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of a software functional unit.

[0245] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiments of the present application, in essence, or the part that contributes to the prior art, or all or part of this technical solution, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to enable a device (which can be a single-chip microcomputer, a chip, etc.) or a processor to execute all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage medium includes: USB flash drives, mobile hard disks, read-only memories (ROM), random access memories (RAM), magnetic disks, or optical discs and other various media that can store program codes.

[0246] The above content is only the specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application should be covered by the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A control method for a motor, characterized in that, The electronic device includes a vibration chip and a motor, and the method includes: At a first moment, a first event for triggering the vibration of the motor is received; In response to the first event, based on first vibration description parameters, the vibration chip is controlled to output a first drive voltage signal to the motor to cause the motor to vibrate, where the first vibration description parameters are vibration description parameters corresponding to the first event; At a second moment, a second event for triggering the vibration of the motor is received, and the second moment is later than the first moment; In response to the second event, after a first duration starting from the second moment, the motor is controlled to stop vibrating and the motor is controlled to vibrate again; Wherein, the vibration description parameters include amplitude parameters arranged in sequence, the amplitude parameters are used to indicate the amplitude of the drive voltage signal, the first duration is the time difference between a target moment and the second moment, the amplitude of the first drive voltage signal at the target moment corresponds to a target amplitude parameter, the target amplitude parameter is any one of the first amplitude parameters, the first amplitude parameter is an amplitude parameter that is after a second amplitude parameter in the first vibration description parameters and indicates that the amplitude of the first drive voltage signal is 0, and the second amplitude parameter is an amplitude parameter corresponding to the amplitude of the first drive voltage signal at the second moment.

2. The method according to claim 1, wherein The target amplitude parameter is the amplitude parameter in the first amplitude parameters that is closest to the second amplitude parameter.

3. The method according to claim 1, wherein The target amplitude parameter is the amplitude parameter in third amplitude parameters that is closest to the second amplitude parameter, the third amplitude parameters include the amplitude parameters in the first amplitude parameters whose corresponding play delays are greater than the interaction delay, and the play delay of the amplitude parameter is the time required from the second moment to the moment when the drive voltage signal corresponding to the amplitude parameter is output.

4. The method according to any one of claims 1 to 3, characterized in that, The method further includes: Obtaining a first parameter and a second parameter, where the first parameter is the number of amplitude parameters in the first vibration description parameters that have been written into the vibration chip, and the second parameter is the number of amplitude parameters in the vibration chip; Determining the second amplitude parameter according to the first parameter and the second parameter; Taking a preset number of zeros after the second amplitude parameter in the first vibration description parameters as the first amplitude parameters; wherein, a zero is an amplitude parameter indicating that the amplitude of the drive voltage signal is 0; Calculating the play delay corresponding to the first amplitude parameter; Obtaining an interaction delay, where the interaction delay is used to indicate the time required to obtain the second parameter; Determining the minimum value of the play delays greater than the interaction delay as the first duration.

5. The method according to any one of claims 1-4, characterized in that, The controlling the vibration chip to output a first drive voltage signal to the motor based on the first vibration description parameters includes: When the amplitude parameters in the first vibration description parameters have not been completely written into the vibration chip and a third event for triggering the motor to stop vibrating has not been received, a parameter subsequence is cyclically written into the vibration chip; wherein, the parameter subsequence includes a plurality of amplitude parameters, and the last amplitude parameter in the parameter subsequence indicates that the amplitude of the drive voltage signal is 0; Control the vibration chip to output the first driving voltage signal to the motor according to the parameter subsequence to control the vibration of the motor.

6. The method according to claim 5, characterized in that The cyclically writing the parameter subsequence to the vibration chip includes: When the first quantity is less than a preset interruption threshold, writing the parameter subsequence to the vibration chip, where the first quantity is the number of amplitude parameters remaining in the vibration chip.

7. The method according to claim 5 or 6, characterized in that, When the second quantity is less than or equal to the third quantity, the parameter subsequence includes all amplitude parameters in the first vibration description parameter that have not been written to the vibration chip; wherein, the second quantity is the number of amplitude parameters in the first vibration description parameter that have not been written to the vibration chip, and the third quantity is the number of amplitude parameters that can be accommodated in the remaining space of the vibration chip; When the second quantity is greater than the third quantity, the parameter subsequence includes the (N + 1)-th to the M-th amplitude parameters in the first vibration description parameter, and the M-th amplitude parameter is the last amplitude parameter indicating that the amplitude of the driving voltage signal is 0 among the (N + 1)-th to the (N + Q)-th amplitude parameters in the first vibration description parameter, N is the number of amplitude parameters in the first vibration description parameter that have been written to the vibration chip, and Q is the third quantity.

8. The method according to claim 7, wherein Before writing the parameter subsequence to the vibration chip, the method further includes: Determining a target quantity according to the second quantity and the third quantity, where the target quantity is the number of amplitude parameters written to the vibration chip; wherein, when the second quantity is less than or equal to the third quantity, the target quantity is the second quantity, and when the second quantity is greater than the third quantity, the target quantity is the number of amplitude parameters separated by the second amplitude parameter and the M-th amplitude parameter; Writing the parameter subsequence to the vibration chip based on the target quantity.

9. The method according to any one of claims 1-8, characterized in that, The first duration satisfies the formula: T = Δ×δt; where T is the first duration, Δ is the number of amplitude parameters separated by the target amplitude parameter and the second amplitude parameter, and δt is a preset time interval.

10. An electronic device, characterized in that, The electronic device includes: a memory, one or more processors, a vibration chip, and a motor; the memory, the vibration chip are coupled to the processor, and the vibration chip is connected to the motor; Wherein, the memory is used to store computer program code, and the computer program code includes computer instructions; when the computer instructions are executed by the processor, the electronic device is caused to execute the method according to any one of claims 1-9.

11. A computer-readable storage medium, characterized in that, Including computer instructions; When the computer instructions run on the electronic device, the electronic device is caused to execute the method according to any one of claims 1-9.