Download presentation
Presentation is loading. Please wait.
Published bySusan Peters Modified over 6 years ago
1
Example 19 Measuring Pulse Widths Using Interrupts
Lecture L8.3
2
PIM_9DP256 Block Diagram Timer module
3
Timer Pins PT0 – PT7 Pins 9,10,11,12, 15,16,17,18
4
Timer Pins PT0 – PT7 Pins 9,10,11,12, 15,16,17,18 PT1 = Pin 10
5
Interrupts on rising and falling edges
HI_time LO_time Interrupts on rising and falling edges
6
MC9S12DP256B Interrupt Vectors
7
// Example 19: Measuring Input Pulse Widths on Channel 1
#include <hidef.h> /* common defines and macros */ #include <mc9s12dp256.h> /* derivative information */ #include "main_asm.h" /* interface to the assembly module */ #pragma LINK_INFO DERIVATIVE "mc9s12dp256b" // Timer channel 1 interrupt service routine void interrupt 9 handler1(){ HILOtimes1(); // update HI-LO times on Ch 1 }
8
void main(void) { int period1; // period of input pulse train on Ch 1 int HI_time1; // measured HI time of pulse train on Ch 1 int LO_time1; // measured LO time of pulse train on Ch 1 PLL_init(); // set system clock frequency to 24 MHz lcd_init(); HILO1_init(); while(1) { HI_time1 = get_HI_time1(); // read new HItime1 LO_time1 = get_LO_time1(); // read new LOtime1 set_lcd_addr(0x00); write_int_lcd(HI_time1); // write HItime on row 1 of lcd set_lcd_addr(0x40); write_int_lcd(LO_time1); // write LOtime on row 2 of lcd period1 = HI_time1 + LO_time1; set_lcd_addr(0x14); write_int_lcd(period1); // write period on row 3 of lcd ms_delay(100); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.