PPM decoding using the capture block of timer 2

26 Apr 2010

Hi everyone,

I'm trying to decode a PPM sum signal using the capture blocks of the LPC17xxx. To my understanding of the datasheet, the code RCSignal is correct. But still, it does not work properly. I'm pretty sure the wiring is correct (PPM signal -> p21 -> p29).

Does anyone have an idea what I'm doing wrong here?

greetings,

Christian

28 Apr 2010

I think I understand what you are trying to do. One thing that is missing is the pin selection for the CAP2.1 pin. Each (physical) pin of the device is multiplexed with up to 4 different possible peripheral functions, so you have to set the appropriate bits in the correct PINSEL register to connect CAP2.1 to the outside world. This is described in Chapter 8 "LPC17xx Pin Connect Block" of the LPC17xx user manual.

CAP2.1 is on (physical chip) pin 80, logical pin P0.5. This is controlled by bits 11:10 of PINSEL0. Setting these bits to binary '11' connects CAP2.1 to this pin; on reset these bits are '00', which indicates GPIO Port P0.5.

You also have to set the mode of the pin using the appropriate bits of the correct pin mode register. P0.5 is controlled by bits 11:10 of PINMODE0 (00 == Pull-up, 10 == Pull none, 11 = Pull down). We have these values already defined for you via the mbed library includes. This is set to '00' on reset.

Finally, you need to select the appropriate peripheral clock. TIM2 is controlled by bits 13:12 of PCLKSEL1. On reset, this is set to 00 (CCLCK / 4). You probably want this set to '01' (CCLK / 1).

Putting all this together, the first part of this initialisation should read something like:

    LPC_SC->PCONP        |= (1 << 0x16);            // turn on timer 2
    LPC_SC->PCLKSEL1     |= (1 << 12);              // Set PCLK to CCLK
    // PINSELx and PINMODEx are controlled by two bits per pin
    LPC_PINCON->PINSEL0  |= (0x3 << (2 * 5));       // Connect P0.5 to CAP2.1
    LPC_PINCON->PINMODE0 |= (PullUp << (2 * 5));    // Select PullUp mode for P0.5

 

[Obviously with the pin mode set to whatever you desire]

I haven't had chance to test this, so I may have slipped up somewhere, but you get the idea. Also, this relies on the fact that PCLKSELx, PINSELx and PINMODEx all reset to '00', so if you have changed these pins any where else before, you will have to clear the appropriate bits out to get zeroes where you need them.

*phew*. We write mbed libraries, so you don't have to.