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

Timer interrupt

hello everyone, is there anybody know how to set timer interrupt with ST10 269

The problem is that: the Tempo of sending data from the my ST10 269 to DAC is not the same everytime, it changes between 10us and 12us, because in my program there are so many jumps for several conditions.

Now I want the tempo of sending of the data everytime the same. for this I want to use the timer. Everytime by starting a new step the timer will start, the algorithm runs the same time ,and wait after computation till the timer finish timing to 20us. then send the signal to DAC, and the second step will follow,as well the time will be reset,and start again.

How can this with C realize.

thanks in advance

Parents
  • I am not sure how you are programming the rest of the device but here is a simple example (assumes 20MHz CPU clock).

    #define Delay_20USEC 0x0031
    
    void InitGpt1(void)	{
      /* timer 3 works in timer mode, counts down */
      T3CON =  0x0080;
      T3    =  Delay_20USEC;
    
      /* - timer 2 works in reload mode */
      T2CON =  0x0027;
      T2    =  Delay_20USEC;
    
      T3IC =  0x007F; /* timer 3 interrupt (ILVL) = 15, (GLVL) = 3 */
      T3R =  1;       /* start timer 3 */
    }
    
    
    void GPT1Tmr3ISR(void) interrupt 0x23 {
      /* do what you want here! */
    }
    
    void main(void) {
      InitGpt1(); /* initialize GPT1 */
      IEN =  1;   /* globally enable interrupts */
    
    	for(;;) {
    	 ; /* loop forever */
    	}
    }
    

Reply
  • I am not sure how you are programming the rest of the device but here is a simple example (assumes 20MHz CPU clock).

    #define Delay_20USEC 0x0031
    
    void InitGpt1(void)	{
      /* timer 3 works in timer mode, counts down */
      T3CON =  0x0080;
      T3    =  Delay_20USEC;
    
      /* - timer 2 works in reload mode */
      T2CON =  0x0027;
      T2    =  Delay_20USEC;
    
      T3IC =  0x007F; /* timer 3 interrupt (ILVL) = 15, (GLVL) = 3 */
      T3R =  1;       /* start timer 3 */
    }
    
    
    void GPT1Tmr3ISR(void) interrupt 0x23 {
      /* do what you want here! */
    }
    
    void main(void) {
      InitGpt1(); /* initialize GPT1 */
      IEN =  1;   /* globally enable interrupts */
    
    	for(;;) {
    	 ; /* loop forever */
    	}
    }
    

Children
  • Thank for your kind help.


    I have actually already defined the address of T3,T3CON,T2,T2CON in register.h. The address in the datasheet is not the same as you gave to me, should I change it?

    In your programm how is the 20 us defined ?
    because I have only seen several addresse,but no variable for the definition of 20us .

  • Not sure where register.h comes from because you can use the Keil supplied header file "regst10f269.h"

    Frequency of T3 = fCPU/(8x2^n) where I defined n = 0. So this gives you a T3 frequency of 2.5MHz (fCPU=20MHz). Which means each tick is 400nsec.

    To get a 20usec timeout perhaps you could take 20usec/400nsec -1 which is 49 decimal or 31 hexadecimal.

    Then in the example I can find this statement:

    #define Delay_20USEC 0x0031
    
    T2 is used to automatically reload T3 after the underflow event.
    T2    =  Delay_20USEC;
    
    So the T3 interrupt comes every 20 microseconds. In the T3 ISR you can add your code to update the DAC here or perhaps setup the PEC to move your data and then you don't even need to vector to the interrupt.

  • Thanks very much. I have tried ,it works already.

    Thanks again for your help