PIT Module

Embed Size (px)

Citation preview

  • 8/17/2019 PIT Module

    1/7

    1

    ME 421: Microprocessorsand Automatic Control Lab

    P.S. Gandhi

    Mechanical Engineering

    IIT Bombay

    Programming fundes: PeriodicInterrupt Timer (PIT)

    1PRASANNA S [email protected]

    Periodic InteruptTimer Interface (PIT)

    Need:

    !  In automatic control systems (example motor here)there are following tasks to be completedcontinuously: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 ourcase: via PWM interface)

    !  If these are done in a loop we do not have precisecontrol over the time for control input updation: thistime is called “sampling time”

    2PRASANNA S GANDHI [email protected]

  • 8/17/2019 PIT Module

    2/7

    2

    Periodic InteruptTimer Interface (PIT)

    Need:

    !  One may argue that use delay but it also willdepend on how much time the rest of the programis taking and if the program changes or programhas multiple if statements the precision ofimplementation is lost

    !  So what is alternative? How to make controlprogram run at precise sampling time interval

    !  PIT module does this job of setting precise “sampling time” for execution of program

    3PRASANNA S GANDHI [email protected]

    Remember Philosophyof interrupt

    !  You are reading a novel and Mom callswhat do you do? you will mark a pageon your novel, finish the call and come

    back again to reading novel.!  The same thing is done in

    implementation of interrupts in

    microcontroller. When a pulse arriveson interrupt pin, current program ispaused, a new specific program called

     “interrupt service routine” is executedPRASANNA S GANDHI [email protected] 4

  • 8/17/2019 PIT Module

    3/7

    3

    Remember Philosophyof interrupt

    !  After execution of ISR again mainprogram execution is resumed. Youmay be doing nothing in main

    program, then its just a wait foranother pulse to come on interrupt

    pin.!  This philosophy is executed along with

    a timer to generate interrupt pulsesperiodically in various microcontrollers.

    We will see specifics of PIT in XEP 100PRASANNA S GANDHI [email protected] 5

    Periodic InteruptTimer Interface (PIT)

    Basic Philosophy of PIT in XEP 100:

    !  The idea implemented in PIT module is that we usecounter based timer (similar to that used in PWM) togenerate a pulses or triggers precisely every

     “sampling time” instant.!  The trigger unmasks a specified interrupt channel.

    There is a function called “interrupt service routine”associated with each interrupt. When interruptchannel gets unmasked this functions starts runningand continues so till that channel is masked again.So to run this ISR once we need to mask theinterrupt channel again by issuing a command atthe end of ISR

    6PRASANNA S GANDHI [email protected]

  • 8/17/2019 PIT Module

    4/7

    4

    Periodic InteruptTimer Interface (PIT)

    Basic Philosophy of PIT in XEP 100:

    !  Now you may write whatever program you wouldlike to be executed every sampling instant in thisfunction of ISR and it would execute without havingto set any delays " 

    !  When program execution finishes the ISR wouldwait again for interrupt channel to get unmasked bypulse generated by the timer and this now continuesfor ever

    !  This masking and unmasking is governed by flagregister in PIT called PITTF

     –  Flag set == interrupt unmasked7PRASANNA S GANDHI [email protected]

    PIT Block

    in XEP 100

    8PRASANNA S GANDHI [email protected]

  • 8/17/2019 PIT Module

    5/7

    5

    PIT Registers to beused (See datasheet)

    !  PITCE_PCE0

    !  PITMUX

    !  PITMTLD0

    !  PITLD0

    !  PITINTE_PINTE0

    PITCFLMT_PITE

     Variousregisters

    !  17.4 FunctionalDescription

    MUST READ

  • 8/17/2019 PIT Module

    6/7

    6

     Variousregisters

    !  17.4 Functional

    DescriptionMUST READ

    Typical Program

    12PRASANNA S [email protected]

    */#include /* common defines and macros */#include "derivative.h" /* derivative-specific definitions */

    void initPIT( void ); // function declaration for initiation of PIT modulewe now write things in function form so as to systematically get to theclosed 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 */}

  • 8/17/2019 PIT Module

    7/7

    7

    Typical Program

    13PRASANNA S [email protected]

    //we can write VectorNumber_Vpit0 or 66- refer MC9S12XEP100.h fileLine no.173

    void interrupt 66 MotorControl ( void ) //VectorNumber_Vpit0 andMotorControl can be any name{

    // Clear the interrupt flag

    // your own routine for ADC in this case or motor control in general orother control application 

    }void initPIT( void )

    { //You will initiate various registers pertaining to PIT in this program}

    Thank You

    PRASANNA S GANDHI [email protected] 14