mrinverter 0 Posted March 24, 2015 Share Posted March 24, 2015 Hi guys, I am trying to implement a pulse counter that counts square wave at around 1-2Hz. The input is at pin 34. I am running WDT interval to function as a clock so that i can use the results to count the interval between the pulses. However, the counter I put into the WDT vector does not count up, but the LED at pin 32 does light, which I am using to check if it enters the interrupt. I was wondering if anyone can provide any assistance with this. #include <msp430.h> volatile unsigned int count; volatile unsigned int beat_count; void InitializeSqWaveInput(void); char string[7]; /* * main.c */ int main(void) { //HW Setup BCSCTL1 = CALBC1_8MHZ; //Set DCO to 8Mhz DCOCTL = CALDCO_8MHZ; //Set DCO to 8Mhz WDTCTL = WDTPW + WDTCNTCL + WDTTMSEL + WDTSSEL + WDTIS1; //WDT SMCLK, Divider (0.064ms WDT Interval Interrupt) IFG1 = ~WDTIFG; // Clear the WDT interrupt flags IE1 = WDTIE; // Enable the WDT interrupts P1SEL = 0; //Set Port 1 to GPIO P1DIR = BIT1 | BIT2; // Set the LEDs on P1.2 as outputs (For Debugging SQ Wave) InitializeSqWaveInput(); } void InitializeSqWaveInput(void) { P1DIR = ~BIT3; // Set sqwave pin as an input pin P1IES ^= BIT3; // Enable Interrupt to trigger on the rising edge (low to high) P1IFG = ~BIT3; // Clear the interrupt flag for the input P1IE = BIT3; // Enable interrupts on port 1 for the input } #pragma vector=PORT1_VECTOR __interrupt void PORT1_ISR(void) { if (P1IES & BIT3) { //Falling edge detected } else { // Rising edge detected P1OUT ^= BIT2; // Turn on P1.2 red LED to indicate Rising Edge Detected beat_count = count; //Transfer interrupt count to beat_count //count = 0; //Reset interrupt count for next beat //15625/beat_count = timeperbeat; WDTCTL = WDTPW + WDTCNTCL + WDTTMSEL + WDTSSEL + WDTIS1; } } #pragma vector=WDT_VECTOR __interrupt void WDT_ISR(void) { if (P1IES & BIT3) { //Falling edge detected } else { // Rising edge detected P1OUT ^= BIT2; // Turn on P1.2 red LED to indicate Rising Edge Detected beat_count = count; //Transfer interrupt count to beat_count //count = 0; //Reset interrupt count for next beat //15625/beat_count = timeperbeat; WDTCTL = WDTPW + WDTCNTCL + WDTTMSEL + WDTSSEL + WDTIS1; } WDTCTL = WDTPW + WDTCNTCL + WDTTMSEL + WDTSSEL + WDTIS1; count++; P1OUT ^= BIT1; // Toggle P1.0 using exclusive-OR } Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.