How to calculate Prescalar and Modulus values for PIT (Programmable Interrupt Timer)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tvnaidu
    Contributor
    • Oct 2009
    • 365

    #1

    How to calculate Prescalar and Modulus values for PIT (Programmable Interrupt Timer)

    How to calculate Prescalar and Modulus values for PIT (Programmable Interrupt Timer). I have microcontroller running at 60MHz. I am thinking of writing 1 milli sec ISR for PIT. I need to calculate prescalar value and modulus value for PIT, prescalar value between 0 and 15, but how can I choose which value for 1ms timer at 60MHz system clock running?. appreciated.
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    The hardware documentation for your PIT ought to explain how timer clock frequency is derived from the chip clock frequency. You may have the choice of several timer clocks due to divider options in a control register. Once you know the timer clock frequency it is a simple matter to compute the counter value (prescalar and modulus) that yields the desired timer frequency.

    I know this is a very general reply, but I don't know what hardware you're using.

    Comment

    • newb16
      Contributor
      • Jul 2008
      • 687

      #3
      It's prescalEr first of all. Then you need overall divisor: 60 mhz/1 khz = 60000. Lets suppose that the timer is 8-bit and supports only values of Modulus(?) up to 255, and suppose that prescaler is dividing main clock frequency by 2**N where N is from 0 to 15, select smallest N such that 60000/(2**N) is less than 255. If timer is 16-bit, the prescaler may be left unused (1:1) and modulus set to 60000.

      Comment

      • tvnaidu
        Contributor
        • Oct 2009
        • 365

        #4
        I am using general PIT, there is 4 bit prescalar and modulus register, prescalar value tells like this:

        PRE system clock div
        0000 2
        0001 4
        0010 8
        0011 16
        0100 32
        0101 64
        0110 128
        0111 256
        1000 512
        1001 1024
        1010 2048
        1011 4096
        1100 8192
        1101 16384
        1110 32768
        1111 65536

        I just need to calculate mod using pre, they didn't give how to derive mod.

        Comment

        • donbock
          Recognized Expert Top Contributor
          • Mar 2008
          • 2427

          #5
          For example, if you set the Prescaler to 256 then the timer clock frequency is (60MHz/256). It will take (0.001)*(60,000 ,000)/256 clock ticks to count out 1 mS. You can perform a similar calculation for each prescaler setting.

          There will typically be a small error of about half the timer clock period due to integer round-off of the computed modulus value.

          The computed result will be too big to fit in the Modulus register for smaller prescaler settings. Choose a prescaler/modulus combination where the modulus value fits in the modulus register and where rounding error is minimized.

          This is still a general answer. Your specific timer hardware may do something different that I'm not aware of.

          Comment

          Working...