This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi
I am generating a PWM to turn on a fan. Here is the code
TA2CCR0 = 1000; // PWM Period
TA2CCTL1 = OUTMOD_7; // CCR1 reset/set
TA2CCR1 = 900; //384; // CCR1 PWM duty cycle
TA2CCTL2 = OUTMOD_7; // CCR2 reset/set
TA2CCR2 = 900; //128 // CCR2 PWM duty cycle
TA2CTL = TASSEL_2 + MC_1 + TACLR; // SMCLK, up mode, clear TAR
I want to be able to turn it on and off. It should restart generating the same PWM with the same duty cycle. Here is the code for turn-off.
//Are these lines needed?
//TA2CCR0 = 0; //TA2CCTL1 = 0;
//TA2CCR1 = 0;
//TA2CCTL2 = 0;
//TA2CCR2 = 0;
//TA2CTL = TASSEL_2 + MC_1 + TACLR;
TA2CTL &= ~(MC_1); //Is only this line sufficient?
Is it enough if I just toggle and set MC_1 or should I set the other registers(Capture compare registers, TACTL etc.) to 0 and re-initialise them?
Thanks
Abhishek
Hi Johnson
This link suggested that I should do TA2CTL &= ~(MC_1) and not TA2CTL |= MC_0
https://e2e.ti.com/support/microcontrollers/msp430/f/166/t/311740?How-to-property-disable-a-timer-
My question also was about whether other registers need to be set to 0 and then re-initialised with the old values or whether changing only TA2CTL is enough.
Thanks and Regards
Abhishek
Setting MC=0 freezes the timer as it is.
If you're doing PWM, the output pins will be held in their current states. Sometimes that's what you want. From what you say, though, I suspect you want them to go back to "idle" (low). What e.g. "TA2CCTL2=0" does is set OUTMOD=0 and OUT=0, forcing the TA2.2 pin low. There's probably no reason to set e.g. TA2CCR2=0 but it won't hurt anything.
If you're doing Capture (I think this is not your case) what "TA2CCTL2=0" would do is set CAP=0, so you won't get stray interrupts from TA2.2/CCI2 pin activity. (Here again setting the CCR=0 isn't needed.)
Hi Bruce
Your suggestion is working. Setting TA2CCTL2 to 0 seems to be doing the trick.
Thanks
Abhishek
**Attention** This is a public forum