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.

# Cannot toggle a pin faster than 31 kHz [CC430F6147]

Other Parts Discussed in Thread: CC430F6147, EM430F6147RF900, MSP430G2553

I'm trying to generate a square wave at 38 kHz on an output pin on a CC430F6147 (on the EVM EM430F6147RF900).  I'm doing this by simply toggling the pin in a timer interrupt of about 76 kHz. I'm also pulsing this oscillation on and off for 0.5 sec at a time, using a separate timer at 2 Hz.  The 2nd timer stops the 1st timer for 0.5 sec, then starts it for 0.5 sec, etc. However the square wave frequency doesn't seem to go past 31 kHz when measured on an oscilloscope. I've been changing the frequency by changing the timer period, which is in up mode. The pulsing doesn't work either at this point, but the pulsing does work for slower frequencies, like on the order of Hz.  The clock I'm using is the default DCO, which is supposed to be about 1 MHz, so I don't understand why I can't get 38 kHz.  The code is below.

volatile short togglePulse = 0;

int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= BIT0; // P1.0 output
P2DIR |= BIT0; // P2.0 output (38kHz signal)
P1OUT &= ~BIT0;
P2OUT &= ~BIT0;

// Timer A1 (2 Hz)
// Timer A0 stopped at every other ISR -> pulse time = 0.5 s
TA1CCTL0 = CCIE; // CCR0 interrupt enabled
TA1CCR0 = 65312; //
TA1CTL = TASSEL_2 + ID_3 + MC_1 + TACLR; // SMCLK, /8, up mode, clear TAR

// Timer A0 (74.6 kHz)
// Pin 2.0 toggled at ISR -> oscillation = 74.6 / 2 = 37.3 kHz
TA0CCTL0 = CCIE; // CCR0 interrupt enabled
TA0CCR0 = 14; //
TA0CTL = TASSEL_2 + MC_1 + TACLR; // SMCLK, up mode, clear TAR

__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, enable interrupts
__no_operation(); // For debugger

while(1)
{
}
}

// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0_A0_ISR(void)
{
P1OUT ^= BIT0;
P2OUT ^= BIT0;
}

// Timer A1 interrupt service routine
#pragma vector=TIMER1_A0_VECTOR
__interrupt void TIMER1_A0_ISR(void)
{
if (togglePulse == 0) {

TA0CCR0 = 0;
togglePulse = 1;
}

else {
P1OUT &= ~BIT0;
P2OUT &= ~BIT0;
TA0CCR0 = 22;
togglePulse = 0;
}
}

• AT 1 MHz to get 38 KHz i advise you to use timer in up mode.

1000/38=26.31, put 31 in timer 1 CCR0 and you will get (app) 38 KHz square wave.

and toggle led or take output toggling the pin in ISR

• Hello, I'm new using the MSP430G2553. I want to generate a 38 KHz ouput for an IR emitter LED.

I have set up the DCO to 1Mhz, but I dont know how to get the 38 division. Do I have to use the TACTL ?? and set up to 38 and how can I approach this

Thanks

• Hi Hector,

This is not the correct forum for your query. Try posting it on Microcontrollers forum.