Input Capture Clarification

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Input Capture Clarification

1,753 Views
Nandav
Contributor I
hi everyone,
I'm currently working on RG60 SLK.
I'm trying input capture.
But i'm not able to get it.
The problem i face is that i can't figure out how to code for capturing two consecutive raise for period calculation.

if possible kindly provide me with an example code.

Thank you.
Labels (1)
0 Kudos
4 Replies

378 Views
bigmac
Specialist III
Hello Handav,
 
Period measurement using an input capture channel is relatively simple, provided the period you are trying to measure is always less than the timer overflow period.  It becomes considerably more complex if the measurement period can be greater than the overflow period, since you also need to take into account the number of timer overflows.  What is your requirement?  Another possibility is to measure the period of each cycle, and calculate the average period over a number of cycles, to reduce the affects of any jitter on the reading, or perhaps to increase resolution.
 
The frequencies you are attempting to measure should be much less than the MCU bus frequency.  You will need to utilise input capture interrupts, and the ISR processing period will need to be less than the minimum period to be measured.  Other interrupts may also delay input capture processing.
 
For a basic measurement, the following steps would be required -
 
1.  Initialise timer channel for input capture interrupt on positive edge.
2.  First time ISR processing - read timer register and store the word value.
3.  Second time ISR processing - read timer register, subtract previously stored value, store the result, flag a new reading, and possibly disable further input capture interrupts if only single period measurement.
 
If the second timer register value is less than the first value, timer overflow has occurred between the two readings, and the result of the subtraction will need to be negated.
 
These are some of the basic considerations for use of input capture.
 
Regards,
Mac
 

Message Edited by bigmac on 2006-09-15 01:34 AM

0 Kudos

378 Views
Nandav
Contributor I
Hello bigmac,
Thank you for your reply. As i've just started input capture, i'm trying to find out the period by subtracting the two consecutive raise times. The problem i face is that i don't know how to switch between the opeations for the first interrupt and the second interrupt. I've used the following logic... initialised a memory, rotated right through carry and then branced if carry clear to first raise where the value is incremented. to get you a clear picture of this i'll give the code i've tried. kindly give me your comments.

data defn:
ORG $50
S1:smileyvery-happy:C.W $0000
S2:smileyvery-happy:C.W $0000
R1:smileyvery-happy:C.W $0000
DUMMY:smileyvery-happy:C.B $0

org $FFF6
FDB RAISE

code:
mainLoop:

MOV #$08 ,TPM1SC ;TOIE DISABLED, BUS CLK SELECTED ,NO PRESCALE
MOV #$44 ,TPM1C0SC ;INTERRUPT ENABLED, RAISING EDGE INPUT CAPTURE


feed_watchdog
BRA mainLoop

RAISE LDHX TPM1C0V
ROR DUMMY
BCC FIRST
STHX S2
LDA S1+1
SUB S2+1
STA R1+1
LDA S1
SBC S2
STA R1
STOP

FIRST: STHX S1
INC DUMMY
BRA mainLoop

hope i'm clear for you.

regards
Nandakumar.V
0 Kudos

378 Views
bigmac
Specialist III
Hello Nandakumar,
 
Correct me if I am wrong, but you seem to have done little assembly coding before - there are numerous fundamental errors in your program structure and detail that suggest this.  You would need to gain understanding of basic structure, and particularly the way interrupt processing works within the MCU, before trying to utilise the input capture processing.  If you have not already done so, I would suggest you examine simple sample programs supplied with CW, such as LED flashing routines, etc. to see how an assembly program should be structured.
 
The following is a very basic outline of an absolute assembly program framework, with one ISR shown.
 
; Specify basic include files -
; Register names and definitions for MCU type, etc
  INCLUDE "DERIVATIVE.INC"
 
********************************************
; Allocate RAM variables:
  ORG    RAM     ; Start of RAM block
VAR1:    DS   1  ; Byte variable allocated
VAR2:    DS   2  ; Word variable allocated
 
********************************************
  ORG    ROMSTART ; Start location for code
 
START:  ; Beginning of initialisation code
        ; Initialise stack pointer
 
        ; Initialise CONFIG, I/O, timer, etc.
 
        CLI    ; Enable interrupts
 
MAINLOOP:
       ; Reset COP timer
 
       ; Main loop processing
 
        JMP   MAINLOOP ; Loop always
 
********************************************
; Sub-routines called by main loop, etc.
 
 
 
********************************************
; Interrupt service routines (ISRs)
 
TMPC0_ISR: ; Timer Ch 0 interrupt service
       PSHH           ; Usually necessary
 
      ; ISR processing
      ; Clear interrupt flag(s)
 
      PULH           ; Restore previous value
      RTI            ; Exit from ISR
 
********************************************
; Setup interrupt vectors:
  ORG $FFF6          ; Timer Ch0 vector
      DC.W  TMPC0_ISR
      ; Other vectors
  ORG $FFFE          ; Reset vector
      DC.W  START         
 
See if you can fit your code into this basic framework.  To answer your specific question - you need to set up a counter that is incremented each time you enter the ISR.  Alternatively, you might utilise a single bit flag that is cleared within the main loop, and set the next time the ISR executes.  The ISR would first test the flag to see if it is already set, or not.  Incidently, never use a STOP instruction unless you have set up a means of waking the MCU.  I would not use it within an ISR.
 
Regards,
Mac
 

Message Edited by bigmac on 2006-09-18 12:24 AM

0 Kudos

378 Views
Nandav
Contributor I
dear mac,
you're right..
i'm totally new to assembly programming.
i was held up with my exams, that's why i could not reply.
I think i'll be comfortable very soon.
I want to thank you for your reply.

Nanda.
0 Kudos