8 years, 10 months ago.

Does mbed library makes nRF51822 interrupt slow?

Hi,

I have problem with interrupt speed in nRF51822 I want to count falling edge of a 40KHz clock with nRF51822 interrupt, But there is a problem in each time i run my program i receive a wrong data

For example if my clock have 300 falling edge in a period of time in another try i receive 299, 298 or 297, Always there is 1-3 edges missed.

Is this because mbed library makes nRF51822 slow or nRF51822 is not capable of reading 40KHz clock?

in below code there is also a Enable signal but i didn't add that to simple my code and i read clock each time enable is Zero and in exact moment enable is High i send counter value

when i use LPC1768 for this clock every time i get 300 for counter but with nRF51822 i always miss some clock

include the mbed library with this snippet

...
InterruptIn clock(P0_0);
...
uint16_t counter;
...

void clockFallCallback(void)
{
   counter++;
}

int main(void)
{
    counter = 0;
   
    clock.fall(clockFallCallback);
    
    ble.init();
    ble.onDisconnection(disconnectionCallback);

    ButtonService buttonService(ble, 100);
    buttonServicePtr = &buttonService;

    /* setup advertising */
    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
    ble.setAdvertisingInterval(2000);
    ble.startAdvertising();

    while (true) 
    {
        ble.waitForEvent();
    }
}


Question relating to:

The nRF51822-mKIT is a low cost ARM mbed enabled development board for Bluetooth® Smart designs with the nRF51822 SoC. The kit gives access to all GPIO pins via pin headers …

Can you share some code snippet ?

posted by Martin Kojtal 10 Jun 2015

I added part of my code related to interrupt but it's very simple I just want to know is there any way to make this interrupt faster?

posted by behrouz psh 10 Jun 2015

After NOT using mbed library and instead using pin_change_int_pca10028 example from nordicsemi website now everything working well and i can count my clock very accurate

posted by behrouz psh 12 Jun 2015

Try removing the bluetooth code and checking if it works. It might be that the BLE interrupts are blocking yours. In that case there is not much you can do about it. Edit: actually if you just want to count edges you can do this entirely in hardware using PPI and the TIMER module.

posted by Tim H 01 Jul 2015
Be the first to answer this question.