Jump to content

Cloudberry

Members
  • Content Count

    2
  • Joined

  • Last visited

  1. Cloudberry

    Setting up timers/ccr MSP430G2152

    Thank you for the insight, as I stated the code is not mine, and the original grace related setup was not included therefore it's no surprise that the timer is not set up at all. I'm trying to work backward from the code to decide how everything was (most likely) setup originally. The original author doesn't seem to be reachable so I'm out of luck there. I'm assuming that the clock source is the internal low frequency oscillator based on the fact that the original project had no external crystal. As to the setup and divider settings for the oscillator, I couldn't tell you. Also everything that you have written about, (poorly coded from an isr standpoint) I came to that same conclusion from going over the code and best practices. Your insight is helpful to me as it explains in a little more depth how the timer is being used in this scenario. Reading the manual trying to infer how to setup a timer is all but useless when you don't know how the timer is being utilized in the code in the first place. Anyway, Thank you again for the help!
  2. Cloudberry

    Setting up timers/ccr MSP430G2152

    I'm trying to replicate the project shown here http://www.mjlorton.com/forum/index.php?topic=284.0 but instead of the g2211 I'm using the g2152. I somewhat understand what the code is doing, however I'm having a hard time setting up the timers and capture compare registers. Additionally I'm not sure how the timer/ccr is being used to differentiate between a long or short button press (is it using nested interrupts?) The original code uses grace included configs which obviously aren't there,I'm trying to infer how things were set up originally. I have the gpio and wdt config figured out but not the timer or ccr (I'm probably missing other things as well) Any insight or hints to push me in the right direction would be helpful. Thanks. //#define DATALOG BIT3 //P1.3 //#define BACKLIGHT BIT4 //P1.4 //#define MAXMIN BIT5 //P1.5 //#define DCAC BIT1//P1.1 //#define VHz BIT2//P1.2 //#define DCAC_OUT BIT6//P2.6 //#define VHz_OUT BIT7//P2.7 /* * ======== Standard MSP430 includes ======== */ #include <msp430g2152.h> /* * ======== main ======== */ int main(void) { WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer P1OUT = BIT1 | BIT2 | BIT3 | BIT4 | BIT5; P1DIR = BIT3 | BIT4 | BIT5; P1REN = BIT1 | BIT2; P1IES = BIT1 | BIT2; P1IFG = 0; P1IE = BIT1 | BIT2; P2SEL2 = BIT3; P2OUT = BIT6 | BIT7; P2SEL &= ~(BIT6 | BIT7); P2DIR = BIT6 | BIT7; P2IES = 0; P2IFG = 0; __bis_SR_register(LPM3_bits | GIE); } #pragma vector = PORT1_VECTOR __interrupt void PORT1_ISR( void ) { P1IE &= ~(BIT1 | BIT2); // // disable interrupt on these pins __delay_cycles(10000); TA0CCR1 = 0; TA0CCTL0 &= ~CCIFG; TA0CTL |= MC_1; // Start timer switch(P1IN & (BIT1 | BIT2)){ case 0: //VHz+DCAC buttons pressed if(P1OUT & BIT3) P1OUT &= ~(BIT3); else P1OUT |= (BIT3); __delay_cycles(20000); break; case 2: //VHz button pressed while (!(P1IN & BIT2) && !(TA0CCTL0 & CCIFG)); TA0CTL &= ~MC1; if (!(TA0CCTL0 & CCIFG)){ P2OUT &= ~(BIT7); __delay_cycles(10000); P2OUT |= (BIT7); } else{ P1OUT &= ~(BIT4); __delay_cycles(10000); P1OUT |= (BIT4); } break; case 4: //DCAC button pressed while (!(P1IN & BIT1) && !(TA0CCTL0 & CCIFG)); TA0CTL &= ~MC1; if (!(TA0CCTL0 & CCIFG)){ P2OUT &= ~(BIT6); __delay_cycles(10000); P2OUT |= (BIT6); } else{ P1OUT &= ~(BIT5); __delay_cycles(10000); P1OUT |= (BIT5); } break; case 6: //no button pressed break; } TA0CTL &= ~(MC1 + MC0); // Clear MCx bits to stop timer while(!(P1IN & (BIT1 | BIT2))) P1IFG &= ~(BIT1 | BIT2); // sets register flag for interrupt to 0: No interrupt is pending P1IE |= (BIT1 | BIT2); // re-enable interrupt on these pins }
×