Ruth Hendrix

Input Capture Code

Discussion created by Ruth Hendrix Employee on Jan 26, 2006

This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.


Posted Dec 17, 2005, 11:37 a.m.


Does anybody have a snippet of code for doing input capture ?


I want to measure an input positive going signal about 46uS long.


In all the time I used the HC08s etc i never had to do input capture before!


Posted: Dec 17, 2005, 8:27 p.m.


Hi, happy to pass on my ignorance.


First setup the timer and timer channel for icap on the prefered edge.


Then setup the interupt routine for that channel to deal with the interupt.


Below is a simple app that just reads the time of a + edge on the timer channel pin.


Processing that info is obviously app specific so whether it's processed in the main loop or in the Irupt sub itself will depend on that app.



**************************************************** * YourProg.asm * Input Capture example ****************************************************  $Base 10T VectorStart EQU $FFDE  *General MCU specific equates $Include ''  org RamStart YourVar ds 2 **************************************************  org RomStart RESET * Setup ports and config regs etc. .... ....  * Setup Timer InitTimer: * bit 5 clears stops timer * bit 4 sets timer to zero * prescale bits 1,0 clear, sets timer resolution to max. mov #%00110000,TSC ; Clear & Stop  * bit 6 enables irupts on channel x * bit 3 sets channel x to ICap. mov #%01000100,TSCx ; ICap 0n, + edge  * clear TSC to restart timer at max resolution mov #%00000000,TSC ; start the timer  cli bra main  **************************************************** *** End of Initialisation ****************************************************  **************************************************** *** Start of Main Loop ****************************************************  MAIN: wait ; wait for ICap  * new ICap event time available for processing * so do stuff with YourVar here .... ....  bra main  **************************************************** * Subroutines ****************************************************  **************************************************** * TChx_isr - Timer Ch1 Interrupt Service Routine. * save H reg to stack * read time of ICap * Process the event (to suit app) * recover H * clear for next ICap on exit **************************************************** TChx_isr pshh ; Save H (just a habit) mov TCH0H,YourVar ; Read high byte mov TCH0L,YourVar+1 ; Read low byte  * Do stuff with "YourVar" here (or in main) .... ....  * exit xTimx lda TSCx ; Read Ch1 SCR bclr 7,TSCx ; clear flag pulh ; recover H rti    **************************************************** * Vectors **************************************************** org Vectorstart .... ....