AnsweredAssumed Answered

PIN state  change problem

Question asked by Chayan Roy on Mar 1, 2017
Latest reply on Mar 1, 2017 by Ian Legg

Hello, I   am trying to  create  100us seconds pulse which periodically triggers  a triac. Timer 1 is used for periodic delay and a while loop is under the  timer1 isr for 100us pulse. Problem is it is not working,Interrupt occurs but pin state doesn't change.  Here is the code:

 

 #include "STM8S003F3P.h"

 

 

 

 

 


void InitialiseSystemClock(void);

 

 

 


unsigned int i=500;

 

 

 

void main(void){

 

                   InitialiseSystemClock();  // Internal  RC clock initialization ,frequency 16MHZ
            
                                
                 PD_DDR |=(1<<1);  //PROT D is set as output
                 PD_CR1 |=(1<<1);
                 PD_CR2 |=(1<<1);
                                
                              
                                
                                
                                 TIM1_PSCRH=0;        //timer1 setup for periodic interrupt
                                 TIM1_PSCRL=16;
                                 TIM1_ARRH=200;
                                 TIM1_ARRL=255;
                                 TIM1_IER=(1<<0);
                                 TIM1_CR1 =(1<<0);
 
                

 

                  

 


                 _asm("rim"); // Enable global interrupt
                   
                                 while(1){
              
}

 

}

 

@far @interrupt void TIMER1_INTERRUPT (void){     // timer1 isr
PD_ODR |=(1<<1);                             // PD1  high
while(i !=0){

 

i--;                                                 // some micro seconds delay

                     

}
PD_ODR &=~(1<<1);              // PD1  low

 

 

 

TIM1_SR1 =~(1<<0);

return;
}

 

 

Plese  guide me,what to do.

Outcomes