PWM Timer TIMER0 Learning notes

Source: Internet
Author: User

PWM Timer TIMER0 Learning notes:

First, the timer TIMER0 code used in the register. What these register functions are. What is the meaning of the bits involved in the initialization of these registers. : TCFG0 function is: Timer configuration register, you can set the first Prescaler frequency and the second prescaler frequency of the prescaler frequency factor.
The timer 0,1 uses the first Prescaler frequency device, and the timer 2,3,4 uses the second Prescaler frequency device.
Setting: 第0-7位. Meaning is: 65 = 01000001, set the first prescaler frequency coefficient of 65, the pclk=1m as a timer 0,1 clock source.
The second Prescaler frequency factor is not set because only timer 0 is used. The TCFG1 feature is: Configure the timer's clock selector (MUX).
It is a bit frequency for the timer to select the clock source.
Setting: Set the 2nd bit 00000100 meaning: the timer 0 selects 16 frequency divider, at this time the timer 0 clock source rate is 1/16mhz.
Tcon function: Used to control the start of timer 0,1,2,3,4, automatic loading, update tcntbn.
Settings: No. 0, 1, 3 bits. Meaning: The 1th bit is 1, then the value of tcntb0,tcmpb0 "manual" Update register TCNT0,TCMP0, used to set the timer 0 of the initial count and comparison values, updated after the 1th position 0. The No. 0 position 1, means to open the timer "switch", let the timer 0 work.
The 3rd position 1 indicates that the value in the Count register TCNT0 is reduced to 0 o'clock and automatically loads the values in the TCNTB0 registers to the TCNT0.
TCNTB0 function: Timer 0 count Buffer registers.
Set: 第0-31位, set to 62500.
Meaning: The register saves the user set the initial count value, the value is loaded into the TCNT0 to do since minus 1 operation, because the clock source is 1/16mhz= 62500HZ, so 62500 since minus 1 to 0 is 1s.
TCMPB0 Function: Timer 0 comparison registers. 
Settings: Not set.
Meaning: Mainly used for output PWM pulse width can be modulated clock signal.
TCNTO0 function: Timer 0 Count value registers.
Setting: No meaning is set: reading the register can get the value in the TCNT0 at this time.
Tint_cstat: function: Set timer 0,1,2,3,4 interrupt to enable and break state.
Setting: No. 0 Meaning: No. 0 position 1, indicating that timer 0 allows interrupts.
Second, please specify how the timer TIMER0 work clock frequency is how to produce. CPU through the Xxti pin to introduce the clock source, after the frequency multiplier and a series of frequency division to get pclk=66m,tcfg0 set the first Prescaler frequency divider for the 66,PCLK after the first Prescaler frequency converter to 1M ; Set the second bit of TCFG1 to let timer 0 select the clock selector switch 16 frequency divider, that gets the timer0 working frequency is 1/16m= 62500Hz.
Third, the timer Timer0 how the interruption is produced. Sets the No. 0 bit of the register Tint_cstat, allowing Timer0 to trigger interrupts. The value of the Timer0 TCNT0 count register is reduced to 0 to trigger the TIMER0 interrupt, and the TIMER0 interrupt is the interrupt signal in the VIC0. Set the 21st bit of the vic0intenable to Timer0 interrupt, set the Vic0intselect 21-bit to cause the TIMER0 to be IRQ-interrupted, and set the entry address Timer0 (int) of the interrupt processing function for the vic0vectaddr21= interrupt Asm_ Irq_handler.
In summary, Timer0 interrupted by: Timer enable interrupt--> Interrupt controller enable interrupt--> set interrupt for irq--> timer 0 trigger Interrupt--> Interrupt handler function--> jump back automatically load TCNT0 continue execution.
A brief description of what we will do when the sample code for this timer runs.
Print the character A-Z on the terminal, and when the TIMER0 triggers the interrupt, print the "+" number (there are spaces in the middle), while the buzzer rings and loops. The implementation of an arm code, it can run the horse lights (only 3 lights at the end) at the same time, accurate to every 2 seconds for the buzzer to ring, and if pressed K4 button to let the horse lamp is not used by the 4th light.  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.