EmbeddedRelated.com
Forums

TimerB OutputMode

Started by andre_chouinard March 3, 2005
I'm using timerB to generate two separate time intervals.

I looked at the TI examples notice they use OUTMOD_4 (toggle), and 
read the section on output modes in the msp430 manual. 

I don't quite understand the significance of the toggle mode?

Thanks. 




Beginning Microcontrollers with the MSP430

Hi,

--- In msp430@msp4..., "andre_chouinard"
<andre_chouinard@y...> wrote:
> 
> I'm using timerB to generate two separate time intervals.
> 
> I looked at the TI examples notice they use OUTMOD_4 (toggle), and 
> read the section on output modes in the msp430 manual. 
> 
> I don't quite understand the significance of the toggle mode?

The toggle mode is needed if not all the frequencies are equal (or
multiples of each other).

You set the timer in UP mode, and use the CCR1, CCR2 etc. to output
the PWM signals. You use the CCIFG1, CCIFG2, etc. interrupts to update
the CCR registers (if you want a 50% duty cycle, for instance, you'll
add half the period to CCRx on every CCIFGx interrupt).

HTH,
Patrick




The output modes dertermine what happens on the I/O pin associated with 
that timer compare. In toggle mode the output pin will change state at 
each compare event. So if you set output mode to toggle, running an 8MHz 
clock, and set a timer value of 4000 (clock cycles) then, in the ISR add 
4000 to the CCBRx register you will get a 1kHz waveform output.

Al

andre_chouinard wrote:

>I'm using timerB to generate two separate time
intervals.
>
>I looked at the TI examples notice they use OUTMOD_4 (toggle), and 
>read the section on output modes in the msp430 manual. 
>
>I don't quite understand the significance of the toggle mode?
>
>Thanks. 
>
>
>
>
>
>.
>
> 
>Yahoo! Groups Links
>
>
>
> 
>
>
>
>
>
>  
>


use the timer in continuous mode unless you are using a common PWM 
period and the PWM modes of the timer. The OP made no mention of PWM, 
simply two different time intervals, hence TBR + N gives one interval, 
TBR + m gives a second, irrespective of whether the clock overflows in 
the middle. Toggle can be used in continuous mode with ISR to generate 
any m/S ratio signal. Toggle can also be used to generate a single pulse 
by setting the output to a know state then setting it to toggle on compare.

Al

patrick_huesmann wrote:

>Hi,
>
>--- In msp430@msp4..., "andre_chouinard"
><andre_chouinard@y...> wrote:
>  
>
>>I'm using timerB to generate two separate time intervals.
>>
>>I looked at the TI examples notice they use OUTMOD_4 (toggle), and 
>>read the section on output modes in the msp430 manual. 
>>
>>I don't quite understand the significance of the toggle mode?
>>    
>>
>
>The toggle mode is needed if not all the frequencies are equal (or
>multiples of each other).
>
>You set the timer in UP mode, and use the CCR1, CCR2 etc. to output
>the PWM signals. You use the CCIFG1, CCIFG2, etc. interrupts to update
>the CCR registers (if you want a 50% duty cycle, for instance, you'll
>add half the period to CCRx on every CCIFGx interrupt).
>
>HTH,
>Patrick
>
>
>
>
>
>.
>
> 
>Yahoo! Groups Links
>
>
>
> 
>
>
>
>
>
>  
>


Hmmm... i'm actually very new to embeded programming. 

I'd really just like to use timerB to generate interrupts every 
~375us and ~10ms...

Heres what i'm doing...

void initialiseTimerB(void)
{
  TBCTL = TBSSEL_1 + TBCLR + TBIE;       
  TBCCTL5 =  OUTMOD_4 + CCIE;           
  TBCCTL6 = OUTMOD_4 + CCIE;		    
  TBCCR5 = 328;
  TBCCR6 = 12;
  TBCTL |= MC1;                         }

interrupt[TIMERB1_VECTOR] void timerB1 (void)
{
  switch( TBIV )
  {
    case 10:						  	
      P1OUT ^= 0x01;
      TBCCR5 += 328;   ~ 10msec		  		
      break;					
    case 12:						  	
      P1OUT ^= 0x01;				  	  
      TBCCR6 += 12;      ~375usec          
      break;	
    case 14: 
      //P1OUT ^= 0x01;                
  }
}

I don't think the above is correct, i'm trying to make sense of the 
example below, but I don't really understand where the '2' comes
from.

// P1.1 = CCR0 = 32768/(2*4) = 4096Hz
// P1.2 = CCR1 = 32768/(2*16) = 1024Hz
// P1.3 = CCR2 = 32768/(2*100) = 163.84Hz 


so does that mean the above will togle the pin every 244usec, 
976usec, 6.13 msec respectivly?

Hmmmm...


--- In msp430@msp4..., "patrick_huesmann" 
<patrick.huesmann@g...> wrote:
> 
> Hi,
> 
> --- In msp430@msp4..., "andre_chouinard"
> <andre_chouinard@y...> wrote:
> > 
> > I'm using timerB to generate two separate time intervals.
> > 
> > I looked at the TI examples notice they use OUTMOD_4 (toggle), 
and 
> > read the section on output modes in the
msp430 manual. 
> > 
> > I don't quite understand the significance of the toggle mode?
> 
> The toggle mode is needed if not all the frequencies are equal (or
> multiples of each other).
> 
> You set the timer in UP mode, and use the CCR1, CCR2 etc. to output
> the PWM signals. You use the CCIFG1, CCIFG2, etc. interrupts to 
update
> the CCR registers (if you want a 50% duty cycle,
for instance, 
you'll
> add half the period to CCRx on every CCIFGx
interrupt).
> 
> HTH,
> Patrick