Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

Cannot toggle a pin faster than 31 kHz [CC430F6147]

$
0
0

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. 

Thanks in advance for any advice!

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;
}
}


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>