I got some issues about msp430 code, I connected infrared sensor with p1.0, so I just identify whether p1.0 is high or low level, then let p1.7 generate different duty cycle PWM i.e. 7.5% at high level and 13% at low level.
but the result is that P1.7 just produces 7.5% PWM even if the sensor produces 0 and 1 output.
Here is my code,
#include <msp430.h>
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
// Configure P1.0 as input mode with pull-down resistor enabled
P1DIR &= ~BIT0; // P1.0 input mode
P1REN |= BIT0; // P1.0 pull-up/down resistor enabled
P1OUT &= ~BIT0; // P1.0 pull-down resistor enabled
// Configure P1.7 as output mode
P1DIR |= BIT7; // P1.7 output mode
P1SEL |= BIT7;
// Setup Timer_A0
TA0CCR0 = 20000; // Set Timer_A0 upper limit value
TA0CTL = TASSEL__SMCLK + MC__UP + TACLR; // Select SMCLK as clock source, UP mode, clear Timer_A0 counter
TA0CCTL1 = OUTMOD_7; // Set output mode 7 for PWM
while(1)
{
if(P1IN & BIT0) // P1.0 high input state
{
TA0CCR1 = 2600; // 13% duty cycle
}
else // P1.0 low input state
{
TA0CCR1 = 1600; // 8% duty cycle
}
}
}
Thanks