Real time clock + external interrupt in one PIC possible?


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116

    Default Real time clock + external interrupt in one PIC possible?

    Hello you all!

    its several years since I postet something here.

    My current problem:

    I need to measure the average speed of a car. I got an input signal from the driveshaft (one per revolution) wich I use for a distance couter with a 16F88 . The program uses "on interrupt" Now I need to divide the distance by real time after pushing a button. I got two favorite PICs because I´m an total inept programmer : 16F88 and 18F1320. Wrote my last program some years ago.
    The clock and the incomming driveshaft pulses both use interrupts and I think thats too much for one of these PICs. No I´m not migrating to DSPic or 24F.

    Any suggestions out there?

  2. #2
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Real time clock + external interrupt in one PIC possible?

    The PIC18F1320 would be my choice only given the 2 you offered. It easily can handle 2 Interrupts, and offers an internal Oscillator.

    - I would run the OSC at 4 MHz.
    - I would use INT0 (RB0) for the driveshaft trigger input. The Interrupt Handler should increment your counter variable every time the driveshaft makes another pass.
    - I would use TMR1 to create the 1 second timer (actually 1/2 second timer).
    > T1CON = %0011000X; .7 = TMR1H & TMR1L written to independently, <5-4> = 1:8 Prescale, .1 = Clock source is Fosc/4, .0 = On/Off
    > Preload TMR1 = 3035 (T1 will tick at 0.000008 seconds, times 62500 (65535 - 3035) = 0.5 seconds); TMR1H = $0B, TMR1L = $DB

    Since your TMR1_INT will occur every half second, it would probably be easiest to calculate your vehicle's speed by running the math around that. Say for instance your counter variable = 35 when your TMR1_INT overflows. You double it and get 70 driveshaft pulses per second. If you need better resolution, you could create a variable that will count 1/2 second TMR1 Interrupts and calculate vehicle speed only after 10 have occurred; which is 5 seconds. Be sure to clear your counter variable after using it in your calculation.

    There is some detail here, and some things left ambiguous. Hopefully this guides you to a working piece.

Similar Threads

  1. real time clock
    By maria in forum Code Examples
    Replies: 44
    Last Post: - 1st March 2022, 13:13
  2. Real Time Clock
    By in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 2nd June 2012, 05:52
  3. Real time clock
    By PlantBob in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 10th February 2011, 14:01
  4. Real Time Clock
    By savnik in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th December 2006, 03:02
  5. ds1307 real-time clock
    By mle in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 16th August 2004, 17:22

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