카테고리 없음

MSP430, CCS, Timer, pwmLED

CoyoteUgly 2018. 9. 4. 01:58

MSP430, CCS, Timer, pwmLED



msp430.h 를 사용하는 소스입니다.


Did you have a look at the example codes for the MCU that is provided by TI for almost every processor?


www.ti.com/lit/zip/slac536


The following examples show how to set up the clocks:

msp430fr59xx_cs_01.c       Configure MCLK for 8MHz operation
msp430fr59xx_cs_02.c       Configure MCLK for 16MHz operation
msp430fr59xx_cs_03.c       Output 32768Hz crystal on XT1 and observe failsafe
msp430fr59xx_cs_04.c       ACLK = XT1 = 32768Hz, SMCLK= XT2 = 8MHz, MCLK = DCO
msp430fr59xx_cs_05.c       Using LFXT in bypass mode, failsafe operation shown


0. 참고 사항



출처: http://coyoteugly.tistory.com/188 [마이콤 개발자를 위한 여행]

0. 참고 사항


1. 소스 설명

full 소스는 아래 github를 통해 확인하세요.

8MHz Clock
P1.3 / TA1.2


#include <msp430.h>
#include <msp430fr6989.h> // it's same with msp430.h

int main(void)
{
    unsigned int i, duty = 500;

    WDTCTL = WDTPW | WDTHOLD;                 // Stop WDT

    // Configure GPIO
    P1DIR |= BIT3;                     // P1.2 and P1.3 output
    P1SEL0 |= BIT3;                    // P1.2 and P1.3 options select

    // Disable the GPIO power-on default high-impedance mode to activate
    // previously configured port settings
    PM5CTL0 &= ~LOCKLPM5;

    CSCTL0_H = CSKEY >> 8;                    // Unlock CS registers
    CSCTL1 = DCOFSEL_6;                       // Set DCO to 8MHz
    CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK;// Set ACLK = VLO; SMCLK = DCO/8
    CSCTL3 = DIVA__8 | DIVS__8 | DIVM__8;     // Set all dividers
    CSCTL0_H = 0;

    TA1CCR0 = 1000-1;                         // PWM Period
    TA1CCTL2 = OUTMOD_7;                      // CCR2 reset/set
    TA1CCR2 = duty;                            // CCR2 PWM duty cycle
    TA1CTL = TASSEL__SMCLK | MC__UP | TACLR;  // SMCLK, up mode, clear TAR

    //__bis_SR_register(LPM0_bits);             // Enter LPM0
    __no_operation();                         // For debugger

    while(1)
    {
        for(i=0; i<50; i++)
            _delay_cycles(8000);                // Wait 8,000 CPU Cycles, 1ms

        duty += 100;

        if (duty >= 1000)
            duty = 0;

        TA1CCR2 = duty;                            // CCR2 PWM duty cycle
    }
}
 


2. 소스


3. 결과

TA1CCR2= 500


TA1CCR2= 250