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

timers

Hello EveryOne,

I am using LPC2368 controller I am using timer0/counter in interrupt mode initially i set the value T0MR0 register 100 as shown in following program .this timer is running at 1 MHz frequency Suppose i want to change this value at run time . What changes i should do .


void init_timer0 (void) {


T0PR = 0x0000003B;
T0MR0 = 100;

T0MCR = 0x03;
T0TCR = 1;


VICVectAddr4 = (UWORD32)tc0;
VICIntEnable = 1 << 4;
return;
}

Parents
  • No need for any "return;" at end of a function.
    A return statement is only needed if you either have a value to return, or you want to exit the function before you reach the ending brace.

    What changes to do? Well that would obviously depend on what result you want. Changing the value of the match register will change how far the timer ticks before it generates a reset and restarts from zero. By the way - are you sure you want the value 100 and not actually 99? 99 is the required value if you want a frequency of 10kHz in case the timer ticks at 1MHz.

Reply
  • No need for any "return;" at end of a function.
    A return statement is only needed if you either have a value to return, or you want to exit the function before you reach the ending brace.

    What changes to do? Well that would obviously depend on what result you want. Changing the value of the match register will change how far the timer ticks before it generates a reset and restarts from zero. By the way - are you sure you want the value 100 and not actually 99? 99 is the required value if you want a frequency of 10kHz in case the timer ticks at 1MHz.

Children
  • Thanks Sir for your kind support

    Actually Sir i want to control the stepper motor of a printer.The motor has 120 step of different pulse width ranging from 5000us to 368us according to speed .That,s why i run timer at 1 MHz so that i can give value in match register in Microsecond.I want to change the step duration during running time by giving different value in T0MR0 register.Initially i set this value at 100.But in ISR I want to change this value according to step duration as shown in following code

    MAX_ACCER_STEP = 120;

    void tc0 (void) __irq
    {
    
    
    
                                         switch(motor_step)
                                             {
    
                                              case 1:
                                              FIO0SET = PH1_M;FIO0SET =     PH2_M;
                                              if(acc_step<MAX_ACCER_STEP){
                                              T0MR0=accer_table[acc_step];
                                              acc_step++;
                                              }
                                               FIO0CLR = STROBE1;
    
    
    
                                              break;
    
                                              case 2:
                                              FIO0CLR = PH1_M;FIO0SET =     PH2_M;
    
    
                                              if(acc_step<MAX_ACCER_STEP){
                                              T0MR0=accer_table[acc_step];
                                              acc_step++;
                                              }
                                              s_strob = 0;
    
                                              motor_step++;
    
                                              break;
    
                                              case 3:
                                              FIO0CLR = PH1_M;FIO0CLR =     PH2_M;
                                              if(acc_step<MAX_ACCER_STEP){
                                              T0MR0=accer_table[acc_step];
                                              acc_step++;
                                              }
                                              FIO0CLR = STROBE1;
    
    
    
                                              motor_step++;
    
                                              break;
    
                                              case 4:
                                              FIO0SET = PH1_M;FIO0CLR = PH2_M;
    
                                              if(acc_step<MAX_ACCER_STEP){
                                              T0MR0=accer_table[acc_step];
                                              acc_step++;
                                              }
                                              motor_step = 1;
    
    
                                              break;
    
    
                                             }
                                              T0IR        = 1;
                                              VICVectAddr = 0;
                                              return;
                                     }
    
                                     }
    

    Here accer_table is table of step duration value.

    Thanks & Regards
    Rohit

  • Not sure if there was a question hidden there somewhere.

    Anyway - note that each timer can have up to four match register values.
    And for each match register, you could reset the timer (which would obviously only work well if used with the match register with the highest value).
    And for each match register, you could generate an interrupt.
    And for each match register, the hardware could control an output pin.

    So you could control multiple windings with same timer without loading the processor with the interrupts, as long as the motor is run at constant velocity. With interrupts at end of the sequence you could reconfigure the match registers for increasing or decreasing the motor speed.