Peripheral functions that the microcontroller must understand - timer/interrupt function

In the previous issue of "Peripheral Functions Must Be Known by Microcontrollers - GPIO/Serial Communication" , we learned about the structure and usage of peripheral functions of the microcontroller. This article mainly introduces the timer interrupt function that the microcontroller must understand.

This serial will be described with the circuit board "GR-SAKURA" equipped with Renesas Electronics' RX63N as an example. Please try it out! Handle the processing of time and time in one hand!

In the single-chip microcomputer, not only the time display such as "â—‹â—‹â—‹â—‹â—‹â—‹â—‹â—‹" is frequently used, but the past time and a certain period are also frequently used. For example, "How long has the program passed since the start of the operation?", "Transmission of 128 signals per second" and so on. In addition, it is often used in the case of "waiting for a specified time" and "moving to the next processing after a specified time has elapsed". The peripheral functions that are handled in relation to time and time are the timers (Figure 1).

Figure 1: The timer is processing related to time and time.

Instead of using a timer for peripheral functions (hardware), we can calculate the time by software. An example of timing using software will be described below with reference to Fig. 2, which assumes that the processing of the loop (repetition) portion takes 1 μs (microseconds: 1 millionth of a second). From this, it can be calculated that it takes 1 ms (milliseconds: one thousandth of a second) to repeat the cycle for 1000 times, and it takes 1 second to repeat 1 million times. That is: the time is calculated by "waiting for the time specified by the loop processing". However, the CPU will concentrate on the processing of the time calculation and cannot perform other processing. Moreover, only one cycle of time can be calculated. In reality, the MCU needs to correspond to various cycles of 0.1 second and 1/1024 seconds.

In addition, the CPU's timer frequency (drive speed) will also have an impact on the software. If you change the 100MHz drive CPU to 50MHz, the time required to cycle once will be twice as long. Therefore, it is necessary to correct the software for calculating the time. As mentioned above, since it takes time and error in management, it is extremely difficult to avoid calculating time by software.

Figure 2: Example of a timer that is timed by software

Slightly introduce the contents of the interruption...

Below, we briefly introduce the technology that is inseparable from the timer - "interrupt function". The "interrupt function" in a single-chip microcomputer refers to a request for "starting other processing" for some reason during the execution of a program. Since the interrupt function can be used, the CPU can be made to concentrate on one process.

Let's imagine the use of the "interruption function" in daily life. When we pour hot water into the instant noodle box, if we keep staring at the clock for 3 minutes, then we can't do other things during this time. thing. But if you set the kitchen timer for 3 minutes, we can do other things before the kitchen timer alarm sounds. In this example, "always staring at the clock" is equivalent to the "waiting for the time specified by the loop processing" described in the previous section, so you can't do anything else until the end of the process. At the same time, the kitchen timer alarm is equivalent to the interrupt function. You can do other things before the interruption occurs.

There are various timers in the peripheral functions of the microcontroller. These timers send interrupt signals to the CPU at the specified time or at the end of processing. Not only are timers, but many peripheral functions transfer interrupt information to the CPU at the time of "change" and "process start/end". Therefore, the CPU can continue to do other work before the interrupt function occurs, thereby improving the work efficiency. The details of the interrupt function will be described in detail in the fourth issue of the external interrupt function IRQ. In this issue, we first know in advance the content of “transferring information from the peripheral function to the CPU in the form of an interrupt”.

Among the various timers, there is also a "watchdog timer"!

Among the peripheral functions of the microcontroller, the most intimate timer is a timer that calculates the specified time and a timer that interrupts at regular intervals. In addition, Renesas Electronics' RX63N MCU is equipped with a timer for generating a pulse width modulation/demodulation (PWM) signal for controlling the servo motor, a timer for calculating the input signal interval, and an RTC (Real Time Clock) for displaying the current time. A variety of timers.

Among the timers, the most distinctive one is the WDT (Watchdog Timer). The watch dog in its name Watch Dog TIme means "watchdog", its job is to monitor the program for out of control. The program monitored by the WDT is started by writing the set value to the WDT in advance. The WDT subtracts the written value at regular intervals. When the program runs normally, the WDT is cleared and then terminated before the processing ends. However, if the program is out of control (into an unexpected repetitive state and cannot be stopped), the value written to the WDT will be less than 0 (called underflow), thus notifying the CPU that the program has run out of control. In an important system that does not allow sleep, the "watchdog timer" - WDT installed in the microcontroller plays an extremely important role.

Try to use the timer easily

Although it says: "We actually use the timer through the program...", but in fact, in order to be proficient in using the timer, you must first understand the operating steps of the microcontroller. Moreover, it is necessary to understand not only the steps of operating through software, but also the hardware (structure) of the microcontroller and the specifications of the components used.

Therefore, please use the "database" when you need help. For the GR-SAKURA board equipped with the RX63N microcontroller, we have prepared several databases related to time and time.

Sketch parameters of SAKURA: Sakura library time (English only)

In this program, the LED on the GR-SAKURA is illuminated in a certain period. Although it is only a very simple operation, it is necessary to use a timer in order for the LED to emit light in the correct cycle. In the "Time" option of the above cherry blossom library, there is a database for calculating the elapsed time, so we use it.

The program is shown in Figure 3. The millis function on line 14 is sent back in milliseconds (milliseconds: one thousandth of a second) from the start of the program, with no parameters. Using this function, the result after 1 second and 2 seconds was obtained by obtaining the difference from the initial measurement (line 14). The loop is generated with the while language, waiting for 1 or 2 seconds from the value of a (line 15, line 19). Thus, LED0 (D1 of the GR-Sakura board) lights up after 1 second, and turns off after 2 seconds. The loop function ends when the light is off, but the operation continues again and again. In addition, the millis function has no symbol and will return a long integer.

Figure 3: Program that uses the timer function to turn the LED on. In this example, it flashes in a cycle of 1 second.

Program that uses the timer function to turn the LED on

※//~ is used for evaluation and does not affect the execution of the program.

Enter the program into the Web compiler and transfer the compiled binary to GR-SAKURA. After the transfer is completed, the four LEDs will be temporarily turned off before starting execution, and LED0 (D1 of the GR-Sakura board) starts flashing.

Let us explain one of the necessary peripheral functions "timer". The processing of time and time is required in all kinds of occasions. Please take this opportunity to actually operate various databases.

However, the numbers "128 times of leap seconds" and "1/1024 seconds" suddenly appear in the text. Did you surprise you? 128 is the 7th power of 2, and 1024 is the 10th power of 2. The RTC has the ability to generate an interrupt every 1/128th of a second... This is a number that is often seen in the world of microcontrollers.

SMT Motor

SMT Motor, original and new ,in stock, quality gaurantee.

SMT motor : actuator motor,servo motor, converyor motor,rail motor, bom stepping motor, rizing motor, Z camera motor, Y camera motor, X camera motor.



Smt Motors

Smt Juki Motors

Original Smt Servo Motor

Original Smt Motors

Holder For Smt Type

Smt Battery Holder

SMT Holder

Battery Holder

Filter For Smt Machine

High Quality Smt Filter

Smt Filter

Smt Machine Filter

Smt Tape Feeder Parts

Feeder Parts For Smt Machine

Smt Machine Spare Parts

Original SMT Feeder

Original SMT Cable

Smt Machine Cable

Smt Spare Parts Fuji Cable

Smt Cable

SMT Belt

Smt Siemens Belt

Smt Juki Belt

Smt Conveyor Belt

Smt Camera

Smt Laser

Camera For Smt

Smt Siemens Camera

Smt Parts Plastic Rail

Smt Plastic Rail

Smt Juki Plastic Rail

Juki Plastic Rail

SMT Nozzle For Yamaha

Yamaha Nozzle

Nozzles For Yamaha Machine

Smt Yamaha Nozzle

Smt SIEMENS Nozzle

Nozzles For Siemens Machine

Smt Nozzle For Siemens

Siemens Nozzle

Smt Nozzle For Samsung

SAMSUNG Nozzle

Nozzles For Samsung Machine

Smt Samsung Nozzle

Panasonic Nozzle

Smt Panasonic Nozzle

Smt Nozzle For Panasonics

Nozzles For Panasonic Machine

Smt Juki Nozzle

Nozzles For Juki Machine

Juki Nozzle

High Pressure Juki Nozzle

I-Pulse Nozzle

High Pressure I-pulse Nozzle

Nozzles For I-pulsemachine

Smt I-pulse Nozzle

High Pressure FUJI Nozzle

Nozzles For Fuji Machine

Fuji Nozzle

Smt Fuji Nozzle

Smt Nozzle

Smt Parts Nozzle

Smt Nozzle For Machine

Smt Spare Parts Nozzle

Yamaha Smt Feeder

YAMAHA Feeder

Smt Machineyamahafeeder

Smt Feeder For Yamaha

Smt Feeder For Siemens

Smt Machine SIEMENS Feeder

Siemens Smt Feeder

Siemens Feeder

Samsung Smt Feeder

Smt Machine SAMSUNG Feeder

Samsung Feeder

Smt Feeder For Samsung

Panasonic Smt Feeder

Panasonic Feeder

Smt Machine Panasonic Feeder

Smt Feeder For Panasonic

Smt Feeder For Juki

JUKI Feeder

Juki Smt Feeder

Smt Machine Juki Feeder

I-Pulse Feeder

Smt I-pulse Feeder

Smt Parts I-pulse Feeder

I-pulse Type Feeder

Pneumatic Feeder

FUJI Feeder

Smt Fuji Feeder

Fuji Smt Tape Feeder

Smt Machine Feeder

Smt Tape Feeder

Smt Feeder

Feeder For Smt Machine

Siemens Control Valves

Smt Siemens Valve

Siemens Vacuum Valve

Siemens Valves

Smt SAMSUNG Valve

Samsung Vacuum Valve

Samsung Control Valves

Samsung Valve

Juki Vacuum Valve

Juki Ejector

Juki Vacuum Ejector

Juki Valve








Smt Motors,Original Smt Motors,Smt Juki Motors,Original Smt Servo Motor

Shenzhen Srisung Technology Co.,Limited , https://www.sr-smts.com