Pulse generation help required


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2005
    Posts
    14

    Default Pulse generation help required

    Hello, I need to generate a 16mS pulse (16F84A).

    Only issue is that I need to do that whilst reading a whole bunch of input signals. If I use Pause or Pulseout the processor does not do anything else during the 16mS and I miss input data.
    I can tolerate a 1mS pulse and not miss input but 16m is way to long.
    Other than using an external 16mS pulse generator triggered by a short pulse from the 16F84A.... is there any way of doing this in PicBasicPro ??

    Assistance appreciated.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default

    Muzza,

    You have various options to choose from.

    The first that springs to mind is to use one of the timers on the chip. TMR1 is usually 16bit wide (look it up in the 'F84 datasheet). It can be set to increment on each tick of the CPU so if your running on a 4MHz X-tal TMR1 will count uS (16mS = 16000uS).

    The timer will generate an interupt when it rolls over from 65535 to 0 so if you preset the timer to 59535 (65535-16000). It will interupt 16mS after it's started.

    You can use PBP OnInterupt to detect it OR just check the TMR1 Interuptflag in a loop to catch it. If you're going to use OnInterupt remember not to use any time consuming commands like pause while waiting for the interupt.

    /Henrik Olsson.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Sorry, my mistake...

    Hi again,
    Im sorry... I just returned from work and checked the datasheet for the 'F84 and it doesn't have TMR1. It does, however have TMR0 and a prescaler that you may be able to use as long as you turn off the WDT.

    If I where you I'd consider changing that 'F84 to something like the 'F628 if at all possible. If you NEED to run it on the 'F84 let us know...

    Here's a quick non tested example of how you could use TMR1 on 'F628. It doesn't use interupts it only polls the TMR1 interupt flag to se if it has rolled over.
    Code:
    Loop:
        If PortB.1 = 0 then Goto Loop       'Wait here until PortB.1 goes high.
    
    
    SetPulse:
       'Preload TMR1 ((232*256) + 143 = 59535)
       TMR1H = 232
       TMR1L = 143
       High PortB.1              'Set the output.
       T1CON.0 = 1             'Start the tmr.
    
    WaitForTimeOut:
       If PIR1.0 = 1 then      'The time is up...
           Low PortB.0          'Turn off the output
           T1CON.0 = 0         'Stop TMR1
           PIR1.0 = 0            'Reset the TMR1 Interupt Flag            
           TMR1H = 232        'Reload TMR1 so it ready for the next pulse
           TMR1L = 143
           Goto Loop
       Endif
    
       'Do your other stuff here.....
       'Don't use any time consuming pauses etc.
    Goto WaitForTimeOut
    Hope that helps a bit more than my first suggestion.
    /Henrik Olsson.

  4. #4
    Join Date
    Nov 2005
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Thanks for the advice

    Hendrik, thanks for the speedy advice.
    Looks like what I need to do to make my implementation work.
    I will go to the F628 as you suggest.
    I am new to this (PICs and PBP) and just learned heaps through investigating your suggested code and studying the datasheets to see how it works.
    Thanks heaps for that.
    Best Regards.
    Murray

Similar Threads

  1. Pulse Capture and byte building
    By boroko in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 21st July 2009, 01:59
  2. Single digit 7 Seg LED clock - PIC16F88
    By thirsty in forum Code Examples
    Replies: 4
    Last Post: - 17th July 2009, 08:42
  3. Replies: 3
    Last Post: - 13th September 2008, 17:40
  4. Unwanted output signal jitter
    By LinkMTech in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 18th January 2008, 02:31
  5. Pulse Frequency Multiplication
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 21st August 2005, 10:39

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