473,748 Members | 8,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

365 Contributor
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.
Nov 10 '09 #1
4 5696
donbock
2,426 Recognized Expert Top Contributor
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.
Nov 10 '09 #2
newb16
687 Contributor
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.
Nov 10 '09 #3
tvnaidu
365 Contributor
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.
Nov 10 '09 #4
donbock
2,426 Recognized Expert Top Contributor
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.
Nov 10 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4719
by: Mark | last post by:
Hello all, I know why the following doesn't work ... I can't figure out how to make it work like I want it to. Basically, I only want the loop computing fibonacci numbers to run for approx 5 seconds. The timer fires, the exception is raised, but it is not caught ... because the execution stack for the function that raises isn't in the same thread as the try: except:. How do you fix this? Is it better to do this without exceptions as...
19
6485
by: Jane Austine | last post by:
As far as I know python's threading module models after Java's. However, I can't find something equivalent to Java's interrupt and isInterrupted methods, along with InterruptedException. "somethread.interrupt()" will wake somethread up when it's in sleeping/waiting state. Is there any way of doing this with python's thread? I suppose thread interrupt is a very primitive functionality for stopping a blocked thread.
41
3114
by: Saurabh Saxena | last post by:
can we calculate the 73! value in c or c++ without loss of significant digits.
10
3282
by: jantod | last post by:
I think there might be something wrong with the implementation of modulus. Negative float values close to 0.0 break the identity "0 <= abs(a % b) < abs(b)". print 0.0 % 2.0 # => 0.0 print -1e-010 % 2.0 # =>1.9999999999 which is correct, but:
5
4261
by: mysli | last post by:
Hi all, I need to write a ISR using Microsoft VC++ 2005. The proplem is I did not found any hint on how to do it. I can register any function as a ISR and it will be called by the hardware interrupt, interrupt 8 (timer) i.e., works fine in my little example progam. But the problem is the compiler ends every function with RETN, after disassembling the result of the compilation this can be seen easiely. Every function starts and ends with:
2
6164
by: mscdex | last post by:
I have a server application that accepts file transfers (utilitzing tcplistener) and was wondering how I would efficiently go about determining the calculate transfer rate while I am transferring the file. The Sub where the transfer actually takes place is called asynchronously. The (psuedo) code in the Sub goes something like this: While byteCount < filesize bytesRead = Bytes read from NetworkStream
0
2271
by: gbagur | last post by:
Does anybody has an example code of using the timer interrupt? I need to generate an event every 33ms. Thank you!
2
7163
by: Eirik Midttun | last post by:
I have seen quite a few times that C programs contain a file named isr.c or files named a_isr.c, b_isr.c where a and b are hardware that generate interrupts. Obviously these files contain code to be executed on interrupts and is most common in embedded application. My own preference is a different one. If I write a scheduler that uses a timer, I would keep the timer interrupt code together with the code that does the initialisation, adds...
1
1753
by: symmer | last post by:
Hello, I am familiar with C language.But I have never tried working on Interrupt routines or Timers. Please help me write a interrupt routine for waiting for an event to occur. If an event occurs I need to reset the Timer. If the event does not occur we increment the counter till the event occurs. Thanks symmer
0
9537
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9243
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8241
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.