This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi,
I am using MSP430G2452 MCU to capture the 840KHz signal and below mentioned the code. i observed that it is not able to capture this higher frequency. I tried supplying throgh signal generator and noticed that upto 300KHz it capturing and beyond that not.
#include <msp430g2152.h>
unsigned int new_cap=0;
unsigned int old_cap=0;
unsigned int cap_diff=0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_16MHZ; // Set Oscillator range
DCOCTL = CALDCO_16MHZ;
P1SEL |= BIT2; // Port 1.2/TACCR1 - Input
P1DIR=0xF0; // P1.4, P1.5, P1.6, P1.7 as a output
P1OUT=0x00; // Initially reset port1
P1OUT |=0x10; // P1.4 High for Green status LED
TACTL = TASSEL_2 +MC_2; // SMCLK = 1 Mhz, continuous mode
TACCTL1 = CM_1+CCIS_0+SCS+CAP+CCIE; // capture on rising edge & falling edge, Timer A select, Sync., capture mode, Enable timer interrupt
__bis_SR_register(LPM0_bits + GIE); // LPM0 mode
}
// Timer A1 interrupt service routine
#pragma vector = TIMER0_A1_VECTOR
__interrupt void TA1_ISR(void)
{
switch( TAIV ) // Efficient switch-implementation
{
case 2: // CCR1 capture value
P1OUT ^= BIT4; //toggling pin4 of PORT 1 and chekcing in CRO
new_cap = TACCR1;
cap_diff = new_cap - old_cap;
old_cap = new_cap; // move current value
break;
}
}
So please let us know is it possible to capture the signal at 840KHz.
Thanks in advance...
Sure it is. Capturing is not the problem. Your processing at the capture event is simply takign up too much time. With 16MHz MCLK and 840kHz signal speed, you only have 19 MCLK cycles between two interrupt events. Including the interrutp latency time, teh tiem for the SIR treturn, teh save and restor of the registers you use inside the ISR and for your code. Doesn't fit. You'll need to speed up the code, raise MCLK (well, not on this MSP) or use other techniques like DMA (not on this MSP too)Vageesh KM said:So please let us know is it possible to capture the signal at 840KHz.
A busy-waiting loop in main might be faster than the interrupt mechanism in your case. But you can do the math by yourself.
Tight things like this cry for hand-optimized assembly code rather then high-level languages. Just to squeeze the last clock cycle from teh code.
**Attention** This is a public forum