Thermal printing method, portable thermal printer, and storage medium

CN122607000APending Publication Date: 2026-08-21ZHUHAI QUIN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510217461.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2025-02-13
Filing Date
2025-02-25
Publication Date
2026-08-21

AI Technical Summary

Benefits of technology

通过获取热打印场景下的第一正弦波、第一采样率、第一载波以及预设更新周期,进而根据所获得的第一正弦波、第一采样率、第一载波得到与第一正弦波相对应的第一占空比数据,而正弦波作为理想的运动控制波形,能够确保电机在运动过程中的平稳性和连续性,减少速度突变带来的冲击和振动。第一占空比数据反映了第一脉冲宽度调制信号中高低电平的比例,直接决定了驱动电机的电流的大小和波形。通过精确计算每个采样点对应的第一占空比,可以确保驱动电机在每个打印周期内都能接收到平滑、连续的电流信号。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122607000A_ABST
    Figure CN122607000A_ABST
Patent Text Reader

Abstract

The application provides a thermal printing method, a portable thermal printer and a storage medium. The method comprises the following steps: obtaining at least one first sinusoidal wave, a first sampling rate, a first carrier and a preset update period in a thermal printing scene to obtain first duty cycle data and storage; obtaining a first preset table; determining a printing time according to received to-be-printed data of a current printing line; in response to a printing instruction, reading the first duty cycle from the first preset table according to the preset update period; generating and outputting a first pulse width modulation signal according to the read first duty cycle; a stepping motor driving chip of the portable thermal printer generates a current signal simulating the first sinusoidal wave according to the first pulse width modulation signal, and outputs the current signal to a driving motor of the portable thermal printer to control movement of the driving motor in the thermal printing scene until the printing time ends. The embodiment of the application can reduce noise in the thermal printing process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of printing technology, and more particularly to a thermal printing method, a portable thermal printer, and a storage medium. Background Technology

[0002] With the rapid development of information technology and e-commerce, printing equipment has been widely used in many fields such as retail, logistics, and finance. As an important branch of printing equipment, portable thermal printers occupy an important position in miniaturized and portable printing scenarios due to their advantages of simple structure, moderate cost, and high reliability.

[0003] Key components of a portable thermal printer include the transmission mechanism, printhead, and control circuitry. The transmission mechanism, responsible for moving the printing media, is crucial for the printer's proper functioning. In practical applications, portable thermal printers need to meet diverse requirements in various scenarios, such as high-speed continuous printing and intermittent printing.

[0004] As printing equipment evolves towards higher speeds and higher quality, greater demands are placed on the stability and performance of portable thermal printers. In portable thermal printers, the motor drive is a crucial component of the thermal printing process. Motors, especially stepper motors, are commonly used as the transmission mechanism, responsible for controlling paper feed and ensuring the paper moves at a predetermined speed and position. Further improvements in the performance of portable thermal printers during operation are currently a pressing issue. Summary of the Invention

[0005] In view of the above, it is necessary to provide a thermal printing method, a portable thermal printer, and a storage medium that can further improve the precise control of the printing process of the portable thermal printer and reduce the overall noise during the thermal printing process, thereby comprehensively improving the printing performance.

[0006] In a first aspect, a thermal printing method is provided, applied to a portable thermal printer. The method includes: acquiring at least one first sine wave, a first sampling rate, a first carrier wave, and a preset update period in a thermal printing scenario; obtaining first duty cycle data corresponding to each first sine wave based on the at least one first sine wave, the first sampling rate, and the first carrier wave, wherein the first duty cycle data includes the first duty cycle of a first pulse width modulation signal corresponding to each sampling point within one period of the corresponding first sine wave; storing the first duty cycle data; obtaining a first preset table based on the first duty cycle data; determining a printing time based on the received printable data of the current print row; the printing speed of the portable thermal printer is x, and the portable thermal printer... The frequency of the drive motor is y; the printing speed and the drive motor frequency satisfy the following relationship: 8mm / s≤x≤15mm / s; 1500hz≤y≤2000hz; in response to the printing command, the first duty cycle data is obtained by querying the first preset table according to the printing time; the first duty cycle is periodically read from the first duty cycle data according to the preset update cycle; a first pulse width modulation signal is generated and output according to the read first duty cycle; the stepper motor drive chip of the portable thermal printer is used to generate a current signal simulating a first sine wave according to the first pulse width modulation signal, and output the current signal to the drive motor of the portable thermal printer to control the movement of the drive motor in the thermal printing scenario until the printing time ends.

[0007] In a second aspect, a portable thermal printer is provided, the portable thermal printer including a memory and at least one processor, the memory storing at least one instruction, which, when executed by at least one processor, implements the thermal printing method as described above.

[0008] Thirdly, a computer-readable storage medium is provided, which stores at least one instruction that, when executed by a processor, implements any of the above-mentioned hot printing methods.

[0009] Implementing the embodiments of this application will have at least the following technical effects: By acquiring the first sine wave, first sampling rate, first carrier wave, and preset update period in a thermal printing scenario, the system obtains the first duty cycle data corresponding to the first sine wave. The sine wave, as an ideal motion control waveform, ensures the smoothness and continuity of the motor during operation, reducing shocks and vibrations caused by sudden speed changes. The first duty cycle data reflects the ratio of high to low levels in the first pulse width modulation signal, directly determining the magnitude and waveform of the current driving the motor. By accurately calculating the first duty cycle corresponding to each sampling point, it can be ensured that the drive motor receives a smooth and continuous current signal in each printing cycle.

[0010] The first duty cycle data is stored in a first preset table for easy and quick subsequent retrieval and use, thus improving data processing efficiency. When a print command is received, the corresponding duty cycle data can be quickly retrieved from the first preset table according to a preset update cycle, and a corresponding first pulse width modulation signal can be generated to control the drive motor.

[0011] By precisely controlling the duty cycle of the first pulse width modulation signal by reading the first duty cycle from the first preset table according to the printing time, precise control of the current of the drive motor can be achieved, reducing noise caused by current fluctuations.

[0012] The stepper motor driver chip of the portable thermal printer generates a current signal simulating a first sine wave based on a first pulse width modulation signal. This current signal matches the motion characteristics of a sine wave, ensuring optimal performance and noise levels for the portable thermal printer at a printing speed of x and a drive motor frequency of y, with the following relationships: 8mm / s ≤ x ≤ 15mm / s; 1500Hz ≤ y ≤ 2000Hz. By ensuring smooth changes in the sine wave current signal, it avoids mechanical shocks, vibrations, and friction between transmission components caused by sudden current changes, reducing the overall vibration and noise of the portable thermal printer and thus comprehensively improving printing performance. Attached Figure Description

[0013] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0014] Figure 1 This is a schematic diagram of the module structure of the portable thermal printer provided in the embodiments of this application.

[0015] Figure 2 This is a schematic flowchart of a thermal printing method provided in an embodiment of this application.

[0016] Figure 3 This is a flowchart illustrating a method for obtaining a first sine wave, a first sampling rate, a first carrier wave, and a preset update period in a thermal printing scenario, as provided in an embodiment of this application.

[0017] Figure 4 This is a flowchart illustrating a thermal printing method for a target scenario provided in an embodiment of this application.

[0018] Figure 5This is a flowchart illustrating another thermal printing method for a target scenario provided in an embodiment of this application.

[0019] Figure 6 This is a schematic flowchart of a thermal printing method in the execution state of a thermal printing task, provided in an embodiment of this application.

[0020] Figure 7 This is a schematic flowchart of a thermal printing method based on the speed feedback of a drive motor, provided in an embodiment of this application.

[0021] Figure 8 This is a schematic flowchart of another thermal printing method provided in an embodiment of this application. Detailed Implementation

[0022] To better understand the above-mentioned objectives, features, and advantages of this application, the application will be described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that, unless otherwise specified, the embodiments and features described herein can be combined with each other.

[0023] Numerous specific details are set forth in the following description to provide a thorough understanding of this application. The described embodiments are merely some, not all, of the embodiments described herein. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.

[0024] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application.

[0025] Please see Figure 1 This application provides an example of a portable thermal printer 100.

[0026] As an example, the portable thermal printer 100 can be a non-floor or desktop printer such as a thermal printer, thermal transfer printer, or thermal sublimation printer.

[0027] The portable thermal printer 100 includes, but is not limited to, a processor 101, a memory 102, a computer program 103 stored in the memory 102, a stepper motor driver chip 104, and a drive motor 105. The processor 101 is communicatively connected to the memory 102 and the stepper motor driver chip 104. The stepper motor driver chip 104 is communicatively connected to the drive motor 105.

[0028] The processor 101 is used to execute the thermal printing method provided in the embodiments of this application.

[0029] In some embodiments, when the processor 101 executes the computer program 103 stored in the memory 102, it can implement the thermal printing method provided in the embodiments of this application. The computer program 103 includes at least one instruction, which, when executed by the processor 101, implements the steps of the thermal printing method in the following embodiments, for example... Figures 2 to 8 The steps are shown.

[0030] In some embodiments, the memory 102 is also used to store data to be processed, such as the first sine wave, the first sampling rate, the first carrier wave, and the preset update cycle in the following thermal printing scenario. When the processor 101 reads the first sine wave, the first sampling rate, the first carrier wave, and the preset update cycle stored in the memory 102 and executes the computer program 103 stored in the memory 102, it implements the thermal printing method provided in the embodiments of this application.

[0031] In some embodiments, the memory 102 is also used to store data to be processed, such as the second sine wave, the second sampling rate, and the second carrier in the target scenario described below. When the processor 101 reads the second sine wave, the second sampling rate, the second carrier, and the preset update period stored in the memory 102 and executes the computer program 103 stored in the memory 102, it implements the thermal printing method provided in the embodiments of this application.

[0032] In some embodiments, the memory 102 is also used to store data to be processed, such as the first preset table, the second preset table and the third preset table described below. When the processor 101 reads the first preset table, the second preset table or the third preset table stored in the memory 102 and executes the computer program 103 stored in the memory 102, it implements the thermal printing method provided in the embodiments of this application.

[0033] The processor 101 and memory 102 described above can be configured separately or integrated. This application embodiment does not specifically limit this.

[0034] After the processor 101 executes the thermal printing method provided in the embodiments of this application, it outputs a corresponding pulse width modulation signal, such as the first pulse width modulation signal, the second pulse width modulation signal, or the third pulse width modulation signal described below, to the stepper motor driver chip 104.

[0035] The stepper motor driver chip 104 is used to generate a simulated sine wave current signal based on the received pulse width modulation signal, and output the current signal to the drive motor 105 to control the movement of the drive motor 105.

[0036] Among them, the stepper motor driver chip 104 can be a regular stepper motor driver chip without micro-step control function.

[0037] The drive motor 105 can be a control motor, such as a stepper motor, including but not limited to: a full-step motor or a half-step motor.

[0038] In some embodiments, the portable thermal printer 100 also includes a printhead (not shown).

[0039] As the drive motor 105 moves, the paper moves along a preset trajectory. During this movement, the print head strikes the paper at the positions specified by the received print commands and data. Each time a print needle strikes the ribbon or thermal paper, it leaves a dot on the paper. As the paper moves and the print head strikes the paper, these dots gradually accumulate, eventually combining to form a complete image or text. The movement of the drive motor 105 refers to the motor movement under the conditions of maintaining the predetermined printing speed and drive motor frequency.

[0040] Those skilled in the art will understand that the schematic diagram is merely an example of the portable thermal printer 100 and does not constitute a limitation on the portable thermal printer 100. It may include more or fewer components than shown, or combine certain components, or different components. For example, the portable thermal printer 100 may also include input / output devices, network access devices, buses, etc.

[0041] In this embodiment, the thermal printing method can be applied to a portable thermal printer 100. The thermal printing function provided by the method of this application can be directly integrated into the portable thermal printer 100, or it can run on the portable thermal printer 100 in the form of a software development kit (SDK).

[0042] Please see Figure 2 This application provides an exemplary embodiment of a thermal printing method.

[0043] like Figure 2 As shown in the figure, the thermal printing method provided in this application embodiment specifically includes the following steps. Depending on different needs, the order of the steps in the flowchart can be changed, and some steps can be omitted.

[0044] Step S201: The portable thermal printer acquires at least one first sine wave, a first sampling rate, a first carrier, and a preset update period in the thermal printing scenario.

[0045] The first sine wave refers to a sine wave preset during the thermal printing process to control the motion trajectory of the drive motor. It represents the expected change in the speed or position of the drive motor over time in the thermal printing scenario.

[0046] By simulating the motion of the first sine wave, the drive motor can achieve smooth, continuous, and controllable movement during printing, reducing noise and thus improving print quality and efficiency. It is understood that different lengths of data to be printed on the current print line may have different printing times. Therefore, different first sine waves can correspond to different printing times. Thus, in step S201, at least one first sine wave can be acquired to achieve fine motor control under various printing times.

[0047] The first sampling rate refers to the frequency at which the waveform of the first sine wave is sampled when acquiring the first sine wave. The first sampling rate determines how many sampling points can be acquired to represent the waveform within each sine wave cycle.

[0048] By acquiring the corresponding initial sampling rate in the printing scenario, the accuracy and resolution of the simulated sine wave in the printing scenario can be affected. The higher the sampling rate, the more sampling points can be acquired, and the closer the simulated sine wave is to the real continuous waveform.

[0049] In this design, the first carrier wave can be a triangular wave with a frequency higher than that of the first sine wave, and is used as the carrier signal for pulse width modulation (PWM). The carrier signal serves as the modulation basis for the PWM signal, simulating the changes of a sine wave by changing the duty cycle of the PWM signal.

[0050] In some embodiments, using a triangular wave as the carrier signal, a current signal simulating a sine wave can be easily generated using PWM technology. When the duty cycle of the PWM signal changes with the sine wave, the carrier signal (triangular wave) will exhibit the characteristics of a sine wave after modulation.

[0051] The preset update cycle refers to the frequency at which the portable thermal printer reads new duty cycle data from a preset table (such as a first preset table, a second preset table, or a third preset table) and updates the PWM signal during the thermal printing process. The preset update cycle determines the speed and accuracy of the PWM signal update.

[0052] Precise control of the drive motor is achieved by obtaining the corresponding preset update cycle in the printing scenario. If the preset update cycle is too long, it may cause discontinuity or delay in the movement of the drive motor; if the preset update cycle is too short, it may increase the processing burden and energy consumption of the portable thermal printer.

[0053] In step S202, the portable thermal printer obtains first duty cycle data corresponding to each first sine wave based on at least one first sine wave, a first sampling rate, and a first carrier wave. The first duty cycle data includes the first duty cycle of the first pulse width modulation signal corresponding to each sampling point within one period of the corresponding first sine wave.

[0054] The first duty cycle refers to the proportion of time occupied by the high level in the first pulse width modulation signal (PWM signal) corresponding to each sampling point within one cycle of the first sine wave.

[0055] As can be understood, the basic principle of SPWM is to compare a sine wave as the modulation signal and a high-frequency triangular wave as the carrier wave. When the amplitude of the sine wave is higher than that of the triangular wave, the output is high; when the amplitude of the sine wave is lower than that of the triangular wave, the output is low. Thus, by changing the pulse width, an equivalent sine wave output can be obtained. The duty cycle of SPWM (the ratio of pulse width to period) is arranged according to the pattern of a sine wave, ensuring that the area of ​​the output waveform in each period is equal to the area of ​​the sine wave, thereby achieving precise control of the output voltage.

[0056] For example, a portable thermal printer determines the number of sampling points required in each cycle based on a first sampling rate. For each sampling point, the high-level duration of the PWM signal, i.e., the first duty cycle, is determined by comparing the amplitudes of a first sine wave (modulation wave) and a first carrier wave (such as a triangular wave). This comparison is typically performed over one carrier cycle, rather than just once at a single sampling point. Therefore, the high-level duration (first duty cycle) of the PWM signal is determined by the interaction between the modulation wave and the carrier wave over one carrier cycle. The PWM signal is high when the amplitude of the modulation wave is greater than the amplitude of the carrier wave; and low when the amplitude of the modulation wave is less than the amplitude of the carrier wave.

[0057] Step S203: The portable thermal printer stores the first duty cycle data and obtains the first preset table based on the first duty cycle data.

[0058] The first preset table can store data on printing time, first sine wave, and first duty cycle. Furthermore, there is a one-to-one mapping relationship between the printing time, first sine wave, and first duty cycle data. Thus, the other two can be retrieved based on any one of the printing time, first sine wave, and first duty cycle data.

[0059] Understandably, the first duty cycle data can be stored in the portable thermal printer's memory in the form of an array or list.

[0060] For example, a two-dimensional array or list can be used, where each element represents the duty cycle data for a sampling point. Alternatively, the data can be stored in a database table, with the duty cycle data for each sampling point as a row or column of the table.

[0061] In step S204, the portable thermal printer determines the printing time based on the received data to be printed for the current print line.

[0062] In some embodiments, the thermal printer controls the printhead heating line by line, thus acquiring the data to be printed for each line. Understandably, the length of the data to be printed is positively correlated with the printing time. In some embodiments, the printing time can be calculated based on the data length, preset printing speed, data transmission delay, etc. This application does not limit the specific steps in step S204 of determining the printing time based on the data to be printed.

[0063] Step S205: The printing speed of the portable thermal printer is x, and the frequency of the drive motor of the portable thermal printer is y; the printing speed and the drive motor frequency satisfy the following relationship: 8mm / s≤x≤15mm / s; 1500hz≤y≤2000hz; In some embodiments, when the printing speed of the portable thermal printer is in the range of 8 mm / s to 15 mm / s, the print head can fully heat the printing medium, avoiding the problem of local overheating deformation or burning of the printing medium that may be caused by the printing speed being too slow. The power consumption of the drive motor is maintained at a reasonable level, which is beneficial to the battery life in portable use scenarios, and ensures the clarity and color saturation of the printed pattern. Moreover, when the frequency of the drive motor of the portable thermal printer is in the frequency range of 1500 Hz to 2000 Hz, the operation of the drive motor is more stable. That is to say, at this printing speed and drive motor frequency, the drive motor can reduce sudden vibrations. By cooperating with the precise control of the output voltage, mechanical vibration can be effectively reduced, and resonance and noise problems that may be generated during low-frequency operation can be reduced. Furthermore, the frequency range is matched with the printing speed, ensuring the accurate positioning and uniform movement of the print head and improving printing accuracy.

[0064] In step S206, the portable thermal printer responds to the printing command by querying a first preset table based on the printing time to obtain the corresponding first duty cycle data.

[0065] In some embodiments, the portable thermal printer includes an instruction receiving module and an instruction parsing module. The instruction receiving module is responsible for listening to and receiving print instructions from external devices (such as computers, mobile devices, or networks) or users. The instruction receiving module transmits the received print instructions to the instruction parsing module for decoding to extract relevant information about the print job, such as print content, print speed, and print quality.

[0066] When acquiring duty cycle data, the portable thermal printer can use an index to locate the correct position in a first preset table. Specifically, the portable thermal printer determines an index value to locate and read the corresponding first duty cycle data from the first preset table based on the printing time. The read first duty cycle data can be temporarily stored in the portable thermal printer's memory, such as a cache, for use in subsequent generation of the first pulse width modulation signal. Throughout the printing process, the portable thermal printer can continuously read the first duty cycle data from the first preset table after each determined printing time and adjust the control of the drive motor accordingly.

[0067] Step S207: Periodically read the first duty cycle from the first duty cycle data according to the preset update cycle.

[0068] For example, a portable thermal printer has a timer or clock module for tracking the time of a preset update cycle. When the preset time point is reached, the timer triggers an interrupt signal, instructing the portable thermal printer to read the corresponding first duty cycle from the first duty cycle data. Understandably, in each printed line, the motor can rotate a preset angle according to the corresponding first duty cycle.

[0069] In step S208, the portable thermal printer generates and outputs a first pulse width modulation signal based on the read first duty cycle. The stepper motor driver chip of the portable thermal printer generates a current signal simulating a first sine wave based on the first pulse width modulation signal and outputs the current signal to the drive motor of the portable thermal printer to control the movement of the drive motor in the thermal printing scenario until the printing time ends.

[0070] For example, the portable thermal printer includes a PWM signal generation module. This module is responsible for generating a corresponding PWM signal, i.e., a first pulse width modulation signal, based on first duty cycle data in a buffer. The frequency and duty cycle of the first pulse width modulation signal are determined by the first duty cycle data and are typically closely related to the printing speed and print quality of the portable thermal printer. The generated first pulse width modulation signal can be transmitted to a stepper motor driver chip via the portable thermal printer's output port or interface.

[0071] After receiving the first pulse width modulation signal, the stepper motor driver chip generates a simulated first sine wave current signal based on the signal's duty cycle and frequency. This current signal drives the portable thermal printer's drive motor to move at a specific speed and acceleration. The generated simulated first sine wave current signal is output to the portable thermal printer's drive motor. The drive motor adjusts its motion state, including rotational speed, direction, and acceleration, based on the waveform and amplitude of the current signal. These motion parameters collectively determine the accuracy and efficiency of the portable thermal printer during the printing process.

[0072] In some embodiments, please refer to Figure 3 Step S201 may include: In step S301, the portable thermal printer determines the step angle and rotation speed of the drive motor in the thermal printing scenario.

[0073] Portable thermal printers determine the stepping angle and rotation speed of the drive motor based on the printing accuracy and speed requirements of the thermal printing scenario.

[0074] The step angle is determined by the structural design and control algorithm of the drive motor, and it determines the angle of rotation of the drive motor in each step. For example, the step angle is 1.8 degrees.

[0075] The rotation speed can be set according to the printhead's movement speed and the complexity of the printing task in the printing scenario to ensure print quality and efficiency.

[0076] In step S302, the portable thermal printer calculates the target frequency and target amplitude of the first sine wave based on the step angle and rotation speed.

[0077] The target frequency is proportional to the rotational speed of the drive motor, while the target amplitude is related to the step angle of the drive motor. For example, the target amplitude is proportional to the step angle.

[0078] It is understood that the specific relationship between the target frequency and the rotational speed of the drive motor, as well as the specific relationship between the target amplitude and the step angle of the drive motor, can be set according to the actual situation, and this application does not impose specific limitations on this.

[0079] In some embodiments, the portable thermal printer can calculate the target frequency and target amplitude of the first sine wave based on the step angle and rotation speed through table lookup, formula calculation, or real-time algorithm. This application does not specifically limit this method.

[0080] In step S303, the portable thermal printer generates a first sine wave based on the target frequency and target amplitude.

[0081] In some embodiments, the portable thermal printer uses digital signal processing (DSP) technology or a timer module in a microcontroller unit (MCU) to generate a first sine wave. In other embodiments, the portable thermal printer can generate a sine wave signal using a pre-stored sine wave data table (e.g., by lookup table) or by using a real-time computing algorithm (e.g., the CORDIC algorithm). This application does not specifically limit the method of generating the first sine wave.

[0082] In step S304, the portable thermal printer determines the first sampling rate and the preset update cycle based on the thermal printing scenario.

[0083] Portable thermal printers determine the first sampling rate based on the physical characteristics of the drive motor and the control precision requirements in the thermal printing scenario. A higher first sampling rate results in higher control precision. For example, different drive motors may have different numbers of phases, and the number of phases is negatively correlated with the step angle of the drive motor. That is, the more phases the drive motor has, the smaller the step angle. Thus, when the drive motor has more phases, a higher first sampling rate can be set to achieve control with a smaller step angle. Furthermore, for portable thermal printers requiring higher control precision, an even higher first sampling rate can be set.

[0084] In some embodiments, a suitable preset update cycle can be selected based on the specific printing needs in the printing scenario and the performance of the drive motor.

[0085] Step S305: Use the target triangular wave as the first carrier wave, wherein the frequency of the target triangular wave is higher than the target frequency.

[0086] In some embodiments, the portable thermal printer uses PWM technology to generate a carrier signal. The carrier signal is a triangular wave with a frequency higher than the target frequency. In other embodiments, the portable thermal printer can generate the triangular wave signal using a timer module and a comparator module in an MCU.

[0087] In the thermal printing scenario, SPWM (Sinusoidal Pulse Width Modulation) is used to sample bipolar waveforms and generate two sinusoidal waveforms with the same frequency but a current phase difference of 90 degrees to drive the motor to rotate smoothly. Therefore, obtaining at least one first sine wave in the thermal printing scenario can include: obtaining two first sine waves with the same frequency in the thermal printing scenario, with a current phase difference of 90 degrees between the two first sine waves.

[0088] Specifically, the portable thermal printer determines the target frequency and target amplitude of a first sine wave in a thermal printing scenario, and generates a corresponding first sine wave based on the target frequency and target amplitude. To generate a second first sine wave with a 90-degree phase difference, the first sine wave undergoes a phase shift. The phase shift can be achieved by adjusting the starting point or index of the sine wave data; this application does not specifically limit this method.

[0089] In some embodiments, please refer to Figure 4 After the printing time has ended, the thermal printing method provided in this application embodiment further includes: Step S401: The portable thermal printer detects the status of the thermal printing task in the thermal printing scenario.

[0090] Portable thermal printers continuously monitor the status of the printing task in real time during the thermal printing process. By detecting the status of the printing task, the portable thermal printer can determine whether the current printing task is about to be completed.

[0091] For example, a portable thermal printer can monitor the status of the print queue to understand the progress of the current print job.

[0092] Step S402: When the hot printing task is in the target state, the printing time is re-determined based on the received data to be printed for the current print line.

[0093] In some embodiments, the target state of a thermal printing task can refer to the state where the thermal printing task is about to end. For example, a portable thermal printer can determine whether a printing task is about to end by timing or counting based on information such as the start time of the printing task, the number of pages or lines printed, etc.

[0094] In some embodiments, after the data to be printed in the current print line has been printed and the hot printing task is confirmed to be in the target state, the printing time can be re-determined based on the received data to be printed in the current print line.

[0095] In other embodiments, a thermal printing task being in a target state can also refer to a thermal printing task being in a state awaiting acceleration. For example, when a print acceleration command generated in response to a user operation is received, it can be determined that the thermal printing task is in a target state.

[0096] In step S403, the portable thermal printer responds to the printing command by querying a second preset table based on the printing time to obtain the corresponding second duty cycle data.

[0097] Understandably, in some embodiments, once the near end of a thermal printing job is detected, the portable thermal printer will take specific action, namely, reading second duty cycle data from a pre-stored second preset table. This data represents the movement of the drive motor at the end of the printing job. At this time, for the same printing time, the second duty cycle is less than the first duty cycle.

[0098] The portable thermal printer reads the second duty cycle data from the second preset table. For example, the portable thermal printer reads the second duty cycle data corresponding to the current printing time from the second preset table. The relevant content of the portable thermal printer reading the second duty cycle data from the second preset table according to the printing time can be referred to step S205 above, and will not be repeated here.

[0099] In other embodiments, when the thermal printing task is in an acceleration-ready state, the portable thermal printer can also read second duty cycle data from a pre-stored second preset table. This data represents the motion used to accelerate the drive motor. In this case, for the same printing time, the second duty cycle is greater than the first duty cycle.

[0100] In step S404, the portable thermal printer reads the second duty cycle from the second duty cycle data according to the preset update cycle, generates and outputs the second pulse width modulation signal to control the movement of the drive motor in the thermal printing scenario until the printing time ends.

[0101] The stepper motor driver chip of the portable thermal printer is used to generate a current signal that simulates a second sine wave based on the second pulse width modulation signal, and outputs the current signal to the drive motor of the portable thermal printer to control the movement of the drive motor when the printing task is in the target state.

[0102] In some embodiments, please refer to Figure 5 Before querying a second preset table based on the printing time to obtain the corresponding second duty cycle data, the thermal printing method provided in this application embodiment further includes: Step S501: The portable thermal printer acquires at least one second sine wave, a second sampling rate, and a second carrier wave in the target scene.

[0103] The second sine wave refers to a sine wave preset during the thermal printing process to control the motion trajectory of the drive motor. It represents the expected change in the speed or position of the drive motor over time in the target scenario.

[0104] The second sampling rate refers to the frequency at which the waveform of the second sine wave is sampled when acquiring the second sine wave. It determines how many sampling points can be acquired within each sine wave cycle to represent the waveform.

[0105] The second carrier wave can be a triangular wave with a frequency higher than that of the second sine wave, which is used as the carrier signal for pulse width modulation (PWM).

[0106] In the printing scenario, the first sine wave, the first sampling rate, and the first carrier wave can be partially different from the second sine wave, the second sampling rate, and the second carrier wave in the target scenario, or all of them can be different.

[0107] In some embodiments, the target scenario can be understood as a scenario nearing the end of printing. At this time, the print queue can be checked, and when only a preset threshold of print jobs remains or only the current job remains and its progress is close to 100%, it can be determined that the print job is about to end, i.e., it is in the target scenario. The preset threshold can be set according to the actual situation, such as 90% or 95%, and this application does not make a specific limitation on it.

[0108] For example, in some embodiments, the portable thermal printer includes a paper sensor for detecting the presence and position of paper. When the paper sensor detects that the paper is about to run out and the current printing task has reached a preset threshold, it can be determined that the printing task is about to end, i.e., the target scenario is reached.

[0109] In other embodiments, the target scenario can be understood as the scenario to be accelerated. In this case, the portable thermal printer can be determined to be in the target scenario upon receiving a print acceleration command. Alternatively, the printing speed of the portable thermal printer can be detected, and the portable thermal printer can be determined to be in the target scenario when the printing speed is detected to be less than a preset speed.

[0110] It is understandable that the method for determining whether one is in the target scenario can be set according to the actual situation, and this application does not impose specific limitations on it.

[0111] In step S502, the portable thermal printer obtains second duty cycle data corresponding to each second sine wave based on at least one second sine wave, a second sampling rate, and a second carrier wave. The second duty cycle data includes the second duty cycle of the second pulse width modulation signal corresponding to each sampling point within one period of the second sine wave.

[0112] The relevant content of step S502 can be referred to step S202, and will not be repeated here.

[0113] In step S503, the portable thermal printer stores the second duty cycle data and obtains a second preset table based on the second duty cycle data. The second duty cycle is less than or greater than the first duty cycle.

[0114] In some embodiments, when the target scene refers to a scene nearing the end of printing, the second duty cycle is less than the first duty cycle.

[0115] Understandably, the duty cycle directly affects the effective level time of the drive signal for the motor, thus determining the average input power of the motor. When the duty cycle decreases, the average input power of the motor decreases, resulting in a decrease in the motor's speed. Therefore, a second duty cycle smaller than the first duty cycle means that when the motor is controlled according to the second duty cycle data, the motor's speed decreases from a higher state to a lower state. A lower duty cycle may reduce vibration and friction in the motor, thereby reducing mechanical noise. A second duty cycle greater than the first duty cycle means that when the motor is controlled according to the second duty cycle data, the motor's speed decreases from a lower state to a higher state. An increased duty cycle can increase the printing speed of the motor.

[0116] In some embodiments, please refer to Figure 6 After the printing time in step S207 ends, the thermal printing method provided in this application embodiment further includes: Step S601: The portable thermal printer detects the status of the thermal printing task in the thermal printing scenario.

[0117] One cycle of a sine wave can contain multiple data points, each representing the duty cycle at that moment. The duty cycle is the ratio of the time the signal is at a high level to the total time of the cycle.

[0118] After reading the duty cycle data, the portable thermal printer needs to determine if there is a thermal print job currently in progress. This can be done, for example, by checking the print queue, print status flags, or received print commands.

[0119] For example, a portable thermal printer has an internal timer that triggers the reading of duty cycle data according to a preset update cycle. After the reading operation is completed, the portable thermal printer checks whether there is a print job currently being executed by querying its internal status register or print queue.

[0120] In step S602, when the thermal printing task is in execution state, the portable thermal printer returns to step S204.

[0121] Understandably, after confirming that there is a print job, the portable thermal printer needs to read the duty cycle data of the next print line in order to generate a new PWM signal to control the drive motor to move in the next print line.

[0122] Stepper motors require precise control signals to ensure they move at the desired step size and speed. Precise control of the motor's movement is achieved by reading and applying new duty cycle data for each print line. When a stepper motor receives a continuous PWM signal, it produces smooth rotational motion. If the same duty cycle data is used for each cycle, the motor's motion will be constant. However, in thermal printing, the motor's speed and acceleration change according to the printing scenario to adapt to different printing requirements. Therefore, by continuously updating the duty cycle data, smooth motor motion can be achieved.

[0123] In some embodiments, please refer to Figure 7 After step S206, the thermal printing method provided in this application embodiment further includes: Step S701: During the printing process, the portable thermal printer detects the speed of the drive motor.

[0124] During the printing process, the portable thermal printer monitors the speed of the drive motor in real time to ensure that it can operate at the predetermined rate to maintain stable print quality and speed.

[0125] For example, a portable thermal printer can detect the rotational speed of a motor using sensors such as Hall effect sensors or photoelectric encoders. These sensors are able to capture the rotational frequency of the motor and convert it into an electrical signal, which is then processed by the portable thermal printer's processor.

[0126] Step S702: When the speed of the drive motor is not within the preset range, the third preset table is queried according to the printing time to obtain the corresponding third duty cycle data. The third duty cycle data includes the third duty cycle of the third pulse width modulation signal corresponding to each sampling point within one cycle of the corresponding first sine wave. The third duty cycle data is obtained by adjusting the first duty cycle data according to the duty cycle adjustment value.

[0127] For example, a portable thermal printer uses an encoder, Hall effect sensor, or other speed detection device to monitor the actual speed of the motor. The detected speed is compared with a preset desired speed, and the error between the actual and desired speeds is calculated. The error value can be positive (indicating that the actual speed is lower than the desired speed) or negative (indicating that the actual speed is higher than the desired speed). Based on the magnitude and direction of the error value, a duty cycle adjustment is determined, resulting in a duty cycle adjustment value. If the error is positive, the duty cycle is increased to increase the motor speed. If the error is negative, the duty cycle is decreased to decrease the motor speed. The duty cycle adjustment value can be based on a simple proportional control algorithm (P control), where the adjustment amount is proportional to the error. More complex control algorithms, such as proportional-integral-derivative (PID) control, can also be used to adjust the duty cycle more precisely.

[0128] In some embodiments, the third preset table stores the printing time, the first sine wave, the third duty cycle data, and the duty cycle adjustment value. Furthermore, there is a one-to-one mapping relationship between the printing time, the first sine wave, the third duty cycle data, and the duty cycle adjustment value. Thus, in step S702, the third preset table can be queried based on the printing time and the corresponding duty cycle adjustment value to determine the corresponding third duty cycle data. By adjusting the duty cycle data, the duty cycle of the motor drive signal can be changed, thereby achieving precise control of the motor speed.

[0129] For example, when the speed needs to be adjusted, the portable thermal printer modifies the data in the first preset table according to the duty cycle adjustment value to obtain new duty cycle data (i.e., third duty cycle data).

[0130] Step S703: Periodically read the third duty cycle from the third duty cycle data according to the preset update cycle.

[0131] Understandably, since the third duty cycle data in step S702 is also the duty cycle of the third pulse width modulation signal corresponding to each sampling point in the first sine wave, the number of duty cycles included in the first duty cycle data and the third duty cycle data is equal. Thus, in step S703, the third duty cycle in the next order of the third duty cycle data can be obtained according to the preset update cycle and the current order of the first duty cycle in the first duty cycle data, so as to realize the adjustment of the printing speed of the motor in the same printing line.

[0132] Understandably, the third preset table can be stored in a preset table for quick retrieval and application when needed.

[0133] Step S704: Generate and output a third pulse width modulation signal based on the read third duty cycle to control the movement of the drive motor in the thermal printing scenario until the printing time ends.

[0134] Thus, by executing step S704, a new PWM signal can be generated and output to transmit the adjusted speed command to the drive motor.

[0135] In some embodiments, the thermal printing method provided in this application satisfies at least one of the following preset printing conditions, which include: The number of sampling points is N, where N is greater than or equal to 300 and less than or equal to 400; The amplitude of the first pulse width modulation signal is greater than or equal to 30% and less than or equal to 47%; The amplitude of the second pulse width modulation signal is greater than or equal to 30% and less than or equal to 47%; The amplitude of the third pulse width modulation signal is greater than or equal to 30% and less than or equal to 47%; The first duty cycle is greater than or equal to 80% and less than or equal to 97%; The default update cycle is any value between 10us and 30us.

[0136] Understandably, in printer scenarios, SPWM amplitude is significantly louder when it is less than 30%, and greater than 47% can easily lead to motor malfunction.

[0137] Please see Figure 8 This application provides an example of another thermal printing method.

[0138] like Figure 8 As shown in the figure, the thermal printing method provided in this application embodiment specifically includes the following steps. Depending on different needs, the order of the steps in the flowchart can be changed, and some steps can be omitted.

[0139] Step S801: Initialize PWM output.

[0140] Initialize the PWM output to generate two PWM waveforms with the same frequency but opposite polarities. These waveforms will be used to drive two phases of the motor.

[0141] For example, the MotoPwmInit function is called to configure PWM parameters. Configuring PWM parameters may include, but is not limited to: setting PWM to edge-aligned mode, setting the PWM frequency to the desired frequency, configuring the PWM channel and time base, setting the initial duty cycle to 50% (the initial duty cycle is just a starting value and will be adjusted later according to the data in the preset table), configuring the hardware pins, and enabling complementary outputs so that the waveforms of the two pins are synchronized and have opposite polarities.

[0142] Among them, the current of the two phases of the drive motor must always be at a 90-degree phase difference, and the waveforms of the two phases must change synchronously to prevent one phase from going out of control and causing the drive motor to operate suddenly.

[0143] Step S802: Store the duty cycle data.

[0144] To simulate a sine wave, duty cycle data is stored, as shown in the first, second, and third preset tables mentioned above. The tables contain the duty cycle of all points within one cycle of the sine wave.

[0145] In some embodiments, the duty cycle is controlled at an upper limit of 95% and a lower limit of 5%.

[0146] For example, an array (e.g., SpwmdutyS) is created to store duty cycle data.

[0147] Step S803: Start the drive motor and set the initial state.

[0148] Before starting the drive motor, you need to set the initial state of the drive motor, including direction, initial duty cycle, etc.

[0149] For example, the MOTORun function is called to set the initial values ​​of PulsNumALen and PulsNumBLen according to the required motor direction. A timer is started to call the interrupt handler function at regular intervals (e.g., 20µs).

[0150] Step S804: Adjust the duty cycle in the timer interrupt.

[0151] In the timer interrupt handler, the duty cycle of the PWM is adjusted based on the stored duty cycle data.

[0152] For example, in the `Motor_inter` function, the values ​​of `PulsNumALen` and `PulsNumBLen` are incremented to iterate through the stored duty cycle data. When `PulsNumALen` or `PulsNumBLen` reaches the length of a preset table, it is reset to 0 to achieve a loop. The `MotoASetDuty` and `MotoBSetDuty` functions are called to retrieve the duty cycle from the preset table based on the current index of `PulsNumALen` and `PulsNumBLen`, and set it to the PWM output. The timer is reset so that the interrupt handler function is called again at the next 20µs cycle.

[0153] For example, if the number of sampling points N is set to 400, then the sine waveform is composed of 400 points, where the change time of each point is 20us, for a total of 8ms. That is, the drive motor completes a rotation of one step angle in 8ms, and each change involves the drive motor rotating at an angle of 1 / 400 of the step angle.

[0154] Step S805: When the hot printing task is completed, turn off the PWM output and release the relevant resources.

[0155] For example, the corresponding function is called to stop the PWM output and release the timer and other related resources. These related resources may include, but are not limited to, memory resources allocated during the thermal printing process. For instance, some memory resources are allocated during the thermal printing process to store data related to the PWM output, such as the first preset table, the second preset table, and the third preset table mentioned above.

[0156] This application provides a portable thermal printer, which includes a memory and at least one processor. The memory stores at least one instruction, and when the at least one instruction is executed by the at least one processor, it implements any of the thermal printing methods described above.

[0157] This application provides a computer-readable storage medium storing at least one instruction, which, when executed by a processor, implements any of the above-described thermal printing methods.

[0158] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and other division methods may be used in actual implementation.

[0159] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0160] Furthermore, the functional modules in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or in the form of hardware plus software functional modules.

[0161] It will be apparent to those skilled in the art that this application is not limited to the details of the exemplary embodiments described above, and that this application can be implemented in other specific forms without departing from the spirit or essential characteristics of this application. Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of this application is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be embraced within this application. No reference numerals in the claims should be construed as limiting the scope of the claims. Furthermore, it is clear that the word "comprising" does not exclude other elements or, and the singular does not exclude the plural. Multiple elements or devices recited in the apparatus claims may also be implemented by a single element or device in software or hardware. The terms "first," "second," etc., are used to indicate names and do not indicate any particular order.

[0162] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application and are not intended to limit it. Although this application has been described in detail with reference to the above preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of this application without departing from the spirit and scope of the technical solutions of this application.

Claims

1. A thermal printing method, characterized in that, Applied to portable thermal printers, the method includes: Obtain at least one first sine wave, first sampling rate, first carrier, and preset update period in the hot printing scenario; The first duty cycle data corresponding to each of the first sine waves is obtained based on at least one first sine wave, the first sampling rate, and the first carrier wave, wherein the first duty cycle data includes the first duty cycle of the first pulse width modulation signal corresponding to each sampling point within one period of the corresponding first sine wave. Store the first duty cycle data, and obtain a first preset table based on the first duty cycle data; The printing time is determined based on the data to be printed in the current print line received. The printing speed of the portable thermal printer is x, and the frequency of the drive motor of the portable thermal printer is y; the printing speed and the drive motor frequency satisfy the following relationship: 8mm / s≤x≤15mm / s; 1500hz≤y≤2000hz; In response to a print command, the first preset table is queried according to the print time to obtain the corresponding first duty cycle data; The first duty cycle is periodically read from the first duty cycle data according to the preset update cycle; The portable thermal printer's stepper motor driver chip generates and outputs the first pulse width modulation signal based on the read first duty cycle. The stepper motor driver chip generates a current signal simulating the first sine wave based on the first pulse width modulation signal and outputs the current signal to the drive motor of the portable thermal printer to control the movement of the drive motor in the thermal printing scenario until the printing time ends.

2. The thermal printing method according to claim 1, characterized in that, After the printing time has ended, the method further includes: Detect the status of the thermal printing task in the described thermal printing scenario; When the hot printing task is in the target state, the printing time is re-determined based on the received data to be printed for the current print line; In response to the print command, the second preset table is queried according to the print time to obtain the corresponding second duty cycle data; According to the preset update cycle, the second duty cycle is read from the second duty cycle data to generate and output the second pulse width modulation signal to control the movement of the drive motor in the thermal printing scenario until the printing time ends.

3. The thermal printing method according to claim 2, characterized in that, Before querying the second preset table based on the printing time to obtain the corresponding second duty cycle data, the method further includes: Acquire at least one second sine wave, a second sampling rate, and a second carrier wave in the target scenario; The second duty cycle data corresponding to each second sine wave is obtained based on at least one second sine wave, the second sampling rate, and the second carrier wave, wherein the second duty cycle data includes the second duty cycle of the second pulse width modulation signal corresponding to each sampling point within one period of the corresponding second sine wave; The second duty cycle data is stored, and the second preset table is obtained based on the second duty cycle data; wherein the second duty cycle is less than or greater than the first duty cycle.

4. The thermal printing method according to claim 1, characterized in that, After the printing time has ended, the method further includes: Detect the status of the thermal printing task in the described thermal printing scenario; When the hot printing task is in the execution state, return to the step of determining the printing time based on the received data to be printed of the current print line.

5. The thermal printing method according to claim 1, characterized in that, After periodically reading the first duty cycle from the first duty cycle data according to the preset update period, the method further includes: During the printing process, the speed of the drive motor is detected; When the speed of the drive motor is not within the preset range, the third preset table is queried according to the printing time to obtain the corresponding third duty cycle data. The third duty cycle data includes the third duty cycle of the third pulse width modulation signal corresponding to each sampling point within one cycle of the corresponding first sine wave. The third duty cycle data is obtained by adjusting the first duty cycle data according to the duty cycle adjustment value. The third duty cycle is periodically read from the third duty cycle data according to the preset update cycle; The third pulse width modulation signal is generated and output based on the read third duty cycle to control the movement of the drive motor in the thermal printing scenario until the printing time ends.

6. The thermal printing method according to claim 1, characterized in that, The acquisition of at least one first sine wave, first sampling rate, first carrier, and preset update period in the thermal printing scenario includes: Determine the stepping angle and rotational speed of the drive motor in the thermal printing scenario; The target frequency and target amplitude of the first sine wave are calculated based on the step angle and the rotation speed. The first sine wave is generated based on the target frequency and the target amplitude; The first sampling rate and the preset update cycle are determined based on the thermal printing scenario. The target triangular wave is used as the first carrier wave, wherein the frequency of the target triangular wave is higher than the target frequency.

7. The thermal printing method according to claim 1, characterized in that, The acquisition of at least one first sine wave in the thermal printing scenario includes: In the thermal printing scenario, two first sine waves of the same frequency are obtained, and the current phase difference between the two first sine waves is 90 degrees.

8. The thermal printing method according to any one of claims 1 to 7, characterized in that, The thermal printing method satisfies at least one of the preset printing conditions, which include: The number of sampling points is N, where N is greater than or equal to 300 and less than or equal to 400; The amplitude of the first pulse width modulation signal is greater than or equal to 30% and less than or equal to 47%; The first duty cycle is greater than or equal to 80% and less than or equal to 97%; The preset update cycle is any value between 10us and 30us.

9. A portable thermal printer, characterized in that, The portable thermal printer includes a memory and at least one processor, the memory storing at least one instruction which, when executed by the at least one processor, implements the thermal printing method as described in any one of claims 1 to 8.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one instruction that, when executed by a processor, implements the thermal printing method as described in any one of claims 1 to 8.