1. Field of the Invention
The invention generally relates to a microcontroller, and more particularly to a method of speeding up the execution of repeatable commands and a microcontroller able to speed up the execution of repeatable commands.
2. Description of the Related Art
A commercial available microcontroller has main functions such as command retrieve, command decoding, command execution and data access. As the technology level of manufacturing microcontroller increases, clock cycle is not the bottleneck of manufacturing command execution circuits. Instead, the main factor affecting the performance of the microcontroller is the retrieval of program commands.
When the microcontroller executes commands, it retrieves commands from a command storage device. At present, the most commonly used command storage device is flash memory and EEPROM. 45 ns˜70 ns of clock speed is typical for the above storage device and is insufficient to match the clock cycle of the microcontroller, thereby deteriorating the performance of the microcontroller.
Even though some approaches such as pre-storing command, diverse detection have been provided to increase the performance of the microcontroller, still they only achieve subtle improvement because of the limitation by the complicated configuration of such microcontroller.
Repeatable commands of a program are temporarily stored in a command register with a fast access speed. When the program is executed to continue the repeatable commands, the stored commands are retrieved and run with higher clock frequency, so as to speed up the execution of the repeatable command and the performance of the microcontroller.
In order to achieve the above and other objectives, a microcontroller able to speed up the execution of repeatable commands includes a command memory used to store a program in order to provide a program command, wherein the program includes at least a repeatable command loop; a command register used to temporarily store the repeatable command loop; a command selecting unit connected to the command memory and the command register so that the command memory retrieves the program command or retrieves the repeatable command loop from the command register; a frequency selecting unit used to switch between a first frequency and a second frequency, wherein the second frequency is higher than the first frequency; and a command processor connected to the command register, the command selecting unit, and the frequency selecting unit. The command processor copies the repeatable command loop to the command register so as to control the command selecting unit to retrieve the program commands or the repeatable command loop. When the command processor has to repeatedly execute the repeatable command loop, the command selecting unit is made to retrieve the repeatable command loop from the command register, and the frequency selecting unit provides the second frequency to process the repeatable command loop. When the command processor has no need to repeatedly execute the repeatable command loop, the command selecting unit retrieves the program command from the command memory so that the frequency selecting unit provides the first frequency to process the program command.
The invention further provides a microcontroller able to speed up the execution of repeatable commands. The microcontroller include a command memory used to store a program in order to provide a program command, wherein the program includes at least a repeatable command loop; a data memory, including a universal data memory used to store data and a scratchpad RAM used to store data or temporarily store the repeatable command loop; a command selecting unit connected to the command memory and the command register so that the command memory can retrieve the program command or so that the repeatable command loop can be retrieved from the command register; a frequency selecting unit used to select one of a first frequency and a second frequency, wherein the second frequency is higher than the first frequency; and a command processor connected to the scratchpad RAM, the command selecting unit and the frequency selecting unit so that the repeatable command loop can be copied to the scratchpad RAM, thereby controlling the command selecting unit to receive the program command or the repeatable command loop. When the command processor needs to repeatedly execute the repeatable command loop, the command selecting unit retrieves the repeatable command loop from the scratchpad RAM and control the frequency selecting unit to provide the second frequency to process the repeatable command loop. When the command processor has no need to repeatedly execute the repeatable command loop, the command selecting unit retrieves the program command from the command memory and controls the frequency selecting unit to provide a first frequency to process the program command.
The invention further provides a method of speeding up the execution of repeatable commands. The method includes steps of (a) retrieving a program command for a program from a command memory, wherein the program includes at least one repeatable command loop; (b) processing the program command and detect if it is the starting point of the repeatable command loop; (c) if the command is at the starting point of the repeatable command loop, then copy the command to a command register, wherein the command register's data storage speed is faster than the command memory's data storage speed; (d) the command process retrieves a subsequent program command; (e) processing the subsequent program command and determine whether the subsequent command is at an end point of the repeatable command loop or not; if the subsequent program command is not at the end point of the repeatable command loop, then copy the subsequent command and go back to step d; (f) if the subsequent program command is at the end point of the repeatable command loop, then determine whether the execution of the repeatable command loop continues or not; (g) if the execution of the repeatable loop will continue, then copy the program command to the command register and switching the clock cycle frequency from the first frequency to the second frequency, wherein the second frequency is higher than the first frequency; and (h) retrieving the repeatable command loop from the command register and executing the repeatable command loop at the second frequency.
To provide a further understanding of present invention, the following detailed description illustrates embodiments and examples of present invention, this detailed descriptions are provided for illustrative purpose only and are not meant to limit the scope of present invention.
Wherever possible in the following description, like reference numerals will refer to like elements and parts unless otherwise illustrated.
Command processor 11 is connected respectively to frequency selecting unit 15, command selecting unit 12, and command register 14. Command processor 11 controls via command selecting unit 12 to retrieve program commands of command memory 13 for processing, if it is a repeatable command loop that is being processed, then the repeatable command loop is copied to command register 14 while being processed. And when the last command of the repeatable command loop is processed; it is detected whether execution of the repeatable command loop shall start again. If the execution of the repeatable command loop shall start again then frequency selecting unit 15 switches from the first frequency to the second frequency, and command selecting unit 12 retrieves the repeatable command loop from command register 14 so as to process the repeatable command loop at the second frequency.
Command processor 11 detects the starting and end points of the repeatable command loop according to a special command in the program.
The repeatable command loop includes a starting point and an end point. The starting point is defined at the start of the repeatable command loop and used for the command processor to identify a starting position of the repeatable command loop. The end point is defined at the end of the repeatable command loop and used for the command processor to identify an end position of the repeatable command loop.
The start of the subprogram is defined as a starting point of a repeatable command loop, in order to notify command processor 11 that this is where the repeatable command loop starts, so as to start recording command code to command register 14; an end of the subprogram is defined as an end point of a repeatable command loop. Furthermore, the end point of the repeatable command loop includes a repeatable command loop assessment command. The repeatable command loop assessment command has a go-to command condition which is defined by condition at the end of the subprogram. The end point of the repeatable command loop notify command processor 11 of the repeatable command loop's ending time, and at this moment it determines if the execution of the repeatable command loop continues. If the go-to command condition of the repeatable command loop is met, command processor unit 11 processes the repeatable command loop in command register 14 at the second frequency. If the condition is not met, command processor 11 controls command selecting unit 12 to retrieve a subsequent program command from command memory 13 so as to process subsequent program command at the first frequency.
The microcontroller further includes a data memory 24, including a universal data memory 241 and a scratchpad RAM 242. Universal data memory 241 is used to store data which will be accessed for processor 11 to process. Scratchpad RAM 242 is used to store data which will be accessed for processor 11 to process, or temporarily store the repeatable command loop for command processor 11 to process. When scratchpad RAM 242 is used to temporarily store the command loop, it will not allow access by command processor 11. Data memory 24 has an access speed higher than command memory 13. Command selecting unit 12 is connected to command memory 13 and scratchpad RAM 242. Under the control of command processor 11, command selecting unit 12 would retrieve the program command from command memory 13, or retrieve a command of the repeatable command loop from scratchpad RAM 242 for command processor 11 to process. Data selecting unit 26 is connected to universal data memory 241 and scratchpad RAM 242. Under the control of command processor 11, data selecting unit 26 would access universal data memory 241 or scratchpad RAM 242.
Command processor 11 is connected to data selecting unit 26, scratchpad RAM 242, command selecting unit 12 and frequency selecting unit 15. Command processor 11 controls the command selecting unit to receive the program command or the repeatable command loop. When command processor 11 needs to repeatedly executes the repeatable command loop, command selecting unit 12 retrieves the repeatable command loop from scratchpad RAM and control the frequency selecting unit to provide the second frequency to process the repeatable command loop. While the command processor has no need to repeatedly execute the repeatable command loop, the command of the repeatable command loop is copied to scratchpad RAM 242. When the last command of the repeatable command loop is processed in command processor 11, it is detected whether execution of the repeatable command loop continues. If the execution of the repeatable command loop continues, then frequency selecting unit 15 switches the first frequency to the second frequency and command selecting unit 12 retrieves command of the repeatable command loop from scratchpad RAM 242 so as to process the repeatable command loop at the second frequency. If the execution of the repeatable command loop ends, then command processor 11 controls command selecting unit 12 to retrieve the subsequent program command from command memory 13 and processes the subsequent command at first frequency; and, the repeatable command loop stored in scratchpad RAM 242 will be discarded.
The ways that command processor 11 detects the starting point and the end point of the repeatable command loop and whether the execution of the repeatable command loop continues or not are the same as the embodiment referred to in
When the command of the repeatable command loop is executed, command processor 11 decodes the commands of the repeatable command loop to detect whether the loop will end (Step 419). If YES, then go to Step S417. If NO, then command processor 11 controls frequency selecting unit 15 to switch back to its original clock cycle frequency (Step S421). Afterward, go back to Step S401.
Command register 14 above can be scratchpad RAM 242 of data memory 24 as shown in the embodiment referred to in
In light of above, the microcontroller retrieves the commands by the command memory since it starts the command execution. The command memory clock cycle is slower. When the repeatable command loop is executed, the repeatable command loop is stored in the command register (or scratchpad RAM) which runs more quickly than the command memory. Therefore, when the execution of the repeatable command loop continues, the subsequent command is retrieved from the command register or the scratchpad RAM and then processed at higher frequency, thereby achieving speeding up the execution of the repeatable commands.
It should be apparent to those skilled in the art that the above description is only illustrative of specific embodiments and examples of present invention. Present invention should therefore cover various modifications and variations made to the herein-described structure and operations, provided that they fall within the scope of the present invention as defined in the following appended claims.
Number | Date | Country | Kind |
---|---|---|---|
96119849 | Jun 2007 | TW | national |