Tool/software: Code Composer Studio
Hello,
I am using the MSP430F6638 in my design. I have to command a motor by pwm and I am creating my pwm signal with timer. However I have a doubt about how to "send" in the program this pwm signal to the motor. I mean which command should I write so the motor start to work. In other words what is the command which from the moment I will write it, the motor will "immediately" start to turn ? Here is my code below.
void motor_ON(void){
P3SEL|=BIT1; //SELECT P3.1 AS TA1 and not I/O
TA1CTL = TASSEL_2 + TACLR+ MC_1; // SMCLK, up mode
TA1CCR0 = PWM_PERIOD-1; // counter value that defines the pwm period
TA1CCTL1 = OUTMOD_6; // toggle/set
TA1CCR1 = motor_DC; // motor duty cycle
}
Is this enough or is still there something to enable so the motor could work ? In others words at which command the motor will "receive" the pwm signal and start working, and if this command is missing what should it be ?
Same question, to stop the motor. What is the proper way to do it ? I thought about a solution but I'm not sure if it's correct. In order to put off the pwm signal and so stop the motor, I just changed the output mode from toggle and set to reset and put the shortest value (1) in the TA1CCR1 register so I will have a really short duty cycle and then as soon as the counter will reach the value "1" (which is really fast) the output of the timer will remain at 0 and then the motor will be stopped. I hope that it's clear. Here is the code below :
void motor_OFF(){
TA1CCTL1 = OUTMOD_5; // reset
TA1CCR1 = 1; // very short DC so the motor remains off quickly
}
So, to start and stop the motor are these the correct way to do it, or is something missing ?
Thank you.
Best regards,
Mike