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
  • Yes, but you didn't say which timer? Secondly, the repeatability would depend on what the core is doing at the time of the occurrence along with the interrupt level. You will ALWAYS have some amount of jitter when using software to make an update, it only a matter of how much you can minimize by your actions (control of the core).

    So you would have an interrupt that will calculate the new set point and another interrupt that is synchronized to an event (or periodic). The easiest way would be to use a PEC channel to make your move as this is simply a MOV instruction injected into the pipeline of the cpu. If this not good enough then perhaps you need another interrupt to put the cpu into an idle state before the actual event will occur (also assuming that no other interrupts would also be allowed) so when the periodic interrupt does occur you should get the most repeatable update.

Reply
  • Yes, but you didn't say which timer? Secondly, the repeatability would depend on what the core is doing at the time of the occurrence along with the interrupt level. You will ALWAYS have some amount of jitter when using software to make an update, it only a matter of how much you can minimize by your actions (control of the core).

    So you would have an interrupt that will calculate the new set point and another interrupt that is synchronized to an event (or periodic). The easiest way would be to use a PEC channel to make your move as this is simply a MOV instruction injected into the pipeline of the cpu. If this not good enough then perhaps you need another interrupt to put the cpu into an idle state before the actual event will occur (also assuming that no other interrupts would also be allowed) so when the periodic interrupt does occur you should get the most repeatable update.

Children
  • i dont know for 20us which timer should i choose, actually my main program interpolate the points between two points,it has used the line algorithm. Beim end of each ring it will send a signal to DAC. I just want tempo of the sending always be 20us.
    Thank you

  • 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 */
    	}
    }
    

  • 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