Other Parts Discussed in Thread: MSP430F5438
Hi,
I am new to TI microcontrollers in general. I am using MSP430F5438.
I am trying to generate a PWM signal on my port 2.2 with a variable duty cycle. Which i am able to do but I need to sweep the PWM signal from a duty cycle 0-100% automated. Right now I am manually changing the
duty cycle value.
I was thinking of a Ramp or some sort of looping which I have tried but doesnt seem to work.
My working code for the PWM with manual change of duty cycle is as follows:
static void pwm_main(void)
{
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
// Set up XT1
P7SEL |= 0x13; // Analog function for XT1 Pins and
// setting P7.4 as ADC for DIM_VOUT
//UCSCTL6 &= ~XT1DRIVE_3; // Lowest drive strength
//UCSCTL6 |= XCAP_0 ; // Internal load cap
P2SEL |= 0x04; // P2 option select
P2DIR |= 0x04; // P2 outputs
//TA1R=0;
TA1CCR0 = 512-0; // PWM Period
TA1CCTL1 = OUTMOD_7; // CCR1 reset/set
TA1CCR1 = 128; // CCR1 PWM Duty Cycle
// | P2.2/TA2|--> CCR1 - 383-->75% PWM
// | P2.2/TA2|--> CCR1 - 128-->25% PWM
// | P2.2/TA2|--> CCR1 - 64-->12.5% PWM
// | P2.2/TA2|--> CCR1 - 32--> 6.26% PWM
// | P2.2/TA2|--> CCR1 - 16--> 3.13% PWM
// | P2.2/TA2|--> CCR1 - 8--> 1.56% PWM
TA1CTL = TASSEL_2 + MC_1 +TA1R ; // SMCLK, upmode, clear TA1R
//__bis_SR_register(GIE); // Enter LPM0, enable interrupts
}