Last active
December 12, 2015 08:39
-
-
Save rclabs/4745806 to your computer and use it in GitHub Desktop.
msp430 msp430g2553 using ccr0, ccr1 and timer overflow interrupts to generate a pwm signal on p1.0 and p1.6
This file contains hidden or 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
| // using ccr0, ccr1 and timer overflow interrupts to generate a pwm signal on p1.0 and p1.6 | |
| #include <msp430.h> | |
| #define interrupt(x) void __attribute__((interrupt (x))) | |
| interrupt(TIMER0_A0_VECTOR) tmr_ccr0 () { | |
| // interrupt flag is automatically reset | |
| // ccr0 | |
| P1OUT &= ~(BIT0); | |
| } | |
| interrupt(TIMER0_A1_VECTOR) tmr () { | |
| switch (TAIV) { | |
| case 0x02: | |
| // ccr1 | |
| P1OUT &= ~(BIT6); | |
| TACCTL1 &= ~(CCIFG); | |
| break; | |
| case 0x0a: | |
| // timer overflow | |
| P1OUT |= BIT0 | BIT6; | |
| TACTL &= ~(TAIFG); | |
| break; | |
| } | |
| } | |
| int main() { | |
| WDTCTL = WDTPW + WDTHOLD; | |
| // configure clocks | |
| DCOCTL = CALDCO_16MHZ; | |
| BCSCTL1 = CALBC1_16MHZ; | |
| // i/o | |
| P1DIR = BIT6 | BIT0; | |
| P1OUT = 0x00; | |
| // timer | |
| TACCR0 = 16000; // 1 ms | |
| TACCR1 = 32000; // 2 ms | |
| TACCTL0 = CCIE; | |
| TACCTL1 = CCIE; | |
| TACTL = TASSEL_2 | MC_2 | TAIE; | |
| __enable_interrupt(); | |
| for (;;) {} | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment