Other Parts Discussed in Thread: MSP430FG4618
Hi there,
I'm new about MSP430 and I'm having problems to suceed at an exercise about Timer B.
I'm using Experimenter's Board, IAR and MSP430FG4618.
Experimenter's Board (EB)'s diagram says pin P2.1 is assigned to TB0 and it also has a LED.
My exercise demands that I load up everything needed about timer B to generate a PWM signal through this assigned pin. How does it possible?
I know that I have to set my Timer B as:
16bits.
ACLK = 32768Hz (TBSSEL_1)
Divided by 8 (ID_3).
UP Mode (MC_1)
OUTMODE is Reset/Set (OUTMOD_7)
And set CCR0 and CCR1 to give me a 75% duty cycle. The period doesn't matter yet.
I thought my code would work...
PS.: I haven't reached MSP430 with C yet, that's why it's in Assembly.
#include <msp430xG46x.h>
;-------------------------------------------------------------------------------
RSEG CSTACK ; Define stack segment
;-------------------------------------------------------------------------------
RSEG CODE ; Assemble to Flash memory
;-----------------------------------------------------------------------------
RESET mov.w #SFE(CSTACK),SP ; Initialize stackpointer
StopWDT mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop WDT
SetupFLL bis.b #XCAP14PF,&FLL_CTL0 ; Configure load caps
SetupP2 bis.b #BIT1,&P2SEL ; P2.1 Peripheral
bis.b #BIT1,&P2DIR ; P2.1 Output
SetupC0 mov.w #CCIE+OUTMOD_7,&TBCCTL0 ; TBCCR0 reset/set and interrupt enabled
mov.w #0x07FF,&TBCCR0 ; TBCCR0 100% flag
SetupC1 mov.w #CCIE+OUTMOD_7,&TBCCTL1 ; TBCCR1 reset/set and interrupt enabled
mov.w #0x03FF,&TBCCR1 ; TBCCR1 50% flag
SetupTB mov.w #TBSSEL_1+MC_1+ID_3+TBIE,&TBCTL ; ACLK, upmode, div by 8, INT
;
Mainloop bis.w #LPM3+GIE,SR ; Enter LPM3, interrupts enabled
nop ; Required only for debugger
;
;------------------------------------------------------------------------------
COMMON INTVEC ; Interrupt Vectors
;------------------------------------------------------------------------------
ORG RESET_VECTOR ; MSP430 RESET Vector
DW RESET ;
ORG TIMERB0_VECTOR ; Timer_B0 Vector, but not used.
DW TB0_ISR ;
END
Making a led blink with interrupts from TimerB, I made it. The problem is doint it by the assigned pin.
If I am misundertanding something, or geting it wrongly, please, let me know the right way!
Thanks so much!