Jump to content

TechIO

Members
  • Content Count

    9
  • Joined

  • Last visited


Reputation Activity

  1. Like
    TechIO reacted to nickn in Add more LEDs with Fading   
    Ok here is the one that I did in CCS (fairly new to using CCS myself):
    #include <msp430.h> void main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer P1DIR |= BIT6; P1SEL |= BIT6; P1OUT&=~BIT6; CCR0 = 1000-1; // PWM Period frequency is determined by //clk freq divided by CCR CCTL1 = OUTMOD_7; // CCR1 reset/set CCR1 = 0; // CCR1 PWM duty cycle TACTL = TASSEL_2 + MC_1;// SMCLK, up mode //SMCLK runns at main clock speed in this micro it's 16 Mhz while(1){ if(CCR1 == 0){ while(CCR1<500){ CCR1= CCR1+1; __delay_cycles(2000); } } else{ while( CCR1 > 0){ CCR1= CCR1-1; __delay_cycles(2000); } } } }
  2. Like
    TechIO reacted to abecedarian in Add more LEDs with Fading   
    The code posted uses PWM, as well as the RED LED connected by default to P1.0; that pin doesn't support PWM.
    The GREEN LED connected to P1.6 does however, which is what the code uses "BIT6".
     
    So you need to find another pin that supports PWM, which on the G2553 LP means P1.2, and connect the LED to that, easily done by removing the jumper above the LED and running a jumper from the pin closest the LED to the LP pin next to the label "P1.2 (UART1)". Now, by adding BIT6 to BIT2, you can have both fading, albeit both do so in parallel.
     
    @@oPossum is a wizard and often makes things which do not make sense somehow work.
     
    Then,

    #include <msp430.h> #include <stdint.h> void main(void) { WDTCTL = WDTPW | WDTHOLD; DCOCTL = 0; BCSCTL1 = CALBC1_16MHZ; DCOCTL = CALDCO_16MHZ; P1DIR = P1SEL = BIT2 + BIT6; // BIT2 = P1.2 / BIT6 = P1.6 TACCTL1 = OUTMOD_7; TACTL = TASSEL_2 | MC_2 | TAIE; _EINT(); } #pragma vector = TIMER0_A1_VECTOR __interrupt void timer_a1_isr(void) { static uint32_t x = 0x00100000L; static unsigned d = 1; TACCR1 = x >> 16; volatile unsigned z = TAIV; if(d) { x += (x >> 7); if(x > 0xF8000000L) d = 0; } else { x -= (x >> 7); if(x < 0x00200000L) d = 1; } }
×
×
  • Create New...