Timers16-Bit Timer Setup ExamplesMN102H75K/F75K/85K/F85K LSI User Manual Panasonic Semiconductor Development Company107Panasonicchange any other operating modes during this step.When TM4MD[1:0] = b’10’ (dur-ing capture), TM4CA andTM4CB become read-only regis-ters. To write to TM4CA orTM4CB, you must first setTM4MD[1:0] = b’00’.3. Set TM4NLD and TM4EN to 1. This starts the timer. Counting begins at thestart of the next cycle.To enable timer 4 capture B interrupts:Cancel all existing interrupt requests. Next, set the interrupt priority level in theTM4CBLV[2:0] bits of the TM4CBICH register (levels 0 to 6), set the TM4BIEbit to 1, and set the TM4BIR bit of TM4CBICL to 0. From this point on, aninterrupt request is generated whenever a timer 4 capture B event occurs.n To service the interrupts and calculate the signal width:1. Run the interrupt service routine. The routine must determine the interruptgroup, then clear the interrupt request flag.Ignore the flags when calculat-ing the signal width, even whenTM3CA is the larger value.2. Calculate the number of cycles the TM4IA signal stays high. Save the con-tents of TM4CA and TM4CB to the data registers, then subtract the contentsof TM4CA from the contents of TM4CB. Since TM4LP is set to 0, the dif-ference will be the correct value even if TM4CA is greater than TM4CB.Timer 4 can input a single-phase capture signal. You must select up counting.Timer 4 does not operate in STOP mode, when B OSC is off. If you use an externalclock, it must be synchronized to BOSC .TM4CA captures the count on the rising edge of TM4IA, and TM4CB capturesthe count on the falling edge of TM4IA. A timer 4 capture B interrupt occurswhen TM4CB captures the count, and the contents of TM4CA and TM4CB areread during the interrupt service routine.In the example timing chart shown in figure 4-36, x’000A’ – x’0007’ = x’0003’,or 3 cycles. The calculation is correct even when TM4CA is the larger value. Theflags are ignored, so for instance, x’0003’ – x’FFFE’ = x’0005’.nFigure 4-36 Single-Phase Capture Input Timing (Timer 4)TM4ENTM4BCB OSC/4TM4CATM4CBTM4IAInterrupt0 1 2 3 40 5 6 7 8 9 A B C D E F 10 11 120 70 AA-7=3B