Multiple Pulsin Measurements


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Multiple Pulsin Measurements

    Sorry to be dense but here goes -
    so for a 1000 uS pulse you get as a result-
    1224 for pulsin
    1300 for your routine
    1100 for just 1 bit sampled?

    You can see I don't think I have this right. If I do, they are all crap IMHO. best being off by 10%!

    I am crafting up a possible solution, but these numbers are messing with me.

    On to more fun stuff. So you have around 50 mS to wait for the next series of pulses correct? If so, what about this:
    when the first pulse starts (or all of them at once, whatever) start a timer.
    XOR the 8 bits (faster if they are all on the same port)
    keep checking until one of more change.
    when they do, grab the counter value and store it with the port value.
    When you have done this 8 times, you will have the counter differences for each bit.

    Now go process the information to determine how long each pulse lasted. Plenty of time left to get back and wait for the next series of 8 pulses. Now if you wanted to use interrupts, have all 8 on IOC pins, then when the ISR fires, grab the counter and states there. This will take a feww cycles longer though.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  2. #2
    Join Date
    Jun 2005
    Location
    Surrey, England
    Posts
    35


    Did you find this post helpful? Yes | No

    Default Re: Multiple Pulsin Measurements

    Thanks for your advice - I will think about your "Fun stuff" - actually the actual timings/test results are the opposite of what you understood from my description:
    so for a 1000 uS pulse you get as a result-
    1224 for pulsin - correct (=~ 1000*48/40)
    1300 for your routine - No I get an answer of around 300
    1100 for just 1 bit sampled? - No I get an answer of around 800

    Whilst using interrrupts etc as you suggest may be a purist answer, I think 8 successive PULSINs are going to be much easier - I cant guarantee the pulses will arrive synchronously, but it is the precision I am worried about, not the sample time it takes (hence the 50 mSec pause between pulses)

  3. #3
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Multiple Pulsin Measurements

    I dont know about the "purist" part, and IMHO anything needing better then 5uS accuracy is not well suited for interrupts.
    Now I understand your numbers, 300 is really 300 iterations of the loop. so its as accurate as the loop takes (given 1000uS pulse, 3.333uS loop time)

    I propose you can achieve 1uS with my suggestion, maybe better. But if you can get the XOR to be 2-3 instructions, 2 jumps = 4more (to the grab time and back), then a couple of instructions to save the timer count and port states. You will be right around 12 instructions I think. So not much better then the pulsein, but nicer in the respect you can get all 8 at once.

    I am assuming you are using this to check the speed of the 8 uP's. something else to consider :
    If they are sending the pulses every 50 mS, you could measure the low pluse (50mS long) instead of the high pulse. This will give you a much bigger window to check the the duration against. 1% is 500 uS in this case. so being off by 3 or 4 uS would then be peanuts.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  4. #4
    Join Date
    Jun 2005
    Location
    Surrey, England
    Posts
    35


    Did you find this post helpful? Yes | No

    Default Re: Multiple Pulsin Measurements

    Thanks so much for your helpful thoughts - I will go away and work at your suggestion - I agree interrupts may not be accurate enough - you are quite correct I am monitoring the 8 baby PICs' oscillator speeds and I agree a longer pulse is easier (more accurate) to measure.
    Peter

  5. #5
    Join Date
    Jun 2005
    Location
    Surrey, England
    Posts
    35


    Did you find this post helpful? Yes | No

    Default Re: Multiple Pulsin Measurements

    I decided to try and make the assembler less ugly first by using indirect addressing to access the Period[8] array but it is no faster than my laborious method and this one will only run on an 18F4550 due to the use of the helpful POSTINC0 operator representing INDF(0) with a post Increment:
    Code:
    _xPULSIN    MOVLW   0xFF
                MOVWF   _pCount  
                MOVLW   0x0F 
                MOVWF   _pCount + 1     ;pCount = $FFF  = 4095
                MOVLW   _Mask
                MOVWF   _k              ;k = Mask
                CLRF    _sample         ;clear sample flag
                
    cycleX      MOVF    _mPort, W       ;Sample the Port
                ANDWF   _k, W
                MOVWF   _j              ;j = Port AND Mask
                MOVLW   High(_Period)   ;Set up FSR to point to Period[0] 
                MOVWF   FSR0H
                MOVLW   Low(_Period)
                MOVWF   FSR0L
                MOVLW   1
                MOVWF   _i              ;Bit Marker = 00000001
    CheckJ      RRCF    _j
                BTFSS   STATUS,C        ;Bit i Set
                    GOTO BCLR
                INCFSZ  POSTINC0        ;Yes - Period[i] = Period[i]+1
                    GOTO NoRoll
                INFSNZ  POSTINC0        ;=Inc and always skip - Period.Hi never Zero
    NoRoll      MOVF    POSTINC0,F      ;=NOP except inc FSR
                MOVF    _i,W
                IORWF   _sample,F       ;Now sampling bit i
    Nexti       RLCF     _i             ;i = i<<1
                BTFSS   STATUS,C        ;Carry set = 8 rotations?
                    GOTO    CheckJ      ;No - Loop round
                MOVF    _k,F            ;Is Mask = 0?
                BTFSC   STATUS,Z
                    RETURN              ;Yes - Finished all samples
    DecCount    DECFSZ  _pCount         ;No - Update counter 
                GOTO    cycleX
                DECFSZ  _pCount + 1
                GOTO    cycleX
                RETURN                  ;Countdown = 0 - Timeout?
    BCLR        MOVF    POSTINC0,F      ;=NOP except inc FSR
                MOVF    POSTINC0,F      ;=NOP except inc FSR
                MOVF    _i,W
                ANDWF   _sample,W       ;Pulse low - already sampling?
                BTFSC   STATUS,Z
                    GOTO    Nexti       ;No - do nothing
                MOVF    _i,W
                XORWF   _k,F            ;Yes - Clear Bit in Mask
                GOTO    Nexti
                
    ;-----------------------------------------------------------------------------            
    _PeriodZ    MOVLW   High(_Period)   ;Set Period[0 to 7] = 0
                MOVWF   FSR0H
                MOVLW   Low(_Period)
                MOVWF   FSR0L
                CLRF    _i          ; i = 0 (counter)
    clr         CLRF    POSTINC0    ;CLRF INDF0 then inc FSR0
                INCF    _i
                BTFSS   _i,4        ; i.4 set = 16        
                    GOTO    clr
                RETURN

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts