You are on page 1of 7

ME 421: Microprocessors

and Automatic Control Lab


Programming fundes: Periodic
Interrupt Timer (PIT)
P.S. Gandhi
Mechanical Engineering
IIT Bombay
PRASANNA S GANDHI
gandhi@me.iitb.ac.in

Periodic Interupt
Timer Interface (PIT)
Need:
n In automatic control systems (example motor here)
there are following tasks to be completed
continuously:
1. Read sensors (potentiometer in our case: ADC interface)
2. Compute control law (Say PD control)
3. Give computed control input to actuator (Motor in our
case: via PWM interface)
n

If these are done in a loop we do not have precise


control over the time for control input updation: this
time is called sampling time
PRASANNA S GANDHI gandhi@me.iitb.ac.in

Periodic Interupt
Timer Interface (PIT)
Need:
n One may argue that use delay but it also will
depend on how much time the rest of the program
is taking and if the program changes or program
has multiple if statements the precision of
implementation is lost
n So what is alternative? How to make control
program run at precise sampling time interval
n PIT module does this job of setting precise
sampling time for execution of program
PRASANNA S GANDHI gandhi@me.iitb.ac.in

Remember Philosophy
of interrupt
You are reading a novel and Mom calls
what do you do? you will mark a page
on your novel, finish the call and come
back again to reading novel.
n The same thing is done in
implementation of interrupts in
microcontroller. When a pulse arrives
on interrupt pin, current program is
paused, a new specific program called
interrupt service routine is executed
n

PRASANNA S GANDHI gandhi@me.iitb.ac.in

Remember Philosophy
of interrupt
After execution of ISR again main
program execution is resumed. You
may be doing nothing in main
program, then its just a wait for
another pulse to come on interrupt
pin.
n This philosophy is executed along with
a timer to generate interrupt pulses
periodically in various microcontrollers.
We will see specifics of PIT in XEP 100
n

PRASANNA S GANDHI gandhi@me.iitb.ac.in

Periodic Interupt
Timer Interface (PIT)
Basic Philosophy of PIT in XEP 100:
n The idea implemented in PIT module is that we use
counter based timer (similar to that used in PWM) to
generate a pulses or triggers precisely every
sampling time instant.
n The trigger unmasks a specified interrupt channel.
There is a function called interrupt service routine
associated with each interrupt. When interrupt
channel gets unmasked this functions starts running
and continues so till that channel is masked again.
So to run this ISR once we need to mask the
interrupt channel
again by issuing a command at 6
PRASANNA S GANDHI gandhi@me.iitb.ac.in
the end of ISR

Periodic Interupt
Timer Interface (PIT)
Basic Philosophy of PIT in XEP 100:
n Now you may write whatever program you would
like to be executed every sampling instant in this
function of ISR and it would execute without having
to set any delays J
n When program execution finishes the ISR would
wait again for interrupt channel to get unmasked by
pulse generated by the timer and this now continues
for ever
n This masking and unmasking is governed by flag
register in PIT called PITTF
Flag set == interrupt
unmasked
PRASANNA S GANDHI gandhi@me.iitb.ac.in

PIT Block
in XEP 100

PRASANNA S GANDHI gandhi@me.iitb.ac.in

PIT Registers to be
used (See datasheet)
n
n
n
n
n
n

PITCE_PCE0
PITMUX
PITMTLD0
PITLD0
PITINTE_PINTE0
PITCFLMT_PITE

Various
registers
n

17.4 Functional
Description
MUST READ

Various
registers

17.4 Functional
Description
MUST READ

Typical Program
*/
#include <hidef.h>
#include "derivative.h"

/* common defines and macros */


/* derivative-specific definitions */

void initPIT( void );


// function declaration for initiation of PIT module
we now write things in function form so as to systematically get to the
closed loop control avoiding confusion you may write similar routine for
ADC as well, it can be any name I chose initPIT
void main(void) {
/* put your own code here */
initPIT();
EnableInterrupts;
for(;;) {
_FEED_COP(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
PRASANNA S GANDHI

12

gandhi@me.iitb.ac.in

Typical Program
//we can write VectorNumber_Vpit0 or 66- refer MC9S12XEP100.h file
Line no.173
void interrupt 66 MotorControl ( void )
MotorControl can be any name
{

//VectorNumber_Vpit0 and

// Clear the interrupt flag


// your own routine for ADC in this case or motor control in general or
other control application
}
void initPIT( void )
{ //You will initiate various registers pertaining to PIT in this program
}
PRASANNA S GANDHI
gandhi@me.iitb.ac.in

13

Thank You

PRASANNA S GANDHI gandhi@me.iitb.ac.in

14

You might also like