Location:
Search - TIM2_CCR1
Search list
Description: 本例展示了如何利用外设TIM2来产生四路频率不同的信号。
TIM2时钟设置为36MHz,预分频设置为2,使用输出比较-翻转模式(Output Compare Toggle Mode)。
TIM2计数器时钟可表达为:TIM2 counter clock = TIMxCLK / (Prescaler +1) = 12 MHz
设置TIM2_CCR1寄存器值为32768,则CC1更新频率为TIM2计数器时钟频率除以CCR1寄存器值,为366.2 Hz。因此,TIM2通道1可产生一个频率为183.1 Hz的周期信号。
同理,根据寄存器TIM2_CCR2 、TIM2_CCR3和 TIM2_CCR4的值,TIM2通道2可产生一个频率为366.3 Hz的周期信号;TIM2通道3可产生一个频率为732.4 Hz的周期信号;TIM2通道4可产生一个频率为1464.8 Hz的周期信号。
可以通过示波器观察各路输出-This example demonstrates how to use peripherals TIM2 to generate four different signal frequencies. TIM2 clock set to 36MHz, pre-divider is set to 2, the use of output compare- flip model (Output Compare Toggle Mode). TIM2 counter clock can be expressed as: TIM2 counter clock = TIMxCLK/(Prescaler+ 1) = 12 MHz set TIM2_CCR1 register value is 32768, then cC1 update frequency for TIM2 counter clock frequency divided by the value of CCR1 register for 366.2 Hz. Therefore, TIM2 channel 1 can generate a frequency of 183.1 Hz for the periodic signal. Similarly, under the register TIM2_CCR2, TIM2_CCR3 and TIM2_CCR4 value, TIM2 channel 2 can have a frequency of 366.3 Hz cycle signal TIM2 channel 3 can have a frequency of 732.4 Hz cycle signal TIM2 Channel 4 can produce a frequency of 1464.8 Hz cycle signal. Can be observed through the oscilloscope various output
Platform: |
Size: 209920 |
Author: chen |
Hits:
Description: 本例展示了如何设置TIM工作在输出比较-非主动模式(Output Compare Inactive mode),并产生相应的中断。
TIM2时钟设置为36MHz,预分频设置为35999,TIM2计数器时钟可表达为:
TIM2 counter clock = TIMxCLK / (Prescaler +1) = 1 KHz
设置TIM2_CCR1寄存器值为1000, CCR1寄存器值1000除以TIM2计数器时钟频率1KHz,为1000毫秒。因此,经过1000毫秒的时延,置PC.06输出为低电平。
同理,根据寄存器TIM2_CCR2 、TIM2_CCR3和 TIM2_CCR4的值,经过500毫秒的时延,置PC.07输出为低电平;经过250毫秒的时延,置PC.08输出为低电平;经过125毫秒的时延,置PC.09输出为低电平。
输出比较寄存器的值决定时延的大小,当计数器的值小于这个值的时候,点亮与PC.06-PC.09相连的LED;当计数器的值达到这个值得时候,产生中断,在TIM2的4个通道相应的中断里,把它们一一关闭。-err
Platform: |
Size: 218112 |
Author: chen |
Hits:
Description: 本例展示了如何利用外设TIM2来产生四路频率不同的信号。
TIM2时钟设置为36MHz,预分频设置为2,使用输出比较-翻转模式(Output Compare Toggle Mode)。
TIM2计数器时钟可表达为:TIM2 counter clock = TIMxCLK / (Prescaler +1) = 12 MHz
设置TIM2_CCR1寄存器值为32768,则CC1更新频率为TIM2计数器时钟频率除以CCR1寄存器值,为366.2 Hz。因此,TIM2通道1可产生一个频率为183.1 Hz的周期信号。
同理,根据寄存器TIM2_CCR2 、TIM2_CCR3和 TIM2_CCR4的值,TIM2通道2可产生一个频率为366.3 Hz的周期信号;TIM2通道3可产生一个频率为732.4 Hz的周期信号;TIM2通道4可产生一个频率为1464.8 Hz的周期信号。
可以通过示波器观察各路输出。-This example shows how to use peripherals the TIM2 to produce four different frequencies of the signal. The TIM2 clock is set to 36 MHz, the prescaler is set to 2, use the output- flip mode (Output Compare Toggle Mode). TIM2 counter clock can be expressed as: TIM2 is counter clock = TIMxCLK/(prescaler. Ppls1) to 12 MHz 32768 set TIM2_CCR1 register, the CC1 update frequency of the TIM2 the counter clock frequency divided by the CCR1 register value, 366.2 Hz,. Therefore, TIM2 channel 1 can produce a periodic signal with a frequency of 183.1 Hz. The same token, value register TIM2_CCR2, TIM2_CCR3 and TIM2_CCR4, TIM2 is channel 2 can produce a frequency of 366.3 Hz periodic signal TIM2 is channel 3 can produce a frequency of 732.4 Hz periodic signal TIM2 is channel 4 can produce a frequency of 1464.8 Hz periodic signal. Each output can be observed through the oscilloscope.
Platform: |
Size: 278528 |
Author: 彭富林 |
Hits:
Description: 本例展示了如何设置TIM,用它来测量一个外部输入信号的频率和占空比。
TIM2时钟设置为72MHz,预分频设置为0,TIM2计数器时钟可表达为:
TIM2 counter clock = TIMxCLK / (Prescaler +1) = 72 MHz,因此可测量的最小频率值为1100Hz。
设置TIM2工作在PWM输入模式(PWM Input Mode),把外部信号作为输入连接到TIM2通道2。
利用TIM2计数器中断来测量信号的频率和占空比。在TIM2_IRQHandler中,计算信号的频率和占空比,方法如下:
变量"Frequency"为由下式得到的外部信号频率:
Frequency = TIM2 counter clock / TIM2_CCR2 单位Hz
变量"Duty_Cycle"为由下式得到的外部信号占空比:
Duty_Cycle = (TIM2_CCR1*100)/(TIM2_CCR2) 单位
-This example shows how to set up the TIM, and use it to measure the frequency and duty cycle of an external input signal. TIM2 clock set to 72MHz and the prescaler is set to 0, TIM2 is counter clock can be expressed as: TIM2 is counter clock = TIMxCLK/(prescaler. Ppls1) = 72 MHz, the minimum measurable frequency value of 1100 Hz. Set TIM2 PWM input mode (PWM Input Mode), the external signal as an input connected to the the TIM2 Channel 2. TIM2 counter interrupt signal to measure frequency and duty cycle. Calculate the frequency and duty cycle of the signal in TIM2_IRQHandler as follows: variable " Frequency" on the grounds of the external signal frequency by the following formula: Frequency = TIM2 is counter clock/TIM2_CCR2 unit Hz variable Duty_Cycle " on the grounds of the following formula to get external duty cycle: Duty_Cycle = (TIM2_CCR1* 100)/(TIM2_CCR2) in
Platform: |
Size: 252928 |
Author: 彭富林 |
Hits: