Código:
El código es el siguiente, se ha agregado la opcion para que el Duty_Cycle sea variable:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************************************************************************* | |
* | |
* 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; | |
} |
Vídeo:
Aquí un pequeño vídeo de funcionamiento:
Aquí un pequeño vídeo de funcionamiento:
Descargas:
Aquí el enlace para DESCARGAR los archivos disponibles desde mi repositorio en GitHub, si no sabes como descargarlo puedes checar aquí, bueno por el momento es todo si tienes dudas, comentarios, sugerencias, inquietudes, traumas, etc. dejarlas y tratare de responder lo mas pronto posible.
Donaciones:
Si te gusta el contenido o si los recursos te son de utilidad, comparte el enlace en tus redes sociales o sitios donde creas que puede ser de interés y la otra puedes ayudarme con una donación para seguir realizando publicaciones y mejorar el contenido del sitio. También puedes hacer donaciones en especie, ya sea con componentes, tarjetas de desarrollo o herramientas. Ponte en contacto para platicar, o puedes volverte uno de nuestros sponsors.
Pido una retroalimentación avisando cada que un enlace no sirva o tenga errores al momento de abrirlo, así también si una imagen no se ve o no carga, para corregirlo en el menor tiempo posible.
0 Comentarios