Timing input pulses and re-outputting them


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2005
    Posts
    44

    Default Timing input pulses and re-outputting them

    Hi,

    Im working on a project that will watch RB.4 for square wave input pulses from a hall effect sensor, and needs to time them, and re-output them on another port. During this process, it will need to check the input pulse, if it doesnt exist (ie pin constantly in one state) for say 0.5 sec (or 0.65 sec if i use timer overflow on ccp), the pic needs to output pulses at a fixed frequency of approx 16hz until the input pulses exceed 16hz, then the output pulses will match the input pulses again. The pic cannot miss any input / output pulses, it must be 1:1.

    The input pulses will vary in frequency, from 0 to about 380 hz. It is a square wave that is usually high, with a low going pulse duty cycle of around 15%

    Think of this circut as a very crude failsafe / frequency corrector, I would like to be able to add a correction to the output signal so I can change the frequency of the output in proportion to the input by + / - 50%.

    The use of this project will be to monitor a shaft's RPM. If the shaft is stopped for > 0.5 sec, then it will output pulses to 'pretend' the shaft is turning at a low speed, until the shaft does indeed start turning again and soon as its turning above the 'pretended' speed (16hz) then the output will be the same as the input plus or minus the correction.
    This should be possible by manipulating the input pulse timings before outputting them.

    My plan is to use CCP to watch the input pulses, Set and clear the timer on initial high to low transition and time time how long it takes to go low to high to give me the low pulse width (xxx), and then time how long it takes from here to go high to low again to get the high part (yyy), then reset the timer to get the next reading. I am pretty sure I can get this part of the code working


    ----|___|-------------|___|------

    Where im stuck is how to create the output pulses and perform the checks on the input pulses without missing any of the input pulses. Also on how to keep the output pulses happening whilst there is no input.


    Ie if I use

    <get ccp timings>

    high output pin,
    pause yyy ,
    low output pin,
    pause xxx etc,

    or

    pulsout outputpin yyy,
    pause xxx,

    I have a feeling that the pulsout and pauses will hang the program thus missing the next input pulse in the sequence while it is completing the operation of sending the output pulse?

    Anyone have any ideas / comments on this, im sorry if the post above is a bit full on and confusing but i had to type it all while it was fresh in my head

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jamie_s View Post
    Where im stuck is how to create the output pulses and perform the checks on the input pulses without missing any of the input pulses. Also on how to keep the output pulses happening whilst there is no input.

    I have a feeling that the pulsout and pauses will hang the program thus missing the next input pulse in the sequence while it is completing the operation of sending the output pulse?

    Anyone have any ideas / comments on this, im sorry if the post above is a bit full on and confusing but i had to type it all while it was fresh in my head
    Check your PBP manual, pages 118 and 204, to handle the pulsin waiting problem.

  3. #3
    Join Date
    Aug 2005
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    Check your PBP manual, pages 118 and 204, to handle the pulsin waiting problem.
    PULSIN is not my issue, i need help with the output

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jamie_s View Post
    PULSIN is not my issue, i need help with the output
    Oh, misread you a bit. How about this:

    Instead of concentrating on timing and monitoring the input with the hardware, why not set up a 50% duty cycle PWM signal on an output, running continuously at 16hz, not needing any help from the program, all driven by the hardware.
    Use the program (pulsin) to monitor the input and change the PWM registers to match the input once it gets above 16hz. Set the pulsin_max to a pulse width corresponding to 16hz at your oscillator speed (ie. OSC is 4mhz, pulsin_max value is 10us per count, pulsin_max = 6250).
    With the PWM module, you can change freq and duty cycle, all you have to do is the math for it and change the registers to suit your needs.

    Or am I still out in left field for what you're wanting...

  5. #5
    Join Date
    Aug 2005
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    I was looking at PWM, but dont beleive it will go as low as 16hz?

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jamie_s View Post
    I was looking at PWM, but dont beleive it will go as low as 16hz?
    Well, if you use a PIC that has a programmable clock source (a lot of the newer ones do), you could change that clock 'on-the-fly' to get it down to 16hz, or do it thru TMR interrupts until the freq gets up to a point where you can use the PWM. For one thing, I don't know which PIC you're going to use ! Also, 16hz is the minimum freq, what's the max?
    Last edited by skimask; - 28th February 2007 at 02:55.

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