s3c6410 pwm 学习

第一次自学直接看数据手册而不是大端的中文资料或者示例代码讲解。。不过这是大家必须要走过的过程。


开始吧!


The 6410 RISC microprocessor comprises of five 32-bit  timers. These timers are used to generate internal
interrupts to the ARM subsystem. In addition, Timers  0 and 1 include a PWM function (Pulse Width Modulation),
which can drive an external I/O signal. The PWM for timer 0 and 1 have an optional dead-zone generator
capability, which can be utilized to support a large current device. Timer 2, 3 and 4 are internal timers with no
output pins。

什么是 dead-zone?

百度了下,才知,死区时间是PWM输出时,为了使H桥或半H桥的上下管不会因为开关速度问题发生同时导通而设置的一个保护时段。通常也指pwm响应时间。

暂时我先不搞模电,接着看。

从上面知,定时器0和1有PWM功能,并且有驱动 I/O signal 的能力。


接着看

32.2 FEATURES
 
The Features supported by the PWM are as follows:
 
•   Five 32-bit Timers.
•   Two 8-bit Clock Prescalers providing first level of divi sion for the PCLK, Five Clock Dividers and Multiplexers
providing second level of division for the Prescaler clock and External Clocks.  
•   Programmable Clock Select Logic for individual PWM Channels.
•   Two Independent PWM Channels with Programmable Duty Control and Polarity.
•   Supports Auto-Reload Mode and One-Shot Pulse Mode.
•   Supports for external inputs to start PWM.
•   Dead Zone Generator on two PWM Outputs.
•   Supports DMA Transfers.
•   Optional Pulse or Level Interrupt Generation.
 
The PWM has two operation modes:
 
•  Auto-Reload Mode
Continuous PWM pulses are generated based on programmed duty cycle and polarity.
•   One-Shot Pulse Mode
Only one PWM pulse is generated based on programmed duty cycle and polarity.

PWM有2个功能,一个是自动加载模式,另外一个是单次脉冲模式(only one pulse)

下面是  PWMTIMER Clock Tree Diagram



Timers 0 and 1 share a programmable 8-bit prescaler that pr ovides the first level of division for the PCLK. Timer 2,
3, and 4 share a different 8-bit prescaler. Each timer has it s own, private clock-divider that provides a second level
of clock division (prescaler divided by 2, 4,8, or 16). Alternatively, the Timers select a clock source from an external
pin. Timers 0 and 1 can select the external clock TCLK0. Timers 2, 3, and 4 can select the external clock TCLK1.
Each timer has its own 32-bit down-counter which is driven by the timer clock. The down-counter is initially loaded
from the Timer Count Buffer register (TCNTBn). When the  down-counter reaches zero, the timer interrupt request
is generated to inform the CPU that the timer operation  is completed. When the timer down-counter reaches zero,
the value of corresponding TCNTBn c an be automatically reloaded into the  down-counter to start the next cycle.
However, if the timer stops, for example, by clearing the timer enable bit of TCONn during the timer running mode,
the value of TCNTBn will not be reloaded into the counter.


差不多就是将设置TCNTBn 设置值,然后减数计数器会自动装载这个值,不断递减,递减为0时,触发中断请求。并且只会又可以将TCNTBn的值自动加载进去。

However, if the timer stops, for example, by clearing the timer enable bit of TCONn during the timer running mode,
the value of TCNTBn will not be reloaded into the counter.


The Pulse Width Modulation function (PWM) uses the value of the TCMPBn register. The timer control logic
changes the output level when the down-counter value matc hes the value of the compare register in the time
control logic. Therefore, the compar e register determines the turn-on time (or turn-off time) of a PWM output.
The TCNTBn and TCMPBn registers are double buffered to allow the timer parameters to be updated in the
middle of a cycle. The new values will not take effect until the current  timer cycle completes.
A simple example of a PWM cycle is shown in the figure below.
 

对于PWM,TCMPBn寄存器用于设置比较值,,比如减法计数的时候,当减到此寄存器值的时候,输出反转。

1.   Initialize the TCNTBn with 159(50+109) and the TCMPBn with 109.  
2.   Start Timer by setting the start bit and manual update bit off.
The TCNTBn value of 159 is loaded into the down-counter, the output is driven low.
3.   When down-counter counts down to the value in the TCMPBn register 109,
the output is changed from low to high
4.   When the down-counter reaches 0,  the interrupt request is generated.  
5.   The down-counter is automatically reloaded with TCNTBn, which restarts the cycle.


上面说的很清楚了。


继续向下看,下图是预分频设置


继续看图


A timer (except the timer channel 4) has TCNTBn, TCNTn, TCMPBn and TCMPn. TCNTBn and TCMPBn are
loaded into TCNTn and TCMPn when the timer reaches 0.  When TCNTn reaches 0, the interrupt request will
occur if the interrupt is enabled. (TCNTn and TCMPn are t he names of the internal regi sters. The TCNTn registe
can be read from the TCNTOn register) 

上面是定时器实现,下面是PWM实现。

首先看图


1.   Enable the auto-reload feature. Set the TCNTBn  as 159(50+109) and the TCMPBn as 109. Set the manu
update bit and inverter bit(on/off). The manual update bit sets the TCNTn,TCMPn to the value of
TCNTBn,TCMPBn.  
And then, set TCNTBn,TCMPBn as 79(40+39) and 39.
2.   Start Timer by setting the start bit and manual update bit off.
3.   When TCNTn has the same value with TCMPn, the logic level of TOUTn is changed from low to high
4.   As soon as TCNTn reaches to 0, the interrupt request is generated.
5.   TCNTn and TCMPn are reloaded automatically with TCNTBn,TCMPBn as (79(40+39)) and 39. In the
ISR(interrupt service routine), the TCNTBn  and TCMPBn are set as 79(20+59) and 59.
6.   When TCNTn has the same value with TCMPn, the logic level of TOUTn is changed from low to high
7.   As soon as TCNTn reaches to 0, the interrupt request is generated.
8.   TCNTn and TCMPn are reloaded automatically with TCNTBn,TCMPBn as (79(20+59)) and 59. In the
ISR(interrupt service routine), auto-reload and interrupt request are disabled to stop the timer.  
9.   When TCNTn has the same value with TCMPn, the logic level of TOUTn is changed from low to high  
10.   Even when TCNTn reaches to 0, No interrupt request is generated.
11.   TCNTn is not any more reloaded and the timer is stopped because auto-reload is disabled.


初始化定时器方法

32.3.5 INITIALIZE TIMER (SETTING  MANUAL-UP DATA AND INVERTER)  
Because an auto-reload operation of the timer occurs when the down counter reaches to 0, a starting value of the
TCNTn has to be defined by the user at first. In this case, the starting value has to be loaded by the manual
update bit. Take the following steps to start a Timer;
 
1)   Write the initial value into TCNTBn and TCMPBn.
2)   Set the manual update bit of the corresponding timer.
(Recommended setting the inverter on/off bit (whether using inverter or not)).  
3)   Set the start bit of the corresponding timer  to start the timer and clear only manual update bit.





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值