• AVR Freaks

Hot!Preamble Detection

Author
Designer
Super Member
  • Total Posts : 506
  • Reward points : 0
  • Joined: 2007/11/20 20:28:41
  • Location: 0
  • Status: offline
2020/03/29 23:12:20 (permalink)
0

Preamble Detection

I'm trying to read incoming pulse stream from a car remote Reciever (EV1527 based). When I press the car remote, its reciever will send data-out to the PIC12F675. I got all the timings, the only problem is it is hard for me to read the Preamble part because at the end of the data stream the repeated data stream start ASAP. Any method to read this? Please refer my waveform.
 
Preamble = 350uS mark time followed by a 10mS space time.
 
Another problem is the RF reciever in idle state gives trancient noise signals, for me it looks like the High time of Preamble period :(
post edited by Designer - 2020/03/29 23:16:40

Attached Image(s)

#1

14 Replies Related Threads

    ric
    Super Member
    • Total Posts : 26943
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Preamble Detection 2020/03/30 01:46:42 (permalink)
    +2 (2)
    There's lots of ways you could go about this, but without seeing any of your code, it's hard to guess what oart you're having trouble doing.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    pcbbc
    Super Member
    • Total Posts : 1687
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Preamble Detection 2020/03/30 03:33:35 (permalink)
    +2 (2)
    Even if the spec says it is a preamble, I would ignore that and handle it as a 350us stop bit and 10ms inter-packet gap.
    It won't make any noticable difference as the data packet is repeated multiple times, but it will make decoding easier, as well as give you a window to actually process the result.
    #3
    Designer
    Super Member
    • Total Posts : 506
    • Reward points : 0
    • Joined: 2007/11/20 20:28:41
    • Location: 0
    • Status: offline
    Re: Preamble Detection 2020/03/31 18:27:03 (permalink)
    0
    Here how I do.
     
    In main loop
    *Wait for a "high pulse".(start edge of the preamble)
    *wait until low.
    * measure above pulse, If it is not around 350uS goto begin.
    *wait until pin goes "high", (this will end the "low" pulse 10mS gap time of preamble)
    *measure the "low" pulse, if it is around 10mS a valud preamble detected.
    *from here measure the remaining 24 bits data bits.
     
    I can capture the incoming remote codes.Working nicely.When a complete packet recieved I make a relay ON.
     
    The problem is when I press & hold the remote, the above code will continue & make the relay toggles very fast.
     
    Thats my problem.
     
    #4
    ric
    Super Member
    • Total Posts : 26943
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Preamble Detection 2020/03/31 18:41:51 (permalink)
    +1 (1)
    Designer
    The problem is when I press & hold the remote, the above code will continue & make the relay toggles very fast.

    So add some code to detect this and only react if there has been a pause.
    This is programming 101
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #5
    pcbbc
    Super Member
    • Total Posts : 1687
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Preamble Detection 2020/04/01 00:10:27 (permalink)
    +1 (1)
    ric
    Designer
    The problem is when I press & hold the remote, the above code will continue & make the relay toggles very fast.

    So add some code to detect this and only react if there has been a pause.
    This is programming 101

    Good practice would also say wait until you have received 2 successive codes with the same “24“ bit value before doing anything.  That will guard against reception errors.
     
    Note the OPs trace only has 12 data bits at most. Unless you are counting each transition as a single bit, which would be peculiar.
    #6
    Designer
    Super Member
    • Total Posts : 506
    • Reward points : 0
    • Joined: 2007/11/20 20:28:41
    • Location: 0
    • Status: offline
    Re: Preamble Detection 2020/04/01 02:10:57 (permalink)
    0
    Ok thanks.I was too lazy to draw the whole 24bits data.

    Ok due to continuosly measuring code I can read 24 bits two times.That I can be done.

    But how to detect a pause period?.That is the hardest part as in my original question.

    If the blank period is more than 10mS then it is a blank?
    #7
    pcbbc
    Super Member
    • Total Posts : 1687
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Preamble Detection 2020/04/01 02:37:51 (permalink)
    +1 (1)
    DesignerBut how to detect a pause period?  That is the hardest part as in my original question.

    Same way you are detecting any other period?  Presumably you are waiting for an edge and checking the TMR0 value?
     
    But as you haven't shared any code, it's hard to say.
     
    I would be connecting the incoming signal to a pin with interrupt facility, then when I got an interupt I'd write the elapsed differential TMR0 value to a FIFO queue.  Extend TMR0 to 16-bits in software if necessary.  Read the queue values in main, and wait for something ≈ 10ms.  Then read the next 24 values checking for approriate approximate durations, anything outside of expected values then back to waiting fo another 10ms.  Once I'd done that twice with no errors, and received two consecutive matching 24 bit values, I'd take it that I'd got a valid reception.
    #8
    Chris A
    Super Member
    • Total Posts : 854
    • Reward points : 0
    • Joined: 2010/07/20 04:37:07
    • Location: 0
    • Status: offline
    Re: Preamble Detection 2020/04/01 03:38:05 (permalink)
    +1 (1)
    You need to filter the output like you would any other keyboard. e.g.
      An identical code must be received n times to be valid/accepted.
      If no code arrives in a time period, no key is pressed.
      If the code changes (identical n times), a new key is pressed.
      etc
     
    You could even implement key repeat if the code remains identical for a period.
     
    You have done the hard part!
    #9
    pcbbc
    Super Member
    • Total Posts : 1687
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Preamble Detection 2020/04/01 05:00:04 (permalink)
    +1 (1)
    Chris AYou have done the hard part!

    DesignerOk due to continuosly measuring code I can read 24 bits two times.That I can be done.

    Reading between the lines of the above statement ("continuosly measuring"), I suspect the OP may be simply sampling the input into a large array and post processing it.  Hence why they perhaps have a problem when they hit a 10ms gap and run out of sample space.
     
    But as they still haven't provided any code, or even a high level algorithm, it's impossible to say.
    #10
    Designer
    Super Member
    • Total Posts : 506
    • Reward points : 0
    • Joined: 2007/11/20 20:28:41
    • Location: 0
    • Status: offline
    Re: Preamble Detection 2020/04/11 07:34:24 (permalink)
    0
    pcbbc
    I would be connecting the incoming signal to a pin with interrupt facility, then when I got an interupt I'd write the elapsed differential TMR0 value to a FIFO queue.  Extend TMR0 to 16-bits in software if necessary.  Read the queue values in main, and wait for something ≈ 10ms.  Then read the next 24 values checking for approriate approximate durations, anything outside of expected values then back to waiting fo another 10ms.  Once I'd done that twice with no errors, and received two consecutive matching 24 bit values, I'd take it that I'd got a valid reception.



    Thanks for the suggessions.Sorry for the dalay.
     
    If I want a relay to turn on permanatly until I reset then my code is ok. Even though the repeated pulse stream continues every 10mS time gap around my main loop.
     
    But If I want to turn on my relay once the remote key presses & the relay should off when the remote key press again, then this cannot be done with my code. Now you got it what my point is?

     
    My main loop is like this.
     
    *Main Loop
    *In the main loop wait for the small High Time of the Preamble (350uS).
    *Got a valid High pulse? No, Then goto Main Loop.
    *If got a valid High pulse, then wait for the 10mS Low Time of the Preamble (10mS).
    *Got a valid Low pulse? No, Then goto Main Loop.
    *If yes, got a valid complete "Preamble Period"
    *Then measure the remaining 24 bits.(Save the Time periods while the port pin changes).
    *Got 24 bits.
    *Compare the "Recieved 24 bit Pulses with the "Saved pulses" which was in the EEPROM.
    *Match is success, Turn the relay ON.
    *goto Main Loop.
     
    So the above code is looping.So the relay toggle every 10mS time if the remote key is pressing.
    post edited by Designer - 2020/04/11 07:38:17
    #11
    davea
    Super Member
    • Total Posts : 228
    • Reward points : 0
    • Joined: 2016/01/28 13:12:13
    • Location: 0
    • Status: offline
    Re: Preamble Detection 2020/04/11 09:11:52 (permalink)
    0
    its like RIC said programing 101
    you need to setup a delay counter
    1 Sec and after you receive 2 valid data packet's
    switch your relay and start the timer then when another packet is received
    only take action if timer = 0 else restart the timer
    IE;
    new data now!
    if(timer == 0){
    process relay
    timer = 250} else {timer = 250}
     
    dec in a loop or ISR to get proper timing
    if(timer != 0){timer--}   
    post edited by davea - 2020/04/11 09:27:15
    #12
    Designer
    Super Member
    • Total Posts : 506
    • Reward points : 0
    • Joined: 2007/11/20 20:28:41
    • Location: 0
    • Status: offline
    Re: Preamble Detection 2020/04/11 21:15:44 (permalink)
    0
    davea
    its like RIC said programing 101
    you need to setup a delay counter
    1 Sec and after you receive 2 valid data packet's
    switch your relay and start the timer then when another packet is received
    only take action if timer = 0 else restart the timer
    IE;
    new data now!
    if(timer == 0){
    process relay
    timer = 250} else {timer = 250}
     
    dec in a loop or ISR to get proper timing
    if(timer != 0){timer--}   


    Very much thanks, Now I got it.I'll do like that.
     
    Another problem is those RF Receivers will pulse out noise signals in idle state.When I hooked up an oscilloscope it is repeating transmitting garbage pulses. Very hard to determine is this a start of a new string or a garbage.
     
    I'll filter that with code.
     
    Many thanks to everybody.
    #13
    pcbbc
    Super Member
    • Total Posts : 1687
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Preamble Detection 2020/04/12 00:40:18 (permalink)
    +1 (1)
    Designer
    Another problem is those RF Receivers will pulse out noise signals in idle state.When I hooked up an oscilloscope it is repeating transmitting garbage pulses. Very hard to determine is this a start of a new string or a garbage.

    If you’re finding it very hard, you’re still doing it wrong.
    It’s the start of a new string (and possibly end of a valid received one) if you’ve just had 10ms of silence. Otherwise it isn’t.
    Waiting for 10ms of silence should be your default start state for your state machine.
    If you ever receive a high or low pulse that doesn’t match the expected width, go back to waiting for 10ms of silence.
    #14
    davea
    Super Member
    • Total Posts : 228
    • Reward points : 0
    • Joined: 2016/01/28 13:12:13
    • Location: 0
    • Status: offline
    Re: Preamble Detection 2020/04/12 12:31:48 (permalink)
    +1 (1)
    here is the way I do bit timing
    TMR0 ISR at 26.6uS
    this is the front-end of a DECODER for PT2262 ENCODER 
    the decoder is in the main loop
    it overcomes the problem of a ISR for every edge of noise
    but it requires any other ISR to be very short...
    and uses 25% of CPU time at 32Mhz
    D_BUFFER[80]
    it does give a false stop every sec or two
    but the decoder detects and clears FLAGbits.stop_bit very fast....
    it may change your thinking
     
    void TMR0_ISR(void)
    {
       //----------------------------------------
       // DO A LOW PASS FILTER
       // TO REMOVE GLITCHES
       //----------------------------------------
       if (PORTCbits.RC3) { // Data in
          SR_data |= 1; // sets bit 0 if hi
       }
       if ((SR_data & 0x80) == 0 && (SR_data & 0x01) == 0) { // 2 BTFSx
          SR_data = 0; // if in and out = 0 clear all
       } else {
          SR_data = SR_data << 1;
       }
       //----------------------------------------
       if ((SR_data & 0x80) != 0) { // pin is hi
          if (!FLAGbits.Last_pin_state) { // they differ
             FLAGbits.Last_pin_state = 1; // clear difference
             D_BUFFER[D_PNT++] = LO_CNT; // get lo count and save it
             LO_CNT = 0;
             LO_CNTS = 0;
             BIT_CNT++;
          } else if ((HI_CNT & 0x40) == 0) { //
             HI_CNT++; // pin still hi and counting
          }
          //*******************************************
       } else // pin is low
          if (FLAGbits.Last_pin_state) { // they differ
          FLAGbits.Last_pin_state = 0; // clear difference
          D_BUFFER[D_PNT++] = (HI_CNT | 0x80); // get hi count and save it
          HI_CNT = 0;                                            // and set hi bit !!
          BIT_CNT++;
       } else if ((LO_CNT & 0x40) == 0) { // stop at 64
          LO_CNT++;
       } else {
          LO_CNTS++; // extra delay needed for STOP bit timing
          if ((LO_CNTS & 0x20) != 0) {
             if ((BIT_CNT & 0x20) != 0) { // at least 32 edge's
                FLAGbits.stop_bit = 1; // let decoder know !!!!!
                Stop_pnt = D_PNT; //  (underflow,s fixed
                NEW_BIT_CNT = BIT_CNT; // in DECODER)
             }
             BIT_CNT = 0;
          }
       }
       //------------------------------------------
       if (D_PNT >= 80) {
          D_PNT = 0; // wrap it
       }
       if (--MOD_500us == 0) {
          MOD_500us = 19;
          NEARbits.DO_500us = 1;
       }
       PIR0bits.TMR0IF = 0;
    }

    post edited by davea - 2020/04/12 12:38:30
    #15
    Jump to:
    © 2020 APG vNext Commercial Version 4.5