MSP-EXP430G2 LaunchPad & CCS: Basic use of PWM


Regards! Following with the basic examples of the MSP-EXP430G2 LaunchPad in CCS, it's time to use the PWM, to start I used the file "msp430g2xx1_ta_16" from the folder of examples provided by TI, I added the option for the Duty_Cycle to be variable.

The firmware is the following:
/*******************************************************************************
*
* MSP-EXP430G2_009: Basic use of PWM
*
*******************************************************************************
* FileName: main.c
* Processor: MSP430G2231
* Complier: CCS 7.2.0.00013
* Author: Pedro Sánchez Ramírez (MrChunckuee)
* Blog: http://mrchunckuee.blogspot.com/
* Email: mrchunckuee.psr@gmail.com
* Description: For this example we will obtain a PWM in P1.6 (LED_GREEN),
* using the Timer_A, the delay routine is very basic and it
* is not the best option, but it fulfills the objective.
*******************************************************************************
* Historial del firmware
* Rev. Date Comment
* v0.01 29/11/2017 - Testing using MSP430G2231
* - Modification to make the duty_cycle variable
******************************************************************************/
#include <msp430.h>
unsigned char DutyPWM = 10;
/********** P R O T O T Y P E S *************/
void MCU_Delayms(unsigned int time);
int main(void){
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
P1DIR |= BIT6; // P1.6 output
P1SEL |= BIT6; // P1.6 TA1/2 options
P1OUT &= ~BIT6; // P1.6 set LOW (Green LED)
CCR0 = 200-1; // PWM Period (Aprox. 5KHz)
CCTL1 = OUTMOD_7; // CCR1 reset/set
CCR1 = DutyPWM; // CCR1 PWM duty cycle
TACTL = TASSEL_2 + MC_1; // SMCLK, up mode
//_BIS_SR(CPUOFF); // Enter LPM0
while(1){
for(DutyPWM=10; DutyPWM<190; DutyPWM++){
CCR1 = DutyPWM;
MCU_Delayms(100);
}
for(DutyPWM=190; DutyPWM>10; DutyPWM--){
CCR1 = DutyPWM;
MCU_Delayms(100);
}
}
}
void MCU_Delayms(unsigned int time){
unsigned int delayCount;
for (delayCount=0; delayCount<time; ++delayCount)
__delay_cycles(1000); // 1ms = 1000 clocks at 1MHz
return;
}
Here is a small working video:


Download:
Here the direct link to DOWNLOAD the available files, you can also check or download the information from my repository on GitHub, if you do not know how to download it you can check here, well for now it's all, if you have doubts, comments, suggestions, concerns, etc. leave them and I will try to answer as soon as possible.


Donations:
If you like the content or if the resources are useful to you, share the link on your social networks or sites where you think it may be of interest, you can also help me with a donation to continue making publications and improve the content of the site. You can also donate in kind, for example components, development boards or tools. Contact me to talk or you can become one of our sponsors.


I ask for feedback notifying each time a link does not work or has errors when opening it, as well as if an image is not visible or does not load, to correct it in the shortest possible time.

Publicar un comentario

0 Comentarios