This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Failure in using of volatile

Hallo ALL,
I have the following problem ....
I use F005 from cygnal.
I have a timer:
......................................
idata U8 volatile HeartbeatLEDTimer;
idata U8 volatile DACTimer;
...................................
void Timer0InterruptHandler(void) interrupt 1 using 1
{
// Reload the timer registers

TR0 = 0;

TL0 = T0_RELOAD_LOW;
TH0 = T0_RELOAD_HIGH;



// DECREMENT_TIMER(HeartbeatLEDTimer);
DECREMENT_TIMER(DACTimer);

TR0 = 1;

}



and in the main()
/*
if(!HeartbeatLEDTimer) {pin_LED_D1 = ~pin_LED_D1; HeartbeatLEDTimer = HEART_BEAT_LED_TIMER;}
*/
.............................

// INTERRUPTS_OFF;
DACTimer=DAC_TIMER;
// INTERRUPTS_ON;
while(DACTimer != 0){; }//delay



it works without INTERRUPTS_OFF if I don't use HeartbeatLEDTimer, but if I use it, I should disable interrupts only before DACTimer=DAC_TIMER and not before HeartbeatLEDTimer = HEART_BEAT_LED_TIMER???
I'm really confused and I thought the problem is in VOLATILE! But it's not so clear.
Please help me to understand what here is really happened.
With best regards,
Sergey

Parents
  • and in the main()
    /*
    if(!HeartbeatLEDTimer)
    {
      pin_LED_D1 = ~pin_LED_D1;
      HeartbeatLEDTimer = HEART_BEAT_LED_TIMER;
    }
    */
    // INTERRUPTS_OFF;
    DACTimer=DAC_TIMER;
    // INTERRUPTS_ON;
    while(DACTimer != 0){; }//delay
    
    If you did not try to convolute your code and wrote it in the style above, you would imeediately see what the problem is.

    Erik

Reply
  • and in the main()
    /*
    if(!HeartbeatLEDTimer)
    {
      pin_LED_D1 = ~pin_LED_D1;
      HeartbeatLEDTimer = HEART_BEAT_LED_TIMER;
    }
    */
    // INTERRUPTS_OFF;
    DACTimer=DAC_TIMER;
    // INTERRUPTS_ON;
    while(DACTimer != 0){; }//delay
    
    If you did not try to convolute your code and wrote it in the style above, you would imeediately see what the problem is.

    Erik

Children
  • Hello ALL!
    Now it works!
    The interrurpt should be enabled before while(DACTimer!=0); and I was completely sure that it is , but....
    this "while" is in the big setup function befor main loop and in one of the setup subfunction befor this call the Interrupt was disabled and it was deadly for this "while".
    In any case THANK YOU ALL VERY MUCH for all your help !
    With respect,
    S.