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.

Issue with toggling the pin with proper counts

UINT16 count;
UINT16 max_count;

void triggerTimer(UINT16 pulse_Frequency, UINT16 pulse_count){

count = CLEAR;
max_count = pulse_count;

P1DIR |=BIT0;
P1OUT &= ~BIT0;

TA0CCTL0 = CCIE; 
TA0CTL = TASSEL_2 + MC_1 + ID_0 ; 
TA0CCR0 = pulse_Frequency;

}

#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A(void)
{
if(count == max_count){
count = CLEAR;
TA0CTL = MC_0 + TACLR;
}
else{
P1OUT ^=BIT0;
count++;
}

}

 I wrote above code toggle the pin ,But it is not entering into ISR itself... How to toggle the pin with proper number of counts? 

  • Is that the whole code?, where do you set GIE bit?
    And where do you disable Watchdog timer? (mov.w   #WDTPW+WDTHOLD,&WDTCTL)

    Try this for the GIE:

    _BIS_SR(LPM0_bits+GIE)     /* Enter Low Power Mode 0 + General Interrupts Enabled */

  • Thanks for your reply.

    I have enabled that in main , calling triggerTimer() function on main itself.

    Sometimes I'm able to see the pulses,sometime not.

    If I put break point in ISR, then I can see the toggling of pulse ,on free run I can't see the toggle. 

    Please suggest me what is the reason for this problem and how to overcome it?

  • At first, all variables that are used in main code as well as in ISR code, should be declared volatile, to avoid the compiler moving the access to them for optimization.

    Then, you should set-up the output value of port pins first, before switching them to output direction. This avoids spikes that may confuse external peripherals.
    But in this case, none of the two is critical.

    Besides this, the code looks okay at first. So the problem is most likely in the surrounding code.

**Attention** This is a public forum