Hello everyone,
this is my first post, I hope someone can help me. I am using the MSP430G2231 for a project and what I am trying to do here is test part of my code that starts and stops a PWM signal that will control a servo.
I was trying to figure out why the PWM nevers stopped using the LED on the Launchpad. No matter what i did it wasn't stopping but instead it was going to full on (as if it was going to 100% duty cycle). during a test I was looking something up without pausing the debugger and when I saw the led again it was working fine. For clarity I made a video illustrating this behaviour. The code I am running is below and there is no input from me,just time. Link to the video (Please visit the site to view this video) the code:
#include <msp430g2231.h>
/* Definitions */
#define SerPin BIT6 // Pin used for servo
#define PWM_Period 20000 // Clock/PWM_Freq
#define Min_Duty 700 // Minimum duty cycle for the servo
#define MaxDuty 2300 // Minimum duty cycle for the servo
#define Min_Step 50 // Minimum servo movement (10*servo_deadband to be sure)
/* Global Variables */
int Last_Position = 700; //Last calculated position
/* Function Definitions */
void Start_PWM(void);
void Stop_PWM(void);
void main(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ; // set the DCO @ 1 MHz
DCOCTL = CALDCO_1MHZ; // "-----------------"
for (;;)
{
Start_PWM();
__delay_cycles(1000000);
Stop_PWM();
__delay_cycles(1000000);
}
}//main
/* PWM Start Function */
void Start_PWM(void) {
TACCTL0 &= ~(CCIE); // Disable interrupts for Timer_A
TACCR0 = PWM_Period-1; // Controls the PWM frequency
TACCR1 = Last_Position; // Set duty cycle 0 ≤ TACCR1 ≤ (TACCR0+1)
TACTL = TASSEL_2 + ID_0 + MC_1; // SMCLK, no division, Up Mode
TACCTL1 = OUTMOD_7; // Reset/Set: Sets at TACCR0, resets at TACCR1 for positive PWM
P1DIR |= SerPin; // Servo pin = output
P1SEL |= SerPin; // Servo pin = TA1 output
}//Start_PWM
/* PWM Stop Function */
void Stop_PWM(void) {
TACTL &= ~MC_3; // Stop
}//Stop_PWM
Any help will be greatly appreciated!