PDA

View Full Version : finding missing pulses



longpole001
- 16th May 2013, 05:25
HI guys , i am stumbling a little on how to do this in the code using pulsin , rctime to determine which pulse is missing in the stream

thought using pulsing to find the 1ms low header then grabbing the next 10 pulses but thats not going to work if some are missing , so need to stop when the next 1ms low is there ???
and then how to find which pulse was missing ??



i have pulse stream that has

1. 1ms low header followed by 10 pulses when all is ok then the 1ms low header for next stream , the duration between first 1ms header and next header pulse is close to constant of about 7ms

The 10 pulses , when all there have a @300us high , with a either a @300us low or @450us low depending on flag set 0 or 1
each pulse position low 1 - 10 relates to a input .

so when the input 6 is not there ( missing ) the signal remains high in the stream for that position
i need to know which pulse input went missing in the stream ( eg did not go low ) , there may be many inputs that go missing at any given time and but i still get the 1ms header at the start

can someone give an example on how to do this


cheers

Sheldon

languer
- 16th May 2013, 08:57
I'm a bit puzzled by this, but I'm thinking a big state machine and a timer.

The state machine starts after the detection of the 1ms pulse (you could use PulseIn for that). Once you have a negative pulse with a duration of 1ms you go into the state machine. Start a timer checking for the first falling edge. If the falling edge is more than 300us you missed a pulse (tag it as missing), stop the timer and start counting again for the next 300us. If you did not miss a pulse (i.e. you got a falling edge - tag it as present), stop the timer and wait for the next rising edge, start your 300us count once more. Do this until your overall count is 10. At that point you should be ready for the next 1ms pulse. I'm probably all over the place, but this seems reasonable. This does nothing to figure whether any present pulse is a 1 or 0; but you can add that after you get the missing pulse detection part.

Ioannis
- 16th May 2013, 10:18
I would suggest Interrupts on Port B, bit 0. It has Interrupt on edge either high or low, and you control this by bit 6 in Option_Reg.

I'll try a test code to show you how.

Do you have a PIC prefference?

Ioannis

richard
- 16th May 2013, 10:24
try something like this, you need a chip with ioc capability and dt ints

you need to set tmr1 to just exceed a 255 count when a pulse is missing

I use this state engine to decode Manchester code it should just a easily find and identify a missing pulse

rec:

pulsin rx ,0,pt
if pt < t1ms then goto rec ; look for 1ms start pulse
bit_cnt = 0 ; clr bit counter
TMR1H=0 ; clr stopped tmr1
TMR1L=0
SB=RX ;read input pin to set int on change status

T1CON=$31 ; start timer : setup timer to count past 255 when pulse missed ie say 450us = a 255 count

INTCON=$88 ; enable interrupts
IOCA.5=1 ; ioc int
while (bit_cnt < 7 ) and ( flg.0=0) ; receive 8 pulses , adjust to suit

wend
IOCA.5=0 ; ints off timer off
INTCON.0=0
T1CON=$30
; if bit_cnt < 7 then missing pulse = bit_cnt
return






rec_isr:

if TMR1H > 0 then flg.0=1 ; timer count > 255 ie. missing pulse

IF TMR1L > t300us THEN ; discriminate between 300/ 430 us
T1CON=$30
pkt.0[BIt_cnt]=!SB ; save 1 for 430 0 for 300
TMR1H=0 ; clr timer
TMR1L=0
T1CON=$31
bit_cnt = bit_cnt+1 ; inc pulse count
ENDIF


SB=RX ;read port to reset ioc state , helps if noise is a problem

INTCON.0=0
endif

@ INT_RETURN

longpole001
- 16th May 2013, 11:23
cheers guys , seems a setting the timer is the way to go and triggered by the 1ms low , working with a state machine , the problem i am seeing is the the timed pulse sometimes drift a little , but i hopping not enough over the 7ms to be incorrect. ill try some of the code and see , i am using DT_int14 for the timer's