Also can you expand on the first was "slow"? Do you mean it was to slow to react to the pulses? were they accurate but offset? How much percision and resolution do you need?
Also can you expand on the first was "slow"? Do you mean it was to slow to react to the pulses? were they accurate but offset? How much percision and resolution do you need?
-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!
OK - the scenario is measuring multiple (8) pulses arising from eight simple 12F675 circuits outputing pulses - I can change that to whatever I want, currently 1mSec pulse every 50 mSec, but the 12F675 has an LC circuit driving its oscillator so the pulse width is altered by the LC circuit (and any adjacent metal/tuned circuit etc.
When I say the Picbasic routine was slow I mean the precision or resolution - using PB PULSIN gives a resolution of 40/OSC uSec - ie. 0.833 uSec at 48 MHz - so a 1000 uSec pulse gives a Pulsin answer of around 1224 - using my PicBasic routine I get a measurement (ie number if cycles of sampling) of only around 300 (ie 3 uSec resolution) and using assembler a similar result, unless I only sample one bit in which case it rises to arounf 800 (ie 1.1 uSec resolution). So a PULSIN resolution of 40/OSC is pretty impressive!
Interestingly, a sequence of several PULSIN commands on each successive pin gives a much better (more precise) result - maybe I should never have started this idea and stuck to dirty successive PULSINs!
Last edited by FinchPJ; - 1st November 2011 at 14:14.
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!
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)
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!
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
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
Bookmarks