Mark Stokes wrote:
Does anyone have any example code that uses Timer_B for say a pwm or a
fixed say 0.1ms pulse?
I'm looking to use Timer_B for two purposes (either or):
1. Generate say 10 fixed 0.1ms pulses. I assume to be counted via IRQ.
2. Generate a 50% duty cycle pulse with a varying frequency.
I've read over the docs in the MSP430 manual about 500 times and it's
still eluding me how to use the Compare mode. I have the capture mode
working perfectly (for Timer_A). I have read through Mark Buccinni's
examples available on TI.com but they are so very basic as to not
really help at all (basically 5 examples of the exact same thing).
Any help would be greatly appreciated.
Here is an example of using Timer B for PWM, plucked from some code I
use on a 43x:
I set things up like so:
#define PWM_freq 200 /* define
PWM period */
int PWM_duty;
P2SEL |= BIT2; /* Select P2.2 for PWM output */
P2DIR |= BIT2; /* Select P2.2 for PWM output */
TBCCR0 = PWM_freq; /* load period register */
PWM_duty = PWM_freq/2; /* start with 50% PWM duty cycle */
TBCCR1 = PWM_duty; /* load duty cycle register CCR1 */
TBCCTL0 = OUTMOD_4; /* set outmode 4 - toggle */
TBCCTL1 = OUTMOD_6 | CLLD_1; /* set outmode 6 - toggle/set */
/* load new CCR1 when TBR = 0 */
TBCTL = TBCLR | MC_1 | TBSSEL_2; /* start TIMER_B up mode, SMCLK
as input clock */
Then later on I manipulate the duty cycle by doing:
TBCCR1 = PWM_duty;
There should be no embarassment felt at failing to comprehend the MSP430
manual. Its WOD (write only documentation). :-)
Regards,
Steve