CN114328002B - Data sampling method in encoder, single chip microcomputer and storage medium - Google Patents

Data sampling method in encoder, single chip microcomputer and storage medium Download PDF

Info

Publication number
CN114328002B
CN114328002B CN202210255787.0A CN202210255787A CN114328002B CN 114328002 B CN114328002 B CN 114328002B CN 202210255787 A CN202210255787 A CN 202210255787A CN 114328002 B CN114328002 B CN 114328002B
Authority
CN
China
Prior art keywords
instruction set
data
execution
processing unit
central processing
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202210255787.0A
Other languages
Chinese (zh)
Other versions
CN114328002A (en
Inventor
孔德保
徐斌
张潇帅
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tianjin Yike Automation Co ltd
Original Assignee
Elco Tianjin Electronics Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Elco Tianjin Electronics Co Ltd filed Critical Elco Tianjin Electronics Co Ltd
Priority to CN202210255787.0A priority Critical patent/CN114328002B/en
Publication of CN114328002A publication Critical patent/CN114328002A/en
Application granted granted Critical
Publication of CN114328002B publication Critical patent/CN114328002B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02PCLIMATE CHANGE MITIGATION TECHNOLOGIES IN THE PRODUCTION OR PROCESSING OF GOODS
    • Y02P90/00Enabling technologies with a potential contribution to greenhouse gas [GHG] emissions mitigation
    • Y02P90/02Total factory control, e.g. smart factories, flexible manufacturing systems [FMS] or integrated manufacturing systems [IMS]

Landscapes

  • Arrangements For Transmission Of Measured Signals (AREA)

Abstract

The invention provides a method for sampling data in a coder, a singlechip and a storage medium, wherein the method is applied to the singlechip and comprises the following steps: the central processing unit responds to the receiving of the trigger signal and determines the number of the received trigger signal; the trigger signal is sent by the timer every other first set time length; the central processing unit executes a first instruction set corresponding to the number of the received trigger signals in the first instruction set; the first instruction set comprises a plurality of first instruction sets, each first instruction set comprises a plurality of assembly instructions, and the execution time length of at least part of the first instruction sets is less than a first set time length; when the first instruction set is executed, the central processing unit samples first data output by the output end of the target sensor; the central processing unit executes the second instruction set under the condition that the execution of the current first instruction set is completed and the next trigger signal is not received; the second instruction set has a lower priority of execution than the first instruction set.

Description

Data sampling method in encoder, single chip microcomputer and storage medium
Technical Field
The invention relates to the field of data processing, in particular to a data sampling method in an encoder, a single chip microcomputer and a storage medium.
Background
During the operation of the encoder, the output data of the position sensor, the temperature sensor and other sensors need to be sampled. In a general encoder, an FPGA chip is generally used to sample a plurality of sensors in parallel, but the cost of the FPGA chip is high.
Compared with the FPGA, the single chip microcomputer is lower in cost, but the single chip microcomputer only has a single central processing unit and does not have the parallel processing capability. If a plurality of sensors are sampled in a serial mode, the problem that the sampling task with high priority and long sampling period causes too long execution interval of the sampling task to the sampling task with low priority due to different execution priorities and different data sampling periods of each sensor can also exist.
Disclosure of Invention
In view of the above, the present invention provides a method for sampling data in an encoder, a single chip, and a storage medium, which at least partially solve the problems in the prior art.
According to one aspect of the application, a method for sampling data in an encoder is provided, and the method is applied to a single chip microcomputer, and the single chip microcomputer comprises the following steps: a central processing unit and a timer; the single chip microcomputer is in communication connection with the target sensor;
the method comprises the following steps:
step S100, the central processing unit responds to the receiving of the trigger signal and determines the number of the received trigger signal; the trigger signal is sent by the timer every other first set time length;
step S200, the central processing unit executes a first instruction set corresponding to the number of the received trigger signals in the first instruction set; the first instruction set comprises a plurality of first instruction sets, each first instruction set comprises a plurality of assembly instructions, and the execution time of at least part of the first instruction sets is less than the first set time; when the first set of instructions is executed, the central processor samples first data output by an output of a target sensor;
step S300, the central processing unit executes a second instruction set under the condition that the execution of the current first instruction set is completed and a next trigger signal is not received; the second instruction set, which includes a number of assembly instructions, has a lower execution priority than the first instruction set.
In an exemplary embodiment of the present application, the step S300 includes:
step S310, the central processing unit determines whether a second instruction set is suspended to be executed or not when the current first instruction set is executed and the next trigger signal is not received; if yes, go to step S311; otherwise, go to step S312;
step S311, resuming the execution of the suspended second instruction set;
step S312, executing a third instruction set; the execution priority of the third instruction set is lower than that of the first instruction set, and the third instruction set comprises a plurality of assembly instructions;
the method further comprises the following steps:
step S400, if the central processing unit receives the trigger signal during the execution of the second instruction set, the execution of the second instruction set is suspended, and the step S100 is executed again.
In an exemplary embodiment of the present application, the central processor is further configured to process the sampled first data when the first set of instructions is executed;
the processing the first data obtained by sampling includes:
and performing CRC check on the first data and performing reverse order processing on the first data.
In an exemplary embodiment of the present application, the single chip further includes a CRC hardware module;
the performing a CRC check on the first data includes:
sending the first data to the CRC hardware module so that the CRC hardware module performs CRC check on the first data;
and receiving a check result sent by the CRC hardware module.
In an exemplary embodiment of the present application, the performing the reverse order processing on the first data includes:
sending the first data and the check parameter to a CRC hardware module;
receiving the processed data sent by the CRC hardware module;
when the CRC hardware module executes CRC check by using the check parameters, a generating polynomial used by the CRC check is 1, a check initial value is 0, a result exclusive OR value is 0, and the data output sequence is in a reverse order.
In an exemplary embodiment of the present application, the first set time period is 1 microsecond to 3 microseconds.
In an exemplary embodiment of the present application, each of the first instruction sets has an execution duration less than a third set duration, and the third set duration is less than the first set duration.
In an exemplary embodiment of the present application, the third set time period is 0.1 microseconds to 0.3 microseconds.
According to an aspect of the present application, there is provided a single chip microcomputer including: the system comprises a central processing unit, a timer, a CRC hardware module and a memory;
the memory is connected to the central processor, the memory storing instructions executable by the central processor, the instructions being arranged to perform the method of any of the preceding claims.
According to an aspect of the present application, there is provided a computer-readable storage medium having stored thereon computer-executable instructions for performing the method of any of the preceding claims.
When the method for sampling data in the encoder is executed, the central processing unit can start to execute the corresponding first instruction set in the first instruction set in response to the receiving of the trigger signal. And executing the second instruction set after the current first instruction set is executed and under the condition that the next trigger signal is not received. In the application, the complete execution of the first instruction set is to complete the sampling of the target sensor once, and the first instruction set is split into a plurality of first instruction sets, and one of the first instruction sets is executed every time a trigger signal is received, so that the sampling task of the target sensor is split into a plurality of sections. At the same time, a second set of instructions of lower execution priority is executed each time before the next trigger signal is received. Therefore, the task with the low execution priority is inserted into the execution process of the task with the high execution priority, the tasks with different execution priorities are operated in parallel through the single chip microcomputer, and the problem that the tasks with the low priority cannot be executed in time due to the fact that the execution cycle of the tasks with the high priority is long is solved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the embodiments will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a flowchart of a method for sampling data in an encoder according to this embodiment.
Detailed Description
Embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
It should be noted that, in the case of no conflict, the features in the following embodiments and examples may be combined with each other; moreover, all other embodiments that can be derived by one of ordinary skill in the art from the embodiments disclosed herein without making any creative effort fall within the scope of the present disclosure.
It is noted that various aspects of the embodiments are described below within the scope of the appended claims. It should be apparent that the aspects described herein may be embodied in a wide variety of forms and that any specific structure and/or function described herein is merely illustrative. Based on the disclosure, one skilled in the art should appreciate that one aspect described herein may be implemented independently of any other aspects and that two or more of these aspects may be combined in various ways. For example, an apparatus may be implemented and/or a method practiced using any number of the aspects set forth herein. Additionally, such an apparatus may be implemented and/or such a method may be practiced using other structure and/or functionality in addition to one or more of the aspects set forth herein.
Referring to fig. 1, according to an aspect of the present application, there is provided a method for sampling data in an encoder, which is applied to a single chip microcomputer, where the single chip microcomputer includes: a central processing unit and a timer. The singlechip is in communication connection with the target sensor. The timer is configured to send a trigger signal to the central processing unit every first set time, where the trigger signal may be an interrupt instruction. The target sensor may be a position sensor.
The method comprises the following steps:
in step S100, the central processing unit determines the number of received trigger signals in response to the reception of the trigger signals.
The trigger signal is sent by the timer every other first set time length. The central processing unit may be configured with a register for recording the number of trigger signals received in the current operation, and perform +1 operation on the number in the register after each new trigger signal is received. The first set time is 1 microsecond to 3 microseconds, and preferably, the first set time is 2 microseconds.
Step S200, the central processing unit executes a first instruction set corresponding to the number of received trigger signals in the first instruction set.
The first instruction set comprises a plurality of first instruction sets, each first instruction set comprises a plurality of assembly instructions, and the execution time of at least part of the first instruction sets is less than the first set time. The central processor samples first data output by an output of a target sensor when the first set of instructions is executed. Preferably, the execution duration of each of the first instruction sets is less than a third set duration, and the third set duration is less than the first set duration. Wherein the third set time period is 0.1-0.3 microseconds, preferably, the third set time period is 0.3 microseconds.
When each first instruction set in the first instruction set is executed, the central processing unit performs sampling operation on the target sensor once, the first instruction set completes one complete execution to perform sampling of one cycle on the target sensor, and in the first instruction set, the number of the first instruction sets can be set according to the output cycle (set cycle) of the target sensor. The execution duration of each first instruction set is influenced by the number of assembler instructions in the first instruction set, and the larger the number of assembler instructions, the longer the execution time. Also, execution of the first set of instructions may be configured not to be interrupted by the trigger signal.
In step S300, the cpu executes the second instruction set when the execution of the current first instruction set is completed and the next trigger signal is not received.
The second instruction set, which includes a number of assembly instructions, has a lower execution priority than the first instruction set.
Because the execution time corresponding to at least part of the first instruction set is less than the first time, the central processing unit may not receive the next trigger signal when the execution of part of the first instruction set is completed, and at this time, if there is no other execution task, the central processing unit may be in an idle state. In this embodiment, under the above circumstances, the central processing unit executes the second instruction set with a lower execution priority to execute the task with a lower execution priority by using the idle time in the execution process of the task with a higher execution priority, so as to implement parallel execution of the tasks with different execution priorities.
The number of the second instruction sets may be multiple, the multiple second instruction sets have their own execution priorities, the execution priorities of the first instruction set and the multiple second instruction sets may be stored in an execution priority list, and the central processing unit determines the corresponding second instruction set by querying the execution priority list when the current first instruction set is executed and a next trigger signal is not received. The second set of instructions may correspond to a different task, such as sampling of a temperature sensor or data processing, etc. In this embodiment, the first instruction set is executed in a loop, and the execution priority is highest among the tasks of the central processing unit. Therefore, the method can adapt to the condition that the position sensor is periodically sampled all the time in the running process of the encoder.
In the data sampling method in the encoder provided by the embodiment, when executed, the central processing unit can start to execute the corresponding first instruction set in the first instruction set in response to the receiving of the trigger signal. And executing the second instruction set after the current first instruction set is executed and under the condition that the next trigger signal is not received. In this embodiment, the complete execution of the first instruction set is to complete sampling of the target sensor once, and the first instruction set is split into a plurality of first instruction sets, and one of the first instruction sets is executed every time a trigger signal is received, so that the task of sampling the target sensor is split into a plurality of segments. At the same time, a second set of instructions of lower execution priority is executed each time before the next trigger signal is received. Therefore, the task with the low execution priority is inserted into the execution process of the task with the high execution priority, the tasks with different execution priorities are operated in parallel through the single chip microcomputer, and the problem that the task with the low priority cannot be executed in time due to the fact that the execution period of the task with the high priority is long is solved.
In an exemplary embodiment of the present application, the method further comprises:
step S400, if the central processing unit receives the trigger signal during the execution of the second instruction set, the execution of the second instruction set is suspended, and the step S100 is executed again.
The step S300 may specifically include the following steps:
step S310, the central processing unit determines whether a second instruction set is suspended to be executed or not under the condition that the execution of the current first instruction set is completed and the next trigger signal is not received; if yes, go to step S311; otherwise, go to step S312;
in step S311, execution of the second instruction set is resumed.
Step S312, executing a third instruction set; the third instruction set, which includes a number of assembly instructions, has a lower execution priority than the first instruction set. Where the third instruction set is named to distinguish it from the second instruction set in the presentation for ease of understanding. Thus, the third instruction set may also be understood as a further second instruction set. Therefore, step S312 can also be understood as executing the second instruction set if there is no second instruction set currently suspended from execution.
And the central processing unit continues to determine a new second instruction set to execute under the condition that the execution of the current second instruction set is completed and the next trigger signal is not received. Because each second instruction set corresponds to different sampling tasks, the execution time length between different second instruction sets also differs. It may happen that the next trigger signal is received when a second instruction set has not yet been executed (i.e., during execution). Because the encoder needs to sample the position sensor according to the set period (set period) and the set time point, and both the real-time performance and the time sequence performance are high, if the current second instruction set is not stopped, the executed first instruction set is delayed to execute, and at least the current sampling task of the first instruction set is delayed, so that the sampling task of the position sensor is influenced to have errors. In this embodiment, to avoid this problem as much as possible, if the central processing unit receives the trigger signal during the execution of the second instruction set, the execution of the second instruction set is suspended, and the step S100 is returned to, that is, the corresponding first instruction set is immediately executed, so as to ensure the real-time performance and the time sequence performance of the sampling task for the position sensor.
Correspondingly, after the execution of the current first instruction set is finished each time, the central processing unit can preferably inquire whether a second instruction set which is suspended from being executed exists currently, if so, the execution is resumed, otherwise, the corresponding second instruction set can be determined according to the execution priority list for execution. Therefore, the situation that the execution cannot be successfully recovered after the second instruction set is interrupted can be avoided.
In an exemplary embodiment of the present application, the central processor is further configured to process the sampled first data when the first set of instructions is executed.
Correspondingly, the processing the first data obtained by sampling includes:
and performing CRC check on the first data and performing reverse order processing on the first data.
After the encoder samples the data output by the target sensor, the data can be correspondingly processed, so that the correctness of the sampled data is ensured, the subsequent processing of the data is convenient, and the like. In this embodiment, after the first data is obtained, CRC check is performed on the first data to ensure that the data is correct, and after a CRC check result is correct, reverse order processing is performed on the first data to facilitate subsequent data transmission and other operations.
Specifically, the single chip microcomputer further comprises a CRC hardware module;
the performing a CRC check on the first data includes:
sending the first data to the CRC hardware module so that the CRC hardware module performs CRC check on the first data;
and receiving a check result sent by the CRC hardware module.
If the CRC check is calculated by using a function or program to instruct the cpu, a large amount of resources of the cpu are occupied. However, as can be seen from the foregoing, since the single chip microcomputer used in the embodiment has only one central processing unit and is limited in calculation power, if the central processing unit is instructed by a function or a program to implement CRC check, the sampling operation of the target sensor is affected, and the processing time is longer. In this embodiment, when the CRC is required to be performed on the first data due to the self-contained CRC hardware module in the single chip microcomputer, the check result can be quickly obtained only by sending the first data to the CRC hardware module, thereby avoiding excessive occupation of the resources of the central processing unit, and the processing efficiency is higher due to the dedicated processing circuit in the CRC hardware module.
In an exemplary embodiment of the present application, the performing the reverse order processing on the first data includes:
sending the first data and the check parameter to a CRC hardware module;
receiving the processed data sent by the CRC hardware module;
when the CRC hardware module executes CRC check by using the check parameters, a generating polynomial used by the CRC check is 1, a check initial value is 0, a result exclusive OR value is 0, and the data output sequence is in a reverse order.
The reverse order processing means that the data arrangement mode is changed from high order priority to low order priority or vice versa. For example, the result of the reverse order processing of the string "123456" is "654321".
In a general single chip microcomputer, a central processing unit is mostly instructed to perform reverse processing on related data in a function or program mode. But this takes up a lot of computing power of the central processing unit. The embodiment provides a method for realizing data reverse order through a CRC hardware module, which realizes application extension of the CRC hardware module on one hand and avoids large occupation of CPU resources on the other hand.
Specifically, in this embodiment, by sending the check parameter to the CRC hardware module, when the CRC hardware module performs CRC check according to the check parameter, the input data is the same as the obtained calculation result, and the CRC hardware module is adjusted to output data in reverse order. After the central processing unit sends the first data and the check parameters to the CRC hardware module, the obtained processed data is the first data after reverse order processing. Therefore, the hardware high-speed processing of the reverse processing is realized, and an independent reverse processing hardware module is not required to be arranged in the single chip microcomputer.
In an exemplary embodiment of the application, the model of the single chip microcomputer is stm32L431, and a CRC hardware module of the single chip microcomputer supports a custom parameter model. The parameter model refers to relevant parameters adopted by the CRC hardware module in CRC check. Which may include data width, generator polynomial, check initial value and result xor value, etc. Most of CRC hardware modules are provided with various standard parameter models for users to select, and the user-defined parameter model means that the users can set each parameter in the parameter models by themselves to obtain a personalized parameter model. In the parameter model, if each parameter is a generator polynomial of 1, the check initial value is 0, and the result exclusive or value is 0, the input data of the CRC check and the check result are the same.
Prior to step S100, the method further comprises:
sending a configuration instruction to the CRC hardware module so that the CRC hardware module can configure the self-defined parameter model into a target model according to the configuration instruction, and allocating an execution identifier to the target model.
The check parameter includes the execution identifier.
Correspondingly, the CRC hardware module performs CRC check on the information to be processed according to the check parameter, including:
determining a target model according to the execution identifier;
and performing CRC on the information to be processed according to the target model.
In this embodiment, before the first instruction set is run, the CRC hardware module may be configured, so that a target model is configured therein, and when the CRC hardware module needs to be used, the CRC hardware module may calculate the first data using the target model by only sending the corresponding execution identifiers to the CRC hardware module together. In this way, the overall amount of data sent to the CRC hardware module is reduced each time data needs to be processed in reverse order, and the CRC hardware module does not need to be temporarily configured each time data needs to be processed in reverse order.
Specifically, since the first instruction set is split into a plurality of first instruction sets to be executed one by one, in this embodiment, when the first data is processed in reverse order, the first data is also split, so as to obtain a plurality of 8-bit binary numbers. Each reverse order process may be performed as a reverse order process on an 8-bit binary number.
In the working process of the encoder, not only the output data of the position sensor needs to be sampled, but also the sampled data needs to be uploaded to an upper computer at fixed frame intervals, so that the upper computer can display the working condition of the motor corresponding to the encoder. Thus, the real-time performance of the sampling task and the data uploading task needs to be guaranteed. However, since the sampling task requires a certain execution time, and in the high-speed sampling and communication scenario, the execution time is usually greater than the frame interval of data uploading. A common encoder uses an FPGA chip to perform parallel processing on a sampling task and communication. However, the cost of the FPGA chip is high, and if a single chip microcomputer is used, the single chip microcomputer only uses one central processing unit, so that the sampling task and the communication need to be processed in series, but because both the two tasks have high requirements on real-time performance and time sequence performance, if a data acquisition request of an upper computer is received in the execution process of the sampling task, the sampling task needs to be executed or interrupted after the sampling task is executed, so that the sampling task or the communication generates a large delay, at least one of the two tasks cannot be executed normally, and the series processing cannot be applied to a scene of high-speed sampling and communication.
In an exemplary embodiment of the present application, the single chip further includes a DMA module. The singlechip is in communication connection with the upper computer.
The method further comprises the following steps:
if the central processing unit receives a data acquisition request sent by the upper computer in the execution process of the current first instruction set, suspending the data acquisition request, and responding to the data acquisition request after the execution of the first instruction set is completed; the execution priority of the data acquisition request is the same as that of the first instruction set, and tasks with the same execution priority are not interrupted.
If the central processing unit receives a data acquisition request sent by the upper computer in the execution process of the second instruction set, suspending the data acquisition request and responding to the data acquisition request; and after the data acquisition request is responded, resuming the execution of the second instruction set.
Wherein the responding to the data acquisition request specifically includes:
determining a target register;
and sending the address pointer of the target register to a DMA (direct memory access) module so that the DMA module reads the first data in the target register and sends the read first data to the upper computer.
The DMA module can work in parallel with the central processing unit, and the target register is used for storing first data (or processed first data) sampled by the central processing unit from the target sensor. The CPU stores the sampled first data into the target register.
In this embodiment, the first instruction set is split into a plurality of first instruction sets, and the plurality of first instruction sets are executed one by one at intervals. If the data acquisition request is received in the execution interval of the adjacent first instruction set, the data acquisition request can be immediately responded; and if the data acquisition request is received in the execution process of the first instruction set, responding to the data acquisition request after the execution of the first instruction set is finished. Therefore, no matter under what condition, the data acquisition request is received, the quick response can be realized, the execution of the sampling task is not interrupted, and the response is not carried out until the whole execution of the sampling task (namely the first instruction set) is finished.
Meanwhile, the method for responding to the data acquisition request is to control the DMA module to read the target register and send the target register to the upper computer. The DMA module can work in parallel with the central processing unit, so that when the central processing unit responds to the data acquisition request, the DMA module can be controlled to independently send the first data only by sending the address pointer of the target register to the DMA module, the time consumption of the response process is short, the sending of the first data does not occupy the resources of the central processing unit, and the central processing unit can quickly return to the processing of the subsequent first instruction set after responding to the data acquisition request.
Therefore, the method provided by the embodiment can realize the parallel operation of the sampling task and the communication, can realize high-speed operation and timely response, and simultaneously ensures the real-time performance and the time sequence performance of the two tasks.
The data acquisition request can be responded to more quickly and timely under the condition that the data acquisition request is received in the execution process of the first instruction set.
In an exemplary embodiment of the present embodiment, the single chip microcomputer and the upper computer communicate with each other through a first communication protocol, and a communication delay error of the first communication protocol is a second set time duration t 2; the execution time length corresponding to each first instruction set in the first instruction set is less than a third set time length t 3; the execution time length corresponding to the response to the data acquisition request is a fourth set time length t 4; where t3= f (t2, t 4). In this embodiment, the baud rate of the serial port is 2.5 MHz.
If t2=0.5-1.5 microseconds, the communication delay error indicates that the upper computer needs to receive the returned first data within 0.5-1.5 microseconds after sending the data acquisition request. Therefore, in this embodiment, t2 is specified according to the first communication protocol, and the processing procedure of t4 is fixed, so that the specific values of t2 and t4 are relatively fixed, and in this embodiment, in order to ensure that the single chip microcomputer can complete the response to the data acquisition request within the allowable communication delay error, the maximum allowable value of t3 needs to be determined according to t2 and t4, so in this embodiment, t3= f (t2, t4) may be t3= t2-t4 or t3 ≦ t2-t4, so that even when the data acquisition request is received during the execution of the first instruction set, the response to the data acquisition request can be completed within the allowable time range of the communication delay error. In this embodiment, t3=0.3 microseconds.
Accordingly, to ensure that the execution time of each first instruction set is less than or equal to the third set duration, in an exemplary embodiment of the present application, the maximum number n of assembler instructions in the first instruction set is determined according to t 3. Further, since t3=0.3 microseconds in this embodiment, n =3 in this embodiment. I.e. 1-3 assembler instructions can be stored in each first instruction set.
In this embodiment, the output cycle of the target sensor is a set cycle, specifically 100 microseconds, so in this embodiment, the execution duration of the first instruction set is greater than or equal to 100 microseconds, where the execution duration refers to a time difference between a time when the first instruction set of the first instruction set starts to be executed and a time when the last first instruction set finishes being executed, that is, the execution duration includes the execution times of the second instruction set and other instructions during the execution of the first instruction set, which is a complete time period.
In this embodiment, the encoder adopts the singlechip to perform sampling of the target sensor and transmission of communication, and because the singlechip is single-core, the sampled data cannot be directly sent to the upper computer, but the first data obtained by sampling needs to be stored first, and after a data acquisition instruction is received, the first data in the register is stored and uploaded. However, the target sensor is periodic to the first data, that is, a period is required to be completed for a period of time to obtain complete data, and the single chip microcomputer is also required to process the sampled data and the like. No matter the sampling task and the processing task need a certain time limit, and under the scene of high-speed communication, the frame interval adopted for communication is smaller than the set period output by the target sensor, so if the central processing unit stores the sampled data in the register A and directly reads and uploads the register A after receiving a data acquisition request sent by an upper computer, the situation of repeated uploading data or incomplete uploading data can occur.
To address the above, in one exemplary embodiment of the present embodiment, the central processor executes the first set of instructions in a loop.
Wherein the first set of instructions comprises a first subset and a second subset, the first subset and the second subset executing sequentially; when the first subset is executed, the central processing unit samples first data output by an output end of a target sensor in sequence and stores the sampled first data to a first register; and when the second subset is executed, determining a first target register according to the current execution times of the first instruction set, sending the first data in the first register to the first target register, and clearing the first register. The first target register is one of a second register and a third register. Specifically, if the current execution times of the first instruction set is singular, the first target register is the second register, and if the current execution times is even, the first target register is the third register. Further, when the second subset is executed, sending the first data in the first register to a first target register and clearing the first register may include: and processing the first data in the first register and sending the first data to a first target register, and clearing the first register after finishing sending all the first data.
Correspondingly, the determining the target register comprises:
and responding to a received data acquisition request sent by the upper computer, and determining a second target register according to the current execution times of the first instruction set.
The second target register is one of a second register and a third register and is different from the first target register. That is, if the second subset should store the first data obtained by sampling each time to the second register in the execution turn of the current first instruction set, the first target register is the second register, and the second target register is the third register.
Correspondingly, the sending the address pointer of the target register to the DMA module includes:
and sending the address pointer of the second target register to a DMA (direct memory access) module so that the DMA module reads the first data in the second target register and sends the read first data to the upper computer.
In this embodiment, after sampling the target sensor, the central processing unit stores the first data obtained by sampling into the first register (i.e., the execution of the first subset). After the target sensor completes one cycle of sampling (i.e., the first subset of execution is completed), the first data in the first register is read and processed in a plurality of times, and the processed first data is stored in the first target register (one of the second register and the third register). In the execution process of the first subset or the second subset, if the first register or the first target register is directly read, the read first data is incomplete, so that when a data acquisition request is received, an address pointer of the second target register different from the first target register is sent to the DMA module, and the DMA module uploads the first data in the second target register to the upper computer. As can be seen from the foregoing, during each round of execution of the first instruction set, the corresponding first target register is switched between the first register and the second register as the number of rounds increases. Therefore, the second target register is actually a register in which the first instruction set finally stores the processed first data during the previous round of execution, and the complete processed first data obtained by the previous round of sampling is stored in the second target register, so that the DMA module uploads the complete processed first data to the upper computer all the time.
In an exemplary embodiment of the present application, the upper computer sends a data acquisition request to the single chip microcomputer according to a set frame interval, and the set frame interval is set according to a communication protocol (i.e., a first communication protocol) between the upper computer and the single chip microcomputer. The target sensor outputs the first data at a set period.
And the duration corresponding to the set frame interval is less than the duration corresponding to the set period and less than the execution duration corresponding to the first instruction set. In this embodiment, the set period is greater than 100 microseconds. The frame interval is set to 60 microseconds. And the execution duration of the first subset is set according to the set period so as to ensure that the target sensor can be subjected to successive sampling of a complete period.
Since the execution of the first instruction set includes both the sampling task and the processing task, the execution duration corresponding thereto is longer than the duration corresponding to the set period. Because the execution duration corresponding to the first instruction set is longer than the duration corresponding to the set frame interval, a data acquisition request may be received more than once in the whole cycle of the execution of the first instruction set, and at this time, in the same cycle, when the data acquisition request is acquired for the second time or for the following times, the address pointer of the second target register corresponding to the first time of acquiring the data acquisition request is still sent to the DMA module. At the moment, the upper computer receives the same first data twice so as to prevent the upper computer from reporting errors due to the fact that the upper computer does not receive the feedback data of the single chip microcomputer. Therefore, the host computer is configured to ignore the first data received later if the same first data is received. It should be noted that, the first data sampled in the execution process of the first instruction set all have corresponding timestamps, and therefore, when the upper computer acquires the first data which is the same as the previous time and ignores the first data, as long as the first data with the correct timestamp can be acquired in a later period, it can be ensured that the first data received by the upper computer is complete and meets the requirements of real-time performance and time sequence.
According to an aspect of the present application, there is provided a single chip microcomputer including: the system comprises a central processing unit, a timer, a CRC hardware module, a DMA module and a memory;
the memory is connected to the central processor, the memory storing instructions executable by the central processor, the instructions being arranged to perform the method of any of the preceding claims.
According to an aspect of the present application, there is provided a computer-readable storage medium having stored thereon computer-executable instructions for performing the method of any of the preceding claims.
The above description is only for the specific embodiment of the present invention, but the scope of the present invention is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present invention are included in the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (10)

1. A data sampling method in an encoder is characterized in that the method is applied to a single chip microcomputer, and the single chip microcomputer comprises the following steps: a central processing unit and a timer; the single chip microcomputer is in communication connection with the target sensor;
the method comprises the following steps:
step S100, the central processing unit responds to the receiving of the trigger signal and determines the number of the received trigger signal; the trigger signal is sent by the timer every other first set time length;
step S200, the central processing unit executes a first instruction set corresponding to the number of the received trigger signals in the first instruction set; the first instruction set comprises a plurality of first instruction sets, each first instruction set comprises a plurality of assembly instructions, and the execution time of at least part of the first instruction sets is less than the first set time; when the first set of instructions is executed, the central processor samples first data output by an output of a target sensor;
step S300, the central processing unit executes a second instruction set under the condition that the execution of the current first instruction set is finished and a next trigger signal is not received; the second instruction set, which includes a number of assembly instructions, has a lower execution priority than the first instruction set.
2. The method of sampling data within an encoder of claim 1,
the step S300 includes:
step S310, the central processing unit determines whether a second instruction set is suspended to be executed or not when the current first instruction set is executed and the next trigger signal is not received; if yes, go to step S311; otherwise, go to step S312;
step S311, resuming the execution of the suspended second instruction set;
step S312, executing a third instruction set; the execution priority of the third instruction set is lower than that of the first instruction set, and the third instruction set comprises a plurality of assembly instructions;
the method further comprises the following steps:
step S400, if the central processing unit receives the trigger signal during the execution of the second instruction set, the execution of the second instruction set is suspended, and the step S100 is executed again.
3. The method of sampling data within an encoder of claim 1, wherein said central processor further processes said sampled first data when said first set of instructions is executed;
the processing the first data obtained by sampling includes:
and performing CRC check on the first data and performing reverse order processing on the first data.
4. The method of sampling data in an encoder of claim 3, wherein the single chip further comprises a CRC hardware module;
the performing a CRC check on the first data includes:
sending the first data to the CRC hardware module so that the CRC hardware module performs CRC check on the first data;
and receiving a check result sent by the CRC hardware module.
5. The method of claim 4, wherein said inverse processing the first data comprises:
sending the first data and the check parameter to a CRC hardware module;
receiving the processed data sent by the CRC hardware module;
when the CRC hardware module executes CRC check by using the check parameters, a generating polynomial used by the CRC check is 1, a check initial value is 0, a result exclusive OR value is 0, and the data output sequence is in a reverse order.
6. The method of sampling data in an encoder according to claim 1, wherein the first set duration is 1-3 μ sec.
7. The method of claim 6, wherein each of the first set of instructions is executed for a duration less than a third set duration, the third set duration being less than the first set duration.
8. The method of sampling data in an encoder according to claim 7, wherein the third predetermined time period is 0.1-0.3 μ sec.
9. A single chip microcomputer is characterized by comprising: the system comprises a central processing unit, a timer, a CRC hardware module and a memory;
the memory is connected to the central processor, the memory storing instructions executable by the central processor, the instructions being arranged for performing the method of any of the preceding claims 1-8.
10. A computer-readable storage medium having stored thereon computer-executable instructions for performing the method of any of the preceding claims 1-8.
CN202210255787.0A 2022-03-16 2022-03-16 Data sampling method in encoder, single chip microcomputer and storage medium Active CN114328002B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210255787.0A CN114328002B (en) 2022-03-16 2022-03-16 Data sampling method in encoder, single chip microcomputer and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210255787.0A CN114328002B (en) 2022-03-16 2022-03-16 Data sampling method in encoder, single chip microcomputer and storage medium

Publications (2)

Publication Number Publication Date
CN114328002A CN114328002A (en) 2022-04-12
CN114328002B true CN114328002B (en) 2022-05-20

Family

ID=81034038

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210255787.0A Active CN114328002B (en) 2022-03-16 2022-03-16 Data sampling method in encoder, single chip microcomputer and storage medium

Country Status (1)

Country Link
CN (1) CN114328002B (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109710312A (en) * 2018-12-13 2019-05-03 华东计算技术研究所(中国电子科技集团公司第三十二研究所) RISC-V instruction set based real-time interrupt processing method and device and industrial control processor
CN110147300A (en) * 2019-05-23 2019-08-20 苏州浪潮智能科技有限公司 A kind of detection method of hardware state, system and associated component
CN110851384A (en) * 2018-08-21 2020-02-28 北京嘉楠捷思信息技术有限公司 Interrupt processing method, system and computer readable storage medium

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110851384A (en) * 2018-08-21 2020-02-28 北京嘉楠捷思信息技术有限公司 Interrupt processing method, system and computer readable storage medium
CN109710312A (en) * 2018-12-13 2019-05-03 华东计算技术研究所(中国电子科技集团公司第三十二研究所) RISC-V instruction set based real-time interrupt processing method and device and industrial control processor
CN110147300A (en) * 2019-05-23 2019-08-20 苏州浪潮智能科技有限公司 A kind of detection method of hardware state, system and associated component

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
"Embedded RTOS Implementation for Twin Nano-Satellite STUDSAT-2";Kamal Lamichhane, Kiran M. 等;《IEEE》;20151231;第1-6页 *
"FreeRTOS-stm32f407学习笔记-任务特点";ly璇;《https://blog.csdn.net/CSDN6233/article/details/113631507》;20210204;第1-3页 *
"STM32单片机基础16——使用硬件CRC校验数据(以SHT30为例)";小熊派开源社区;《https://blog.csdn.net/BearPi/article/details/104311583》;20200214;第1-6页 *

Also Published As

Publication number Publication date
CN114328002A (en) 2022-04-12

Similar Documents

Publication Publication Date Title
CN114328003B (en) Method for realizing data reverse order processing through CRC hardware module
CN103279371B (en) A kind of many methods from the upgrading of machine program on-line synchronous of dcs
CN111984395B (en) Data migration method, system and computer readable storage medium
KR20060089505A (en) Apparatus and method for controling dma
EP3076293A2 (en) Control apparatus
US10877803B2 (en) Control apparatus, control method and non-transitory storage medium
CN105527881A (en) Command processing method and device
JP2016194830A (en) Control device
CN110363980B (en) LoRa acquisition device based on TDMA and Contiki and acquisition method thereof
CN114328002B (en) Data sampling method in encoder, single chip microcomputer and storage medium
US20130145025A1 (en) Programmable controller
CN114328321B (en) Data sampling and communication method in encoder, single chip microcomputer and storage medium
CN114327631B (en) Data sampling and storage method in encoder, single chip microcomputer and storage medium
CN112418412B (en) Trigger device and brain-like computing system
CN115277284B (en) Communication method, communication device, communication system, and computer-readable storage medium
CN106850596B (en) Data acquisition system and method
CN115904719A (en) Data acquisition method and device, electronic equipment and storage medium
CN113094305B (en) Asynchronous communication processing method, device and storage medium
US5812878A (en) System for DMA transfer wherein controller waits before execution of next instruction until a counter counts down from a value loaded by said controller
CN112714454B (en) Monitoring method of wireless sensor network and related equipment
CN114285766A (en) Network bandwidth detection method and device, electronic equipment and storage medium
CN111262757A (en) Network diagnosis parameter display method, device, motor driver, system and medium
CN106371966B (en) Collecting monitoring data related to operation of a data processing system
CN113934671B (en) Interface control chip and network equipment
WO2021181682A1 (en) Master device and communication method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CP01 Change in the name or title of a patent holder

Address after: No.12, Saida 4th branch road, economic development zone, Xiqing District, Tianjin

Patentee after: Tianjin Yike Automation Co.,Ltd.

Address before: No.12, Saida 4th branch road, economic development zone, Xiqing District, Tianjin

Patentee before: ELCO (TIANJIN) ELECTRONICS Co.,Ltd.

CP01 Change in the name or title of a patent holder
CP02 Change in the address of a patent holder

Address after: No. 12 Saida Fourth Branch Road, Xiqing Economic and Technological Development Zone, Xiqing District, Tianjin, 300385

Patentee after: Tianjin Yike Automation Co.,Ltd.

Address before: No.12, Saida 4th branch road, economic development zone, Xiqing District, Tianjin

Patentee before: Tianjin Yike Automation Co.,Ltd.

CP02 Change in the address of a patent holder