Hot!read RC5 code or RC5 decoder

Page: 123 > Showing page 1 of 3
Author
rogerpic
Starting Member
  • Total Posts : 48
  • Reward points : 0
  • Joined: 2018/01/06 04:06:07
  • Location: 0
  • Status: offline
2018/07/02 04:28:12 (permalink)
0

read RC5 code or RC5 decoder

I have a RC decoder code in 18f45k22 it doesn't work i  see two output going high that's all. What i must do is if a key from the keyboard sends a number the corresponding code will be recept through a sensor. That sensor is connected to a input pic 18f45k22 and that input will than send a output high if the correct code is be send but nothing happend. I programmed it but never worked what did i wrong i use XC8 18f45k22 processor and i intern clock. understand you see the code. In the window from mplab there are a device_config.c, ext_int.c, interrupt _manager.c, also my main rc5code.txt and mcc.c and pin_manager.c. all those files mostly are generated by MPLAB configurator. who can help me that the code will work if i program it.what must i change i know it's a bigger program than normally .
#1

53 Replies Related Threads

    DarioG
    Allmächtig.
    • Total Posts : 54080
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re: read RC5 code or RC5 decoder 2018/07/02 04:51:04 (permalink)
    0
    I am doing that exacly these days!
    In the past I did it on a PIC24; now I need to read 5 IR inputs and am porting an old code written in Assembler by another guy.
     
    Your code looks good enough: I'd first check that timer is running at expected frequency...

    GENOVA :D :D ! GODO
    #2
    rogerpic
    Starting Member
    • Total Posts : 48
    • Reward points : 0
    • Joined: 2018/01/06 04:06:07
    • Location: 0
    • Status: offline
    Re: read RC5 code or RC5 decoder 2018/07/02 07:48:41 (permalink)
    0
    I checked TMR0 TMR0 i see working but i checked counter[8] just counter [0] gives a integer value the others stay null. i don't know if the interrupt routine works i don't know how to check that in mplab?
    #3
    DarioG
    Allmächtig.
    • Total Posts : 54080
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re: read RC5 code or RC5 decoder 2018/07/02 07:50:45 (permalink)
    0
    Can you insert a toggling led inside the interrupt handler?

    GENOVA :D :D ! GODO
    #4
    DarioG
    Allmächtig.
    • Total Posts : 54080
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re: read RC5 code or RC5 decoder 2018/07/02 07:51:00 (permalink)
    0
    Add: MPSIMulator may work too for this aim...

    GENOVA :D :D ! GODO
    #5
    rogerpic
    Starting Member
    • Total Posts : 48
    • Reward points : 0
    • Joined: 2018/01/06 04:06:07
    • Location: 0
    • Status: offline
    Re: read RC5 code or RC5 decoder 2018/07/02 09:41:21 (permalink)
    0
    No it seems that it isn't anymore for today. The problem is no output what i send !
    #6
    btbass
    Super Member
    • Total Posts : 350
    • Reward points : 0
    • Joined: 2004/12/10 13:50:32
    • Status: offline
    Re: read RC5 code or RC5 decoder 2018/07/03 01:56:50 (permalink)
    +1 (1)
    Interrupt driven RC5 decoder on Microchip Embedded code source

    http://www.embeddedcodeso...upt-driven-rc5-decoder
    #7
    DarioG
    Allmächtig.
    • Total Posts : 54080
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re: read RC5 code or RC5 decoder 2018/07/03 02:10:31 (permalink)
    0
    btbass
    Interrupt driven RC5 decoder on Microchip Embedded code source

    http://www.embeddedcodeso...upt-driven-rc5-decoder




    yep, that's basically the code OP has posted Smile

    GENOVA :D :D ! GODO
    #8
    btbass
    Super Member
    • Total Posts : 350
    • Reward points : 0
    • Joined: 2004/12/10 13:50:32
    • Status: offline
    Re: read RC5 code or RC5 decoder 2018/07/03 02:43:12 (permalink)
    +1 (1)
    Yes, I see that now, Ive just looked at the code posted.
     
    Still, the decoded does work well, it has been tested on several projects using Pic16, Pic18 and Pic 24 variants.
     
    Suggest, try leaving the original project as is and just modify the 'main' file with your code to see if that works?
     
    You just need to modify the 'init_decoder(void)' function to suit your Pic variant.
    #9
    DarioG
    Allmächtig.
    • Total Posts : 54080
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re: read RC5 code or RC5 decoder 2018/07/03 02:49:05 (permalink)
    0
    I keep on thinking that there's a problem in the Timer IRQ setting/timing...

    GENOVA :D :D ! GODO
    #10
    btbass
    Super Member
    • Total Posts : 350
    • Reward points : 0
    • Joined: 2004/12/10 13:50:32
    • Status: offline
    Re: read RC5 code or RC5 decoder 2018/07/03 03:04:40 (permalink)
    +1 (1)
    Could this be the problem?
    The interrupt should occur on the Falling Edge!
     
    INTCON2bits.INTEDG0 = 1; 
     
    bit 6 INTEDG0: External Interrupt 0 Edge Select bit
    1 = Interrupt on rising edge
    0 = Interrupt on falling edge
     
    You also need to enable the external interrupt
     
    bit 4 INT0IE: INT0 External Interrupt Enable bit
    1 = Enables the INT0 external interrupt
    0 = Disables the INT0 external interrupt
     
    This is important, I cant see where you set the osc freq. to 4MHz?
    The Pic18 has a 16MHz osc?
     
    /* Timer should have an overflow period of greater than 5mS and less than 15mS */
    /* Overflow period = (1 / (oscfreq / 4)) * 256 * prescaler */
    post edited by btbass - 2018/07/03 03:33:10
    #11
    malaugh
    Super Member
    • Total Posts : 330
    • Reward points : 0
    • Joined: 2011/03/31 14:04:42
    • Location: San Diego
    • Status: offline
    Re: read RC5 code or RC5 decoder 2018/07/03 07:40:07 (permalink)
    +1 (1)
    There is also an article here:
     
    http://www.picprojects.net/rc5_decoder/
     
     
    #12
    rogerpic
    Starting Member
    • Total Posts : 48
    • Reward points : 0
    • Joined: 2018/01/06 04:06:07
    • Location: 0
    • Status: offline
    Re: read RC5 code or RC5 decoder 2018/07/06 06:39:00 (permalink)
    0
    I have again sorted my program and if i simulated it stay's in the interrupt routine and never goes back out the interrupt. I use RB0 to my external pin input and tick it 1 cycle high one cycle low for input but i can't use a rc5 code for simulating on the RB0 pin input. Thus i can check if in the main routine a output goes high. Problem is it stays in the interrupt routine is that through the simulated high low it is not the code what inside the controller comes? Is that the error that i made?
    #13
    rogerpic
    Starting Member
    • Total Posts : 48
    • Reward points : 0
    • Joined: 2018/01/06 04:06:07
    • Location: 0
    • Status: offline
    Re: read RC5 code or RC5 decoder 2018/07/06 06:51:21 (permalink)
    +1 (1)
    Now it stay's to line if(RC5_Code.valid) in begin in the main it goes out the routine interrupt that is fixed and now it goes back in the beginning but it stay's there no valid seems to be the problem.
    #14
    btbass
    Super Member
    • Total Posts : 350
    • Reward points : 0
    • Joined: 2004/12/10 13:50:32
    • Status: offline
    Re: read RC5 code or RC5 decoder 2018/07/06 10:15:12 (permalink)
    0
    You really need a RC5 handset to test the code.
     
    'RC5_Code.valid'
    only becomes true when a complete well formatted RC5 Data stream has been received.
     
    ;--- RC5 code is 14 bits each of 1.8mS duration with carrier frequency of 36KHz.
    ;--- A '0' is a mid pulse transition from high to low.
    ;--- A '1' is a mid pulse transition from low to high.
    ;--- The first 2 bits are always 1.
    ;--- The next bit is the toggle bit, indicating a new key press.
    ;--- Then 5 bits of address and 6 bits of command code.
     
    'RC5_Code.valid' is only true if all the above bits are received and are properly formatted!
     
     
    #15
    DarioG
    Allmächtig.
    • Total Posts : 54080
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re: read RC5 code or RC5 decoder 2018/07/06 10:25:43 (permalink)
    0
    anybody checked the IRQ frequency? :D

    GENOVA :D :D ! GODO
    #16
    rogerpic
    Starting Member
    • Total Posts : 48
    • Reward points : 0
    • Joined: 2018/01/06 04:06:07
    • Location: 0
    • Status: offline
    Re: read RC5 code or RC5 decoder 2018/07/06 10:49:18 (permalink)
    0
    What exactly do you mean RC5 handset to test the code. I Had build a transmitter and that sends pulses i see the pulses on my scoop and  i measure them. On a board i see my sensor TSOP18 captures the pulses those pulses i had already send to another controller now to measure the RC5 code and there i am now on designing. The controller must measure decode the RC5 code and in the program i see in simulator that it stopped to 'RC5_Code.valid' in debug. i don't know where exact the fault is. I don't know if the RC code what i send in is correctly. I also program and loaded and connect the sensor. And send a transmitted rc5 CODE what i built with a another controller. Can you follow. My problem where it goes fault is that it doesn't decode and it stops in simulating by RC5_code.valid. For more explanation my design must send from one controller to another controller the RC5 code when i make a selection it sends the code i can send 5 codes and then the other controller must capture exactly that code that all is done by rc5code. So in short what i want to do.
    #17
    Rob_CJ
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2017/10/22 01:11:36
    • Location: 0
    • Status: offline
    Re: read RC5 code or RC5 decoder 2018/07/06 23:36:31 (permalink)
    0
    Since you are using a timer should you also not enable the peripheral interrupt PEIE? If you miss an interrupt you have to reset your decoder when the timer overflows. Next to that did you enable the interrupt to which the receiver is connected, INTE?
     
    Next if you are both making the transmitter and receiver that can lead to issues since you are not sure which one is doing the right job. Do you have a remote control that sends RC5 commands or a TV that is able to receive it? That could help in testing if your transmitter and receiver are working correctly.
     
    Last but not least. RC5 uses Manchester encoding for a reason, it increases reliability. In order to make use of this reliability you need to decode the RC5 message on all edges, falling and trailing and not only on one edge of the signal. 
     
    Hope this helps.
    post edited by Rob_CJ - 2018/07/06 23:50:19
    #18
    btbass
    Super Member
    • Total Posts : 350
    • Reward points : 0
    • Joined: 2004/12/10 13:50:32
    • Status: offline
    Re: read RC5 code or RC5 decoder 2018/07/07 01:13:21 (permalink)
    0
    You have modified the original code?
    Suggestion:
    The code downloadable from 'Microchip Embedded Code Source' is a complete working project.
    The only thing you need to change to suit your Pic variant is the function, 'init_decoder(void)'
    This sets up the input pin, input pin interrupt, input pin interrupt edge, Timer pre-scaler and Timer interrupt.
    If those are set up correctly, the code should work.
    Once you get that working, Then you can modify the main.c file to suit your program.
    #19
    btbass
    Super Member
    • Total Posts : 350
    • Reward points : 0
    • Joined: 2004/12/10 13:50:32
    • Status: offline
    Re: read RC5 code or RC5 decoder 2018/07/07 02:07:13 (permalink)
    +2 (2)
    Decoder Overview.
     
    ;--- RC5 code is 14 bits each of 1.8mS duration with carrier frequency of 36KHz.
    ;--- A '0' is a mid pulse transition from high to low.
    ;--- A '1' is a mid pulse transition from low to high.
    ;--- The first 2 bits are always 1.
    ;--- The next bit is the toggle bit, indicating a new key press.
    ;--- Then 5 bits of address and 6 bits of command code.
     
    It takes about 30mS to decode an RC5 transmission, which is a comparatively long time in terms of processor time. So the decoder uses the interrupt to minimise the processor time.
     
    The IR receiver inverts the RC5 data stream, so the positive edge becomes a negative edge. The decoder only uses the negative edge interrupt so that minimum processor time is taken when decoding an RC5 data stream. It decodes the RC5 data using bit lengths.
     
    A lot of IR handsets use ceramic resonators that are temperature sensitive and drift over time, so the bit times can vary widely from the RC5 spec. To overcome this, the transmitted bit time is calibrated on every transmission received.
     
    The first two bits of a standard RC5 transmission are always one. Knowing this, the timer is used to measure the bit length. As the transmission will suffer some jitter and not all transmitted bits will have the exact same timings, a ~12% tolerance is added to the bit time. (a divide by 8 as this compiles as a right shift sequence).
     
    If you analyse a RC5 data transmission, using only the negative edge, you will see that there are three possible pulse lengths, (the time between two consecutive negative edges).
    They are the calibrated pulse length, a pulse 1.5 times the calibrated pulse length and a pulse two times the calibrated pulse length.
     
    It turns out that to know what each pulse length means, you have to know what the last received bit was. As the data stream always starts with two one's, we can keep track of the last received bit and decode the data.
     
    Timer_0 is used to count the time between negative edges. The timer count is stored and the timer reset to 0 on each negative edge.
     
    The pulse length is then determined from the timer count, and using the last bit received, the data is decoded and added to the received data variable and the last bit received updated.
     
    It also turns out that if the RC5 data stream ends with a '0', there is no last negative edge.
     
    Timer_0 is also used to detect the end of the data stream. The timer prescaler is set so that the timer overflow interrupt occurs if no negative edge has been received to reset the timer. (Typically 5mS to 15mS).
     
    On timer overflow interrupt, the bit count is then checked. If it is the correct number of bits, the data is ok, if it is one short, a '0' is added to the end of the data stream.
     
    The 8-bit pic's have a limited stack space, so no function calls are made and all the code is contained in the interrupt routine to save stack space.
     
    This does make it a little harder to understand.
     
    #20
    Page: 123 > Showing page 1 of 3
    Jump to:
    © 2018 APG vNext Commercial Version 4.5