刚学cc2541,谁能给出个配置pwm输出的代码,最好有注释,万分感激。
刚学cc2541,谁能给出个配置pwm输出的代码,最好有注释,万分感激。
如:将一个管脚设置成pwm输出,可以更改占空比。
Joney,
非常好的想法。
我也希望所有的问题都有一个回答的模板呢:)
PWM并不复杂,你只要照CC2541 的user guide去配置寄存器,并没你想象那么难:)
尝试一下吧:)
9.1 16-Bit Counter
The timer consists of a 16-bit counter that increments or decrements at each active clock edge. The
period of the active clock edges is defined by the register bits, CLKCONCMD.TICKSPD, which set the
global division of the system clock, giving a variable clock-tick frequency from 0.25 MHz to 32 MHz (given
the use of the 32-MHz XOSC as clock source). This frequency is further divided in Timer 1 by the
prescaler value set by T1CTL.div. This prescaler value can be 1, 8, 32, or 128. Thus, the lowest clock
frequency used by Timer 1 is 1953.125 Hz and the highest is 32 MHz when the 32 MHz XOSC is used as
system clock source. When the 16-MHz RCOSC is used as system clock source, then the highest clock
frequency used by Timer 1 is 16 MHz.
The counter operates as a free-running counter, a modulo counter, or an up-and-down counter for use in
center-aligned PWM.
It is possible to read the 16-bit counter value through the two 8-bit SFRs, T1CNTH and T1CNTL, containing
the high-order byte and low-order byte, respectively. When T1CNTL is read, the high-order byte of the
counter at that instant is buffered in T1CNTH so that the high-order byte can be read from T1CNTH. Thus,
T1CNTL must always be read first, before reading T1CNTH.
All write accesses to the T1CNTL register reset the 16-bit counter.
The counter produces an interrupt request when the terminal count value (overflow) is reached. It is
possible to start and halt the counter with T1CTL control register settings. The counter is started when a
value other than 00 is written to T1CTL.MODE. If 00 is written to T1CTL.MODE, the counter halts at its
present value.
http://www.deyisupport.com/question_answer/wireless_connectivity/bluetooth/f/103/t/58384.aspx