Pulsin


Closed Thread
Results 1 to 8 of 8

Thread: Pulsin

  1. #1

    Default Pulsin

    Hello all, I am trying to count some pulses in the 12f683 pic using pulsin command. is an external oscillator necessary to utilize the pulsin command in PBP? if not what defines are necessary to make it work because so far i can't make the pic read pulses. i keep reading "0" for the pulse width. thank you all for your help.

    Jose
    Define Osc 4 '4mhz

    TRISIO = %000100
    LCD var GPIO.0
    T2400 con 396 '2400 baud

    lowP VAR WORD 'falling edge
    hiP VAR WORD 'rising edge
    widthP VAR WORD 'pulse width
    freqIn VAR GPIO.2 'input pulse

    loop:
    pulsin freqIN, 0 , lowP 'low pulse width
    pulsin freqIN, 1 , hiP 'get high pulse width

    widthP = lowP + hiP
    pause 5:serout2 LCD, T2400, ["start", 1, DEC (lowP), ",", DEC (hiP), ",", DEC (widthP), 0]

    pause 500
    goto loop

    '===================
    '===pulse being sent====
    Define Osc 4 '4mhz

    TRISIO = %000000
    pulse VAR GPIO.0

    loop:
    HIGH pulse
    pause 1
    LOW pulse
    pause 1
    goto loop

  2. #2


    Did you find this post helpful? Yes | No

    Default

    by the way i RTFM but didn't understand if it was necessary or not. if i can avoid having to purchase an external oscillator it would be better.
    "Defining an OSC value has no effect on PULSIN. The resolution always
    changes with the actual oscillator speed." thanks

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jmbanales21485 View Post
    "Defining an OSC value has no effect on PULSIN. The resolution always changes with the actual oscillator speed." thanks
    All this means is that pulsin will count as fast as the PIC is running.
    An example...
    Your statement is: Pause 1 and you've got DEFINE OSC 20 and a 20Mhz crystal. PBP adds in a delay loop, a few NOPs, etc, and you'll get a 1 millisecond pause.
    Now, without changing the program, you switch over to a 4Mhz crystal and run the same program. The pause will be 5ms long because PBP figured you wanted a 1ms pause @ 20Mhz.
    Same thing with SERIN/SEROUT, and a few other timing sensitive commands.

    Pulsin is different...It runs just as fast as it can in a nice tight loop checking the pins as fast as it can. You can 'DEFINE OSC xx' all day and not change how fast pulsin runs. The only way you can change it is by changing the oscillator.

    So, yes, for the best resolution with pulsin, you have to go with a faster clock speed.

  4. #4


    Did you find this post helpful? Yes | No

    Default

    got it! i'll get a crystal as soon as i can to get pulsin to work. thanks again skimask.

    jose

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jmbanales21485 View Post
    got it! i'll get a crystal as soon as i can to get pulsin to work. thanks again skimask.

    jose
    The only problem with going with a faster oscillator and using pulsin is that you might end up counting too fast and max out the pulsin statement before you actually finish counting.
    If you've got an idea of the maximum pulse width that you'd ever be sampling, you should base your oscillator choice on that.
    Once you've got that down and working, there are other ways to count pulse widths, using a timer, a capture, and so on...

  6. #6


    Did you find this post helpful? Yes | No

    Default

    I got the ccp interupt working on the 12f683 and i am able to count the pulse width, period, etc with it. but i need to count the pulse on 6 different pins and i could only use the ccp interupt on the ccp pin. therefore i though i should use the "pulsin" to count the pulses so i can use multiple pins.

    i could use "pulsin" on any pin and as many pins i want right? the minimum pulse width is 25us and the maximum pulse is 16.5ms on the system that im trying to interface. do you have any suggestions as to what size crystal i should get? i think im gonna stick with the pic16f84A for this project. it has 13 different I/Os 6 of which are going to be input from the pulses.

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jmbanales21485 View Post
    I got the ccp interupt working on the 12f683 and i am able to count the pulse width, period, etc with it. but i need to count the pulse on 6 different pins and i could only use the ccp interupt on the ccp pin. therefore i though i should use the "pulsin" to count the pulses so i can use multiple pins. i could use "pulsin" on any pin and as many pins i want right? the minimum pulse width is 25us and the maximum pulse is 16.5ms on the system that im trying to interface. do you have any suggestions as to what size crystal i should get? i think im gonna stick with the pic16f84A for this project. it has 13 different I/Os 6 of which are going to be input from the pulses.
    You could 'steer' the different pulses to the ccp pin using a simple logic gate, something like a 2 input AND gate, one input tied to an 'enable' pin, the other input tied to the actual input pulse.

    - Pulsin can be used on as many pins as can be set to inputs.

    - If you used a 20Mhz oscillator, the pulsin resolution is 2us... Therefore, at 25us, you'll get either 12 (24us) or 13 (26us) counts; at 'exactly' 16.5ms (16,500 us), you'll get 8,250 counts.
    (Theoretically, and if the PIC supported it, you should be able to go all the way up to 80Mhz...25us=100 counts, 16,500=33,000 counts).

  8. #8
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    PulsIn ties up the processor for the duration of the pulse. Without knowing the details of the application it's hard to say for certain but it's not a good choice if you need to count pulses on multiple pins simultaneously.

Similar Threads

  1. Better understanding PULSIN
    By Wirecut in forum mel PIC BASIC
    Replies: 12
    Last Post: - 29th June 2008, 10:17
  2. Funny PULSIN values: what is going on???
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th April 2008, 08:02
  3. Pulsin 16F819 problem
    By rekcahlaer in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 11th April 2007, 13:52
  4. Pulsin to pulsout with up than 4MHZ crystal ?
    By RCtech in forum mel PIC BASIC
    Replies: 5
    Last Post: - 18th May 2006, 19:23
  5. PULSIN and RCTIME
    By Dwayne in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th November 2004, 14:45

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