Hi! I am trying to control servo motor with interrupt but it doesnt work :\ what is my mistake?How can I fix it?
#include <msp430.h> void main( void ) { WDTCTL = (WDTPW | WDTHOLD); // Stop watchdog timer BCSCTL1 = CALBC1_1MHZ; // Set DCO range DCOCTL = CALDCO_1MHZ; // Set DCO step and modulation P1DIR = 0x04; // Set P1.2 to output-direction P1REN = (0x08 | 0x10 | 0x20); // Enable resistors at P1.3/4/5 P1OUT = (0x08 | 0x10 | 0x20); // Pull-up resistors at P1.3/4/5 P1IE = (0x08 | 0x10 | 0x20); P1IES = (0x08 | 0x10 | 0x20); P1IFG = (0x08 | 0x10 | 0x20); P1SEL = 0x04; // Set selection register 1 for timer-function TA0CCTL1 = OUTMOD_7; // Reset/set TA0CCR0 = 20000; // Period TA0CCR1 = 1500; // Duty-cycle TA0CTL = (TASSEL_2 | MC_1); // SMCLK, timer in up-mode _BIS_SR(GIE); while( 1 ) // Endless-loop (main-program) {} } #pragma vector=PORT1_VECTOR __interrupt void P1_ISR(void) { if( !(P1IFG & 0x08) ) // Button at P1.3 pressed (S2 on LaunchPad) { TA0CCR1 = 1500; // Servo in middle position (1.5ms) } else if( !(P1IFG & 0x10) ) // Button at P1.4 pressed { TA0CCR1 = 1000; // Servo in minimum position (1.0ms) } else if( !(P1IFG & 0x20) ) // Button at P1.5 pressed { TA0CCR1 = 2000; // Servo in maximum position (2.0ms) } P1IFG = (0x08 | 0x10 | 0x20); }