A brief introduction to the timer A function of the 430 microcontroller[Copy link]
In general, the 430 microcontroller has three timers, timer A, timer B, and watchdog timer. Here we mainly discuss the function of timer A of the 430 microcontroller. The function of timer A is the most powerful timer I have ever seen. The video says that if you use timer A well, it will be of great significance for truly mastering 430 in the future. Let me first introduce the characteristics of timer A: (Common writing methods for science articles in English level 6, total score) 1: Can be used as an asynchronous 16-bit timer, 16-bit counter, the counter has four working modes 2: Adjustable external clock source 3: 3 capture comparison sources 4: Has the function of output PWM 5: Asynchronous input and output latches 6: Multiple interrupt sources In fact, I have really mastered the method by reading the datasheet now. After reading the introduction, the key is to understand the following picture, and be familiar with the operation of related registers when programming And there is also a sequence for looking at the pictures, because the machine is dead and depends on the vibration of the crystal oscillator to operate, so when looking at the picture, you can look at it according to the main line of the clock source First, focus on number 1. Feature 2 talks about the adjustable external clock source. There are 4 types of clock sources that can be used. Then label 2 is a divider, which can perform three types of frequency division. Then label 3 is a 16-bit workspace, which is an add-one counter. Then label 4 is a counter. The counter has four counting modes. Here we still need to pay attention to the blue control bit. The TACLR control bit is the reset control bit of the counter and timer. If this bit is set, the clock source, division ratio, and direction of the counter need to be reset. Set TAIFG is the interrupt flag of the counter.
The next part is the highlight, capture comparison, label 5 is the comparison source of capture mode, there are four capture mode options Label 6 is a capture clock source synchronization selection, generally choose to be consistent with the internal clock to avoid internal resource conflicts Label 7 is a capture register, used to store different timestamps, and then calculate the length of the pulse width Label 8 is a latch bit Label 9 is used to select capture mode or comparison mode Label 10 is used to output various control waveforms, such as PWM waveforms, etc. Next, according to the common method of reading science in CET-6, we come to the structure of points and the introduction of the timer mode of 430. Actually, there is nothing much to say about the timer. It just has a clock source and the division ratio can be set to get the timing effect required by the user. It should be noted that when TACLR is set, the external clock source and the division ratio will be cleared. When using them again, the user needs to reset them, so the operation of this bit needs to be cautious. Next, we will introduce the counter mode. 430 provides three counting modes: up counting mode, continuous counting mode and up-down counting mode. In the up-counting mode, it should be noted that the up-counting mode is similar to the continuous counting mode, both of which output sawtooth waveforms, but their peak values are different, because the peak value of the up-counting mode is set by the user, and the set value is stored in the TACCR0 register, but the peak value of the continuous counting mode is fixed, and it keeps counting until all 16 bits overflow, so the peak value is 0xffff
As shown in the figure, 1 represents the up-counting mode, and 2 represents the continuous counting mode It is worth noting that when the value is in the up-counting mode, if the value on TACCR0 is suddenly changed, it means that the peak value is changed. Suppose the original peak value A becomes peak value B If the peak value B is smaller than the peak value A, the counter will immediately become 0 and the technique will be restarted. If the peak value B is larger than the peak value A, the counter will exceed A and keep increasing B.After it becomes 0, it outputs a sawtooth wave with a peak value of B. Next is the increase and decrease counting mode, which is more interesting. It can get a triangular wave, as shown in the figure:
Note that the peak value of the triangular wave can also be adjusted, and the triangular wave technology has memory, so you need to pay attention when using it. The so-called memory means that when A pauses, it will pause, and after resuming, the counting direction will not change Next is to select capture mode or comparison mode, which is selected by the CAP control bit When working in capture mode, the microcontroller captures the preset pulse and records the timestamp of the pulse. The two timestamps are then subtracted to obtain the pulse width. However, if the timestamp is not removed in time, repeated capture will occur, and the timestamp of the last time will be overwritten. The comparison mode is usually CAP = 0. When the timer works in comparison mode, it is usually used to output PWM waveforms. At this point, most of the functions of timer A have been understood, but there is still one most important module, which is the pulse output module. Timer A can output a large number of waveforms that users can choose from. This function is really super powerful. This output module requires very specific engineering practice skills and a deep theoretical foundation. But when needed, when output waveforms are needed, MSP430 can be given priority.