Exact delay for a loop


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default No need to use interrupt

    Hi,

    Even if you turn-off the Global Interrupt enable bit or the respective peripheral interrupt enable bits the Interrupt Flag for respective peripherals do get set on a PIC. So you just need to poll the Flag and all of them are accessible in PBP. Since your timer is rolling over you have enough time to poll the flags between rollovers. If you use less prescaler and a tight loop then possibilly the delay in testing the condition would suffice your need. As I mentioned in the previous post please mention the PIC and the Oscillator frequency to give you a better idea.
    For example if you are using Timer0 and your prescaler is around 1:8 (divide by 256) then your timer will overflow 15.25 times every second. So if your loop polls the flag 15 times you increase the seconds counter. Remember to clear the flag just after polling and getting a set bit. By adjusting the offset and using interrupt it is possible to get more accurate time base. But if your application permits you can choose this way. You can keep the prescaler low so that errors in every cycle is reduced however that solely depends how much code you need to excute in your loop. If the loop is lengthy in terms of execution time then you can put in frequent checking through gosubs and calling your check routine every now and then. Kind'a PBP On-Interrupt Scheme.
    Regards

    Sougata

  2. #2
    Join Date
    Apr 2006
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    Actually i just need it to use in my RPM counter program ,the loop which need to be executed is a repeated count loop that add a variable everytime a pin becomes LOW.(which i use a photosensor to scan the revolution per minutes for my DC motor).i use PIC16F877 and 4MHZ crystal for my application
    So for a certain time (1 minutes ) i know that how many times my motor slice has through my sensor ,by this way i can know the RPM of the motor,or is there any other way i can achieve that?Thanks.

  3. #3
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Better to do with Interrupt

    Hi,

    Don't tell me you will be counting pulses for 1 minute and update your display. Too boring for a RPM counter. Why not check it every second and multiply the reading by 60. 1 sec refresh rate for your display. It is best to use Timer1 in counter mode and dumping the results every 1 second. For that you need a 1 sec timebase. If you are not accustomed with interrupts then this is high time to get going. Darrel has done a great job look here http://www.picbasic.co.uk/forum/showthread.php?t=3251 or http://darreltaylor.com/DT_INTS-14/intro.html and here http://darreltaylor.com/DT_INTS-14/elapsed.html for your timebase thing.
    Regards

    Sougata

  4. #4
    Join Date
    Apr 2006
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    Thanks sougata for the info,i'll try and work it out then .thanks!

  5. #5
    Join Date
    Apr 2006
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    Hi there ,yesterday i had tried the timer interrupt function but ,i think i need one more interrupt for my sensor to detect (i use RB0 to trigger the pin) but i encounter 1 problem ,which is in my program i need 2 interrupt with differnt priority,any idea how to accomplish this ?thanks.

Similar Threads

  1. Controlsystem for compact sporting (clay shooting)
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 30th July 2009, 17:48
  2. 16F628A - Stops if release power switch.
    By dene12 in forum General
    Replies: 16
    Last Post: - 14th February 2009, 08:57
  3. Old and beyond help ?
    By DavidFMarks in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 11th December 2008, 16:23
  4. Memory Space of the PIC16F84...
    By Tear in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 1st July 2005, 20:55
  5. Problem with saving to EEPROM...
    By Tear in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 1st July 2005, 01:10

Members who have read this thread : 0

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