Need help with INTerrupts


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2004
    Location
    CA
    Posts
    78

    Default Need help with INTerrupts

    I have a project that has a sensor connected to the analog pins of the microcontroller.
    PIC18F6520 is the controller part number which I am using The sensor is sending a
    train of pulses at a certain frequency. I would like to measure the length of time
    the signal is high, and the period od the entire pulse so that I can measure the frequency and the duty cycle of the pulse.


    I was thinking that I should implement a interrupt and two timers Timer0 and Timer1.

    the timer0 can measure the time the pulse is high, and timer1 can measure the period of the pulse.

    I know this is possible but I need your help. My question is from the code below. how will the timer know when the input pulse made a transition from high to low and when to stop the timer.

    here is what I ahve thus far.

    I have started interrupt and the timer0(the timer that will measure the high pulse).
    I was wondering how to use the On inteerupt command that PBP comes. so whenever the interrupt comes I can jump into the ISR and begin measureing the pulse with timer0


    CODE----------------------------------------------------------

    Value VAR Byte 'value for how long the pulse was high.
    TrisD = %11000000


    On Interrupt goto ISR_INT

    start:
    if(PortD.7 = 1)&&(PortD.6 = 0) then
    T0CON = %11000011 'Timer0 is turned on
    INTCON.7 = 1 'Globale interrupt enabled
    endif
    if(PortD.7 = 0)&&(PortD.6 = 1) then
    T0CON = %11000011 'Timer0 is turned on
    IntCON.7 = 1 'Global interrupt enabled

    endif

    Goto Start

    Disable


    ISR_INT:

    T0CON = %11000011 'Timer0 is turned on
    'Timer0 prescalar to 16
    'Timer0 increment on low to high transition

    Value = TMR0L 'store the value of the lower 8 bits of TIMER0 into the Value variable

    INTCON.1=0 'clear the timer0

    Resume
    Enable

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    There's an example of using the capture module in this thread
    to measure high/low pulse width, and period;
    http://www.picbasic.co.uk/forum/showthread.php?t=6719
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. Instant Interrupts - Revisited
    By Darrel Taylor in forum Code Examples
    Replies: 772
    Last Post: - 17th February 2016, 22:14
  2. Clock using Instant Interrupts
    By PICpocket in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th February 2009, 21:43
  3. Microcode studio - PIC16F877A Interrupts
    By mcbeasleyjr in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th January 2009, 06:10
  4. DT's Instant Interrupts trouble
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th November 2008, 20:48
  5. help: TMR0 interrupts disabling PORTAchange interrupts???
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th August 2008, 15:10

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts